greprag 5.43.1 → 5.43.2
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/dist/commands/inbox-watch-supervisor.js +21 -2
- package/dist/commands/inbox-watch-supervisor.js.map +1 -1
- package/dist/commands/watcher-registry.d.ts +93 -73
- package/dist/commands/watcher-registry.js +254 -288
- package/dist/commands/watcher-registry.js.map +1 -1
- package/dist/hook.js +18 -11
- package/dist/hook.js.map +1 -1
- package/dist/session-id.d.ts +18 -10
- package/dist/session-id.js +24 -16
- package/dist/session-id.js.map +1 -1
- package/package.json +1 -1
|
@@ -166,6 +166,21 @@ async function runSupervisor() {
|
|
|
166
166
|
const onSigterm = () => forward('SIGTERM');
|
|
167
167
|
process.on('SIGINT', onSigint);
|
|
168
168
|
process.on('SIGTERM', onSigterm);
|
|
169
|
+
// Supervisor self-protection (2026-06-13). A stray throw in the supervisor's OWN
|
|
170
|
+
// code (the heartbeat, the spawn path, the exit promise) used to crash it
|
|
171
|
+
// uncaught — and Monitor `persistent:true` does NOT restart a dead command
|
|
172
|
+
// (verified live), so the watcher simply vanished until the next turn re-armed
|
|
173
|
+
// it. Exit NON-ZERO on any uncaught error so the bash relauncher
|
|
174
|
+
// (`armMonitorCommand`) relaunches a fresh supervisor — turn-free recovery, the
|
|
175
|
+
// missing rung for supervisor death. adr: adr/monitor-resilience.md
|
|
176
|
+
const onFatalError = (label) => (err) => {
|
|
177
|
+
console.error(`${LOG_PREFIX} supervisor ${label}: ${(err && err.message) || String(err)}`);
|
|
178
|
+
process.exit(1); // non-zero (not 0/64) → the relauncher relaunches us
|
|
179
|
+
};
|
|
180
|
+
const onUncaught = onFatalError('uncaughtException');
|
|
181
|
+
const onRejection = onFatalError('unhandledRejection');
|
|
182
|
+
process.on('uncaughtException', onUncaught);
|
|
183
|
+
process.on('unhandledRejection', onRejection);
|
|
169
184
|
// Re-invoke the same JS entrypoint via the Node binary we're running
|
|
170
185
|
// under. Skips the bash/sh npm shim on respawn — the shim's fork
|
|
171
186
|
// pressure is paid once at initial invocation, not once per restart.
|
|
@@ -267,7 +282,9 @@ async function runSupervisor() {
|
|
|
267
282
|
// missing anchor. Respawning would loop forever.
|
|
268
283
|
if (exit.err === null && exit.code === exports.FATAL_EXIT_CODE) {
|
|
269
284
|
terminalReason = 'fatal(no-respawn: bad key/4xx/anchor)';
|
|
270
|
-
|
|
285
|
+
// Exit 64 (FATAL_EXIT_CODE), not 1, so the bash relauncher BREAKS on a
|
|
286
|
+
// known-bad config instead of relaunching it forever. adr: adr/monitor-resilience.md
|
|
287
|
+
process.exitCode = exports.FATAL_EXIT_CODE;
|
|
271
288
|
break;
|
|
272
289
|
}
|
|
273
290
|
// Child signaled "my consumer is gone" — the Monitor task's stdout/stderr
|
|
@@ -299,12 +316,14 @@ async function runSupervisor() {
|
|
|
299
316
|
if (heartbeat)
|
|
300
317
|
clearInterval(heartbeat);
|
|
301
318
|
if (session)
|
|
302
|
-
(0, watcher_registry_1.
|
|
319
|
+
(0, watcher_registry_1.removeWatcherEntry)(session, process.pid);
|
|
303
320
|
if (leaseEnabled) {
|
|
304
321
|
await bestEffortFetch(deregisterUrl(cfg.apiUrl, session), cfg.apiKey, 'DELETE', GOODBYE_TIMEOUT_MS);
|
|
305
322
|
}
|
|
306
323
|
process.off('SIGINT', onSigint);
|
|
307
324
|
process.off('SIGTERM', onSigterm);
|
|
325
|
+
process.off('uncaughtException', onUncaught);
|
|
326
|
+
process.off('unhandledRejection', onRejection);
|
|
308
327
|
}
|
|
309
328
|
/** Sleep that polls a shutdown predicate every 100ms so the supervisor
|
|
310
329
|
* wakes promptly on signal-driven shutdown without needing a shared
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox-watch-supervisor.js","sourceRoot":"","sources":["../../src/commands/inbox-watch-supervisor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;qCA0BqC;;;AA0DrC,8DAWC;AA0DD,
|
|
1
|
+
{"version":3,"file":"inbox-watch-supervisor.js","sourceRoot":"","sources":["../../src/commands/inbox-watch-supervisor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;qCA0BqC;;;AA0DrC,8DAWC;AA0DD,sCAoLC;AAjTD,iDAAoD;AACpD,+CAAgF;AAChF,yDAA8G;AAE9G,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,6EAA6E;AAC7E,yCAAyC;AACzC,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,WAAW;AACX,4EAA4E;AAC5E,8EAA8E;AAC9E,iFAAiF;AACjF,oEAAoE;AACpE,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,6CAA6C;AAE7C,gFAAgF;AAChF,oBAAoB;AACpB,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACpC,6EAA6E;AAC7E,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAEjC,oEAAoE;AACpE,iEAAiE;AACjE,qCAAqC;AACxB,QAAA,aAAa,GAAG,qBAAqB,CAAC;AAEnD,2DAA2D;AAC3D,+DAA+D;AAC/D,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAC1C,MAAM,yBAAyB,GAAG,MAAM,CAAC;AACzC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AACpC,qEAAqE;AACrE,oDAAoD;AACpD,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAE3C,oEAAoE;AACpE,qEAAqE;AACrE,qEAAqE;AACrE,kEAAkE;AACrD,QAAA,eAAe,GAAG,EAAE,CAAC;AAElC;;;;;;yBAMyB;AACzB,SAAgB,yBAAyB;IACvC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;QACtC,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAA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AC,GAAG,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC;QACF,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,65 +1,73 @@
|
|
|
1
|
-
/** Local watcher process registry +
|
|
1
|
+
/** Local watcher process registry + COUNT-CAP (the post-saga model).
|
|
2
2
|
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* (consumer dead, process still respawning) as "armed". Two local signals fix
|
|
10
|
-
* that:
|
|
3
|
+
* THE LESSON (adr/monitor-resilience.md, "⭐ The watcher in one pass"): a
|
|
4
|
+
* functional watcher and an orphaned-but-alive one are EXTERNALLY
|
|
5
|
+
* INDISTINGUISHABLE — same command line, same live PID. Only the watcher itself
|
|
6
|
+
* can tell, via its own stdout pipe (EPIPE). So every external reaper that
|
|
7
|
+
* *judged* orphan-ness (ancestry, owner-pid, monitor-pid) was guessing, and the
|
|
8
|
+
* guesses false-killed live watchers — the 548-kill saga in one line.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* to gate re-arming with zero cloud dependency and zero ghost-lease lag.
|
|
15
|
-
* Paired with EPIPE-terminal in the watcher (a watcher whose consumer pipe
|
|
16
|
-
* breaks exits and removes its own pidfile), a live pidfile means a live,
|
|
17
|
-
* *consumed* watcher.
|
|
10
|
+
* This module no longer judges. Two reliable facts replace the one unknowable
|
|
11
|
+
* one:
|
|
18
12
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* unrelated node server. A bug can at worst kill a watcher that then
|
|
26
|
-
* re-arms; it can never touch the operator's work.
|
|
13
|
+
* 1. **pidfile registry** — `~/.greprag/watchers/<short>.json` is a LIST of every
|
|
14
|
+
* supervisor armed for that session (`{short,pid,startedAt,ownerPid}`). A
|
|
15
|
+
* supervisor appends on arm and removes its own entry on terminal exit; a
|
|
16
|
+
* hard kill leaves a dead entry that the alive-filter sweeps. `isLocallyArmed`
|
|
17
|
+
* = "any entry alive". (Multiple live supervisors per session is normal under
|
|
18
|
+
* the June-8 spray; the count-cap bounds them.)
|
|
27
19
|
*
|
|
28
|
-
*
|
|
20
|
+
* 2. **count-cap** — `reapOrphanWatchers` keeps the K freshest LIVE watchers per
|
|
21
|
+
* session and kills only the surplus, NEVER below K. No death-detection → no
|
|
22
|
+
* false-kill; a floor of K → it can never reap to zero, so the bug that broke
|
|
23
|
+
* liveness every time is structurally impossible. "Freshest" is a *bias*
|
|
24
|
+
* toward the just-armed functional one, not a guarantee — and that's fine:
|
|
25
|
+
* EPIPE kills a wrongly-kept orphan in ~30s and the supervisor respawns. It is
|
|
26
|
+
* **snapshot-free** (per-session file reads + `pidAlive()` syscalls), so the
|
|
27
|
+
* 06-05b conhost-OOM engine — a `powershell Get-CimInstance` per SessionStart —
|
|
28
|
+
* is gone from the cleanup path entirely.
|
|
29
|
+
*
|
|
30
|
+
* EPIPE-terminal (in the watcher) + the supervisor's programmatic respawn do the
|
|
31
|
+
* real liveness work; the count-cap only bounds the pile. adr: adr/monitor-resilience.md */
|
|
32
|
+
/** Default per-session watcher floor: keep this many freshest live watchers, reap
|
|
33
|
+
* only the surplus above it, never below it. K=2 = the live one + one margin. */
|
|
34
|
+
export declare const DEFAULT_WATCHER_CAP = 2;
|
|
29
35
|
export interface WatcherPidRecord {
|
|
30
36
|
short: string;
|
|
31
37
|
pid: number;
|
|
32
38
|
startedAt: number;
|
|
33
39
|
ownerPid?: number;
|
|
34
40
|
}
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* without enumerating the process table. Best-effort: a failed write only means
|
|
38
|
-
* `isLocallyArmed` falls back to re-arming, never a crash. */
|
|
41
|
+
/** APPEND this supervisor's entry to the session's list (pruning dead entries as
|
|
42
|
+
* it goes). Best-effort. adr: adr/monitor-resilience.md */
|
|
39
43
|
export declare function writeWatcherPidfile(short: string, pid: number, ownerPid?: number): void;
|
|
44
|
+
/** Remove THIS supervisor's entry (called on a supervisor's terminal exit). */
|
|
45
|
+
export declare function removeWatcherEntry(short: string, pid: number): void;
|
|
46
|
+
/** Remove a session's whole pidfile (legacy / full sweep). */
|
|
40
47
|
export declare function removeWatcherPidfile(short: string): void;
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
48
|
+
/** The session→owner record at `~/.greprag/watchers/<short>.owner`: the CURRENT
|
|
49
|
+
* claude.exe PID for a session, refreshed on every SessionStart (so a restart
|
|
50
|
+
* re-resolves it within seconds), plus a `deadSince` stamp the GC uses to reap an
|
|
51
|
+
* owner only after it has stayed dead past the grace window — NOT a frozen
|
|
52
|
+
* arm-time PID, which was the owner-pid reaper's fatal flaw. adr: adr/monitor-resilience.md */
|
|
53
|
+
export interface SessionOwner {
|
|
54
|
+
pid: number;
|
|
55
|
+
ts: number;
|
|
56
|
+
deadSince?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Append-only diagnostic audit log at ~/.greprag/watchers/audit.log. ALWAYS ON so
|
|
59
|
+
* every arm / terminal exit / cap-kill leaves a trail. Behaviour-neutral: pure
|
|
60
|
+
* observation, never gates a kill or an arm. adr: adr/monitor-resilience.md */
|
|
47
61
|
export declare function watcherAuditLog(event: string): void;
|
|
48
|
-
/** Local-first arm check:
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* dead, socket still open) as armed and so both (a) suppresses re-arm when the
|
|
53
|
-
* real watcher is gone and (b) lets re-arm stack new watchers on undead
|
|
54
|
-
* orphans. A dead-PID pidfile is swept here so the next turn re-arms. */
|
|
62
|
+
/** Local-first arm check: does this session have ANY live watcher process on THIS
|
|
63
|
+
* machine? Ground truth for "armed" — the consumer (the Monitor task) is local,
|
|
64
|
+
* so a live local entry means a live, consumed watcher. Sweeps dead entries as it
|
|
65
|
+
* reads, so a hard-killed watcher doesn't read as armed. */
|
|
55
66
|
export declare function isLocallyArmed(short: string): boolean;
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* is computed on demand from ground truth, never a cached/replicated list, so it
|
|
61
|
-
* cannot go stale the way the cloud `/attached` registry does. adr:
|
|
62
|
-
* adr/monitor-resilience.md */
|
|
67
|
+
/** Every session whose watcher process is alive on THIS machine right now —
|
|
68
|
+
* computed on demand from the pidfile registry + OS liveness, sweeping dead
|
|
69
|
+
* entries. Most-recently-armed first. This is what the desk-line returns when the
|
|
70
|
+
* cloud asks "what's truly active?". adr: adr/monitor-resilience.md */
|
|
63
71
|
export declare function listLocalLiveWatchers(): WatcherPidRecord[];
|
|
64
72
|
export interface ProcRow {
|
|
65
73
|
pid: number;
|
|
@@ -67,35 +75,47 @@ export interface ProcRow {
|
|
|
67
75
|
name: string;
|
|
68
76
|
cmd: string;
|
|
69
77
|
}
|
|
70
|
-
/** Resolve the owning claude.exe PID for the CURRENT process by walking its
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* 2026-06-05: a supervisor's ancestry to claude.exe is already severed at arm
|
|
75
|
-
* time). The hook stamps the result into the watch command (`--owner-pid`) so
|
|
76
|
-
* the reaper can later ask "is that exact claude.exe still alive?" instead of
|
|
77
|
-
* re-walking a chain that no longer exists. Returns null if no claude.exe
|
|
78
|
-
* ancestor is found (caller omits the flag → reaper falls back to ancestry).
|
|
79
|
-
* adr: adr/monitor-resilience.md */
|
|
78
|
+
/** Resolve the owning claude.exe PID for the CURRENT process by walking its parent
|
|
79
|
+
* chain. MUST be called from a hook (a live descendant of claude.exe). Stamped
|
|
80
|
+
* into the arm command (`--owner-pid`) for audit continuity. Cache hit skips the
|
|
81
|
+
* snapshot. Returns null if no claude.exe ancestor. adr: adr/monitor-resilience.md */
|
|
80
82
|
export declare function resolveClaudeOwnerPid(cacheShort?: string): number | null;
|
|
81
|
-
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
export declare function
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
/** Pure verdict (testable): given a session's LIVE entries, keep the K freshest
|
|
84
|
+
* (by startedAt), return the older surplus to kill. Never kills when count ≤ K;
|
|
85
|
+
* never kills more than count − K; never the K freshest. This is the entire
|
|
86
|
+
* liveness-safety guarantee — no death judgment, just a count + a floor. */
|
|
87
|
+
export declare function capSurplusVerdict(entries: WatcherPidRecord[], K: number): {
|
|
88
|
+
keep: WatcherPidRecord[];
|
|
89
|
+
kill: WatcherPidRecord[];
|
|
88
90
|
};
|
|
89
91
|
export interface ReapResult {
|
|
90
92
|
scanned: number;
|
|
91
93
|
orphans: number;
|
|
92
94
|
killed: number[];
|
|
93
95
|
}
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* the
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
/** Count-cap every session: keep the K freshest LIVE watchers, kill only the
|
|
97
|
+
* surplus. NO death-detection, NO process snapshot — per-session file reads +
|
|
98
|
+
* `pidAlive()`, and a `taskkill` only when there is genuine surplus. Run at
|
|
99
|
+
* SessionStart (via the recap hook) and exposed as `greprag inbox reap`. The name
|
|
100
|
+
* is retained for its callers; the behaviour is "cap", not "judge orphans".
|
|
101
|
+
* adr: adr/monitor-resilience.md */
|
|
102
|
+
export declare function reapOrphanWatchers(K?: number): ReapResult;
|
|
103
|
+
/** Minutes a session's owner must stay CONTINUOUSLY dead before its watchers are
|
|
104
|
+
* GC'd. Must exceed the worst-case claude.exe restart→SessionStart window (which
|
|
105
|
+
* is seconds), so a restart can never be mistaken for a death. */
|
|
106
|
+
export declare const GC_GRACE_MS: number;
|
|
107
|
+
/** Pure GC decision (testable): given a session's owner record and whether its PID
|
|
108
|
+
* is alive right now, decide keep / start-the-grace-clock / reap. */
|
|
109
|
+
export declare function gcVerdict(owner: {
|
|
110
|
+
ts: number;
|
|
111
|
+
deadSince?: number;
|
|
112
|
+
} | null, ownerAlive: boolean, now: number, graceMs: number): 'keep' | 'mark-dead' | 'reap';
|
|
113
|
+
export interface GcResult {
|
|
114
|
+
reaped: string[];
|
|
115
|
+
killed: number[];
|
|
116
|
+
}
|
|
117
|
+
/** Reap every watcher of a session whose owning claude.exe has stayed dead past the
|
|
118
|
+
* grace window. Run at SessionStart, AFTER refreshing THIS session's own owner
|
|
119
|
+
* (so it is never its own victim). No process snapshot — owner-file reads +
|
|
120
|
+
* pidAlive() syscalls. adr: adr/monitor-resilience.md */
|
|
121
|
+
export declare function gcDeadSessions(graceMs?: number): GcResult;
|