Skip to content

fix(sqlite): best-effort snapshot reads fail when snapshot cleanup stays busy - #170605

Merged
steipete merged 1 commit into
mainfrom
fix/sqlite-lease-best-effort-cleanup
Oct 13, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/sqlite-lease-best-effort-cleanup

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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 --deep on 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 resolve false only after warning and keeping the directory registered, and strict bases already throw with their cause before this point. Lease cleanup therefore returns false again and does not close the producer, so custody stays with the cleanup registry.

Preparation startClose() still throws on false: a close can't discharge producer custody that removal never released. Orphan cleanup (no remaining lease) keeps its existing rejection. Synchronous cleanup() after a refused async cleanup now reports false instead of true.

Evidence

  • Regression test in sqlite-readonly-location.cleanup.test.ts: a real best-effort adoptPreparedLocation base goes through the single-flight lease with EBUSY on removal. Before the fix, it fails with the exact production error. After the fix, cleanupAsync() resolves false, the warning fires once, the bytes survive, and cleanupSnapshotOperations() reclaims them.
  • pnpm test over 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.
  • oxlint, oxfmt and tsgo -p test/tsconfig/tsconfig.core.test.infra.json are clean. Independent Codex autoreview at P0–P2 came back scoped-clean.
  • Gap: native Windows Bun 1.4.2 A/B proof was attempted on two AWS Windows leases and a Parallels Windows 11 VM. All three hit infrastructure failures (SSH loss, then guest-exec stalls) before either the old or new code ran, so there is no Windows runtime evidence here.

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.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 13, 2026 03:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T03:54:03.781944Z e30ffd7 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Lease cleanup throws "SQLite snapshot lease cleanup did not complete", replacing the successful read result.
  • After: Lease cleanup resolves false, the read result survives, and the directory remains registered for later cleanup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused repair with meaningful owner-boundary coverage and no identified defect; runtime confidence is limited to harness evidence.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored status exempts this PR from the ordinary contributor proof gate; available evidence exercises the real cleanup owner through a regression harness, without native Windows after-fix proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A successful snapshot-backed inspection can fail solely because its best-effort temporary copy remains busy.
Reason: The feature owner restores the existing nonfatal cleanup contract with a narrow shared fix and preserves the intentionally simplified lifecycle.

Regression provenance

Possible 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
Reviewed head: e30ffd7d4c2980361180e76e9adfe2823b65399e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Windows Bun snapshot-read run demonstrates a successful result with deferred EBUSY cleanup; the body reports a baseline-failing owner-boundary regression using mocked filesystem refusal.
Agent review details

How this fits together

SQLite 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
Loading

Technical review

Best 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

  • Lease cleanup, orphan settlement, and preparation close changes intended behavior with a stated reason (19fe879: refactor(infra): simplify database and worker coordination #168859 consolidated snapshot coordination around one cleanup owner and accepted exceptional cleanup remaining for maintenance; this PR explains the accidental widening of a preparation-close failure into ordinary best-effort lease cleanup.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Galin Iliev: Raw commit 4269cd4 adds src/infra/sqlite-readonly-location.cleanup.test.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 4269cd4e1afb; files: src/infra/sqlite-readonly-location.cleanup.test.ts)

PR surface

Source +13, Tests +23. Total +36 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 22 9 +13
Tests 1 23 0 +23
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 45 9 +36

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +22/-9 lines; tests +23/-0 lines The small production increase preserves orphan and preparation-close failure semantics while restoring best-effort lease behavior; the regression covers refusal and later reclamation.

Labels

Label changes:

  • add P2: This is a focused current-main regression affecting snapshot-backed inspection when private-file removal fails, with limited demonstrated blast radius.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a focused current-main regression affecting snapshot-backed inspection when private-file removal fails, with limited demonstrated blast radius.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record a native Windows Bun snapshot-backed read that returns its result while EBUSY cleanup is deferred.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 12, 2026, 11:57 PM ET / October 13, 2026, 03:57 UTC.

@steipete
steipete merged commit db220ac into main Oct 13, 2026
192 of 193 checks passed
@steipete
steipete deleted the fix/sqlite-lease-best-effort-cleanup branch October 13, 2026 04:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant