Skip to content

test(coding-agent): cover the shutdown recovery path per call site (senpi#3067 L5) - #6146

Merged
code-yeongyu merged 2 commits into
code-yeongyu:mainfrom
surlymochan:fix/3067-l5-shutdown-call-sites
Nov 7, 2026
Merged

code-yeongyu merged 2 commits into
code-yeongyu:mainfrom
surlymochan:fix/3067-l5-shutdown-call-sites

Conversation

@surlymochan

@surlymochan surlymochan commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes L5 of #3067 only (test gap for the shutdown-level recovery). L1 is #6118, L2/L3/L4 are untouched, so this PR does not close #3067. Test-only change, no production code touched.

What changed

  • New packages/coding-agent/test/suite/regressions/3067-shutdown-call-sites.test.ts: one test per call site that can throw before the child is signalled (or right after its stop), each showing the child still receives SIGTERM, then SIGKILL, and is reaped, and shutdown still exits 1 with the generation left intact (by design: an unobserved child exit leaves its generation, pointer and settings intact):
    • drain.stop throws (!childStopStarted path — the recovery reaps the child);
    • stopWatchers throws after the child stop;
    • clients.destroyAll throws after the child stop.

RED → GREEN

The tests drive real performShutdown with a real SIGTERM-ignoring child and fake timers for the 5 s + 30 s waits (plus a real event-loop turn per slice, so the SIGKILLed child's exit is actually observed — without it the mocked 30 s kill wait fires first and the recovery reports the exit unobserved). Test-only, so there is no pre-fix code failure to show: these are the missing coverage, not a bug fix.

Tests

  • New: 3067-shutdown-call-sites.test.ts — 3 passed.
  • bun run check (oxlint, fmt, tsc, locks) — exit 0.
  • Local changelog gate (node scripts/check-pr-changelog.mjs --base <merge-base>) — PASS (no runtime source changes detected, no fragment needed for a test-only PR).

Out of scope

L2 (wall-clock steps / /proc ticks), L3 (once-per-generation logging), L4 (recovery error chaining, #6144) — left for follow-ups.

Notes

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

Summary by cubic

Adds missing test coverage for the shutdown recovery path in performShutdown (L5 of #3067), with two gradations: drain.stop throwing before the child is signalled (where the recovery reap drives SIGTERM then SIGKILL), and stopWatchers or clients.destroyAll throwing after the ordinary child stop. Each test drives a real shutdown with a SIGTERM-ignoring child under fake timers and asserts the child is signalled SIGTERM, then SIGKILL, is reaped, and shutdown exits 1 with the generation left intact. The tests also pin each call site's position in the failure sequence and verify the stop intent distinguishes the recovery reap from the ordinary child stop. Test-only change; there is no fix to exercise, so these tests just document the expected behavior.

Written for commit 62e56cc. Summary will update on new commits.

View guided diff

…enpi#3067 L5)

L5 of code-yeongyu#3067 only; L1 is code-yeongyu#6118, L2/L3/L4 are untouched, so this does not close code-yeongyu#3067.
@code-yeongyu

Copy link
Copy Markdown
Owner

Thanks @surlymochan. We've queued this for review and will post the findings here.

@code-yeongyu

Copy link
Copy Markdown
Owner

Thanks @surlymochan. The review at ea49ae0 asks for changes before merge. All three main points are about whether the tests can fail when the behavior regresses:

  1. SIGTERM is never asserted (3067-shutdown-call-sites.test.ts:161-176). The comment says each test shows "SIGTERM, then SIGKILL", but the child ignores SIGTERM and the only assertion is signalCode === "SIGKILL". A recovery path that skips the SIGTERM grace step (host-lifecycle-shutdown.ts:189-192) would still pass. Record the signals received (or stub process.kill and assert the call order).
  2. The stopWatchers and destroyAll cases never reach the recovery reap (:178-202). By then childStopStarted is already true and the ordinary stopChild (:160-177) has already SIGKILLed the child. So these two only fail on regressions all three tests share, not on their own call sites. Set up each case so its own call site is the one that drives the reap.
  3. settle() is a fixed-step timer loop (:148-159, 40 × 1 s plus a real setTimeout(0)). Its own comment says the 30 s kill-exit timer wins if the real event loop is late, so this can flake under load. Loop until the awaited promise settles, with a bound.

Smaller items: stubbing process.kill also removes the 10 s real readiness wait (:43-62); cleanup still races a fixed 5 s real timeout (:132-137); and exitProcess.mockRestore() on line 129 does nothing after vi.restoreAllMocks().

@surlymochan

Copy link
Copy Markdown
Contributor Author

Addressed the review at ea49ae0 (all changes in 3067-shutdown-call-sites.test.ts, test-only):

  1. SIGTERM is now asserted. process.kill is stubbed to record every signal call in order: SIGTERM is recorded but not delivered, SIGKILL is delivered for real so the child is still reaped. All three tests assert ["SIGTERM", "SIGKILL"]. A recovery path that skips the SIGTERM grace step now fails the drain test — verified: with the grace step removed, the drain test fails with expected [ 'SIGKILL' ] to deeply equal [ 'SIGTERM', 'SIGKILL' ], while the previous version of the test passed.
  2. Per-call-site coverage. Each test now pins where its failure aborts the sequence — drain.stop / stopWatchers / admission.flush / clients.destroyAll, called or not called — plus the stop intent (absent in the drain case, where the recovery reap drives the signals; present with reason: "signal:SIGTERM" in the other two, where the ordinary child stop already reaped the child). A swallowed stopWatchers throw now fails only the stopWatchers test.
  3. settle() is promise-driven. It advances fake time in 100 ms steps, yielding to the real loop after each step, and stops as soon as the awaited shutdown settles, with a 60 s fake-time bound that raises a clear error instead of hanging.

Smaller items: the 10 s real readiness wait is gone (nothing can kill the child before its handler is installed now that SIGTERM is never delivered); cleanup awaits the shutdown promise with the same bounded loop instead of racing a fixed 5 s real timeout; the dead exitProcess.mockRestore() after vi.restoreAllMocks() is removed.

One thing I did not change, and why: the review asks for the stopWatchers/destroyAll cases to be set up so their own call site drives the recovery reap. That cannot happen without reordering performShutdown itself: childStopStarted is set before stopChild, and a normally-returning stopChild means the child is already dead by the time stopWatchers/destroyAll run, so the catch block's !childStopStarted reap can never run for them. The tests instead pin each call site's place in the failure sequence. If you would rather have the recovery reap reachable from those call sites, that needs a production reorder — happy to do it if you direct it.

Tests: 3067-shutdown-call-sites.test.ts — 3 passed before the change (2.53 s), 3 passed after (1.79 s). oxfmt --check and oxlint on the file are clean.

@code-yeongyu

Copy link
Copy Markdown
Owner

Thanks @surlymochan. The review is CLEAR at 62e56cc: SIGTERM order is asserted and each call site now drives its own recovery reap. One note for later: settle() (3067-shutdown-call-sites.test.ts:183-191) still waits on the real child exit after SIGKILL, so it can be slow under load. The full-suite run at this head is queued, and I'll merge when it passes.

@code-yeongyu
code-yeongyu merged commit d295cca into code-yeongyu:main Nov 7, 2026
11 checks passed
@code-yeongyu

Copy link
Copy Markdown
Owner

Merged as d295cca. Thanks @surlymochan!

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.

rpc host child identity: DST fall-back and wall-clock steps can misread a live child (review follow-ups from #3057)

2 participants