Repository navigation
Conversation
Reuse each database worker across alternating maintenance operations while preserving the global archive FIFO, existing admission, idle retirement, and failed-close custody. Keep the worker registry bound to successful lifecycle retirement.
|
🦞👀 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 maintainer review before merge. Reviewed September 22, 2026, 8:36 AM ET / 12:36 UTC (Revision 3). ClawSweeper reviewWhat this changesRetain a database-cleanup worker for each agent database, document retirement behavior, and update worker-reuse and embeddings-cleanup tests. Merge readiness✅ Ready for maintainer review This remains a useful, well-supported optimization: inspected main and the latest release still retain only one reclamation worker globally. No blocking correctness findings remain. Priority: P2 Review scores
Verification
How this fits togetherSession reclamation performs database maintenance and removes obsolete session data in background workers. Requests enter a shared queue, obtain current database authority, and return committed results before their worker becomes idle. flowchart TD
A[Session cleanup and maintenance] --> B[Shared request queue]
B --> C[Worker registry by database]
C --> D[Current identity and write admission]
D --> E[SQLite operation and committed result]
E --> C
C --> F[Idle expiry or lifecycle retirement]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +28, Tests +22, Docs +5. Total +55 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep worker reuse within the existing reclamation owner, preserving per-request authority, global ordering, and complete lifecycle retirement. Do we have a high-confidence way to reproduce the issue? Yes: alternating maintenance between two databases reaches main's single-slot replacement path; the supplied Testbox comparison independently demonstrates the churn. This reviewer did not execute the workload. Is this the best way to solve the issue? Yes: extending the existing worker owner's retention registry removes the measured churn while preserving admission, commit, queue, and cleanup contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 774687378d80. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Assert queued reclamations share their database worker and preserve other-store identity. Replace polling in embedding cleanup fixtures with entry signals and settle started requests and provider lifetimes before restoring transport.
…nclaw#155677) * perf(state): retain reclamation workers across database switches Reuse each database worker across alternating maintenance operations while preserving the global archive FIFO, existing admission, idle retirement, and failed-close custody. Keep the worker registry bound to successful lifecycle retirement. * perf(state): finish worker reuse and cleanup regression coverage Assert queued reclamations share their database worker and preserve other-store identity. Replace polling in embedding cleanup fixtures with entry signals and settle started requests and provider lifetimes before restoring transport.
What Problem This Solves
Maintenance that alternates between agent databases repeatedly closes and boots reclamation Workers because the retained Worker slot is global.
Related: #154662.
User Impact
Multi-agent maintenance reuses each database's admitted Worker, reducing repeated startup work. One recently used Worker can remain per database instead of one globally; the existing 30-minute idle expiry, critical-memory retirement, and database-close drainage still apply. No configuration, schema, durability, integrity policy, or update behavior changes.
Why This Change Was Made
Retain Workers by canonical database path while preserving the global archive FIFO and existing file, state-owner, and request-authority checks. Remove a registry entry only after successful retirement and only if it still identifies that Worker; failed cleanup retains custody. Canonical-validation scopes remain separate. Net production change: +28 lines.
The maintenance opens already execute inside
withWorkerWriteAdmission, and their nested synchronous opens reuse the admitted connection. Archive read-only opens check schema and ownership without a full integrity scan. The measured defect is cross-database Worker churn, so this change does not add another admission helper.Evidence
A disposable Testbox probe used two synthetic SQLite databases of 1,077,166,080 bytes each, with current host verification, and alternated
maintenance-plan,maintenance-pages, andmaintenance-statisticsoperations.Observed alternating-workload time fell 85.6%; timings are samples, not a production latency guarantee. The deterministic improvement is eight fewer Worker starts and physical opens. Warm requests need no physical reopen. The open timer excludes module bootstrap.
The new regression failed on the original implementation with six Workers instead of two, and passes with the fix. It also checks host-proof reuse and retirement of all idle Workers on critical memory pressure. Existing coverage retains revoked-proof checks, current admission, FIFO settlement, idle expiry, and crashed-Worker lease cleanup.
CI also exposed a sibling diagnostic test that still required three Worker IDs for requests spanning two databases. Its assertions now require the two same-database requests to share an ID and the other database to use a different ID. Separately, the embeddings HTTP cleanup fixture had a one-second polling deadline and left its cleanup gate closed on failure, poisoning later tests. Those equivalent cases now use an explicit cleanup-entry signal and settle requests/provider lifetimes in
finally; the test file shrinks by 15 lines, with no production embedding changes or timeout increases.All heavy validation used
blacksmith-testbox, profileopenclaw-check:tbx_01m348hrxbqftrnyyggyv778gp:node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-lane105.bench.test.ts src/config/sessions/session-accessor.sqlite-reclamation-reuse.test.tspassed 22 baseline tests. The disposable probe passed again on the candidate with the measurements above.node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-reclamation-reuse.test.ts -t 'retains maintenance Workers'failed on the original implementation as expected (six Workers, expected two).tbx_01m3494a5c7c3fxz0td4bp485m:pnpm test src/config/sessions/session-accessor.sqlite-reclamation-reuse.test.ts --maxWorkers=1passed all 22 tests, 56.93 s wrapper wall time including cold Worker compilation; the new regression took 1.613 s.node scripts/run-vitest.mjswith the siblingsession-accessor.sqlite-reclamation-{worker,admission-race,memory,wal}.test.tsfiles passed all 16 tests and its required runtime build (75 s). These native Worker tests protect admission, lease settlement, and thread reuse that an in-process mock cannot establish.tbx_01m34a1s575sxq7z036k9tysc3:node scripts/check-changed.mjs --base HEAD -- docs/reference/database-schemas/integrity-and-recovery.md src/config/sessions/session-accessor.sqlite-reclamation-reuse.test.ts src/config/sessions/session-accessor.sqlite-reclamation-worker.tspassed, exit 0. The command completed in 34m21s including remote setup and all 25 core-test typecheck shards; core typechecking, changed-file lint, formatting, dead-export scans, and selected storage/plugin guards passed.tbx_01m34cz4rp408azvdnckhhmafz:pnpm test src/config/sessions/session-accessor.sqlite-reclamation.test.ts src/config/sessions/session-accessor.sqlite-reclamation-reuse.test.ts --maxWorkers=1passed all 56 tests in 123.61 s wrapper wall time. The corrected queued-identity case took 1.669 s. Its test-only changed checks passed. The original 12-fileagentic-control-plane-http-modelsshard was replayed with its recorded two-worker input descriptor throughscripts/ci-run-node-test-shard.mtsand passed 429 tests in 240.42 s before the embeddings fixture repair; that passing replay is not claimed as proof of a fix.pnpm test src/gateway/embeddings-http.test.ts --maxWorkers=1runs passed all 43 tests each (137 s cold wrapper wall; 45–92 s subsequent runs). 3/3 original-shard replays passed all 429 tests each (223.68, 187.98, and 188.54 s Vitest wall). These tests exercise real HTTP request selection, local-provider admission, disconnects, and cleanup through a suite-level Gateway. No new Gateway boot per case was added. Finalnode scripts/check-changed.mjs --base HEAD -- src/config/sessions/session-accessor.sqlite-reclamation.test.ts src/gateway/embeddings-http.test.tspassed both affected typecheck graphs, lint, and selected guards. The combined repetition/check command exited 0 in 36m6s. All four task-owned leases were stopped.Independent review through P2: scoped-clean for the production change and both CI corrections. Local changed-file formatting and
git diff --checkpassed. No local test, build, or typecheck execution.CI run 35725516661 passed for
7278894c5d847a605cd7bdbd062631f4b71cac51, including both previously failing jobs. The queued Worker-identity regression took 0.948 s in CI. The four embedding cleanup cases took 0.517–0.644 s each; their original 12-file HTTP group passed 429 tests in 123.49 s. The containing packed jobs took 385 s and 628 s including setup and other groups.Validation recovery and scope
The first test invocation stopped before tests because remote dependencies were missing;
pnpm install --frozen-lockfilesucceeded on each isolated lease. The first candidate reuse-suite run was interrupted after the benchmark succeeded because the adapted explicit-retirement fixture called an unwrapped close function while awaiting its wrapper notification. Correcting that fixture produced the clean 22-test result above. The defaultnode scripts/check-changed.mjsrun selected unrelated changes from shalloworigin/mainhistory, so it was stopped and replaced by the fixed-base, explicit-path invocation. No production change was needed for either validation issue. The disposable large-database probe is not added to per-PR CI.The first PR CI run, 35718735185, failed the two test assumptions described above; the other selected jobs passed. The follow-up preserves the queued identity check, replaces cleanup-entry polling with an actual callback signal, and settles cleanup even when an assertion fails.
The reported 24-second production scans and eight
maintenance-planrejections were not reproduced. Source inspection identifies stale maintenance input after a foreground write as a possible rejection path, but the supplied log excerpt omitserroranderrorFrame; no cause is asserted and no authority check or retry policy is weakened. No live Gateway was changed.