Repository navigation
fix: shutdown test fails before recap model starts - #162133
Conversation
Wait for the actual model-start signal instead of polling while the real history worker prepares the recap. Keep test-abort cleanup and cancellation/drain assertions intact. Local task: shutdown-b21
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. Reviewed September 30, 2026, 6:01 PM ET / 22:01 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch makes the Gateway shutdown test wait for the activity recap model to start before checking cancellation, connection drain, and late persistence. Merge readiness⛔ Needs changes before merge - 1 item remains Current main and the latest release retain the timing-sensitive assertion. This focused repair has stronger flake evidence than the overlapping open PR, which is not a safe superseding target. Priority: P2 Review scores
Verification
How this fits togetherGateway subscriptions start activity recaps from session transcripts and dispose of them during connection shutdown. This test checks that in-flight model work is canceled before connection work drains and that no late recap is saved. flowchart LR
A[Session transcript] --> B[Gateway subscriptions]
B --> C[Activity recap]
C --> D[Model start signal]
D --> E[Shutdown test]
E --> F[Connection drain]
E --> G[No late recap saved]
Before merge
Agent review detailsSecurityNone. PR surfaceTests +4. Total +4 across 1 file. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep one event-gated Gateway shutdown regression test that preserves the cancellation, drain-order, and no-late-persistence checks. Do we have a high-confidence way to reproduce the issue? Yes. The captured CI failure and reported fresh-main six-file replay reach the same model-call assertion, which current main still contains; this read-only review did not rerun the shard. Is this the best way to solve the issue? Yes. Waiting for the model-start event addresses the false one-second timing assumption without changing production behavior or weakening the shutdown assertions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5fe8304fd622. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Wait for the actual model-start signal instead of polling while the real history worker prepares the recap. Keep test-abort cleanup and cancellation/drain assertions intact. Local task: shutdown-b21
What Problem This Solves
Fixes the shutdown cancellation regression test failing before its model work starts on resource-constrained CI workers.
Related: #151218. This separate repair PR was explicitly requested by a maintainer.
User Impact
No user-visible behavior changes. The test continues to verify cancellation before connection drain, waiting for physical model settlement, and suppression of late recap persistence.
Why This Change Was Made
ensure()returns a projected state before the real transcript worker finishes reading. The test incorrectly treated the default one-secondvi.waitForpolling window as a model-start guarantee. In a fresh-main six-file replay with two CPUs and two workers, admission succeeded immediately, imports and scope preparation completed within 5 ms, the assertion failed at 1,004 ms, and the worker returned 64 transcript events at 2,408 ms—after cleanup had already disposed the service.Wait for an explicit signal from the mocked model call instead. Use the existing test-abort-aware helper so timeout still unwinds fixture cleanup, and
it.forto receive that test context. No production changes, timeout increases, sleeps, retries, broader mocks, or weakened assertions.Evidence
1bf0175f8c78a845f04692a07b62de6bfa6f2fbe: 57/58 in the original six-file, two-CPU/two-worker shard. Original CI failure.check:changed --staged --base 1bf0175f8c78a845f04692a07b62de6bfa6f2fbe --timedpassed, including gateway-server typecheck, formatting, lint, ratchets, boundaries, and dead-export scans.git diff --checkpassed.eed6c21dd00cf512ab77a2c26f94b122ce006507.3bf892b2158ca4ed52b4e54ef8c7d3068064574dand matching open PRs before publication; no competing fix found in the shutdown test/direct source.Full repository build/test suites were not run for this one-file test-only change; GitHub CI remains the broader integration gate. No live Gateway or original PR worktree was modified.
Test-value audit, mutation proof, and cost
Retain this integration regression. It checks that Gateway shutdown cancels auxiliary recap work before draining inherited connection work, still joins physical settlement, and rejects late persistence. Generic connection-work tests and recap-service disposal tests do not exercise that wiring together.
Breaking mutation: in a fresh isolated checkout, delete only the
params.signal.addEventListener("abort", stopSessionBackgroundWork, { once: true })subscription. The unchanged shutdown assertion then fails becausemodelSignal.abortedis false, while the before-startup case and all 60 cheaper component siblings remain green (61 passed / 1 failed). The exact published candidate passes the control 2/2. The audit harness checked the intended assertion and sibling counts, then exited 0. Mutation proof run. This deliberate mutation is not part of the PR.Simplification/LOC: 0 production LOC changed; test diff +8/−4, net +4 (136 → 140 physical lines). No new helper, dependency, timeout, sleep, or polling loop. The existing shared helpers replace the polling assertion. Both event gates are necessary: one observes model admission, the other controls physical completion. Model and audit I/O are already stubbed; replacing the remaining integration path with service mocks would lose the demonstrated wiring coverage.
Before/after timing: original six-file, two-CPU/two-worker diagnostic run: 83.85s, 57/58 tests. Corrected runs: 86.57s / 84.75s / 86.81s, 58/58 each. Shutdown case: 2.981s failing before, 3.203s / 4.382s / 2.865s passing after. These observations are not a speedup claim: the before run fails and includes diagnostics. The repair removes an invalid one-second race rather than optimizing runtime.
Single-worker file command wall time:
pnpm test src/gateway/server-runtime-subscriptions.shutdown.test.ts --maxWorkers=1passed all twenty runs. Measured with/usr/bin/timein secretless AWS Crabbox (Node 24.19.0, process affinity restricted to two CPUs): 45.52s for the initial invocation, then 35.16–36.09s for the subsequent nineteen invocations. These are whole-command wall times, including startup/source preparation—not individual test-case durations or GitHub CI file seconds. Startup/source preparation dominates the approximately 3–4 seconds spent in the cases.