Repository navigation
fix: wait for final chat writes during restart handoff - #196493
Conversation
Keep late terminal persistence within the original drain budget and retain final custody checks. Report bounded redacted holder facts through Gateway RPC errors and both journals. Preserve the synchronous idle path and immediate freeze behavior.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 038fb4289f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed review item 1 (bundled updater RPC deadline) in
The branch and PR evidence are current. The Gateway remains the sole settlement-wait owner. Final writes and live authority checks remain required. @clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR waits for late final-chat writes within the existing drain budget and preserves bounded holder diagnostics through failed handoff responses. Example: Handoff starts 6 seconds after preparation, with final-chat writes settling another second later.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a current handoff failure, resolves the previous authority-proof concern, and has no actionable introduced defect identified. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherAdministrative suspension RPCs connect update controllers to the Gateway’s suspension coordinator, which checks active-work custody before transferring shutdown to the process-owning host. flowchart LR
A[Update controller] --> B[Gateway request dispatcher]
B --> C[Suspension handler]
C --> D[Suspension coordinator]
D --> E[Final write inventory]
D --> F[Host shutdown owner]
C --> G[Bounded failure diagnostics]
Technical reviewBest possible solution: Keep settlement waiting in the existing suspension coordinator, preserving the original deadline, final custody checks, and live requester authority. Do we have a high-confidence way to reproduce the issue? Pinned main immediately rejects a pending final write after readiness, and the submitted regression reports red-before/green-after evidence; this review verified the source path without executing it. Is this the best way to solve the issue? The change uses the existing coordinator and host owner, retains the synchronous idle path, and updates the affected caller timeout without adding competing state or shutdown policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 261b24e6bc8e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +78, Tests +171, Docs +8, Other +174. Total +431 across 15 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 10, 2026, 2:33 AM ET / 07:33 UTC (Revision 3). |
|
Final head is @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Addressing every open item in ClawSweeper’s review at
Command: @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
* fix: wait for late final writes during gateway handoff Keep late terminal persistence within the original drain budget and retain final custody checks. Report bounded redacted holder facts through Gateway RPC errors and both journals. Preserve the synchronous idle path and immediate freeze behavior. * fix: keep updater handoff transport open for terminal settlement * test: normalize nullable handoff transport timeout * test: prove handoff authority through terminal settlement
* fix: wait for late final writes during gateway handoff Keep late terminal persistence within the original drain budget and retain final custody checks. Report bounded redacted holder facts through Gateway RPC errors and both journals. Preserve the synchronous idle path and immediate freeze behavior. * fix: keep updater handoff transport open for terminal settlement * test: normalize nullable handoff transport timeout * test: prove handoff authority through terminal settlement (cherry picked from commit c96584a) Release adaptation: omit optional benchmark; preserve candidate owners. Proof: RPC regression red, 197 tests across seven files green; targeted types, lint, formatting, docs, syntax and allocation checks pass. Independent local review omitted by explicit release-owner instruction. Live deployment and stable upgrade remain qualification gaps. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit 36bb0cf580122d335c004ffd696cf62f3542cf6e)
What Problem This Solves
A restart handoff could refuse a final chat write that appeared after READY, even with most of the drain budget remaining. The refusal named no holder, and the deployment controller discarded the structured RPC failure.
User Impact
Finishing chat writes can settle before handoff without requiring a deferred deployment retry. A leaked holder still refuses handoff, now with its count, oldest observed terminal-event age, and bounded redacted run IDs in both journals and RPC error details. No configuration or migration is required.
Why This Change Was Made
The Gateway owns the wait, bounded by the original 30-second drain budget; the existing 15-second cleanup grace is untouched. It first attempts the synchronous handoff, so the idle path does no extra registry scan. Only a terminal-persistence refusal waits, then requester authority and final write custody are checked again. Freeze handoffs remain immediate. The controller change only preserves recognized diagnostic fields from failed JSON RPC output.
No new config, environment variables, state, caches, or schema. Production delta +100 lines supplies the bounded wait and diagnostics at their owners and the controller egress; tests +171 lines (matching allocation), standalone benchmark 150 lines, docs +8 lines. The eight-ID/256-character cap omits session keys; unknown ages are null. The controller's final status check may still defer before handoff if it observes custody there; this fixes the later handoff refusal.
Evidence
a65cb61a7d14c7dbee97f92d442f9a378c88a688: pending writes return immediate, unattributed UNAVAILABLE. Final 77 focused Gateway/coordinator/activity tests pass (55.65 s wrapper wall time, mostly compilation). Coverage includes settlement after READY, refusal at the original deadline, resumed lease, oldest age, count/cap, control stripping, and redaction.tsconfig.core.test.cli-update.jsongraph fails before and passes after. Targeted lint/format and Codex review pass. Production code is unchanged by this correction.pnpm test src/gateway/server-methods.suspension-admission.test.tspasses 36/36 (44.33 s wrapper; compilation dominated). This harness calls the real core method registry, request dispatcher, captured operator guard, handoff handler/coordinator, host lifecycle andmarkGatewayRestartDraining; final assertions inspect the real restart-draining state. Allowed late settlement commits; read-only scope is FORBIDDEN; admin scope downgraded while waiting is FORBIDDEN with unchanged shutdown state. Mutation proof removing only the post-waitassertCurrent()makes the revoked case fail because shutdown actually commits (4 other cases pass); restoring it returns all 36 to green. The test does not launch a live Gateway or kill a process; it exercises the privileged commit boundary in-process with synthetic identities and fake time. Gateway-server test types, lint/format and independent Codex review pass.pnpm check:changedcompleted. Its patch-local lint findings were fixed and rechecked. Its remaining dead-export failure reproduces exactly on the parent: 32 production + 10 full-tree findings, no additions/omissions; script scan passes. These are main regressions, not ignored failures. Attribution is below.Synthetic owner measurements
Command:
node --import ./scripts/tsx.mjs scripts/perf/handoff-terminal-persistence-measure.ts --source-root <checkout> --mode <idle|refusal|settlement> --sessions 10800 --iterations 20. Five fresh-process A/A pairs and five interleaved A/B pairs per mode; warm measured operations exclude imports/setup. CPU is process CPU; allocations use HeapProfiler sampling including collected objects. Host load is recorded (comparison one-minute load roughly 13–24 on 32 CPUs).A/A wall median/p95: idle 10.90/13.41 vs 10.97/12.94 ms; refusal 12.22/14.22 vs 12.90/17.26 ms; settlement refusal 12.06/14.46 vs 12.22/13.98 ms. No microbenchmark speedup is claimed. Diagnostics add about 8% allocation to refusals. Waiting deliberately adds inventory work: the successful settlement attempt uses about 24 ms more CPU and 19 MiB more sampled allocation than one failed baseline attempt; this comparison excludes the baseline's later deployment retry. The requested behavioral gain is avoiding that deferral, while retaining write protection. An initial implementation added an idle scan and regressed CPU 25%; the final implementation deletes that scan (final idle CPU +2%).
This is an intentionally large in-memory registry fixture: 10,800 registered sources, ten pending terminal writes. No database/workspace I/O occurs at this boundary. It does not establish 35 GiB database, filesystem-scale, live model, or btrfs performance. CPU profiles confirm inventory traversal remains the dominant work.
Exact-parent local dead-export failures and source attribution
node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mtsreproduces byte-identical finding lists ona65cb61a7d14. No changed runtime module contributes a finding. Source/parent-relative attribution:c7152f3bda8e). MCP directory helpers: improve(tools): let models call listed MCP tools without searching first #196252 (80ba593b8b14).625945b7ae01).b4262689db5d), fix(update): prevent Gateway respawn during package replacement #103537 (7713e8fb749e) / retained by refactor(daemon): split launchd into concept modules #121929 (3d707a9b963b), and fix: report stale Gateway service policy in Doctor and update status #151777 (5e5912058286).56617cd00086).071f606eae77), refactor(plugins): forward auth and catalog to their owners #190205 (f63e5cd0f6d3), feat(test): compile subprocesses once per invocation #132716 (964fa991c0af), refactor(agents): move live model policy to test owner #129184 (33d8f24c9926), and direct commita7436c8b4a93.cf1ae7bb6a72). Browser pairing constant: feat(pairing): pair a browser with a short code approved on the host #191513 (d85ebfe8daad). Dashboard helper: Dashboards gallery: Display menu with list view, ordering and grouping #194455 (cde34f111b4d).These remain main regressions for separate repair; no ignores, export removals, or unrelated fixes were added here.
The final CI main-parent test-line failure is reproduced and attributed: at
261b24e6bc8e3012687f5b27623b0e26f3defff6, the canonical checker reports 6,618,989 lines versus ceiling 6,618,696: 293 over. Initial parenta65cb61a7d14is exactly at its ceiling. #194996 (e6afc3c54002b6c2aca7eefb2a12038482e93506) introduced 71 unallocated lines; #188748 (441b6139039d18701357e93665dcc59f787f439d) introduced 223; intervening #194429 removed 1. Canonical runs at both introducing commits reproduce the debt. Their affected files and the checker remain unchanged in the tested merge. This PR adds 171 lines with 171 allocation, leaving the same 293 debt. Final branch check against its original parent passes exactly at ceiling 6,618,478. These are main regressions for follow-up, not ignored noise.ClawSweeper’s review on
88723a019477c0bd52af23a8b9431fa81917f11ccleared all three authority-proof items: no open checklist items, no findings, no security concern. OpenGrep, CodeQL Security High, and Critical Quality all passed on attempt 2 after confirmed GitHub SARIF-upload recovery. Main CI completed with all functional/type/lint/UI/PostgreSQL checks passing; only the reproduced inherited test-line ratchet and its aggregate gate remain red. The native pinned-head exception is limited to that attributed ratchet failure.