@ouro.bot/cli 0.1.0-alpha.1713 → 0.1.0-alpha.1715
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.json +14 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/cli-defaults.js +2 -0
- package/dist/heart/daemon/cli-exec.js +17 -0
- package/dist/heart/daemon/handoff-blockers.js +5 -4
- package/dist/heart/versioning/ouro-version-manager.js +13 -0
- package/dist/heart/versioning/self-update-defaults.js +15 -69
- package/dist/heart/versioning/self-update-lock.js +151 -0
- package/dist/heart/versioning/self-update.js +43 -12
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "Each pull request writes its own change note under changes/; the release job on main gives each landed change its version and adds the notes here (scripts/release-version.cjs). On main this file stops at the last version set by hand; the published package has every release. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1715",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Test-only: the habit lifecycle child writes its JSON result atomically, so the parent never reads a half-written file."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1714",
|
|
12
|
+
"changes": [
|
|
13
|
+
"The unattended updater no longer rolls back a healthy daemon because a newer release came up while it waited. On 2026-11-27 a pass installed 0.1.0-alpha.1710, the `ouro up` it runs to restart the daemon found and installed 0.1.0-alpha.1711, and the pass then read the daemon answering on 1711 as a failure: it marked 1710 failed, pinned 0.1.0-alpha.1704 and stopped the healthy 1711 daemon. Now a daemon that answers on the target or any newer release counts as healthy, and the restart is judged by health rather than by an exact version match.",
|
|
14
|
+
"`ouro up` no longer installs a release while a self-update pass is running, including the `ouro up` that pass runs itself: both now take the same update lock, and the one that finds it held leaves updating to the holder. A lock left by a crashed process is taken over once its owner is gone or it is older than two hours, so a crash never stops updates.",
|
|
15
|
+
"A rollback no longer stops a daemon that still answers on a version other than the failed one. It reactivates and pins the previous version and leaves that daemon running. A pass also leaves alone a daemon running a newer release than the active one, unless that release already failed on this machine."
|
|
16
|
+
]
|
|
17
|
+
},
|
|
4
18
|
{
|
|
5
19
|
"version": "0.1.0-alpha.1713",
|
|
6
20
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1715</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -70,6 +70,7 @@ const bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
|
70
70
|
const ouro_bot_global_installer_1 = require("../versioning/ouro-bot-global-installer");
|
|
71
71
|
const version_intent_1 = require("../versioning/version-intent");
|
|
72
72
|
const self_update_defaults_1 = require("../versioning/self-update-defaults");
|
|
73
|
+
const self_update_lock_1 = require("../versioning/self-update-lock");
|
|
73
74
|
const update_state_1 = require("../versioning/update-state");
|
|
74
75
|
const host_self_update_1 = require("../versioning/host-self-update");
|
|
75
76
|
const logs_prune_1 = require("./logs-prune");
|
|
@@ -911,6 +912,7 @@ function createDefaultOuroCliDeps(socketPath = socket_client_1.DEFAULT_DAEMON_SO
|
|
|
911
912
|
distTag: update_checker_1.CLI_UPDATE_DIST_TAG,
|
|
912
913
|
});
|
|
913
914
|
},
|
|
915
|
+
acquireSelfUpdateLock: () => (0, self_update_lock_1.acquireSelfUpdateLock)((0, ouro_version_manager_1.getOuroCliHome)()),
|
|
914
916
|
readVersionIntent: () => (0, version_intent_1.readVersionIntent)(),
|
|
915
917
|
writeVersionIntent: (intent) => (0, version_intent_1.writeVersionIntent)(intent),
|
|
916
918
|
installCliVersion: async (version) => {
|
|
@@ -7304,10 +7304,26 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
|
|
|
7304
7304
|
// ── versioned CLI update check ──
|
|
7305
7305
|
const versionIntent = deps.readVersionIntent?.() ?? null;
|
|
7306
7306
|
const pinnedUpdate = versionIntent?.mode === "pinned" && !command.latest;
|
|
7307
|
+
// The update lock keeps this `ouro up` from installing a release in the middle of a self-update pass, including
|
|
7308
|
+
// the pass's own `ouro up` restart of the daemon (2026-11-27: that restart installed a newer release and the pass
|
|
7309
|
+
// rolled back the healthy daemon running it).
|
|
7310
|
+
const releaseUpdateLock = deps.checkForCliUpdate && !pinnedUpdate && deps.acquireSelfUpdateLock
|
|
7311
|
+
? deps.acquireSelfUpdateLock()
|
|
7312
|
+
: undefined;
|
|
7307
7313
|
if (deps.checkForCliUpdate && pinnedUpdate) {
|
|
7308
7314
|
progress.startPhase("update check");
|
|
7309
7315
|
progress.completePhase("update check", `pinned to ${versionIntent.targetVersion}`);
|
|
7310
7316
|
}
|
|
7317
|
+
else if (deps.checkForCliUpdate && releaseUpdateLock === null) {
|
|
7318
|
+
progress.startPhase("update check");
|
|
7319
|
+
progress.completePhase("update check", "skipped: another update is running");
|
|
7320
|
+
(0, runtime_1.emitNervesEvent)({
|
|
7321
|
+
component: "daemon",
|
|
7322
|
+
event: "daemon.cli_update_check_skipped_for_update_in_progress",
|
|
7323
|
+
message: "left updating to the self-update pass or ouro up that holds the update lock",
|
|
7324
|
+
meta: {},
|
|
7325
|
+
});
|
|
7326
|
+
}
|
|
7311
7327
|
else if (deps.checkForCliUpdate) {
|
|
7312
7328
|
progress.startPhase("update check");
|
|
7313
7329
|
progress.updateDetail(`current runtime: ${(0, bundle_manifest_1.getPackageVersion)()}\nchecking npm registry\ncontinuing startup if it stays quiet`);
|
|
@@ -7376,6 +7392,7 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
|
|
|
7376
7392
|
});
|
|
7377
7393
|
}
|
|
7378
7394
|
/* v8 ignore stop */
|
|
7395
|
+
releaseUpdateLock?.();
|
|
7379
7396
|
if (pendingReExec) {
|
|
7380
7397
|
progress.end();
|
|
7381
7398
|
deps.reExecFromNewVersion(args);
|
|
@@ -6,6 +6,7 @@ exports.handoffSnapshot = handoffSnapshot;
|
|
|
6
6
|
exports.unsettledReason = unsettledReason;
|
|
7
7
|
exports.judgeRestartAfterUpFailure = judgeRestartAfterUpFailure;
|
|
8
8
|
const runtime_1 = require("../../nerves/runtime");
|
|
9
|
+
const ouro_version_manager_1 = require("../versioning/ouro-version-manager");
|
|
9
10
|
/** Everything `ouro up`'s final daemon check refuses on, in the order it reports them: workers, senses, health checks. */
|
|
10
11
|
/**
|
|
11
12
|
* The exit code `ouro up` uses when it refuses to hand off only because the final daemon check found the daemon's
|
|
@@ -77,14 +78,14 @@ function unsettledReason(before, after) {
|
|
|
77
78
|
* `ouro up` refuses while any sense is down, so one sense's outage (BlueBubbles while its macOS account is logged
|
|
78
79
|
* out) rolled back every release for a day and marked each one failed (2026-10-24, and alpha.1559 to alpha.1586 on
|
|
79
80
|
* 2026-11-25). A release is only at fault for what it broke: it passes when `ouro up` failed only on the final
|
|
80
|
-
* health check, the daemon answers on it with a settled status, and every blocker it reports was already there,
|
|
81
|
+
* health check, the daemon answers on it (or on a newer release) with a settled status, and every blocker it reports was already there,
|
|
81
82
|
* at the same severity, before the update.
|
|
82
83
|
*/
|
|
83
84
|
function judgeRestartAfterUpFailure(input) {
|
|
84
85
|
if (!input.upRefusedOnHandoffHealth) {
|
|
85
86
|
return { ok: false, detail: input.upFailure };
|
|
86
87
|
}
|
|
87
|
-
if (input.seenVersion
|
|
88
|
+
if (input.seenVersion === null || !(0, ouro_version_manager_1.cliVersionAtLeast)(input.seenVersion, input.expectedVersion)) {
|
|
88
89
|
const answered = input.seenVersion ? `; the daemon answered with ${input.seenVersion}` : "; the daemon did not answer";
|
|
89
90
|
return { ok: false, detail: `${input.upFailure}${answered}` };
|
|
90
91
|
}
|
|
@@ -111,7 +112,7 @@ function judgeRestartAfterUpFailure(input) {
|
|
|
111
112
|
return {
|
|
112
113
|
ok: true,
|
|
113
114
|
detail: carried.length > 0
|
|
114
|
-
? `came up on ${input.
|
|
115
|
-
: `came up on ${input.
|
|
115
|
+
? `came up on ${input.seenVersion}; still blocked by what was already wrong before the update: ${carried.join("; ")}`
|
|
116
|
+
: `came up on ${input.seenVersion}`,
|
|
116
117
|
};
|
|
117
118
|
}
|
|
@@ -42,6 +42,7 @@ exports.listInstalledVersions = listInstalledVersions;
|
|
|
42
42
|
exports.validateInstalledVersionForActivation = validateInstalledVersionForActivation;
|
|
43
43
|
exports.installVersion = installVersion;
|
|
44
44
|
exports.activateVersion = activateVersion;
|
|
45
|
+
exports.cliVersionAtLeast = cliVersionAtLeast;
|
|
45
46
|
exports.compareCliVersions = compareCliVersions;
|
|
46
47
|
exports.selectVersionsToPrune = selectVersionsToPrune;
|
|
47
48
|
exports.pruneOldVersions = pruneOldVersions;
|
|
@@ -307,6 +308,18 @@ function activateVersion(version, deps) {
|
|
|
307
308
|
* any version that doesn't match the pattern (so unexpected version
|
|
308
309
|
* formats sort consistently rather than throwing).
|
|
309
310
|
*/
|
|
311
|
+
/**
|
|
312
|
+
* True when `version` is `floor` or a release after it. Anything that cannot be
|
|
313
|
+
* ordered by release number (such as the "unknown" a daemon shows when it
|
|
314
|
+
* reports no version) is never taken for a newer release.
|
|
315
|
+
*/
|
|
316
|
+
function cliVersionAtLeast(version, floor) {
|
|
317
|
+
if (version === floor)
|
|
318
|
+
return true;
|
|
319
|
+
const versionMatch = /alpha\.(\d+)$/.exec(version);
|
|
320
|
+
const floorMatch = /alpha\.(\d+)$/.exec(floor);
|
|
321
|
+
return Boolean(versionMatch && floorMatch && compareCliVersions(version, floor) > 0);
|
|
322
|
+
}
|
|
310
323
|
function compareCliVersions(a, b) {
|
|
311
324
|
const aMatch = /alpha\.(\d+)/.exec(a);
|
|
312
325
|
const bMatch = /alpha\.(\d+)/.exec(b);
|
|
@@ -33,8 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.releaseSourceDeps = void 0;
|
|
37
|
-
exports.isSelfUpdateLockHeld = isSelfUpdateLockHeld;
|
|
36
|
+
exports.isSelfUpdateLockHeld = exports.releaseSourceDeps = void 0;
|
|
38
37
|
exports.createDefaultSelfUpdateDeps = createDefaultSelfUpdateDeps;
|
|
39
38
|
exports.launchUnattendedSelfUpdate = launchUnattendedSelfUpdate;
|
|
40
39
|
exports.ensureDefaultUpdaterAgent = ensureDefaultUpdaterAgent;
|
|
@@ -53,6 +52,8 @@ const handoff_blockers_1 = require("../daemon/handoff-blockers");
|
|
|
53
52
|
const runtime_replacement_handoff_1 = require("../daemon/runtime-replacement-handoff");
|
|
54
53
|
const ouro_version_manager_1 = require("./ouro-version-manager");
|
|
55
54
|
const release_sources_1 = require("./release-sources");
|
|
55
|
+
const self_update_lock_1 = require("./self-update-lock");
|
|
56
|
+
Object.defineProperty(exports, "isSelfUpdateLockHeld", { enumerable: true, get: function () { return self_update_lock_1.isSelfUpdateLockHeld; } });
|
|
56
57
|
const update_state_1 = require("./update-state");
|
|
57
58
|
const updater_launchd_1 = require("./updater-launchd");
|
|
58
59
|
const version_intent_1 = require("./version-intent");
|
|
@@ -140,63 +141,6 @@ async function daemonHandoffSnapshot(socketPath) {
|
|
|
140
141
|
}
|
|
141
142
|
const EMPTY_HANDOFF_SNAPSHOT = { blockers: [], workers: [], healthCheckCount: 0 };
|
|
142
143
|
exports.releaseSourceDeps = { fetchJson, execFile: execFileText, ...(0, release_sources_1.selfUpdateE2eOverrides)(process.env) };
|
|
143
|
-
function isPidAlive(pid) {
|
|
144
|
-
try {
|
|
145
|
-
process.kill(pid, 0);
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
function lockPath(cliHome) {
|
|
153
|
-
return path.join(cliHome, "self-update.lock");
|
|
154
|
-
}
|
|
155
|
-
/** The pid holding the update lock when that process is still alive. */
|
|
156
|
-
function liveLockOwner(cliHome) {
|
|
157
|
-
try {
|
|
158
|
-
const pid = Number.parseInt(fs.readFileSync(lockPath(cliHome), "utf8"), 10);
|
|
159
|
-
return Number.isFinite(pid) && pid > 0 && isPidAlive(pid) ? pid : null;
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/** True when another live process is in the middle of an update pass. */
|
|
166
|
-
function isSelfUpdateLockHeld(cliHome) {
|
|
167
|
-
const owner = liveLockOwner(cliHome);
|
|
168
|
-
return owner !== null && owner !== process.pid;
|
|
169
|
-
}
|
|
170
|
-
function acquireLock(cliHome) {
|
|
171
|
-
const file = lockPath(cliHome);
|
|
172
|
-
fs.mkdirSync(cliHome, { recursive: true });
|
|
173
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
174
|
-
try {
|
|
175
|
-
const fd = fs.openSync(file, "wx", 0o600);
|
|
176
|
-
fs.writeSync(fd, `${process.pid}\n`);
|
|
177
|
-
fs.closeSync(fd);
|
|
178
|
-
return () => {
|
|
179
|
-
try {
|
|
180
|
-
fs.unlinkSync(file);
|
|
181
|
-
}
|
|
182
|
-
catch { /* already released */ }
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
if (error.code !== "EEXIST")
|
|
187
|
-
throw error;
|
|
188
|
-
// A lock is stale only when its owner is gone; a long install by a live
|
|
189
|
-
// owner keeps it, however long it takes.
|
|
190
|
-
if (liveLockOwner(cliHome) !== null)
|
|
191
|
-
return null;
|
|
192
|
-
try {
|
|
193
|
-
fs.unlinkSync(file);
|
|
194
|
-
}
|
|
195
|
-
catch { /* raced with the owner releasing it */ }
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
144
|
function versionEntry(cliHome, version) {
|
|
201
145
|
return path.join(cliHome, "versions", version, "node_modules", "@ouro.bot", "cli", "dist", "heart", "daemon", "ouro-entry.js");
|
|
202
146
|
}
|
|
@@ -256,15 +200,17 @@ function createDefaultSelfUpdateDeps(options = {}) {
|
|
|
256
200
|
}
|
|
257
201
|
const deadline = Date.now() + DAEMON_HEALTH_WAIT_MS;
|
|
258
202
|
let seen = null;
|
|
203
|
+
// A newer release can come up in place of the expected one (someone else updated meanwhile); that is healthy too.
|
|
204
|
+
const answeredOnTarget = (version) => version !== null && (0, ouro_version_manager_1.cliVersionAtLeast)(version, expectedVersion);
|
|
259
205
|
while (Date.now() < deadline) {
|
|
260
206
|
seen = await runningDaemonVersion(socketPath);
|
|
261
|
-
if (seen
|
|
207
|
+
if (answeredOnTarget(seen))
|
|
262
208
|
break;
|
|
263
209
|
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
264
210
|
}
|
|
265
211
|
if (upFailure !== null) {
|
|
266
212
|
let after = null;
|
|
267
|
-
if (upRefusedOnHandoffHealth && seen
|
|
213
|
+
if (upRefusedOnHandoffHealth && answeredOnTarget(seen)) {
|
|
268
214
|
// Judge only a settled status: one read before health checks run or workers register hides problems.
|
|
269
215
|
const settleDeadline = Date.now() + DAEMON_HEALTH_WAIT_MS;
|
|
270
216
|
for (;;) {
|
|
@@ -276,11 +222,11 @@ function createDefaultSelfUpdateDeps(options = {}) {
|
|
|
276
222
|
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
277
223
|
}
|
|
278
224
|
}
|
|
279
|
-
return (0, handoff_blockers_1.judgeRestartAfterUpFailure)({ upFailure, upRefusedOnHandoffHealth, expectedVersion, seenVersion: seen, before, after });
|
|
225
|
+
return { ...(0, handoff_blockers_1.judgeRestartAfterUpFailure)({ upFailure, upRefusedOnHandoffHealth, expectedVersion, seenVersion: seen, before, after }), runningVersion: seen };
|
|
280
226
|
}
|
|
281
|
-
if (seen
|
|
282
|
-
return { ok: true };
|
|
283
|
-
return { ok: false, detail: seen ? `daemon answered with ${seen}, expected ${expectedVersion}` : "daemon did not answer after ouro up" };
|
|
227
|
+
if (answeredOnTarget(seen))
|
|
228
|
+
return { ok: true, runningVersion: seen };
|
|
229
|
+
return { ok: false, runningVersion: seen, detail: seen ? `daemon answered with ${seen}, expected ${expectedVersion} or newer` : "daemon did not answer after ouro up" };
|
|
284
230
|
},
|
|
285
231
|
isDevMode: () => fs.existsSync(path.join(cliHome, "dev-config.json")),
|
|
286
232
|
isDaemonReplacementStranded: () => {
|
|
@@ -308,7 +254,7 @@ function createDefaultSelfUpdateDeps(options = {}) {
|
|
|
308
254
|
},
|
|
309
255
|
});
|
|
310
256
|
},
|
|
311
|
-
acquireLock: () =>
|
|
257
|
+
acquireLock: () => (0, self_update_lock_1.acquireSelfUpdateLock)(cliHome),
|
|
312
258
|
diskSpace: () => {
|
|
313
259
|
try {
|
|
314
260
|
const stats = fs.statfsSync(cliHome);
|
|
@@ -409,7 +355,7 @@ function launchUnattendedSelfUpdate(options = {}) {
|
|
|
409
355
|
const config = (0, host_self_update_1.readHostSelfUpdateConfig)(cliHome);
|
|
410
356
|
if (!config?.enabled)
|
|
411
357
|
return "not-enabled";
|
|
412
|
-
if (isSelfUpdateLockHeld(cliHome))
|
|
358
|
+
if ((0, self_update_lock_1.isSelfUpdateLockHeld)(cliHome))
|
|
413
359
|
return "busy";
|
|
414
360
|
const launcher = path.join(cliHome, "bin", "ouro-launcher.js");
|
|
415
361
|
if (!fs.existsSync(launcher))
|
|
@@ -452,7 +398,7 @@ function ensureDefaultUpdaterAgent(options = {}) {
|
|
|
452
398
|
mkdirp: (dir) => fs.mkdirSync(dir, { recursive: true }),
|
|
453
399
|
exec: (command) => { require("child_process").execSync(command, { stdio: "ignore" }); },
|
|
454
400
|
runningUnderUpdaterAgent: process.env.XPC_SERVICE_NAME === updater_launchd_1.UPDATER_PLIST_LABEL,
|
|
455
|
-
updateInProgress: isSelfUpdateLockHeld((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
401
|
+
updateInProgress: (0, self_update_lock_1.isSelfUpdateLockHeld)((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
456
402
|
});
|
|
457
403
|
(0, runtime_1.emitNervesEvent)({
|
|
458
404
|
component: "daemon",
|
|
@@ -474,7 +420,7 @@ function restoreDefaultUpdaterAgentIfMissing(options = {}) {
|
|
|
474
420
|
userUid: os.userInfo().uid,
|
|
475
421
|
fileExists: (filePath) => fs.existsSync(filePath),
|
|
476
422
|
exec: (command) => { require("child_process").execSync(command, { stdio: "ignore", timeout: 10_000 }); },
|
|
477
|
-
updateInProgress: () => isSelfUpdateLockHeld((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
423
|
+
updateInProgress: () => (0, self_update_lock_1.isSelfUpdateLockHeld)((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
478
424
|
});
|
|
479
425
|
}
|
|
480
426
|
function isDefaultUpdaterAgentInstalled(options = {}) {
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SELF_UPDATE_LOCK_MAX_AGE_MS = void 0;
|
|
37
|
+
exports.selfUpdateLockPath = selfUpdateLockPath;
|
|
38
|
+
exports.isSelfUpdateLockHeld = isSelfUpdateLockHeld;
|
|
39
|
+
exports.acquireSelfUpdateLock = acquireSelfUpdateLock;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
+
/**
|
|
44
|
+
* One lock for everything that installs or activates a CLI release on this
|
|
45
|
+
* machine: the unattended `ouro self-update` pass and the update check in
|
|
46
|
+
* `ouro up`. Without it, the `ouro up` a pass runs to restart the daemon can
|
|
47
|
+
* install a newer release in the middle of the pass (2026-11-27).
|
|
48
|
+
*
|
|
49
|
+
* The lock file holds its owner's pid. A crashed owner never wedges it: the
|
|
50
|
+
* lock is stale once that pid is gone, or once the file is older than any pass
|
|
51
|
+
* can run, which also covers a crashed owner whose pid now belongs to an
|
|
52
|
+
* unrelated process.
|
|
53
|
+
*/
|
|
54
|
+
exports.SELF_UPDATE_LOCK_MAX_AGE_MS = 2 * 60 * 60 * 1000;
|
|
55
|
+
function selfUpdateLockPath(cliHome) {
|
|
56
|
+
return path.join(cliHome, "self-update.lock");
|
|
57
|
+
}
|
|
58
|
+
function defaultIsPidAlive(pid) {
|
|
59
|
+
try {
|
|
60
|
+
process.kill(pid, 0);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function lockOwnerPid(cliHome) {
|
|
68
|
+
try {
|
|
69
|
+
const pid = Number.parseInt(fs.readFileSync(selfUpdateLockPath(cliHome), "utf8"), 10);
|
|
70
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The pid holding the lock while it still counts, or null when nobody holds it or the lock is stale. */
|
|
77
|
+
function liveLockOwner(cliHome, deps) {
|
|
78
|
+
const pid = lockOwnerPid(cliHome);
|
|
79
|
+
if (pid === null)
|
|
80
|
+
return null;
|
|
81
|
+
const isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;
|
|
82
|
+
if (!isPidAlive(pid))
|
|
83
|
+
return null;
|
|
84
|
+
let writtenAtMs;
|
|
85
|
+
try {
|
|
86
|
+
writtenAtMs = fs.statSync(selfUpdateLockPath(cliHome)).mtimeMs;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
/* v8 ignore next -- the lock vanished between reading and stat-ing it @preserve */
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const now = deps.now ?? (() => Date.now());
|
|
93
|
+
return now() - writtenAtMs > exports.SELF_UPDATE_LOCK_MAX_AGE_MS ? null : pid;
|
|
94
|
+
}
|
|
95
|
+
/** True when another live process holds the lock. */
|
|
96
|
+
function isSelfUpdateLockHeld(cliHome, deps = {}) {
|
|
97
|
+
const owner = liveLockOwner(cliHome, deps);
|
|
98
|
+
return owner !== null && owner !== (deps.pid ?? process.pid);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Takes the lock and returns its release, or null while another process holds
|
|
102
|
+
* it. Release removes the file only while it still names this process.
|
|
103
|
+
*/
|
|
104
|
+
function acquireSelfUpdateLock(cliHome, deps = {}) {
|
|
105
|
+
const file = selfUpdateLockPath(cliHome);
|
|
106
|
+
const pid = deps.pid ?? process.pid;
|
|
107
|
+
fs.mkdirSync(cliHome, { recursive: true });
|
|
108
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
109
|
+
try {
|
|
110
|
+
const fd = fs.openSync(file, "wx", 0o600);
|
|
111
|
+
fs.writeSync(fd, `${pid}\n`);
|
|
112
|
+
fs.closeSync(fd);
|
|
113
|
+
return () => {
|
|
114
|
+
if (lockOwnerPid(cliHome) !== pid)
|
|
115
|
+
return;
|
|
116
|
+
try {
|
|
117
|
+
fs.unlinkSync(file);
|
|
118
|
+
}
|
|
119
|
+
catch { /* v8 ignore next -- already released @preserve */ }
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
/* v8 ignore next -- permission or disk errors are not a held lock @preserve */
|
|
124
|
+
if (error.code !== "EEXIST")
|
|
125
|
+
throw error;
|
|
126
|
+
const owner = liveLockOwner(cliHome, deps);
|
|
127
|
+
if (owner !== null) {
|
|
128
|
+
(0, runtime_1.emitNervesEvent)({
|
|
129
|
+
component: "daemon",
|
|
130
|
+
event: "daemon.self_update_lock_busy",
|
|
131
|
+
message: "another process is installing or activating a CLI release",
|
|
132
|
+
meta: { owner, pid },
|
|
133
|
+
});
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
(0, runtime_1.emitNervesEvent)({
|
|
137
|
+
level: "warn",
|
|
138
|
+
component: "daemon",
|
|
139
|
+
event: "daemon.self_update_lock_reclaimed",
|
|
140
|
+
message: "took over a self-update lock whose owner is gone or that is older than any pass",
|
|
141
|
+
meta: { stalePid: lockOwnerPid(cliHome), pid },
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
fs.unlinkSync(file);
|
|
145
|
+
}
|
|
146
|
+
catch { /* v8 ignore next -- raced with the owner releasing it @preserve */ }
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/* v8 ignore next -- two processes reclaimed the same stale lock at once and the other won @preserve */
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
@@ -22,8 +22,11 @@ const ouro_version_manager_1 = require("./ouro-version-manager");
|
|
|
22
22
|
* 4. Activate it. If the daemon was running, restart it on the new version
|
|
23
23
|
* and check that it answers; otherwise leave the daemon stopped.
|
|
24
24
|
* 5. On a failed check, reactivate the previous version, pin it with reason
|
|
25
|
-
* "auto-rollback",
|
|
26
|
-
* version
|
|
25
|
+
* "auto-rollback", and never retry the failed version. Restart the daemon
|
|
26
|
+
* on the previous version only when the failed one is what runs (or
|
|
27
|
+
* nothing answers): a rollback never stops a daemon that answers on
|
|
28
|
+
* another version, and a daemon answering on a newer release than the
|
|
29
|
+
* target is a success, not a failure (2026-11-27).
|
|
27
30
|
*/
|
|
28
31
|
exports.PIN_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
29
32
|
/**
|
|
@@ -83,17 +86,31 @@ async function runLocked(deps) {
|
|
|
83
86
|
};
|
|
84
87
|
/**
|
|
85
88
|
* Restart the daemon on `target`. On a failed health check, never retry
|
|
86
|
-
* `target
|
|
87
|
-
*
|
|
89
|
+
* `target` and pin and reactivate `fallback`; restart on it only when the
|
|
90
|
+
* daemon runs `target` or does not answer. Returns the rolled-back result,
|
|
91
|
+
* or the version the daemon is healthy on.
|
|
88
92
|
*/
|
|
89
93
|
const restartOrRollBack = async (target, fallback, source) => {
|
|
90
94
|
const health = await deps.restartDaemon(target);
|
|
91
95
|
if (health.ok)
|
|
92
|
-
return
|
|
96
|
+
return { healthyOn: health.runningVersion ?? target };
|
|
97
|
+
const why = health.detail ?? "no detail";
|
|
98
|
+
const answering = await deps.runningDaemonVersion();
|
|
99
|
+
if (answering && answering !== target && (0, ouro_version_manager_1.cliVersionAtLeast)(answering, target)) {
|
|
100
|
+
// A newer release came up while this pass waited on its own: the machine is ahead of the target, not broken.
|
|
101
|
+
(0, runtime_1.emitNervesEvent)({
|
|
102
|
+
level: "warn",
|
|
103
|
+
component: "daemon",
|
|
104
|
+
event: "daemon.self_update_newer_release_running",
|
|
105
|
+
message: "the daemon came up on a newer release than the one this pass installed; counting it as healthy",
|
|
106
|
+
meta: { target, running: answering, detail: why },
|
|
107
|
+
});
|
|
108
|
+
return { healthyOn: answering };
|
|
109
|
+
}
|
|
93
110
|
failedVersions.push(target);
|
|
94
111
|
if (!fallback) {
|
|
95
112
|
return finish("rolled-back", {
|
|
96
|
-
summary: `${target} did not come up healthy (${
|
|
113
|
+
summary: `${target} did not come up healthy (${why}) and there is no previous version to return to`,
|
|
97
114
|
latestVersion: target,
|
|
98
115
|
source,
|
|
99
116
|
});
|
|
@@ -106,9 +123,17 @@ async function runLocked(deps) {
|
|
|
106
123
|
reason: "auto-rollback",
|
|
107
124
|
});
|
|
108
125
|
deps.activate(fallback);
|
|
126
|
+
if (answering && answering !== target) {
|
|
127
|
+
// The failed release is not what runs, so stopping the daemon would only take a healthy one down.
|
|
128
|
+
return finish("rolled-back", {
|
|
129
|
+
summary: `${target} did not come up healthy (${why}); rolled back to ${fallback} and left the daemon running on ${answering}`,
|
|
130
|
+
latestVersion: target,
|
|
131
|
+
source,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
109
134
|
const restored = await deps.restartDaemon(fallback);
|
|
110
135
|
return finish("rolled-back", {
|
|
111
|
-
summary: `${target} did not come up healthy (${
|
|
136
|
+
summary: `${target} did not come up healthy (${why}); rolled back to ${fallback}${restored.ok ? "" : ` but the daemon did not answer on it either (${restored.detail ?? "no detail"})`}`,
|
|
112
137
|
latestVersion: target,
|
|
113
138
|
source,
|
|
114
139
|
});
|
|
@@ -152,9 +177,12 @@ async function runLocked(deps) {
|
|
|
152
177
|
// A pass killed between activation and restart leaves the old daemon
|
|
153
178
|
// running; finish the job instead of reporting "current" forever.
|
|
154
179
|
const daemonVersion = deps.isDevMode() ? null : await deps.runningDaemonVersion();
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
180
|
+
// A daemon ahead of CurrentVersion was updated by someone else and stays, unless it runs a release that failed here.
|
|
181
|
+
const daemonNeedsRestart = daemonVersion !== null && daemonVersion !== currentVersion
|
|
182
|
+
&& (!(0, ouro_version_manager_1.cliVersionAtLeast)(daemonVersion, currentVersion) || failedVersions.includes(daemonVersion));
|
|
183
|
+
if (daemonVersion && daemonNeedsRestart) {
|
|
184
|
+
const restart = await restartOrRollBack(currentVersion, failedVersions.includes(daemonVersion) ? null : daemonVersion);
|
|
185
|
+
if (!("healthyOn" in restart))
|
|
158
186
|
return restart;
|
|
159
187
|
return finish("updated", {
|
|
160
188
|
summary: `daemon was still running ${daemonVersion}; restarted it on ${currentVersion} and it is healthy`,
|
|
@@ -257,13 +285,16 @@ async function runLocked(deps) {
|
|
|
257
285
|
}
|
|
258
286
|
deps.writeIntent({ schemaVersion: 1, mode: "latest", targetVersion: latest });
|
|
259
287
|
deps.activate(latest);
|
|
288
|
+
let healthyOn = latest;
|
|
260
289
|
if (daemonWasRunning) {
|
|
261
290
|
const restart = await restartOrRollBack(latest, currentVersion, installSource);
|
|
262
|
-
if (restart)
|
|
291
|
+
if (!("healthyOn" in restart))
|
|
263
292
|
return restart;
|
|
293
|
+
healthyOn = restart.healthyOn;
|
|
264
294
|
}
|
|
295
|
+
const healthy = healthyOn === latest ? "; daemon restarted and healthy" : `; daemon restarted and healthy on ${healthyOn}`;
|
|
265
296
|
return finish("updated", {
|
|
266
|
-
summary: `updated ${currentVersion ?? "unknown"} -> ${latest} via ${installSource}${daemonWasRunning ?
|
|
297
|
+
summary: `updated ${currentVersion ?? "unknown"} -> ${latest} via ${installSource}${daemonWasRunning ? healthy : "; daemon was not running and was left stopped"}`,
|
|
267
298
|
latestVersion: latest,
|
|
268
299
|
source: installSource,
|
|
269
300
|
});
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1715",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1715",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1715",
|
|
4
4
|
"description": "Ouroboros, the agent harness: agents with durable memory that live where you talk (terminal, Teams, iMessage, mail, voice) and use real tools. Start with npx ouro.bot@latest.",
|
|
5
5
|
"homepage": "https://ouroboros.bot/",
|
|
6
6
|
"engines": {
|