Repository navigation
fix: preserve session caches when database workers exit - #173239
Conversation
Release worker handle custody without advancing data write revisions. Real native settlement and quarantine retain their invalidation paths; final-handle retirement and physical-file readmission stay intact.
|
🦞👀 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 SummaryThis 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: 1abf08ee10
ℹ️ 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".
|
Codex review: needs real behavior proof before merge. What this changesThis PR releases exiting workers’ database references without invalidating surviving session and auth caches. Example: A worker finishes updating proof.value to 43, then exits while a sibling keeps the database open.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep this PR open: preserving idle-reader caches is useful, but removing all exit-time invalidation also preserves stale receipts after an interrupted writer commits. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe shared SQLite admission registry receives worker reference changes and native write settlements, then publishes revisions used by session caches and authorization consumers. flowchart TD
A[Database worker] --> B[Native SQLite operation]
B --> C[Write settlement]
C --> D[Shared admission revisions]
A --> E[Worker exit cleanup]
E --> D
D --> F[Session and auth caches]
D --> G[Placement grant dispatch guard]
Technical reviewBest possible solution: Preserve idle-reader receipts while retaining shared invalidation for writers whose native changes may have committed without settlement. Do we have a high-confidence way to reproduce the issue? Current-main source invalidates receipts whenever a departing worker retains an open reference, including an idle reader; the PR reports a failing real-worker regression, but this review executed no target code. Is this the best way to solve the issue? The shared admission owner is the right repair boundary, but unconditional preservation also removes recovery for unpublished committed writes. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 055e1f877573. Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: The removed crash invalidation protects receipts consumed by the final placement-grant authorization guard. EvidenceSecurity concerns:
What I checked:
Likely related people:
PR surfaceSource -7, Tests -25, Docs +2. Total -30 across 4 files. Added test files: 0. View PR surface stats
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 October 15, 2026, 11:48 AM ET / 15:48 UTC. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c7ba1d435
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa4a984251
ℹ️ 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".
) Keep handle retirement separate from data-write revisions so idle worker exits preserve actor, auth, and session facts. Track unsettled native writes in the existing worker reference cell and publish invalidation before retiring a worker that may have committed without a receipt. Real writes, quarantine, and final-handle retirement retain their invalidation semantics. Validated with 89 owner tests (3 existing skips), native COMMIT crash regressions, final-head type/lint/source-contract/Madge/database-ratchet/PostgreSQL/security gates, and a Knip scan with only exact inherited findings. The unrelated concurrent agent-ownership claim failure is reproduced on the baseline and routed to its owner; landing uses the authorized inherited-failure exception. Warmed SQL/request measurements and a forced idle-worker-exit diagnostic are recorded in the PR.
What Problem This Solves
Session turns reread actor, auth, and session facts when an admitted database worker exits, even though releasing its handle changes no data. Worker exit advanced both the database-wide and unscoped write revisions, invalidating every cache using those receipts.
User Impact
Live session caches survive an idle reader's exit. Real writes, quarantine, schema changes, final-handle retirement, and physical-file replacement retain their existing invalidation and admission behavior. No schema, configuration, SDK, or stored-data changes.
Why This Change Was Made
The shared admission owner releases the departing worker's reference without manufacturing a write receipt. The existing per-worker reference metadata also records the number of native writes awaiting receipt publication. The native write owner increments that count once per connection and clears it after publishing scoped and database-wide receipts. Before handle retirement, the receipt owner invalidates only databases with an interrupted native write. The broker already joins worker exit before settling the caller. This covers COMMIT-before-receipt crashes, including writes without a domain grant, without adding SQL, worker requests, or admission handshakes. Final-handle retirement remains intact; this does not restore the reverted final-close retention change from #172676.
Removed check and accepted edge: worker exit no longer assumes an unobserved write merely because a handle was open. Idle and fully settled workers may exit without invalidating data facts. A crash during a native write still invalidates that database, even if SQLite ultimately rolled it back; losing a committed write's receipt is not accepted.
Evidence
The real-worker regression fails on the base in both ordinary and retained-worker modes: termination increments the write token from 1 to 2 despite no write. It also verifies that a real worker commit invalidates receipts and that quarantine revokes scoped receipts and admission facts.
Two isolated Codex review rounds completed. Review identified a real COMMIT-before-receipt window. The final repair (
af7bbee21910) tracks native writes directly and deletes the interim grant-specific tracker; generic shared-state writes need no separate domain grant. The ungranted credential write cited in review independently fails closed on unknown settlement, but the missing physical write receipt still needed repair. The native and schema-maintenance crash regressions intercept the actual COMMIT, terminate the worker before its observer returns, require receipt invalidation before caller rejection, and read back the durable row. The final four owner test files passed: 89 tests, with 3 existing skips, including both native-COMMIT crash cases. The test wrapper completed successfully, including generated-output verification. All three P1 review threads are addressed and resolved; the requested two-round review limit was retained.Changed-file formatting and type-aware lint pass. The initial 46 focused lifecycle/receipt tests passed. Prior-head CI passed type, lint, source-contract, Madge, PostgreSQL conformance, and database ratchet jobs. Its durability test timed out at a queued
chat.send; focused base and candidate replays both timed out earlier atsessions.createunder heavy host load, so the original CI failure remains unclassified rather than being called inherited. Final-head CI completed: types, lint, source contracts, architecture/Madge, database ratchets, PostgreSQL conformance, and security checks pass. The sole failing CI test,serializes concurrent ownership claims for one unowned database, is inherited. Single stock-test replays passed on both base and candidate because the fixture signals an earlier integrity transaction. A focused baseline reproduction at7cd0f47de8bused the sameensureOpenClawAgentDatabaseSchemaentrypoint, pausing both processes at the actual schema BEGIN after their ownership/emptiness reads. Releasing them produced two successful claims (expected one), final ownerworker-b, and both owners in the registry. Only scheduling was instrumented; production code and SQL were unchanged. The schema-owner source is byte-identical on base and candidate. This is routed to the agent-database owner; this PR changes no agent-owner code. Landing uses the authorized inherited-failure exception, not a claim that CI is green.The exact final-head Knip export scan completed on native Blacksmith Testbox, pinned to
af7bbee21910. Its production findings (prepareWorkerGitHubBindingGrant,DropdownMenuController,scrollState) and full-tree findings (DropdownMenuController,openDropdownSubmenu) all match the same rule and files in main's dependency job. None is in a changed file. The script scan passes with zero entries. The lease is stopped. No update cell applies: this changes handle and write-receipt bookkeeping, not the schema, migration implementation, update, Doctor, plugin loading, or service lifecycle.Measured SQL and request counts
Three alternating base/candidate pairs, ten warmed turns each, using the copied shared harness and exact-pin builds: base
7cd0f47de8b, candidateaf7bbee21910, Node 24.21.0. Values are median [min–max] across the three per-run means. Causal counts follow turn attribution; raw counts include background work in the warm execution windows (requests use dispatch windows).The ordinary warm median does not regress. The first baseline had four exit-triggered agent-database invalidations during warmed turns (89.8 SQL / 28.8 requests per turn); the other two baselines had none during warmed turns. No candidate run emitted a release-triggered revision increment. The saving is conditional on an exit, not a universal reduction on every turn. First-turn raw statement medians are 1050 → 1050 and request medians 158 → 154. Whole measured workload medians are 3719 → 3667 SQL and 768 → 758 requests. Whole-workload MAIN is exactly 467 on every run: the same 13 background plugin-lifecycle lease reads shift between first-turn and warm windows. Zero causal MAIN is not a claim of zero background MAIN.
Forced worker exit
A separately labeled pair starts one extra real read-only admitted worker after the first turn, then terminates it after warm turn five. Its real exit event calls
releaseWorker; the actor writer remains alive. Both sides remove the departing reference (1 → −1, then absent), preserve all 12 sibling references, and retain admission. Base revisions advance 93 → 94 and 5 → 6; candidate revisions remain 93 → 93 and 5 → 5. The reader has no pending write; pending-write settlement and native COMMIT-before-receipt crashes are separately exercised through the production tracker tests.The next turn avoids 18 statements and 6 requests: 14 SELECTs plus two BEGIN/COMMIT pairs, with INSERT/UPDATE counts unchanged. Neighboring turns are 80 SQL / 27 requests on both pins. Across all ten diagnostic warm turns, causal means are 83.2 → 81.4 SQL and 27.9 → 27.3 requests; raw warm means are 84.7 → 83.9 SQL and 28.3 → 28.1 requests. The generic operation deltas are
execute: −6 SQL / −2 requests, andtask: −12 SQL / −4 requests across the ten turns. Read-family participating-request counts overlap and are not summed. Receipt instrumentation reports zero errors.Measurement limitations: two candidate attempts failed before the first turn from the inherited fresh-store catalog-before-schema race fixed separately by #173196 (
55d9dab98ad4); both are excluded. Pair 3 was repeated on both pins with a bounded wait for the existing initial-schema receipt, issuing no SQL or RPC; the forced pair uses the same wait. One initial readiness-helper path mismatch also failed before any measured turn and is excluded. Earlier matching pairs remain valid. Every included run completed all 13 top-level turns, the spawned child, compaction, and clean shutdown. Cron is unmeasured because the fixture lacks a stored inference account. The forced probe is an exit diagnostic, not a startup benchmark; its full-workload totals are 3705 → 3707 SQL and 767 → 763 requests. No latency claim on the loaded host.LOC: production +51/−29 (net +22); tests/fixtures +127/−65; docs +10/−4; total +188/−98 across 9 files. The obsolete synthetic test asserting exit-time invalidation is deleted; the real-worker lifecycle test owns the regression.