dorfl 0.11.1 → 0.11.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.
@@ -3,6 +3,7 @@ import { existsSync, readFileSync } from 'node:fs';
3
3
  import { NullHarness, pidAlive, registerHarness, } from './harness.js';
4
4
  import { generateSessionPath } from './session-path.js';
5
5
  import { lastAssistantText } from './watch-session.js';
6
+ import { reapProcessGroup } from './reap-agent-tree.js';
6
7
  /**
7
8
  * The **pi** harness adapter (ADR §5) — the first real agent harness
8
9
  * `dorfl` drives. It fulfils the harness seam introduced by
@@ -186,8 +187,47 @@ export class PiHarness {
186
187
  cwd: input.dir,
187
188
  env: input.env ?? process.env,
188
189
  stdio: ['pipe', 'pipe', 'pipe'],
190
+ // PROCESS-GROUP LEADER (observation
191
+ // `checkpoint-releases-lock-while-predecessor-agent-still-writes`): pi's
192
+ // pgid becomes its own pid, so the deadline stop can signal the WHOLE
193
+ // agent tree with `kill(-pgid)` and VERIFY it is gone. Without this,
194
+ // `child.kill()` reached exactly one pid: subagents / MCP servers / tool
195
+ // subshells survived, were re-parented to init (so no ppid walk could even
196
+ // find them), and kept writing into the worktree while a SUCCESSOR agent
197
+ // was already editing it. A pgid is inherited by every descendant and is
198
+ // unaffected by re-parenting, which is why it is the only usable handle.
199
+ // We deliberately do NOT `unref()` here: the parent keeps supervising the
200
+ // child (and forwards its own termination to the group, below).
201
+ detached: true,
189
202
  });
190
203
  record.pid = child.pid; // the liveness anchor, recorded like spawnSync.
204
+ // The group id equals the leader's pid because we spawned `detached`.
205
+ const pgid = child.pid;
206
+ // `detached: true` takes pi OUT of our terminal's foreground process group,
207
+ // so a Ctrl-C / `kill` aimed at the runner would no longer reach it — which
208
+ // would WIDEN the very "aborting `do` does not kill the spawned agent tree"
209
+ // gap this change is closing. Forward our own termination to the group for
210
+ // as long as the child is live, so detaching strictly improves reachability
211
+ // instead of trading one orphan class for another.
212
+ const forwardSignal = (signal) => () => {
213
+ if (pgid === undefined) {
214
+ return;
215
+ }
216
+ try {
217
+ process.kill(-pgid, signal);
218
+ }
219
+ catch {
220
+ // Already gone; nothing to forward to.
221
+ }
222
+ };
223
+ const onSigint = forwardSignal('SIGINT');
224
+ const onSigterm = forwardSignal('SIGTERM');
225
+ process.on('SIGINT', onSigint);
226
+ process.on('SIGTERM', onSigterm);
227
+ const stopForwarding = () => {
228
+ process.off('SIGINT', onSigint);
229
+ process.off('SIGTERM', onSigterm);
230
+ };
191
231
  let stderr = '';
192
232
  child.stderr?.on('data', (chunk) => {
193
233
  stderr += chunk.toString('utf8');
@@ -225,19 +265,32 @@ export class PiHarness {
225
265
  return;
226
266
  }
227
267
  timedOut = true;
268
+ // Signal the whole GROUP, not just pi: the descendants are exactly the
269
+ // processes that outlive it and keep writing to the worktree.
228
270
  try {
229
- child.kill('SIGTERM');
271
+ if (pgid !== undefined) {
272
+ process.kill(-pgid, 'SIGTERM');
273
+ }
274
+ else {
275
+ child.kill('SIGTERM');
276
+ }
230
277
  }
231
278
  catch {
232
- // Best-effort: a already-exited child throws ESRCH; the `exit`
233
- // handler will still settle the promise.
279
+ // Best-effort: an already-exited group throws ESRCH; the `exit`
280
+ // handler will still settle the promise, and the post-exit reap below
281
+ // is what actually VERIFIES the tree is gone.
234
282
  }
235
283
  hardTimer = setTimeout(() => {
236
284
  if (settled) {
237
285
  return;
238
286
  }
239
287
  try {
240
- child.kill('SIGKILL');
288
+ if (pgid !== undefined) {
289
+ process.kill(-pgid, 'SIGKILL');
290
+ }
291
+ else {
292
+ child.kill('SIGKILL');
293
+ }
241
294
  }
242
295
  catch {
243
296
  // Best-effort: see above.
@@ -253,6 +306,7 @@ export class PiHarness {
253
306
  }
254
307
  settled = true;
255
308
  clearDeadlineTimers();
309
+ stopForwarding();
256
310
  reject(new Error(`failed to spawn pi (${this.piBin}): ${err.message}`));
257
311
  });
258
312
  // Resolve on `exit` (pi itself terminated), NOT `close`: `close` waits for
@@ -265,6 +319,7 @@ export class PiHarness {
265
319
  }
266
320
  settled = true;
267
321
  clearDeadlineTimers();
322
+ stopForwarding();
268
323
  // Release our end of the stdio pipes so a leaked grandchild's inherited
269
324
  // FDs stop keeping our streams referenced; `unref` the child handle too.
270
325
  child.stdout?.destroy();
@@ -272,15 +327,56 @@ export class PiHarness {
272
327
  child.stdin?.destroy();
273
328
  child.unref?.();
274
329
  const status = code ?? -1;
275
- resolve({
276
- ok: status === 0 && !timedOut,
277
- record,
278
- detail: status === 0 && !timedOut ? undefined : stderr.trim() || undefined,
279
- timedOut: timedOut ? true : undefined,
280
- // Read the agent's ANSWER from the `.jsonl` at `exit` — the same
281
- // last-assistant-text read `launch` does at return (task
282
- // `harness-agent-output`); the process has exited so the log is final.
283
- output: readLastAssistantText(sessionFile),
330
+ const settleWith = (reap) => {
331
+ resolve({
332
+ ok: status === 0 && !timedOut,
333
+ record,
334
+ detail: status === 0 && !timedOut
335
+ ? undefined
336
+ : stderr.trim() || undefined,
337
+ timedOut: timedOut ? true : undefined,
338
+ ...(reap ? { reap } : {}),
339
+ // Read the agent's ANSWER from the `.jsonl` at `exit` — the same
340
+ // last-assistant-text read `launch` does at return (task
341
+ // `harness-agent-output`); the process has exited so the log is final.
342
+ output: readLastAssistantText(sessionFile),
343
+ });
344
+ };
345
+ if (!timedOut || pgid === undefined) {
346
+ // Normal exit: we signalled nothing, so there is nothing to prove and
347
+ // nothing to kill. Byte-for-byte the pre-existing behaviour — in
348
+ // particular we do NOT reap a group the agent may have deliberately left
349
+ // running behind a successful run.
350
+ settleWith();
351
+ return;
352
+ }
353
+ // DEADLINE STOP: pi's own exit says NOTHING about its descendants — that
354
+ // assumption is the defect. Before this promise resolves (which is the
355
+ // runner's cue to save WIP, release the lock and dispatch a SUCCESSOR into
356
+ // this same worktree), reap the group and VERIFY it is gone. Bounded by
357
+ // construction, so this cannot reintroduce the resolve-on-`exit` hang the
358
+ // doc-comment above guards against: a tree that will not die resolves with
359
+ // `reaped: false` and the caller refuses to release the lock.
360
+ void reapProcessGroup({ pgid })
361
+ .then((result) => {
362
+ settleWith({
363
+ reaped: result.reaped,
364
+ pgid,
365
+ escalatedToSigkill: result.escalatedToSigkill,
366
+ detail: result.detail,
367
+ });
368
+ })
369
+ .catch((err) => {
370
+ // A throw here means we could not even RUN the verification, which is
371
+ // indistinguishable from "might still be alive" — report it as an
372
+ // unproven reap rather than silently claiming success.
373
+ settleWith({
374
+ reaped: false,
375
+ pgid,
376
+ detail: `could not verify that the agent process group ${pgid} exited ` +
377
+ `(${err instanceof Error ? err.message : String(err)}); treating ` +
378
+ 'the predecessor as possibly still writing to the worktree.',
379
+ });
284
380
  });
285
381
  });
286
382
  // Feed the same prepared prompt on stdin, then close it (pi reads to EOF).
@@ -1 +1 @@
1
- {"version":3,"file":"pi-harness.js","sourceRoot":"","sources":["../src/pi-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,UAAU,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AACjD,OAAO,EACN,WAAW,EACX,QAAQ,EACR,eAAe,GAOf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AA4BhD;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAS;IACZ,OAAO,GAAG,IAAI,CAAC;IACP,KAAK,CAAS;IACd,SAAS,CAAW;IAErC,YAAY,UAA4B,EAAE;QACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC;QAC7C,IAA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,OAAO,KAAK,IAAI,EAAE,CAAC;QAC9B,OAAO,IAAI,SAAS,CAAC,EAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,IAAI,WAAW,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * **Reap a stopped agent's whole PROCESS TREE, and VERIFY it is gone** (spec
3
+ * `graceful-pre-timeout-wip-checkpoint`, observation
4
+ * `checkpoint-releases-lock-while-predecessor-agent-still-writes`).
5
+ *
6
+ * ## The gap this closes
7
+ *
8
+ * The deadline checkpoint used to `child.kill('SIGTERM')` the agent process and
9
+ * treat the signal as if it were the outcome: the moment pi's own `exit` fired,
10
+ * the runner saved the WIP, RELEASED the item lock, and let the next tick
11
+ * dispatch a CONTINUATION agent into the SAME worktree. But `child.kill` signals
12
+ * exactly ONE pid, and a modern agent is a TREE (subagent processes, MCP servers,
13
+ * model proxies, tool subshells). Those descendants survive the parent's SIGTERM,
14
+ * and once pi exits they are re-parented to init — so they can no longer even be
15
+ * FOUND by walking `ppid`, while they keep writing into the worktree.
16
+ *
17
+ * Observed on a real run: the checkpoint saved WIP at 02:13, a continuation agent
18
+ * onboarded into the same worktree at ~02:15, and the predecessor's session log
19
+ * kept being written until 02:19:29 — four minutes INTO the successor's run,
20
+ * whose opening `git status` had already read the tree as clean. Nothing was lost
21
+ * only because the two happened to touch different files. The shape is the
22
+ * defect: one lock, one working tree, two live writers. A write landing after the
23
+ * successor's `git status` is invisible to it; a write landing during its edits
24
+ * can be clobbered either way; and the successor can commit the predecessor's
25
+ * half-finished edits as its own, under a message describing something else.
26
+ *
27
+ * ## Why the PROCESS GROUP is the handle
28
+ *
29
+ * A pid-tree walk cannot work here: the descendants we must reap are precisely
30
+ * the ones that OUTLIVE the parent, and an orphan's `ppid` is gone. A process
31
+ * GROUP id, by contrast, is inherited by every descendant and is NOT changed by
32
+ * re-parenting. So if the agent is spawned as a group LEADER (`detached: true`,
33
+ * making its pgid equal its pid), `kill(-pgid, …)` reaches the entire tree,
34
+ * orphans included — which is why {@link reapProcessGroup} takes a pgid and why
35
+ * `pi-harness.ts` spawns the deadline-capable async launch detached.
36
+ *
37
+ * ## Signal, then VERIFY — never assume
38
+ *
39
+ * The point of the whole module is that sending a signal is not evidence that
40
+ * anything died. So: SIGTERM the group, POLL until it is actually gone, escalate
41
+ * to SIGKILL after a grace, keep polling, and if it STILL will not die, say so
42
+ * LOUDLY and let the caller refuse to release the lock. A checkpoint that cannot
43
+ * prove the predecessor is dead must not hand the worktree to a successor.
44
+ */
45
+ /**
46
+ * How long to wait after SIGTERM before escalating to SIGKILL. Matches
47
+ * `pi-harness.ts`'s `DEADLINE_SIGKILL_GRACE_MS` intent: enough for an agent to
48
+ * flush its session log and exit cleanly, short enough not to stall a CI leg.
49
+ */
50
+ export declare const REAP_SIGTERM_GRACE_MS = 10000;
51
+ /** How long to keep waiting after SIGKILL before declaring the reap FAILED. */
52
+ export declare const REAP_SIGKILL_TIMEOUT_MS = 5000;
53
+ /** The outcome of a {@link reapProcessGroup} attempt. */
54
+ export interface ReapResult {
55
+ /**
56
+ * True iff the group is VERIFIED gone (observed non-existent, not merely
57
+ * signalled). Only a `true` here licenses releasing the item lock and
58
+ * dispatching a successor into the same worktree.
59
+ */
60
+ reaped: boolean;
61
+ /** True iff SIGKILL was needed (the tree ignored SIGTERM) — worth reporting. */
62
+ escalatedToSigkill: boolean;
63
+ /** Total wall-clock ms spent waiting for the tree to die. */
64
+ waitedMs: number;
65
+ /** A human-readable account, always populated (the LOUD failure text). */
66
+ detail: string;
67
+ }
68
+ /**
69
+ * Is any process still alive in process group `pgid`?
70
+ *
71
+ * `process.kill(-pgid, 0)` is the liveness probe: signal 0 performs the
72
+ * permission/existence check WITHOUT delivering a signal (the same technique
73
+ * `harness.ts`'s {@link pidAlive} uses for a single pid, widened to the group).
74
+ *
75
+ * - It THROWS `ESRCH` when no process in the group exists ⇒ the group is gone.
76
+ * - It THROWS `EPERM` when the group exists but we may not signal it. That is
77
+ * still "alive", and reporting it as dead would be the very assumption this
78
+ * module exists to remove — so `EPERM` reads as ALIVE.
79
+ * - It succeeds ⇒ alive.
80
+ */
81
+ export declare function processGroupAlive(pgid: number): boolean;
82
+ /**
83
+ * SIGTERM process group `pgid`, wait for it to ACTUALLY exit, escalate to
84
+ * SIGKILL after {@link REAP_SIGTERM_GRACE_MS}, and report whether the tree is
85
+ * VERIFIED gone.
86
+ *
87
+ * Bounded by construction: at worst `sigtermGraceMs + sigkillTimeoutMs` before it
88
+ * returns `reaped: false` with a loud `detail`. It never waits indefinitely, so
89
+ * it cannot reintroduce the runner-hang the async launch's resolve-on-`exit`
90
+ * discipline exists to avoid.
91
+ */
92
+ export declare function reapProcessGroup(params: {
93
+ /** The process GROUP id to reap (the group leader's pid). */
94
+ pgid: number;
95
+ sigtermGraceMs?: number;
96
+ sigkillTimeoutMs?: number;
97
+ /** Injectable sleep so tests need not burn real seconds. */
98
+ wait?: (ms: number) => Promise<void>;
99
+ /**
100
+ * Injectable liveness probe (default {@link processGroupAlive}). Exists so the
101
+ * REFUSAL path — a tree that survives SIGTERM *and* SIGKILL — can be tested
102
+ * deterministically. There is no portable way to create a genuinely unkillable
103
+ * process, and the alternative (a group we truly cannot signal) would risk the
104
+ * test process itself, so the probe is the seam.
105
+ */
106
+ alive?: (pgid: number) => boolean;
107
+ }): Promise<ReapResult>;
108
+ //# sourceMappingURL=reap-agent-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reap-agent-tree.d.ts","sourceRoot":"","sources":["../src/reap-agent-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAKH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAE5C,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,OAAQ,CAAC;AAE7C,yDAAyD;AACzD,MAAM,WAAW,UAAU;IAC1B;;;;OAIG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB,gFAAgF;IAChF,kBAAkB,EAAE,OAAO,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;CACf;AAUD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgBvD;AAWD;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC9C,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4DAA4D;IAC5D,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CAClC,GAAG,OAAO,CAAC,UAAU,CAAC,CAyEtB"}
@@ -0,0 +1,173 @@
1
+ /**
2
+ * **Reap a stopped agent's whole PROCESS TREE, and VERIFY it is gone** (spec
3
+ * `graceful-pre-timeout-wip-checkpoint`, observation
4
+ * `checkpoint-releases-lock-while-predecessor-agent-still-writes`).
5
+ *
6
+ * ## The gap this closes
7
+ *
8
+ * The deadline checkpoint used to `child.kill('SIGTERM')` the agent process and
9
+ * treat the signal as if it were the outcome: the moment pi's own `exit` fired,
10
+ * the runner saved the WIP, RELEASED the item lock, and let the next tick
11
+ * dispatch a CONTINUATION agent into the SAME worktree. But `child.kill` signals
12
+ * exactly ONE pid, and a modern agent is a TREE (subagent processes, MCP servers,
13
+ * model proxies, tool subshells). Those descendants survive the parent's SIGTERM,
14
+ * and once pi exits they are re-parented to init — so they can no longer even be
15
+ * FOUND by walking `ppid`, while they keep writing into the worktree.
16
+ *
17
+ * Observed on a real run: the checkpoint saved WIP at 02:13, a continuation agent
18
+ * onboarded into the same worktree at ~02:15, and the predecessor's session log
19
+ * kept being written until 02:19:29 — four minutes INTO the successor's run,
20
+ * whose opening `git status` had already read the tree as clean. Nothing was lost
21
+ * only because the two happened to touch different files. The shape is the
22
+ * defect: one lock, one working tree, two live writers. A write landing after the
23
+ * successor's `git status` is invisible to it; a write landing during its edits
24
+ * can be clobbered either way; and the successor can commit the predecessor's
25
+ * half-finished edits as its own, under a message describing something else.
26
+ *
27
+ * ## Why the PROCESS GROUP is the handle
28
+ *
29
+ * A pid-tree walk cannot work here: the descendants we must reap are precisely
30
+ * the ones that OUTLIVE the parent, and an orphan's `ppid` is gone. A process
31
+ * GROUP id, by contrast, is inherited by every descendant and is NOT changed by
32
+ * re-parenting. So if the agent is spawned as a group LEADER (`detached: true`,
33
+ * making its pgid equal its pid), `kill(-pgid, …)` reaches the entire tree,
34
+ * orphans included — which is why {@link reapProcessGroup} takes a pgid and why
35
+ * `pi-harness.ts` spawns the deadline-capable async launch detached.
36
+ *
37
+ * ## Signal, then VERIFY — never assume
38
+ *
39
+ * The point of the whole module is that sending a signal is not evidence that
40
+ * anything died. So: SIGTERM the group, POLL until it is actually gone, escalate
41
+ * to SIGKILL after a grace, keep polling, and if it STILL will not die, say so
42
+ * LOUDLY and let the caller refuse to release the lock. A checkpoint that cannot
43
+ * prove the predecessor is dead must not hand the worktree to a successor.
44
+ */
45
+ /** Poll interval while waiting for a signalled group to actually exit. */
46
+ const REAP_POLL_MS = 50;
47
+ /**
48
+ * How long to wait after SIGTERM before escalating to SIGKILL. Matches
49
+ * `pi-harness.ts`'s `DEADLINE_SIGKILL_GRACE_MS` intent: enough for an agent to
50
+ * flush its session log and exit cleanly, short enough not to stall a CI leg.
51
+ */
52
+ export const REAP_SIGTERM_GRACE_MS = 10_000;
53
+ /** How long to keep waiting after SIGKILL before declaring the reap FAILED. */
54
+ export const REAP_SIGKILL_TIMEOUT_MS = 5_000;
55
+ /** Sleep helper (injectable clock is not needed: callers inject `wait` in tests). */
56
+ function sleep(ms) {
57
+ return new Promise((resolve) => {
58
+ const timer = setTimeout(resolve, ms);
59
+ timer.unref?.();
60
+ });
61
+ }
62
+ /**
63
+ * Is any process still alive in process group `pgid`?
64
+ *
65
+ * `process.kill(-pgid, 0)` is the liveness probe: signal 0 performs the
66
+ * permission/existence check WITHOUT delivering a signal (the same technique
67
+ * `harness.ts`'s {@link pidAlive} uses for a single pid, widened to the group).
68
+ *
69
+ * - It THROWS `ESRCH` when no process in the group exists ⇒ the group is gone.
70
+ * - It THROWS `EPERM` when the group exists but we may not signal it. That is
71
+ * still "alive", and reporting it as dead would be the very assumption this
72
+ * module exists to remove — so `EPERM` reads as ALIVE.
73
+ * - It succeeds ⇒ alive.
74
+ */
75
+ export function processGroupAlive(pgid) {
76
+ if (!Number.isInteger(pgid) || pgid <= 1) {
77
+ // pgid 0/1 (or a bogus value) would mean "our own group" / init — signalling
78
+ // those would be catastrophic, so never claim they are ours to reap.
79
+ return false;
80
+ }
81
+ try {
82
+ process.kill(-pgid, 0);
83
+ return true;
84
+ }
85
+ catch (err) {
86
+ const code = err.code;
87
+ if (code === 'EPERM') {
88
+ return true; // exists, just not signallable by us.
89
+ }
90
+ return false; // ESRCH (or anything else): treat as gone.
91
+ }
92
+ }
93
+ /** Signal a whole process group, tolerating an already-dead group. */
94
+ function signalGroup(pgid, signal) {
95
+ try {
96
+ process.kill(-pgid, signal);
97
+ }
98
+ catch {
99
+ // ESRCH: already gone — the wait loop below observes that and succeeds.
100
+ }
101
+ }
102
+ /**
103
+ * SIGTERM process group `pgid`, wait for it to ACTUALLY exit, escalate to
104
+ * SIGKILL after {@link REAP_SIGTERM_GRACE_MS}, and report whether the tree is
105
+ * VERIFIED gone.
106
+ *
107
+ * Bounded by construction: at worst `sigtermGraceMs + sigkillTimeoutMs` before it
108
+ * returns `reaped: false` with a loud `detail`. It never waits indefinitely, so
109
+ * it cannot reintroduce the runner-hang the async launch's resolve-on-`exit`
110
+ * discipline exists to avoid.
111
+ */
112
+ export async function reapProcessGroup(params) {
113
+ const { pgid, sigtermGraceMs = REAP_SIGTERM_GRACE_MS, sigkillTimeoutMs = REAP_SIGKILL_TIMEOUT_MS, wait = sleep, alive = processGroupAlive, } = params;
114
+ const started = Date.now();
115
+ if (!alive(pgid)) {
116
+ return {
117
+ reaped: true,
118
+ escalatedToSigkill: false,
119
+ waitedMs: 0,
120
+ detail: `agent process group ${pgid} was already gone (nothing to reap).`,
121
+ };
122
+ }
123
+ // 1. SOFT: ask the whole tree to stop, then WAIT for it to be observably gone.
124
+ signalGroup(pgid, 'SIGTERM');
125
+ while (Date.now() - started < sigtermGraceMs) {
126
+ if (!alive(pgid)) {
127
+ const waitedMs = Date.now() - started;
128
+ return {
129
+ reaped: true,
130
+ escalatedToSigkill: false,
131
+ waitedMs,
132
+ detail: `agent process group ${pgid} exited on SIGTERM after ${waitedMs}ms ` +
133
+ '(verified gone).',
134
+ };
135
+ }
136
+ await wait(REAP_POLL_MS);
137
+ }
138
+ // 2. HARD: the tree ignored SIGTERM through the grace. SIGKILL it and keep
139
+ // verifying — a wedged agent still holding the worktree must not survive
140
+ // into the successor's run.
141
+ signalGroup(pgid, 'SIGKILL');
142
+ const killDeadline = Date.now() + sigkillTimeoutMs;
143
+ while (Date.now() < killDeadline) {
144
+ if (!alive(pgid)) {
145
+ const waitedMs = Date.now() - started;
146
+ return {
147
+ reaped: true,
148
+ escalatedToSigkill: true,
149
+ waitedMs,
150
+ detail: `agent process group ${pgid} ignored SIGTERM and was SIGKILLed; ` +
151
+ `exited after ${waitedMs}ms (verified gone).`,
152
+ };
153
+ }
154
+ await wait(REAP_POLL_MS);
155
+ }
156
+ // 3. LOUD FAILURE: we cannot prove the predecessor is dead. Say exactly that,
157
+ // and exactly what the caller must not do as a result.
158
+ const waitedMs = Date.now() - started;
159
+ return {
160
+ reaped: false,
161
+ escalatedToSigkill: true,
162
+ waitedMs,
163
+ detail: `REFUSING TO PROCEED: agent process group ${pgid} is STILL ALIVE ${waitedMs}ms ` +
164
+ 'after SIGTERM and SIGKILL (an unkillable/uninterruptible descendant — e.g. a ' +
165
+ 'process wedged in a kernel call, or one we lack permission to signal). It may ' +
166
+ 'still be WRITING to the worktree, so the item lock must NOT be released and no ' +
167
+ 'successor agent may onboard here: two live writers in one working tree can ' +
168
+ 'silently clobber each other and let a successor commit the predecessor’s ' +
169
+ `half-finished edits. Inspect and kill it by hand (\`ps -g ${pgid}\`, ` +
170
+ `\`kill -9 -${pgid}\`) before re-running this item.`,
171
+ };
172
+ }
173
+ //# sourceMappingURL=reap-agent-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reap-agent-tree.js","sourceRoot":"","sources":["../src/reap-agent-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,0EAA0E;AAC1E,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE5C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAkB7C,qFAAqF;AACrF,SAAS,KAAK,CAAC,EAAU;IACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACtC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC7C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;QAC1C,6EAA6E;QAC7E,qEAAqE;QACrE,OAAO,KAAK,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,CAAC,IAAI,CAA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ORKING-TREE writer sentinel** (observation
3
+ * `checkpoint-releases-lock-while-predecessor-agent-still-writes`).
4
+ *
5
+ * The per-item lock (`item-lock.ts`) guards the ITEM: it answers "who owns this
6
+ * task?" and it is what claim / requeue / bounce move around. Nothing guarded the
7
+ * WORKING TREE. Those are different resources, and the deadline checkpoint is
8
+ * exactly where they come apart: the checkpoint releases the item lock so the
9
+ * next tick can continue the task, but the tree the previous agent was editing is
10
+ * reused by the successor. If the predecessor is still alive, two agents write to
11
+ * one tree.
12
+ *
13
+ * The primary fix is to reap the predecessor and VERIFY it is gone before the
14
+ * lock moves (`reap-agent-tree.ts`). This sentinel is the INDEPENDENT backstop:
15
+ * even if a live writer survives by some route the reap did not cover (a
16
+ * deliberately `setsid`-ed grandchild, a stale run from a crashed runner, an
17
+ * operator manually re-driving an item), a second agent physically cannot onboard
18
+ * into a tree that already has a LIVE holder. It is deliberately keyed on the
19
+ * TREE, not on the item: two different items sharing one worktree is just as
20
+ * unsafe as two attempts at the same item.
21
+ *
22
+ * ## Where the sentinel lives, and why not in the tree
23
+ *
24
+ * It is written to the worktree's PRIVATE git directory (`git rev-parse
25
+ * --absolute-git-dir`, which for a linked worktree is
26
+ * `.../.git/worktrees/<name>/`), NOT to a file inside the working tree. That
27
+ * placement is load-bearing:
28
+ *
29
+ * - it is per-worktree (linked worktrees each get their own git dir), which is
30
+ * precisely the granularity we are guarding;
31
+ * - it can never appear in `git status`, so it cannot be mistaken for agent work,
32
+ * cannot be swept into a commit by a `git add -A`, and needs no new exclusion
33
+ * in the empty-diff backstop / `gc`'s cleanliness predicate (unlike
34
+ * `.dorfl-job.json`, which each of those has to filter out by name);
35
+ * - it is removed with the worktree, so it cannot outlive what it guards.
36
+ *
37
+ * ## Liveness, not presence
38
+ *
39
+ * A pid file that only records presence becomes a permanent blocker the first
40
+ * time a runner is `kill -9`ed. So the holder is checked for LIVENESS (its
41
+ * process group first, falling back to its pid) and a dead holder's sentinel is
42
+ * treated as stale and taken over. Only a genuinely live foreign writer refuses.
43
+ */
44
+ /** The sentinel filename inside the worktree's private git directory. */
45
+ export declare const WRITER_SENTINEL_FILENAME = "dorfl-writer.json";
46
+ /** The recorded holder of a worktree's writer sentinel. */
47
+ export interface WorktreeWriter {
48
+ /** The runner process that owns the agent writing in this tree. */
49
+ pid: number;
50
+ /** The agent's process GROUP, when the harness spawned a killable one. */
51
+ pgid?: number;
52
+ /** The item being built in this tree (diagnostics: names the other writer). */
53
+ slug: string;
54
+ /** ISO timestamp of acquisition (diagnostics: how long it has been held). */
55
+ startedAt: string;
56
+ }
57
+ /** The outcome of trying to become a worktree's sole writer. */
58
+ export type WorktreeWriterLock = {
59
+ acquired: true;
60
+ /** Release the sentinel. Idempotent, and safe if it was already stolen. */
61
+ release(): void;
62
+ } | {
63
+ acquired: false;
64
+ /** The LIVE holder that refused us (when it could be parsed). */
65
+ holder?: WorktreeWriter;
66
+ /** Human-readable refusal, naming the other writer. */
67
+ reason: string;
68
+ };
69
+ /** The sentinel path for `dir`, or `undefined` when `dir` is not a worktree. */
70
+ export declare function writerSentinelPath(dir: string, env?: NodeJS.ProcessEnv): string | undefined;
71
+ /** Read + parse the sentinel, or `undefined` when absent/corrupt. */
72
+ export declare function readWorktreeWriter(dir: string, env?: NodeJS.ProcessEnv): WorktreeWriter | undefined;
73
+ /**
74
+ * Is the recorded holder still running? Prefers the agent's process GROUP (which
75
+ * survives the group leader's death and so catches exactly the orphaned-writer
76
+ * case this exists for), and falls back to the runner pid.
77
+ */
78
+ export declare function writerAlive(holder: WorktreeWriter): boolean;
79
+ /**
80
+ * Claim `dir` as the SOLE agent-writable working tree for `slug`.
81
+ *
82
+ * Refuses when a DIFFERENT, still-LIVE writer holds it — the second-agent case
83
+ * the observation describes. A dead holder's sentinel is stale and is taken over
84
+ * silently (a `kill -9`ed runner must not poison the worktree forever), and our
85
+ * OWN pid re-acquiring is a no-op re-entry rather than a refusal.
86
+ *
87
+ * When `dir` is not a git worktree there is nowhere private to record the
88
+ * sentinel; that is reported as acquired with a no-op release, because this is a
89
+ * defence-in-depth backstop and must never become a new way for a legitimate run
90
+ * to fail.
91
+ */
92
+ export declare function acquireWorktreeWriterLock(params: {
93
+ dir: string;
94
+ slug: string;
95
+ /** The agent's process group, when known (the strongest liveness anchor). */
96
+ pgid?: number;
97
+ env?: NodeJS.ProcessEnv;
98
+ }): WorktreeWriterLock;
99
+ //# sourceMappingURL=worktree-writer-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktree-writer-lock.d.ts","sourceRoot":"","sources":["../src/worktree-writer-lock.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,yEAAyE;AACzE,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAE5D,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC9B,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,gEAAgE;AAChE,MAAM,MAAM,kBAAkB,GAC3B;IACA,QAAQ,EAAE,IAAI,CAAC;IACf,2EAA2E;IAC3E,OAAO,IAAI,IAAI,CAAC;CACf,GACD;IACA,QAAQ,EAAE,KAAK,CAAC;IAChB,iEAAiE;IACjE,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;CACd,CAAC;AAmBL,gFAAgF;AAChF,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,MAAM,EACX,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,GACrB,MAAM,GAAG,SAAS,CAKpB;AAED,qEAAqE;AACrE,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,MAAM,EACX,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,GACrB,cAA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