Repository navigation
fix(sqlite): best-effort snapshot reads fail when snapshot cleanup stays busy - #170605
Conversation
A shared SQLite snapshot lease threw "SQLite snapshot lease cleanup did not complete" whenever its base cleanup resolved false. Best-effort bases (prepareSqliteReadOnlyLocation without a signal) resolve false only after warning and keeping the directory registered for exit cleanup, so the lease turned successful reads into failures and dropped the original error. On native Windows Bun, private snapshots stay busy after logical close, which made withSqliteSnapshotSource, read-only state opens, the update guard and ownership inspection fail. #168859 merged lease release and preparation close into one helper and widened a throw that #160946 had scoped to preparation close. Lease cleanup now resolves false again without closing the producer, so custody stays with the cleanup registry. Preparation close and orphan cleanup still throw: a close cannot discharge producer custody that removal never released. Strict bases are unchanged because they already throw with their cause. Synchronous cleanup after a refused async cleanup now reports false instead of true. Schema preflight still treats false as fatal by its own policy; #169572 handles that separately.
|
🦞👀 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 changesThis PR lets successful SQLite snapshot reads return when best-effort temporary-file deletion fails, while retaining warnings and cleanup ownership. Example: A best-effort snapshot read succeeds, but removing its private directory returns EBUSY.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current-main best-effort cleanup regression in the shared snapshot owner, preserves strict cleanup, and introduces no definite code defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSQLite inspection callers acquire shared private snapshots through single-flight coordination; the cleanup registry owns deferred removal, while callers receive read results and cleanup outcomes. flowchart TD
A[State and inspection callers] --> B[Snapshot preparation]
B --> C[Single flight leases]
C --> D[Private SQLite snapshot]
C --> E[Cleanup registry]
E --> F[Removal or deferred warning]
D --> A
Technical reviewBest possible solution: Restore best-effort lease results through the existing cleanup registry while preserving strict failures and producer custody. Do we have a high-confidence way to reproduce the issue? Source shows a best-effort false cleanup result becoming a fatal lease exception, and the body reports a baseline-failing regression; native Windows execution was not completed. Is this the best way to solve the issue? The patch repairs the shared lease boundary without weakening strict cleanup, adding a parallel owner, or restoring the retired coordination machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 799b7a347c50. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +23. Total +36 across 2 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 12, 2026, 11:57 PM ET / October 13, 2026, 03:57 UTC. |
|
Merged via squash.
|
…penclaw#170605) A shared SQLite snapshot lease threw "SQLite snapshot lease cleanup did not complete" whenever its base cleanup resolved false. Best-effort bases (prepareSqliteReadOnlyLocation without a signal) resolve false only after warning and keeping the directory registered for exit cleanup, so the lease turned successful reads into failures and dropped the original error. On native Windows Bun, private snapshots stay busy after logical close, which made withSqliteSnapshotSource, read-only state opens, the update guard and ownership inspection fail. openclaw#168859 merged lease release and preparation close into one helper and widened a throw that openclaw#160946 had scoped to preparation close. Lease cleanup now resolves false again without closing the producer, so custody stays with the cleanup registry. Preparation close and orphan cleanup still throw: a close cannot discharge producer custody that removal never released. Strict bases are unchanged because they already throw with their cause. Synchronous cleanup after a refused async cleanup now reports false instead of true. Schema preflight still treats false as fatal by its own policy; openclaw#169572 handles that separately.
What Problem This Solves
Fixes: best-effort SQLite snapshot reads fail with "SQLite snapshot lease cleanup did not complete" when the private snapshot can't be removed right away. On native Windows Bun, snapshots stay busy (EBUSY) after logical close.
User Impact
User impact: read-only state opens,
withSqliteSnapshotSource, the update/Doctor guard, and ownership inspection now return their successful result when best-effort temp cleanup is deferred. The existing "SQLite read-only snapshot cleanup failed" warning is still logged, and the directory stays registered for exit cleanup. Strict (signal-scoped) snapshot cleanup is unchanged and still fails with its cause.openclaw gateway status --deepon Windows Bun is covered by #169572, merged earlier: schema preflight requests strict cleanup and defers only EBUSY after a successful read. This PR covers the remaining best-effort consumers.Why This Change Was Made
#168859 merged lease release and preparation close into one helper,
releaseSnapshot. That widened a throw #160946 had scoped to preparation close, so a best-effort refusal became fatal and lost its cause. Best-effort bases resolvefalseonly after warning and keeping the directory registered, and strict bases already throw with their cause before this point. Lease cleanup therefore returnsfalseagain and does not close the producer, so custody stays with the cleanup registry.Preparation
startClose()still throws onfalse: a close can't discharge producer custody that removal never released. Orphan cleanup (no remaining lease) keeps its existing rejection. Synchronouscleanup()after a refused async cleanup now reportsfalseinstead oftrue.Evidence
sqlite-readonly-location.cleanup.test.ts: a real best-effortadoptPreparedLocationbase goes through the single-flight lease withEBUSYon removal. Before the fix, it fails with the exact production error. After the fix,cleanupAsync()resolvesfalse, the warning fires once, the bytes survive, andcleanupSnapshotOperations()reclaims them.pnpm testover all 22 sqlite-readonly-location, sqlite-snapshot-source, sqlite-snapshot-single-flight and openclaw-state-db-readonly test files: 3 shards passed, 102 tests, about 66 s wall time. The new test adds a few milliseconds and no timers.tsgo -p test/tsconfig/tsconfig.core.test.infra.jsonare clean. Independent Codex autoreview at P0–P2 came back scoped-clean.