fix(coding-agent): keep the pre-signal error when shutdown recovery throws (senpi#3067 L4)

Merged
SU
16d ago
+207-1

Summary

Fixes L4 of #3067 only (the recovery error hides the original cause). L1 is #6118, L2/L3/L5 are untouched, so this PR does not close #3067.

Root cause

In stopChild (host-lifecycle-shutdown.ts), when the shutdown fails before the child is signalled and the recovery (reapChildAfterFailure) itself throws, the recovery error replaced the original: performShutdown logged the recovery error as the shutdown failure and the original error never appeared anywhere.

What changed

  • packages/coding-agent/src/modes/rpc/host-lifecycle-shutdown.ts: the reapChildAfterFailure call in stopChild's catch is wrapped so a recovery failure logs the original error first, then the recovery error, and the original is still rethrown. The performShutdown catch path already logged both, so it is unchanged.

RED → GREEN

New regression packages/coding-agent/test/suite/regressions/3067-recovery-keeps-original.test.ts (senpi#3067 L4):

  • Failed pre-fix with the original error must be logged: expected -1 not to be -1 — the captured log held only shutdown failed ... exit unobserved 30000ms after recovery SIGKILL, the injected injected before child SIGTERM was absent.
  • Passes post-fix: both errors are logged, original first, and the supervisor exits 1.

The test drives real performShutdown → stopChild → reapChildAfterFailure with a never-exiting child (a reaped pid), a throwing clock for the pre-signal failure (same injection as the supervisor fixture's inject-stop-error), and fake timers for the 5 s + 30 s recovery waits. The supervisor log module is recorded rather than spawned, because it writes with a synchronous fd write that a unit test cannot observe through process.stderr; the mock only records, what is logged is decided by production code.

Tests

  • New: 3067-recovery-keeps-original.test.ts — 1 passed.
  • Directly affected: 4216-supervisor-startup-stop.test.ts (same shutdown unit) — 2 passed.
  • bun run check (oxlint, fmt, tsc, locks) — exit 0.

Out of scope

L2 (wall-clock steps / /proc ticks), L3 (once-per-generation logging), L5 (shutdown-recovery test gaps) — left for follow-ups.

Notes

  • AI 协助说明:本 PR 由 AI 助手协助撰写,测试与核查如正文所示。
  • CLA:待用户本人签署。

Summary by cubic

Fixes #3067 L4 only: when shutdown fails before the child is signalled and the recovery reap itself throws, the original error was lost and only the recovery error surfaced. Now both errors are logged exactly once, the original still rethrown as the shutdown failure.

  • stopChild logs only the recovery error; performShutdown logs the original once when the rethrow reaches it, so the original is no longer swallowed or duplicated.
  • Regression test 3067-recovery-keeps-original.test.ts drives real performShutdown → stopChild → reapChildAfterFailure with a reaped pid and a throwing clock, stubbing process.kill so no real signal is sent, and asserts both errors are logged in order and the supervisor exits 1.
  • Add changelog fragment changes/unreleased/6144.md covering the fix and its merge conflict zone.

L1 (#6118), L2, L3, and L5 of #3067 are untouched; this PR does not close the issue.