Repository navigation
fix: keep session writes responsive during archive cleanup - #156014
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 23, 2026, 1:50 AM ET / 05:50 UTC (Revision 5). ClawSweeper reviewWhat this changesMoves archive cleanup into existing database workers, permits session writes between cleanup units, and forwards completed shutdown checkpoints to resume deferred disk-budget maintenance. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 1 item remains This PR retains useful work beyond the merged scheduling fix, and no actionable introduced defect was found. GitHub now reports the reviewed head as mergeable, resolving the previous conflict concern. Priority: P2 Review scores
Verification
How this fits togetherSession maintenance measures stored conversation data and removes eligible archives when disk budgets are exceeded. Database workers perform cleanup while the Gateway coordinates foreground writes, current ownership, and checkpoint recovery. flowchart TD
A[Disk-budget pressure] --> B[Archive maintenance]
B --> C[History worker reads]
C --> D[Current ownership checks]
D --> E[Writer queue]
F[Foreground session writes] --> E
E --> G[Archive removal and page reclamation]
G --> H[Checkpoint and budget recovery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +522, Tests +511, Docs +24. Total +1057 across 40 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep archive maintenance with the existing reader and writer owners, preserving per-unit FIFO admission, conditional deletion, and fenced checkpoint recovery. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that fetched main still runs ordinary archive database work on the host during disk-budget cleanup. Runtime failures were not independently reproduced in this read-only review. Is this the best way to solve the issue? Yes. The patch extends existing database workers and lifecycle owners, preserves main's adaptive reclamation budgets, and adds focused ownership and recovery coverage without introducing another persistence model. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 80bab7e23ce0. 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
HistoryReview history (4 earlier review cycles)
|
d2edd21 to
2769976
Compare
|
Maintainer assessment of the remaining compatibility item at The worker close path reads an optional private hook after successful backend close and returns the receipt in the in-memory reply. It does not write that receipt to SQLite. The host publication waits for native and lease cleanup and checks the original incarnation and database identities before publishing a checkpoint observation. The agent/shared schema, migration, and generated-database files are byte-identical to merge base Compatibility evidence includes real existing-database reopen and integrity/registration cases, exact archive-row preservation across changed publication, stale/replaced-database checkpoint rejection, shared-state shutdown with ordinary admission revoked, and cold backup round trips that preserve exact events without the original archive. The integration passed 117 tests; the CI follow-up passed 512 tests across 12 files, including those cold backup and read-fence flows. CI on the current head remains a separate required gate; its newly reported lifecycle-test failure is under investigation. |
Preserve the archive-pruning reader and current cold-metadata reader with distinct result shapes and the existing database custody owner. Retain both lifecycle synchronization contracts after integration with main. Validation: 35 archive and Gateway tests passed; core types passed; managed review found no actionable P0-P2 findings. Elapsed test time was affected by host contention and is not performance evidence.
|
Merged via squash auto-merge.
|
The original settled-failure regression read the terminal session row and then gave claim cleanup a separate one-second polling deadline. Failure persistence commits that row before appending its transcript receipt and closing the writer. Under CPU contention, the row is visible while the claim must still remain active for the receipt's authority checks. Replace the persistence spy and post-write polls with the registry's existing onClearRequested publication. Keep the active-while-blocked assertion, verify the exact notified claim, and check the persisted terminal status, clear-requested owner state, and absence of persistence warnings after settlement. Product lifecycle ordering, timeouts, durability, and permissions stay unchanged. Observed in run 35819233517, job 107047566903, in the 22-file agentic-gateway-server-isolated-hosted-4 plan. Reproduced the same case in a Crabbox-managed Testbox with two-CPU affinity and CPU pressure. Endurance proof used base b373c9a; the final test bytes are unchanged while integrating the archive-cleanup owner from #156014. Proof: baseline 0/20 standalone failures and 1/1 original-plan shard failure (the reported assertion, 263 siblings passing); fixed 20/20 standalone passes and 3/3 original-plan shard passes. Both phases used CPUs 0-1 plus a busy process, standalone OPENCLAW_VITEST_MAX_WORKERS=8, and the CI planner's two-worker fallback for the constrained host. The original job actually detected eight CPUs and selected eight workers. An extra eight-workers-on-two-CPUs stress probe passed F111 in all three runs (4713/4203/3773 ms), but models-connect-publication.integration hit its existing 60-second whole-test budget in two runs; its passing run took 52908 ms. That case combines Gateway boot, ten client connections, catalog races, RPC checks, and cleanup. The particular await is unknown; no safe owner fix was established and no timeout or retry was changed. These extra oversubscription results are not clean shard proof. Owner/sibling checks: 148 tests passed; updated-main integration passed 85 tests. The single-worker file command took 203.46 s wall on the busy Mac, including 167.86 s Vitest time dominated by cold transforms; the existing nine cases exercise real SQLite writes and Gateway settlement. Changed-file checks, direct type-aware lint with a rejecting canary, oxfmt, diff checks, and independent P2 review passed. Initial Testbox harness dependency-link failures occurred before valid measurements; those attempts are excluded from the test failure rates. The nine-case file passed again after resolving the concurrent fixture change and integrating the archive-cleanup implementation on main; fresh review of the resolved diff is P2 clean.
…156014) * fix: keep session writes responsive during archive cleanup * fix: load archive history reader lazily * fix: resume budget cleanup after pooled worker checkpoints * fix: keep archive maintenance fixtures on their host owner
The original settled-failure regression read the terminal session row and then gave claim cleanup a separate one-second polling deadline. Failure persistence commits that row before appending its transcript receipt and closing the writer. Under CPU contention, the row is visible while the claim must still remain active for the receipt's authority checks. Replace the persistence spy and post-write polls with the registry's existing onClearRequested publication. Keep the active-while-blocked assertion, verify the exact notified claim, and check the persisted terminal status, clear-requested owner state, and absence of persistence warnings after settlement. Product lifecycle ordering, timeouts, durability, and permissions stay unchanged. Observed in run 35819233517, job 107047566903, in the 22-file agentic-gateway-server-isolated-hosted-4 plan. Reproduced the same case in a Crabbox-managed Testbox with two-CPU affinity and CPU pressure. Endurance proof used base 352ecb7; the final test bytes are unchanged while integrating the archive-cleanup owner from openclaw#156014. Proof: baseline 0/20 standalone failures and 1/1 original-plan shard failure (the reported assertion, 263 siblings passing); fixed 20/20 standalone passes and 3/3 original-plan shard passes. Both phases used CPUs 0-1 plus a busy process, standalone OPENCLAW_VITEST_MAX_WORKERS=8, and the CI planner's two-worker fallback for the constrained host. The original job actually detected eight CPUs and selected eight workers. An extra eight-workers-on-two-CPUs stress probe passed F111 in all three runs (4713/4203/3773 ms), but models-connect-publication.integration hit its existing 60-second whole-test budget in two runs; its passing run took 52908 ms. That case combines Gateway boot, ten client connections, catalog races, RPC checks, and cleanup. The particular await is unknown; no safe owner fix was established and no timeout or retry was changed. These extra oversubscription results are not clean shard proof. Owner/sibling checks: 148 tests passed; updated-main integration passed 85 tests. The single-worker file command took 203.46 s wall on the busy Mac, including 167.86 s Vitest time dominated by cold transforms; the existing nine cases exercise real SQLite writes and Gateway settlement. Changed-file checks, direct type-aware lint with a rejecting canary, oxfmt, diff checks, and independent P2 review passed. Initial Testbox harness dependency-link failures occurred before valid measurements; those attempts are excluded from the test failure rates. The nine-case file passed again after resolving the concurrent fixture change and integrating the archive-cleanup implementation on main; fresh review of the resolved diff is P2 clean.
What Problem This Solves
Fixes foreground session edits and transcript writes waiting behind archive cleanup, while moving durable archive database work off the Gateway main thread.
User Impact
Session writes can proceed between reclamation units. Cleanup preserves canonical recovery archives when ownership or publication changes, and completed worker shutdown checkpoints release deferred disk-budget maintenance. Archive order, retention policy, schema versions, stored formats, and update behavior are unchanged; no configuration or migration is required.
Why This Change Was Made
Main's #155631 now supplies adaptive vacuum units and part of the writer-fairness repair. This PR keeps those budgets and finishes the worker cutover through the existing history reader and agent execution broker. Metadata uses the existing maintenance lane; ordinary durable previews remain foreground reads and never create missing storage; explicitly selected native maintenance and incognito scopes retain their existing owner.
Each canonical archive removal retains one writer section through selection, derived-file unlink, and exact-row conditional deletion. A changed row preserves the canonical recovery copy and stops cleanup. Legacy removal checks canonical ownership and unlinks inside one immediate worker transaction, after current host authority is granted. Captured physical identity prevents queued work from following a retargeted database path.
A private close receipt carries the actual checkpoint result through the existing broker lifecycle. Publication waits for native and lease cleanup and checks the original generation and database identities. Public close signatures remain unchanged. An already-delivered operation failure is no longer reported again as cleanup failure; genuine cleanup failures retain their existing recovery owner.
Maintainer compatibility assessment.
Stored-data compatibility:
sqlite-store.worker.tsadds and validates a private in-memory checkpoint receipt and forwards it after successful close. It adds no table, column, index, schema version, or persisted representation. Existing database/row preservation, replacement, revocation, reopen, integrity, and shutdown flows are exercised by the tests; no data migration is introduced.Evidence
74dc63a9b8f34760f4c0ce505c17f03ebda1b7c0incorporates mainada417148e2dc3fa671cf865274c3fbd8d5f1ba7. It preserves main’s adaptive eight-page starting units, 25 ms scheduling target, 512-page unit ceiling, caller total budgets, first-use creation, committed replacement publication, and cold-metadata reader alongside archive pruning. The final integrated tree passed 35 focused tests: 16 archive-admission cases and 19 Gateway persistence/history cases across three files. Core typechecking passed; fresh managed review found no actionable P0–P2 findings. All ten reviewed source hashes match the committed files. The two test shards took 1,082.65 seconds under severe host contention; this is correctness evidence, not a performance result. Exact-head GitHub CI and Security Review passed; native auto-merge landed this head asb981f930dc295e0b7e383df61c4fa61539a5658c.c2961b235917, committed asd49edfea55c47e44cea0e2c4b3cb0a7b035d1764passed 117 tests across nine files: 84 archive/worker/parent-turn cases in 124.96 seconds, plus 33 creation, registration, and integrity cases in 54.64 seconds. Core typechecking and the complete architecture check passed.39104784passed every substantive job except a terminal-owner fixture that checked cleanup before the newly asynchronous failure report settled. The pre-edit local Git tree exactly matched CI merge51a3f7dd. The fixture now awaits the matching real persistence receipt using its stored target identity, then performs the original claim-cleanup assertion. No timeout or production authorization changed. All 32 tests in that fixture and its failure-report sibling passed; targeted lint passed. Local command wall time was 787.23 seconds during heavy host contention, not a performance result.These are synthetic flow and concurrency checks. They do not establish production-wide CPU savings or resolution of every event-loop stall.
Measured test cost
Each file below ran separately on macOS through
/usr/bin/time -l node scripts/run-vitest.mjs <file> --maxWorkers=1, at published revision2769976130df54b5b62b4de2282dece17fe7dc86, before the current main integration. All passed. These are measured local command wall times and maximum RSS, not per-file CI durations or proof of the later merged candidate. The grouped integration result is reported separately above.manager-publication-settlement.test.tsattempt-prompt-submit.retention.test.tsdisk-budget.zero-byte.test.tssession-accessor.sqlite-page-reclamation.binding.test.tssession-accessor.sqlite-reclamation-wal.test.tssession-accessor.sqlite-reclamation.test.tssession-accessor.sqlite-scope.test.tssession-accessor.sqlite-writer-owners.test.tssession-history-archive-pruning.admission.test.tssession-history-eviction.writer-fairness.test.tssession-history-wal-budget.test.tssqlite-worker-input.test.tssqlite-worker-store.test.tsopenclaw-agent-worker-store.test.tsCI run 35814968475 at
d49edfea55cexposed missing fork ownership for archival fixtures, an outdated first-unit assertion, two shadowed bindings, and the retired helper export. Its nine substantive failed jobs consumed 1,868 job-seconds in total, ranging from 91 to 382 seconds per job; these whole-job times include setup and other files, overlap in wall time, and are not per-file runtime or successful proof. The downstream CI gate took four seconds. Each failed log was retained once, and the follow-up preserves production admission guards and behavioral assertions. The final head passed its enforced CI gate before merge.