Repository navigation
fix(update): prevent idle agent cleanup outside maintenance scope - #186783
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 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. |
|
Codex review: needs maintainer review before merge. What this changesThe PR prevents idle eviction of agent database handles owned by an active maintenance resource scope. Example: Doctor maintenance holds two writable agent databases for 31 seconds.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR fixes premature maintenance-handle cleanup still present on main, with no actionable patch defects found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe agent database lifecycle manages cached SQLite handles, idle timers, durable leases, and cleanup coordinated with Doctor's maintenance resource scope. flowchart TD
A[Doctor maintenance] --> B[Scope owned agent handles]
B --> C[Detached idle timer]
C --> D[Existing resource owner lookup]
D --> E[Defer idle eviction]
B --> F[Scoped checkpoint close and lease release]
Technical reviewBest possible solution: Keep maintenance-owned handles under their existing scope until scoped cleanup completes, preserving ordinary idle eviction. Do we have a high-confidence way to reproduce the issue? Source confirms the detached timer can close a maintenance-owned handle before lease release; the author reports a matching base failure and candidate success, which this read-only review did not rerun. Is this the best way to solve the issue? The existing resource-owner lookup is the smallest complete fix: it prevents unauthorized cleanup at its producer while retaining the established scoped closer and cache-transfer behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6bd45e1ba982. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +7, Tests +43. Total +50 across 2 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 28, 2026, 10:03 AM ET / 14:03 UTC. |
Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after #186783. Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change.
Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after #186783. Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change.
* perf(state): keep agent startup inspection proportionate Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after #186783. Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change. * refactor(state): keep quarantine dispatch behind verification boundary * fix(state): settle deferred writers when readers retire Resume existing shutdown idle timers when dependent resources release, preserving clean seals and the pre-sidecar lease handoff. Keep bounded SQLite header facts at their native catalog owner, separate the verifier leaf contract, and retain foreground repair cancellation proof. * docs(state): distinguish startup admission from crash recovery receipts * fix(state): let resource owners settle before idle writer cleanup * fix(sessions): retire idle readers during shutdown cleanup * test(gateway): keep configured stores in the suite registry * docs(state): align idle retirement with restart marker persistence
…8459) * perf(state): keep agent startup inspection proportionate Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after openclaw#186783. Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change. * refactor(state): keep quarantine dispatch behind verification boundary * fix(state): settle deferred writers when readers retire Resume existing shutdown idle timers when dependent resources release, preserving clean seals and the pre-sidecar lease handoff. Keep bounded SQLite header facts at their native catalog owner, separate the verifier leaf contract, and retain foreground repair cancellation proof. * docs(state): distinguish startup admission from crash recovery receipts * fix(state): let resource owners settle before idle writer cleanup * fix(sessions): retire idle readers during shutdown cleanup * test(gateway): keep configured stores in the suite registry * docs(state): align idle retirement with restart marker persistence
What Problem This Solves
Fixes agent database cleanup warnings during native update/Doctor maintenance lasting longer than the one-shot CLI's 30-second idle window.
User Impact
Maintenance retains its agent database handles until scoped cleanup can checkpoint, close, and release their leases with the required authority. No schema, configuration, retention policy, or authorization changes are required. The candidate runtime must contain this fix; the installed updater needs no change.
Why This Change Was Made
Agent handles already belong to the maintenance resource scope, but their detached idle timer also attempted to close them. The timer checkpointed and closed SQLite before its shared-state lease release failed with
StateDatabaseMaintenanceScopeError. A later scoped retry could clear the lease but could no longer publish the original clean-close seal.Idle eviction now consults the existing resource owner and leaves maintenance handles to that scope. Ordinary idle eviction is unchanged. This adds seven net production lines (an existing-owner lookup and early return, plus import/comment formatting) to enforce the existing ownership boundary; it adds no cache, retry, exception suppression, or alternate cleanup path.
Evidence
fef5e6bfc485, published as16a8dfc8a351after an unrelated UI-only rebase; P2+, scoped-clean with no actionable findings. The helper refused before inference because its requested provider did not match operator configuration; configuration was not changed. Ownership escape after skipped expiry was source-reviewed, not separately exercised.This is a correctness fix on idle cleanup, with no performance claim or hot-path change. Gateway load testing and owner microbenchmarks would not exercise the faulty maintenance timer.