Repository navigation
fix: avoid shutdown waits behind shared-state readers - #197219
Conversation
|
🦞👀 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. |
|
The final candidate is @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR disables SQLite busy waits when retiring shared-state handles and adds a pinned-reader regression, measurement tooling, and documentation. Example: An agent worker retires while another connection holds a shared-state WAL snapshot.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a concrete shared-state retirement delay still present on current main, with no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherShared-state lifecycle code receives retiring database handles, stops WAL maintenance, closes native connections, and publishes clean-close proof only when existing safety checks permit it. flowchart TD
A[Agent worker retirement] --> B[Shared-state lifecycle owner]
B --> C[Zero busy timeout]
C --> D[Final WAL checkpoint]
E[Peer reader snapshot] --> D
D --> F[Native connection close]
F --> G[Conditional clean-close seal]
Technical reviewBest possible solution: Apply the existing zero-timeout retirement policy at the shared-state native lifecycle owner while retaining checkpoint, WAL preservation, and seal safeguards. Do we have a high-confidence way to reproduce the issue? The source exposes the timeout-bearing final checkpoint, and the PR reports a real pinned-reader baseline failure at 5389 ms; this review executed no target code. Is this the best way to solve the issue? The patch restores the policy already used by agent database retirement at the correct shared owner, without adding a competing lifecycle path or weakening clean-close checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 93e4800f6df9. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +30, Docs +5, Other +352. Total +392 across 6 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 Reviewed November 11, 2026, 8:16 AM ET / 13:16 UTC. |
|
Merged via squash.
|
* fix: avoid shutdown waits behind shared-state readers * chore: expose shutdown measurement trace imports to checks * chore: satisfy shutdown benchmark lint rules * chore: preserve trace receivers without a lint suppression
What Problem This Solves
Fixes: Gateway shutdown can wait five seconds per retiring shared-state connection when another reader holds a WAL snapshot, including connections borrowed by agent workers.
User Impact
Retirement stops waiting for peer readers. Existing snapshots and committed writes remain available in the WAL; clean-close proof still requires successful checkpoint/close and empty journals. No schema, configuration, or durability-policy change.
Why This Change Was Made
Agent database close already disables the normal write busy timeout. Shared-state handle retirement omitted that policy, so the agent close step could spend its time waiting on the worker's shared-state TRUNCATE checkpoint. Apply the same policy at the shared-state native lifecycle owner.
The smallest complete repair adds five production lines, including an existing-helper import and the already-closed retry guard. The 30-line regression checks a real reader, preserved WAL/snapshot and persisted writes; its separate test-line allocation covers exactly this growth. No new runtime abstractions or caches.
Evidence
Acceptance, set before the comparison: on a warm 34.94 GiB synthetic agent DB with 10,000 sessions, one million transcript events and roughly 31 MiB of newly written WAL, remove the shared-reader checkpoint wait and bring median async agent retirement below one second, with no 20% CPU or sampled allocation regression. Two A/A controls, five counterbalanced baseline/candidate pairs, and a separate five-pair allocation pass. Native pragma timings include worker connections; sampled JS allocation is main-isolate only.
Baseline A/A: 5531.4/5523.1 ms. Every paired run retained the final agent seal. Allocation median increased 8.2% with overlapping ranges; no allocation improvement is claimed, and it remained below the predeclared 20% regression threshold. Native allocations and worker-isolate JS allocations are not measured. Source hashes distinguish both owner versions in every output row. Reproducer:
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/agent-db-close-small-wal-measure.mjs --root .local/close-fixture --worker --scatter --shared-reader --samples 5; its header gives the synthetic seed command.The new regression fails on the unmodified owner at 5,389 ms and passes with the fix. Shared-state cleanup and clean-close admission suites pass (20 tests). No optimize, ANALYZE, or integrity scan occurs during ordinary close. Planner maintenance is already bounded and outside shutdown.
Limits: macOS/APFS with warm filesystem caches; this is the real native agent retirement owner, not whole-Gateway or Linux/btrfs proof. Production attribution and next-handoff timings remain unverified.
Codex autoreview of the complete local change against
b45c0f4a0da1554d9902457694e2fe17a47b3db9: scoped-clean through P2, no actionable findings. Runtime delta +5 lines; test delta +30; reproducible measurement tooling +350. The cleanup suite passes 9 tests in a 2.22 s harness run; the admission suite passes 11 in 3.02 s, excluding compiler-cache preparation. UI import-boundary search found no affected browser consumers. Exact-head CI run 43026790597 passed.pnpm check:changedcompleted with failures in dead-export and script lint checks. The PR-caused script findings were fixed; the exact script lint command, script-export scan, and final benchmark smoke pass. All other selected checks (core/test types, core lint, format, database boundaries and remaining guards) passed. The remaining 57 production and 32 full-tree dead-export findings reproduce identically with the canonical checker on exact parentb45c0f4a0da1554d9902457694e2fe17a47b3db9, with zero module-resolution errors and zero script findings. This is a real main check regression, not a green full check.Inherited dead-export attribution
Existing source-cutover attribution is reused from #196784; the exact-parent reproduction was rerun for this PR. Newer entries were traced through their introducing owner patches. No claim of historical green Knip runs for every introduction.
9b7dcdc7a66dc(#196767), new exported definitions without recognized external production consumersb22f35f7ed765(#196991), new exported definitions with local/test consumers5f2f21a7ee193(#196388), new exported definitions with local consumers37a3b162a0c58(#196380)c7152f3bda8e5(#196207), consumer moved into its owner625945b7ae01d(#192552), consumers redirected to narrower owners80ba593b8b14b(#196252), local production uses56617cd000864(#191326), local production usef63e5cd0f6d38(#190205), consumers redirected to narrower owners964fa991c0aff(#132716), consumers redirected to narrower owners071f606eae77(#139911), direct consumer replaced with injected owner resolver33d8f24c9926(#129184), last external production consumer removeda7436c8b4a93b(provider-hook runtime split), consumers redirectedcf1ae7bb6a729(#190544), contracts and callers moved to provider-auth-typesThe first CI run exposed one PR-caused failure in
test/scripts/lint-suppressions.test.ts: the trace helper had added a suppression. The helper now passes its database receiver explicitly instead. The exact failed suite passes locally (14 tests, 267 ms test time; 8.55 s harness), focused lint and the real worker-close smoke pass, and the follow-up Codex review is scoped-clean through P2. No allowlist or check was relaxed.Landed as
78407f8cbfd97c4fb22514f629aed4b63550d720from tested head39785544987633f8eaa3bd96caaee3288d496277. Final-head CI passed; ClawSweeper final review has zero findings and zero open items. No deployment or production performance claim.