Skip to content

refactor(#1472): one killProcessGroup(child, { graceMs }) with SIGKILL escalation; pushLines on RingBuffer (closes the AsyncSubprocess trigger) - #1557

Merged
admarble merged 5 commits into
mainfrom
feature/1472-refactor-drivers-mcp-one-killprocessgroup-child-gr
Oct 19, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/1472-refactor-drivers-mcp-one-killprocessgroup-child-gr

Conversation

@admarble

@admarble admarble commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

All five ACs for #1472 are met, and both derived ACs too. The branch feature/1472-refactor-drivers-mcp-one-killprocessgroup-child-gr is pushed with two commits (1cf65d2e6, f7bdcfa6d). I opened no PR because this run is orchestrated (SEQUANT_ORCHESTRATOR=sequant-run), so the orchestrator opens it from this summary.

What changed:

  • New shared helper: src/lib/process-group.ts holds the only killProcessGroup(child, { graceMs }), which returns { requested }.
    • It sends SIGTERM to the group, ignores "process already gone" errors (ESRCH), and falls back to a direct kill on other errors.
    • It sends SIGKILL after graceMs unless the child has closed. Without graceMs there is no escalation.
    • It sends nothing to a child that has already exited, and a second call on the same child sends nothing.
    • The drivers' grace is a new constant, DRIVER_SIGKILL_GRACE_MS = 5000, defined here once rather than imported from the MCP tool.
  • RingBuffer: gains a { maxLineChars } option and pushLines(text: string). Capped lines come out byte-identical to the old driver form.
  • codex and opencode drivers: the local copies of both helpers are deleted. Each driver now records killRequested and passes it to its evaluator. A SIGKILL close after the driver's own kill now reports as Timeout after Ns.
  • src/mcp/tools/run.ts: the local killProcessGroup and sendSignal are deleted. All four call sites pass { graceMs: SIGKILL_GRACE_MS }; the constant and its fix(run): a watchdog-killed run writes no run log and half-deletes a clean worktree — worktree removal outruns the 5 s SIGKILL grace #1222 comment stay. The refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471 resolveLogDir import and the fix(mcp): sequant_run reports another run's issues and verdict when its own run log is missing — a runId lookup miss falls back to the time window #1515 fallback are untouched.
  • Intended behaviour changes in run.ts:
    • A timeout racing a cancel no longer schedules a second SIGKILL.
    • A child that closed before the kill call is no longer signalled.
    • The fallback for errors other than ESRCH now uses process.kill(pid) instead of proc.kill().
  • CHANGELOG: one [Unreleased] line.
  • Health baseline: regenerated. emptyCatch dropped from 119 to 118. proseGate.lines rose by 57 only because the new AC-2b block sits in opencode.test.ts, which already mentions SKILL.md. npm run lint:health now prints "no metric rose".

AC verification

AC Source Status Evidence (all run)
AC-1 Original ✅ The two rg counts return 1 and 1
AC-2 Original ✅ npx vitest run src/lib/process-group.integration.test.ts → 8 passed: cases (a)–(d) on real detached children, plus no-grace, ESRCH, non-ESRCH fallback and no-pid
AC-2b Original ✅ -t "timeout" on the two driver test files → 10 passed (was 4). The new tests per driver: an evaluator case, a driver case where abort plus a SIGKILL close reads as a timeout, and a negative case
AC-3 Original ✅ rg returns 3 and 1; the three suites pass with the existing kill assertions unchanged
AC-4 Original ✅ The accretion CLI prints not_fired, exit 0
Derived Error handling ✅ SIGKILL without killRequested (false or absent) still reads Process killed by signal: SIGKILL in both drivers
Derived Regression ✅ ring-buffer.test.ts checks a 2500-character line against x×2000 + "… [2500 chars]"

The /spec open questions are settled as recommended: SIGKILL escalation is on for the drivers, the grace is 5000 ms, and the constant lives in process-group.ts. AC-2b's "≥ 4 passed" threshold in the issue text is still vacuous (4 pass on main), but the real count is now 10, so the owner may want to edit it to "≥ 6".

Checks

  • Build and lint: npm run build ✅, npm run lint ✅, npm run lint:health ✅.
  • Affected tests: npx vitest run --changed origin/main in three shards (103 files): 2297 passed, 1 failed. Listing those file paths alongside --changed restricts the run to their overlap instead of adding to it, so the extra tests got a separate call.
  • Extra tests: the tautology detector, health-report.test.ts, and the MCP progress and run tests. (The runner restored this line after the exec body was cut off here; the full extra-test list is in the exec log.)
  • The 1 failure: src/lib/workflow/drivers/__tests__/driver-conformance.test.ts > commit: git add and git commit succeed inside the driver's default sandbox. Settled against base: it also fails on main at ace33fc in this checkout (1 failed, 33 passed; macOS only). It is tracked by test(drivers): codex conformance commit item fails locally on macOS — git add exits 128 inside the sandbox #1480, and CI on Linux passes it.

Mutation-verified: AC-2 — deleted the SIGKILL escalation call in process-group.ts; src/lib/process-group.integration.test.ts > 1472 process-group — killProcessGroup > 1472 AC-2 (a) escalates to SIGKILL after graceMs for a child that traps TERM failed; restored.
Mutation-verified: AC-2 — deleted the WeakSet early return in process-group.ts; src/lib/process-group.integration.test.ts > 1472 process-group — killProcessGroup > 1472 AC-2 (d) two calls on one child send one SIGTERM failed; restored.

Fixes #1472

QA verdict: AC_MET_BUT_NOT_A_PLUS — acceptance criteria met, but not A+. The run broke to this PR for review rather than entering the quality loop; see the QA review comment for improvement notes.

Runner verification (2026-10-19)

After merging main (#1503, #1511, #1521, #1528), the runner re-ran AC-1..AC-4 at d9fad08:

The runner reproduced both AC-2 mutations above. The AC-2b marker comes from exec and was not repeated.

Baseline:

Open, not blocking: AC-2 case (a) waits a fixed 150 ms for bash to install its trap. QA rated the flake risk on a loaded CI runner as low, and no failure has been observed.


🤖 Generated with Claude Code

…L escalation; pushLines on RingBuffer

src/lib/process-group.ts replaces the codex, opencode and MCP run.ts copies. Drivers escalate after DRIVER_SIGKILL_GRACE_MS and report a SIGKILL close after a requested kill as a timeout; run.ts keeps SIGKILL_GRACE_MS. RingBuffer gains a maxLineChars option and pushLines(text).

Entire-Checkpoint: 65cc8854d44a
emptyCatch 119 -> 118 (three kill copies -> one); proseGate.lines +57 from the AC-2b block appended to opencode.test.ts, which already mentions SKILL.md.

Entire-Checkpoint: 7d726196a1cc
…-drivers-mcp-one-killprocessgroup-child-gr

# Conflicts:
#	scripts/qa/health-baseline.json
…ines +57 (owner ruling: SKILL.md-path files)

Entire-Checkpoint: 9b139eee7c8d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(drivers,mcp): one killProcessGroup(child, { graceMs }) with SIGKILL escalation; pushLines on RingBuffer (closes the AsyncSubprocess trigger)

1 participant