Repository navigation
fix(gateway): retain shared state until cleanup finishes - #142286
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 8, 2026, 12:16 PM ET / 16:16 UTC. ClawSweeper reviewWhat this changesThe PR keeps shared Gateway state available until shutdown callbacks and plugin cleanup actually finish, with regression tests and lifecycle documentation. Merge readiness⛔ Blocked before merge - 1 item remains This remains a useful, focused repair: current main and the latest release retain the premature shared-state closure. No blocking patch defect was found. The related aggregate explicitly delegates this work to smaller PRs, and the protected maintainer submission should remain open. Priority: P2 Review scores
Verification
How this fits togetherGateway shutdown coordinates hooks, plugin runtimes, network listeners, and shared SQLite state. Cleanup may outlast its initial grace period; this change lets independent teardown proceed while delaying dependent resource closure. flowchart TD
A[Stop or restart request] --> B[Start cleanup callbacks]
B --> C[Wait through grace period]
C --> D[Close independent listeners]
D --> E[Join actual cleanup]
E --> F[Finish active plugin cleanup]
F --> G[Close shared state]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +31, Tests +184, Docs +7. Total +222 across 7 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the documented completion-before-release contract and existing process watchdog, while keeping previously retired-registry cleanup in its separately acknowledged follow-up. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the path: hold a cleanup callback beyond its grace period and let it access SQLite after teardown advances. The added regressions exercise this ordering; this review did not execute them. Is this the best way to solve the issue? Yes. Reusing the existing asynchronous work owner and joining cleanup before resource release addresses the lifecycle boundary without adding configuration, changing schemas, or extending initial grace periods. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 512d2a0ad469. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Retaining the documented shutdown tradeoff. A grace timeout permits independent teardown to advance; it cannot make a still-running cleanup callback safe to use after its database closes. Embedded close therefore waits for actual cleanup, and the existing process-owned watchdog remains unchanged. The native and compiled proofs cover continued teardown, late SQLite use, and eventual closure. The review found no actionable patch defect. Earlier hot-retired registry cleanup remains the separately tracked follow-up described in this PR. |
|
Merged via squash.
|
…2286) * fix(gateway): retain shared state until cleanup finishes * docs(plugins): clarify active registry cleanup scope
Related: #140674
What Problem This Solves
Fixes an issue where Gateway shutdown or restart could close shared SQLite and reset plugin state while a slow cleanup callback was still using it. The initial timeout allowed shutdown to continue, but did not cancel the callback.
Why This Change Was Made
The existing shutdown owners retain actual hook and runtime cleanup work through their grace periods, let independent teardown proceed, and join that work before releasing dependent shared state. Active plugin host cleanup now finishes before the shared database closes. Registry retirement still revokes runtime authority immediately.
User Impact
Slow cleanup can finish using its existing resources without racing a closed database. A callback that never settles can hold graceful in-process shutdown open; existing forced process-exit behavior and initial grace periods are unchanged.
Evidence
Five native SQLite regressions failed before the repair: shutdown and pre-restart hooks, harness cleanup, and plugin lifecycle callbacks and their tracked child work. All 135 focused tests passed after the repair, along with the full changed-file gate and builds.
An isolated compiled Gateway with a synthetic plugin served a successful health check, then shut down through its actual signal handler. Shutdown, harness, and lifecycle callbacks remained pending beyond their five-second grace periods. Each performed a successful late SQLite read; independent service teardown advanced; the process then exited successfully and the captured connection closed. A read-only reopen preserved the schema version and passed the integrity check. This used the existing private-QA observation build and task-owned state; it does not claim live failed-startup or external MCP/LSP service coverage. Cleanup from a registry retired by an earlier hot reload remains a separate follow-up; this slice joins the active-registry close owner.
The focused suite took 43.449 seconds, the final changed-file gate 298.109 seconds, the ordinary build 258.446 seconds, and the compiled Gateway case 20.258 seconds. Initial test-type and synthetic-fixture failures were corrected without changing assertions, trust rules, or product timeouts.