@nodii/dev 0.6.69 → 0.6.71
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/README.md +20 -3
- package/dist/cli.js +8 -2
- package/dist/core.js +1 -1
- package/dist/flags.js +1 -1
- package/dist/lanes.js +41 -4
- package/dist/starting.js +25 -4
- package/dist/watchdog.js +22 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -441,6 +441,17 @@ nodii-dev lane resume --host-lost [--min-free-gb N] [--stagger-seconds N]
|
|
|
441
441
|
nodii-dev lane transfer KEY --reason TEXT [--to-agent ID]
|
|
442
442
|
# move a host_lost lane to the recovering agent on this
|
|
443
443
|
# machine under a fresh run (AGENT-HARNESS-67)
|
|
444
|
+
nodii-dev lane resume KEY --profile PATH --class long|short|no-build
|
|
445
|
+
# coordinator or staff (MW1-38.5): start the fresh run on
|
|
446
|
+
# another registered account, read fresh first. The lane
|
|
447
|
+
# keeps its key, branch, worktree, slot and history; Dev
|
|
448
|
+
# records both accounts on the run and in the audit log.
|
|
449
|
+
# Refused with LANE_PROCESS_LIVE while its process is live,
|
|
450
|
+
# ACCOUNT_BAND_REFUSED if the account's band doesn't admit
|
|
451
|
+
# the class, ACCOUNT_LIMIT_UNAVAILABLE for an unregistered,
|
|
452
|
+
# offline or unread account, and LANE_ALREADY_ON_ACCOUNT. A
|
|
453
|
+
# lane stopped by two deaths moves off an exhausted account
|
|
454
|
+
# with no amendment or override, and its death count restarts
|
|
444
455
|
nodii-dev lane resume KEY [--override --reason TEXT]
|
|
445
456
|
# --override (coordinator): resume a lane the two-identical-
|
|
446
457
|
# deaths rule stopped; Dev refuses it with
|
|
@@ -519,9 +530,15 @@ gone, and watched worktrees whose HEAD has commits absent from its configured
|
|
|
519
530
|
remote branch. Each observation is posted to the watched run by the machine
|
|
520
531
|
coordinator; `process_dead` transitions it to explicit `orphan` immediately.
|
|
521
532
|
Every watched run whose PID is alive (or whose lane supervisor is, between
|
|
522
|
-
same-session continuations) is reported as `process_alive`.
|
|
523
|
-
|
|
524
|
-
|
|
533
|
+
same-session continuations) is reported as `process_alive`. That is not a
|
|
534
|
+
heartbeat: a lane run with no heartbeat still goes Quiet at 15 minutes (MW1-36),
|
|
535
|
+
and Dev holds it at Quiet, short of Orphan, while its Mac still sees the process.
|
|
536
|
+
Only a coordinator run takes `process_alive` as its heartbeat.
|
|
537
|
+
Each sweep also reads Dev's live runs for the machine. A dead process is reported
|
|
538
|
+
again while Dev still holds its run as running, and a live lane or coordinator
|
|
539
|
+
run with no local record is listed as `unwatchedRuns`.
|
|
540
|
+
`coordinator start` installs this job under the coordinator's own config: the job
|
|
541
|
+
runs as one agent, and a sweep by any other agent is refused.
|
|
525
542
|
A sweep leaves a dead lane runtime alone while its lane supervisor still lives
|
|
526
543
|
(the supervisor reports the exit itself) and skips it once the supervisor has
|
|
527
544
|
reported.
|
package/dist/cli.js
CHANGED
|
@@ -66,7 +66,7 @@ import { docsCommand, rulebookCommand, rulesCommand } from "./upload.js";
|
|
|
66
66
|
import { changeSetCommand, guidelineCommand } from "./guidelines.js";
|
|
67
67
|
import { designCheck, designCheckChangeSet, designCheckText, designRoles, designRolesText, surfacesBehind, surfacesBehindText } from "./design.js";
|
|
68
68
|
import { assertKnownFlags } from "./flags.js";
|
|
69
|
-
import { watchdogCommand } from "./watchdog.js";
|
|
69
|
+
import { installWatchdog, watchdogCommand } from "./watchdog.js";
|
|
70
70
|
import { machineCapacityCommand } from "./accounts.js";
|
|
71
71
|
import {
|
|
72
72
|
ALIASES,
|
|
@@ -282,6 +282,12 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
282
282
|
# its last death; the reason is kept on the new run. Any resume is
|
|
283
283
|
# refused (LANE_PROCESS_LIVE) while the lane has a running run or a
|
|
284
284
|
# fresh lane-agent heartbeat since the death: one process per lane
|
|
285
|
+
lane resume <key> --profile PATH --class long|short|no-build
|
|
286
|
+
# coordinator or staff (MW1-38.5): start the fresh run on another registered
|
|
287
|
+
# account. Dev refuses it while the process is live (LANE_PROCESS_LIVE), or if the
|
|
288
|
+
# account's band doesn't admit the class (ACCOUNT_BAND_REFUSED). The lane keeps its
|
|
289
|
+
# key, branch, worktree, slot and history. A lane stopped by two deaths moves off
|
|
290
|
+
# an exhausted account with no amendment or override
|
|
285
291
|
lane resume --host-lost [--min-free-gb N] [--stagger-seconds N]
|
|
286
292
|
# coordinator, after a reboot: resume every host_lost lane on this machine
|
|
287
293
|
# in priority order under its own key, agent, worktree and branch. No
|
|
@@ -793,7 +799,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
793
799
|
}
|
|
794
800
|
return;
|
|
795
801
|
}
|
|
796
|
-
if (command === "coordinator") return emitCommand(await coordinatorCommand(action, f));
|
|
802
|
+
if (command === "coordinator") return emitCommand(await coordinatorCommand(action, f, { installWatchdog }));
|
|
797
803
|
if (command === "lane" && action === "launch") return emitCommand(await launchLaneCommand(rest[0], f));
|
|
798
804
|
if (command === "lane" && action === "amend") return emitCommand(await amendLaneCommand(rest[0], f));
|
|
799
805
|
if (command === "lane" && action === "gather") {
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.71";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/flags.js
CHANGED
|
@@ -33,7 +33,7 @@ export const COMMAND_FLAGS = {
|
|
|
33
33
|
"lane evidence": ["pr", "commit", "figma", "deploy", "dev-check"],
|
|
34
34
|
"lane done-check": ["evidence"],
|
|
35
35
|
"lane heartbeat": ["note"],
|
|
36
|
-
"lane resume": ["override", "reason", "host-lost", "min-free-gb", "stagger-seconds"],
|
|
36
|
+
"lane resume": ["override", "reason", "host-lost", "min-free-gb", "stagger-seconds", "profile", "class"],
|
|
37
37
|
"lane transfer": ["reason", "to-agent"],
|
|
38
38
|
"lane stop": ["reason"],
|
|
39
39
|
"lane land": [],
|
package/dist/lanes.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { readFile, realpath, writeFile } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute } from "node:path";
|
|
3
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { coordinatorMachineId, listAccounts, profilePath, reportUsage } from "./accounts.js";
|
|
4
6
|
import { CliError, encode, devRequest, query, readConfig, requireFlag } from "./core.js";
|
|
5
7
|
import { launchRecovery } from "./runtime-launcher.js";
|
|
6
8
|
import { recordReviewReceipt, reviewCommitContext } from "./safety.js";
|
|
@@ -53,7 +55,9 @@ export async function inferGitContext() {
|
|
|
53
55
|
return { repo, branch: need(branch, "Detached HEAD: pass --branch."), worktree };
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
// `building` is the lane's phase, not a process: say when nothing healthy is running (MW1-36).
|
|
59
|
+
const laneLiveness = (x) => x.liveness && x.liveness !== "active" ? `\t${x.liveness.toUpperCase()}` : "";
|
|
60
|
+
const laneLine = (x) => `${x.key}\t${x.status}\t${x.kind}/${x.side}\t${x.title}${x.stuck ? "\tSTUCK" : ""}${laneLiveness(x)}`;
|
|
57
61
|
// GATHER-NA: a step the coordinator ruled not applicable is never shown as done.
|
|
58
62
|
const stepState = (s) => s.state === "not_applicable" ? `not applicable: ${s.notApplicableReason ?? "(no reason recorded)"}` : s.state;
|
|
59
63
|
const detailText = (x) => [laneLine(x), ...(x.steps ?? []).map((s) => ` ${s.side}\t${stepState(s)}\t${s.stepKey}\t${s.label}`)].join("\n");
|
|
@@ -316,9 +320,28 @@ const positiveNumber = (value, flag, fallback) => {
|
|
|
316
320
|
* memory shows, and the run stops at the memory floor: the lanes it holds stay
|
|
317
321
|
* host_lost, so running it again carries on.
|
|
318
322
|
*/
|
|
323
|
+
// MW1-38.1: read the limits a move depends on: the account it goes to, and the
|
|
324
|
+
// others of that runtime, one of which is the account it leaves. A failed read
|
|
325
|
+
// is not fatal: Dev refuses a missing or stale reading on the new account and
|
|
326
|
+
// names the command that fixes it.
|
|
327
|
+
async function refreshMoveAccounts(profile, { request, config }) {
|
|
328
|
+
try {
|
|
329
|
+
const machineId = await coordinatorMachineId({ request, config });
|
|
330
|
+
const accounts = await listAccounts(machineId, { request });
|
|
331
|
+
const target = accounts.find((account) => account.profile === profile);
|
|
332
|
+
if (!target) return;
|
|
333
|
+
const others = accounts.filter((account) => account.runtime === target.runtime && account !== target);
|
|
334
|
+
await reportUsage(others, { request });
|
|
335
|
+
// The move is about to spend this account, so an opted-in Codex account may probe.
|
|
336
|
+
await reportUsage([target], { request, probe: true });
|
|
337
|
+
} catch {}
|
|
338
|
+
}
|
|
339
|
+
|
|
319
340
|
async function resumeHostLost(flags, deps, { request, config }) {
|
|
320
341
|
if (flags.override || flags.reason !== undefined)
|
|
321
342
|
throw new CliError("USAGE", "lane resume --host-lost needs no --override: a restart is not a death.", 2);
|
|
343
|
+
if (flags.profile !== undefined || flags.class !== undefined)
|
|
344
|
+
throw new CliError("USAGE", "lane resume --host-lost resumes each lane on its own account; move one with lane resume <key> --profile PATH --class CLASS.", 2);
|
|
322
345
|
const floor = positiveNumber(flags["min-free-gb"], "--min-free-gb", HOST_LOST_MIN_FREE_GB) * GIB;
|
|
323
346
|
const stagger = positiveNumber(flags["stagger-seconds"], "--stagger-seconds", HOST_LOST_STAGGER_SECONDS) * 1000;
|
|
324
347
|
const { memory = availableMemoryBytes, sleep = (ms) => new Promise((done) => setTimeout(done, ms)) } = deps;
|
|
@@ -364,7 +387,7 @@ async function resumeHostLost(flags, deps, { request, config }) {
|
|
|
364
387
|
}
|
|
365
388
|
|
|
366
389
|
export async function laneCommand(action, args, flags, deps = {}) {
|
|
367
|
-
const { request = devRequest, config = readConfig, gitContext = inferGitContext, commitsOf = branchCommits, read = (path) => readFile(path, "utf8"), reviewContext = reviewCommitContext, reviewReceipt = recordReviewReceipt, picker = pickDocuments, warm = warmPicker, firstPickTimeoutMs = PICKER_FIRST_PICK_TIMEOUT_MS, timings = { record: recordPickTiming, read: readPickTimings }, changedPaths = laneChangedPaths, gatherTimeoutMs = GATHER_TIMEOUT_MS, deadline: outerDeadline, storeFreeze = storeGatherFreeze, launch = launchRecovery, rebind = rebindLaneConfig, catalog = loadDsCatalog, pickLock = withPickLock, check: checkDeps = {} } = deps;
|
|
390
|
+
const { request = devRequest, config = readConfig, refreshAccounts = refreshMoveAccounts, gitContext = inferGitContext, commitsOf = branchCommits, read = (path) => readFile(path, "utf8"), reviewContext = reviewCommitContext, reviewReceipt = recordReviewReceipt, picker = pickDocuments, warm = warmPicker, firstPickTimeoutMs = PICKER_FIRST_PICK_TIMEOUT_MS, timings = { record: recordPickTiming, read: readPickTimings }, changedPaths = laneChangedPaths, gatherTimeoutMs = GATHER_TIMEOUT_MS, deadline: outerDeadline, storeFreeze = storeGatherFreeze, launch = launchRecovery, rebind = rebindLaneConfig, catalog = loadDsCatalog, pickLock = withPickLock, check: checkDeps = {} } = deps;
|
|
368
391
|
if (action === "resume" && flags["host-lost"]) {
|
|
369
392
|
if (args[0]) throw new CliError("USAGE", "lane resume --host-lost takes no <key>: it resumes every host_lost lane on this machine.", 2);
|
|
370
393
|
return resumeHostLost(flags, deps, { request, config });
|
|
@@ -854,10 +877,23 @@ export async function laneCommand(action, args, flags, deps = {}) {
|
|
|
854
877
|
const overrideReason = typeof flags.reason === "string" ? flags.reason.trim() : "";
|
|
855
878
|
if (flags.override && !overrideReason) throw new CliError("USAGE", "--reason needs TEXT: why resuming the amended lane is safe.", 2);
|
|
856
879
|
if (overrideReason.length > 2_000) throw new CliError("USAGE", `--reason is ${overrideReason.length} characters; Dev keeps at most 2,000.`, 2);
|
|
880
|
+
// NODII-DEV-CLI-53 (MW1-38.5): --profile starts the run on another registered
|
|
881
|
+
// account. Dev keeps no class for a lane, so it is named here, as at launch.
|
|
882
|
+
if ((flags.profile === undefined) !== (flags.class === undefined))
|
|
883
|
+
throw new CliError("USAGE", "lane resume --profile PATH and --class long|short|no-build go together.", 2);
|
|
884
|
+
let move = {};
|
|
885
|
+
if (flags.profile !== undefined) {
|
|
886
|
+
const profile = typeof flags.profile === "string" ? profilePath(flags.profile.trim()) : "";
|
|
887
|
+
if (!isAbsolute(profile)) throw new CliError("USAGE", "--profile must be an absolute runtime profile path.", 2);
|
|
888
|
+
const workClass = { long: "long", short: "short", "no-build": "no_build" }[flags.class];
|
|
889
|
+
if (!workClass) throw new CliError("USAGE", "--class must be long, short or no-build (a one-file fix, a publish or verify relaunch, or an evidence-only step).", 2);
|
|
890
|
+
await refreshAccounts(profile, { request, config });
|
|
891
|
+
move = { profile, workClass };
|
|
892
|
+
}
|
|
857
893
|
const payload = await request(
|
|
858
894
|
"POST",
|
|
859
895
|
`/api/v1/lanes/${encode(id)}/resume`,
|
|
860
|
-
flags.override ? { override: true, reason: overrideReason, ...via }
|
|
896
|
+
{ ...(flags.override ? { override: true, reason: overrideReason } : {}), ...move, ...via },
|
|
861
897
|
);
|
|
862
898
|
const launched = await launchReserved(payload);
|
|
863
899
|
return {
|
|
@@ -870,7 +906,8 @@ export async function laneCommand(action, args, flags, deps = {}) {
|
|
|
870
906
|
? `${next.side}/${next.step}`
|
|
871
907
|
: "the lane's next unfinished step";
|
|
872
908
|
const override = response.data.run.resumeOverrideReason;
|
|
873
|
-
|
|
909
|
+
const moved = response.data.accountMove;
|
|
910
|
+
return `${ref}: ${moved ? `moved from the account at ${moved.fromProfile ?? "an unrecorded profile"} to ${moved.toProfile}; ` : ""}resumed fresh run ${runId} as PID ${launched.pid}; continuing ${continuation} from ${checkpoint}.${override ? ` Override past the two-deaths stop recorded ("${override}"); the death count restarts.` : ""}`;
|
|
874
911
|
},
|
|
875
912
|
};
|
|
876
913
|
}
|
package/dist/starting.js
CHANGED
|
@@ -198,7 +198,7 @@ const coordinatorState = (machine, run, agentId) => ({
|
|
|
198
198
|
* Adopt this session's own running coordinator run again (CLI-16): rewrite the
|
|
199
199
|
* state file and restart the heartbeater. Dev's run is unchanged.
|
|
200
200
|
*/
|
|
201
|
-
async function adoptCoordinatorRun(machine, run, c, { save, heartbeater, existingHeartbeater }) {
|
|
201
|
+
async function adoptCoordinatorRun(machine, run, c, { save, heartbeater, existingHeartbeater, installWatchdog }) {
|
|
202
202
|
await save(stateFile(machine), coordinatorState(machine, run, c.agentId));
|
|
203
203
|
const expected = run.expectedHeartbeatSeconds ?? 60;
|
|
204
204
|
// A heartbeater still beating this run keeps it; a second is never started.
|
|
@@ -208,13 +208,15 @@ async function adoptCoordinatorRun(machine, run, c, { save, heartbeater, existin
|
|
|
208
208
|
try { heartbeaterPid = await heartbeater({ runId: run.id, machine, pid: run.watched.pid, processStartedAt: run.watched.processStartedAt ?? null, intervalSeconds: Math.max(5, Math.floor(expected / 2)) }); }
|
|
209
209
|
catch (error) { heartbeaterError = error?.message ?? String(error); }
|
|
210
210
|
}
|
|
211
|
+
const watchdogTakeover = await takeOverWatchdog(installWatchdog);
|
|
211
212
|
return {
|
|
212
|
-
payload: { data: { adopted: true, run, machine: { id: run.metadata.machineId, name: machine } }, heartbeaterPid },
|
|
213
|
+
payload: { data: { adopted: true, run, machine: { id: run.metadata.machineId, name: machine } }, heartbeaterPid, ...watchdogTakeover },
|
|
213
214
|
human: [
|
|
214
215
|
`Coordinator ${run.id} is this session's run on ${machine}; adopted it again (last heartbeat ${run.lastHeartbeatAt ?? "never"}).`,
|
|
215
216
|
heartbeaterPid
|
|
216
217
|
? `heartbeater ${heartbeaterPid} keeps the run alive while session ${run.watched.pid} lives`
|
|
217
218
|
: `heartbeater not started${heartbeaterError ? ` (${heartbeaterError})` : ""}: the run goes quiet without heartbeats`,
|
|
219
|
+
...watchdogLines(watchdogTakeover),
|
|
218
220
|
].join("\n"),
|
|
219
221
|
};
|
|
220
222
|
}
|
|
@@ -304,6 +306,21 @@ export async function coordinatorHeartbeatLoop({ machine, runId, pid, processSta
|
|
|
304
306
|
}
|
|
305
307
|
|
|
306
308
|
/** Register each --account, then report every account's usage (MW1-38.1). */
|
|
309
|
+
/**
|
|
310
|
+
* The launchd job runs as one agent, so a new coordinator has to take it over
|
|
311
|
+
* or every sweep is refused (WATCHDOG_COORDINATOR_REQUIRED; NODII-DEV-CLI-42).
|
|
312
|
+
*/
|
|
313
|
+
async function takeOverWatchdog(installWatchdog) {
|
|
314
|
+
if (!installWatchdog) return { watchdog: null, watchdogError: null };
|
|
315
|
+
try { return { watchdog: await installWatchdog(), watchdogError: null }; }
|
|
316
|
+
catch (error) { return { watchdog: null, watchdogError: `${error?.code ?? "WATCHDOG_INSTALL_FAILED"}: ${error?.message ?? error}` }; }
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const watchdogLines = ({ watchdog, watchdogError }) => [
|
|
320
|
+
...(watchdog ? [`watchdog ${watchdog.label} runs under this coordinator${watchdog.changed ? " (updated)" : ""}`] : []),
|
|
321
|
+
...(watchdogError ? [`WATCHDOG NOT RUNNING under this coordinator (${watchdogError}); no sweep reports dead processes until nodii-dev watchdog install succeeds`] : []),
|
|
322
|
+
];
|
|
323
|
+
|
|
307
324
|
async function coordinatorCapacity(machineId, flags, { request, readers }) {
|
|
308
325
|
// The run is already started: a refused registration is reported, not thrown.
|
|
309
326
|
const refused = [];
|
|
@@ -325,6 +342,8 @@ export async function coordinatorCommand(action, flags, {
|
|
|
325
342
|
isAlive = async (pid, startedAt) => (await import("./watchdog.js")).isProcessAlive(pid, startedAt),
|
|
326
343
|
sessionPid = coordinatorRuntimePid,
|
|
327
344
|
existingHeartbeater = runningHeartbeater,
|
|
345
|
+
// Only the CLI passes launchd's installer, so no caller touches launchd by default.
|
|
346
|
+
installWatchdog = null,
|
|
328
347
|
} = {}) {
|
|
329
348
|
if (action === "heartbeat") {
|
|
330
349
|
const result = await heartbeatLoop({
|
|
@@ -361,7 +380,7 @@ export async function coordinatorCommand(action, flags, {
|
|
|
361
380
|
// CLI-16: the run's session is this session (its heartbeater or state file
|
|
362
381
|
// was lost): adopt the run again and restart its heartbeater.
|
|
363
382
|
if (sessionAlive && pid === (await sessionPid().catch(() => null)))
|
|
364
|
-
return adoptCoordinatorRun(machine, live, c, { save, heartbeater, existingHeartbeater });
|
|
383
|
+
return adoptCoordinatorRun(machine, live, c, { save, heartbeater, existingHeartbeater, installWatchdog });
|
|
365
384
|
const interval = live.expectedHeartbeatSeconds ?? 60;
|
|
366
385
|
if (!coordinatorRunStale(live, now()))
|
|
367
386
|
throw new CliError("COORDINATOR_ALREADY_RUNNING", `Coordinator run ${live.id} for ${machine} is live (last heartbeat ${live.lastHeartbeatAt ?? "never"}); it is taken over only after 3x its ${interval}s heartbeat interval with its session gone. Run coordinator start from that run's own session to adopt it again.`, 1);
|
|
@@ -418,8 +437,9 @@ export async function coordinatorCommand(action, flags, {
|
|
|
418
437
|
catch (error) { heartbeaterError = error?.message ?? String(error); }
|
|
419
438
|
}
|
|
420
439
|
const accounts = await coordinatorCapacity(payload.data.machine.id, flags, { request, readers });
|
|
440
|
+
const watchdogTakeover = await takeOverWatchdog(installWatchdog);
|
|
421
441
|
return {
|
|
422
|
-
payload: { ...payload, accounts, heartbeaterPid },
|
|
442
|
+
payload: { ...payload, accounts, heartbeaterPid, ...watchdogTakeover },
|
|
423
443
|
human: (p) => [
|
|
424
444
|
`Coordinator ${p.data.run.id} is watching ${p.data.machine.name}.`,
|
|
425
445
|
`running lanes: ${p.data.runningLanes.length}`,
|
|
@@ -432,6 +452,7 @@ export async function coordinatorCommand(action, flags, {
|
|
|
432
452
|
heartbeaterPid
|
|
433
453
|
? `heartbeater ${heartbeaterPid} keeps the run alive while session ${watched.pid} lives`
|
|
434
454
|
: `heartbeater not started${heartbeaterError ? ` (${heartbeaterError})` : ""}: the run goes quiet without heartbeats`,
|
|
455
|
+
...watchdogLines(watchdogTakeover),
|
|
435
456
|
...(accounts.length
|
|
436
457
|
? accounts.map((result) => `account ${usageLine(result)}`)
|
|
437
458
|
: [`accounts: none registered; add one with --account claude:/path/to/profile (lane launch needs its usage)`]),
|
package/dist/watchdog.js
CHANGED
|
@@ -221,6 +221,21 @@ export async function sweepWatchdog({
|
|
|
221
221
|
const byId = new Map(loaded.records.map((record) => [record.runId, record]));
|
|
222
222
|
const effectiveMachineId = machineId ?? (await coordinatorMachine({ request })).machineId;
|
|
223
223
|
const orphanedRuns = [];
|
|
224
|
+
// Dev's live runs are the authority, not the local flags (NODII-DEV-CLI-42):
|
|
225
|
+
// a run Dev still holds as running gets its dead process reported again, and
|
|
226
|
+
// a run with no local record is one this sweep cannot see. Without Dev's list
|
|
227
|
+
// the local records still get checked.
|
|
228
|
+
let devLiveRuns = null;
|
|
229
|
+
try {
|
|
230
|
+
const state = await request("GET", `/api/v1/run-watchdog?machine=${encode(effectiveMachineId)}`);
|
|
231
|
+
devLiveRuns = Array.isArray(state?.data?.liveRuns) ? state.data.liveRuns : null;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
facts.errors.push({ kind: "live_runs", code: error?.code ?? "RUN_WATCHDOG_STATE_FAILED" });
|
|
234
|
+
}
|
|
235
|
+
const devLiveIds = new Set((devLiveRuns ?? []).map((run) => run.id));
|
|
236
|
+
const unwatchedRuns = (devLiveRuns ?? [])
|
|
237
|
+
.filter((run) => ["lane", "coordinator"].includes(run.kind) && !byId.has(run.id))
|
|
238
|
+
.map((run) => ({ runId: run.id, kind: run.kind, lastHeartbeatAt: run.lastHeartbeatAt }));
|
|
224
239
|
// Record the non-terminal observations first: process_dead transitions the
|
|
225
240
|
// run to Orphan immediately, and must not prevent its stale socket or local
|
|
226
241
|
// commits from reaching Dev in the same sweep.
|
|
@@ -252,8 +267,8 @@ export async function sweepWatchdog({
|
|
|
252
267
|
facts.errors.push({ kind: "run", runId: record.runId, observation: "worktree_unpushed", code: error?.code ?? "RUN_WATCHDOG_REPORT_FAILED" });
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
|
-
//
|
|
256
|
-
//
|
|
270
|
+
// A PID this Mac sees alive holds a lane run at Quiet, short of Orphan, and is
|
|
271
|
+
// a coordinator run's heartbeat. It is not a lane run's heartbeat (MW1-36).
|
|
257
272
|
for (const live of facts.liveRuns ?? []) {
|
|
258
273
|
const record = byId.get(live.runId);
|
|
259
274
|
if (!record || record.orphanReportedAt || record.terminalSeenAt) continue;
|
|
@@ -268,7 +283,8 @@ export async function sweepWatchdog({
|
|
|
268
283
|
}
|
|
269
284
|
for (const dead of facts.deadRuns) {
|
|
270
285
|
const record = byId.get(dead.runId);
|
|
271
|
-
if (!record
|
|
286
|
+
if (!record) continue;
|
|
287
|
+
if ((record.orphanReportedAt || record.terminalSeenAt) && !devLiveIds.has(record.runId)) continue;
|
|
272
288
|
try {
|
|
273
289
|
const observedAt = now().toISOString();
|
|
274
290
|
const response = await request("POST", `/api/v1/runs/${encode(record.runId)}/watchdog`, observationBody({
|
|
@@ -278,7 +294,7 @@ export async function sweepWatchdog({
|
|
|
278
294
|
if (response?.data?.run?.livenessState === "orphan") {
|
|
279
295
|
record.orphanReportedAt = observedAt;
|
|
280
296
|
orphanedRuns.push({ runId: record.runId, pid: record.pid, reportedAt: record.orphanReportedAt });
|
|
281
|
-
} else if (["done", "handed_off", "failed"].includes(response?.data?.run?.status)) {
|
|
297
|
+
} else if (["done", "handed_off", "failed", "blocked"].includes(response?.data?.run?.status)) {
|
|
282
298
|
record.terminalSeenAt = observedAt;
|
|
283
299
|
} else {
|
|
284
300
|
throw new CliError("RUN_WATCHDOG_RESPONSE_INVALID", "Dev recorded process_dead without returning the run as orphan or terminal.", 1);
|
|
@@ -299,7 +315,7 @@ export async function sweepWatchdog({
|
|
|
299
315
|
} catch (error) {
|
|
300
316
|
facts.errors.push({ kind: "usage", code: error?.code ?? "ACCOUNT_USAGE_REPORT_FAILED" });
|
|
301
317
|
}
|
|
302
|
-
const report = { ...facts, orphanedRuns, accounts };
|
|
318
|
+
const report = { ...facts, orphanedRuns, unwatchedRuns, accounts };
|
|
303
319
|
return report;
|
|
304
320
|
}
|
|
305
321
|
|
|
@@ -360,7 +376,7 @@ export async function watchdogCommand(action, flags, dependencies = {}) {
|
|
|
360
376
|
}
|
|
361
377
|
if (action === "sweep") {
|
|
362
378
|
const data = await sweepWatchdog(dependencies);
|
|
363
|
-
return { payload: { data }, human: `Watchdog sweep: ${data.orphanedRuns.length} orphaned run(s), ${data.staleSockets.length} stale socket(s), ${data.unpushedWorktrees.length} unpushed worktree(s), ${data.errors.length} error(s).` };
|
|
379
|
+
return { payload: { data }, human: `Watchdog sweep: ${data.orphanedRuns.length} orphaned run(s), ${data.unwatchedRuns.length} unwatched run(s), ${data.staleSockets.length} stale socket(s), ${data.unpushedWorktrees.length} unpushed worktree(s), ${data.errors.length} error(s).` };
|
|
364
380
|
}
|
|
365
381
|
throw new CliError("USAGE", "watchdog install [--interval SECONDS] | watchdog sweep", 2);
|
|
366
382
|
}
|