Repository navigation
fix: leftover SQLite snapshot copies from Doctor and triage are never reclaimed - #193229
Conversation
Doctor lint inspects a private copy of the state directory, staged inside the installation's SQLite snapshot namespace, and points OPENCLAW_STATE_DIR at it. Every snapshot taken in that context was staged under a namespace hashed from that throwaway path, so each run created a new ~/Library/Caches/openclaw/sqlite-<hash>/ that the Gateway's reclamation never visits. Any copy left there, by a crash, a kill or a failed cleanup, stayed forever, and each run also left an empty namespace directory. When the resolved state directory lies inside an existing snapshot namespace, reuse that namespace. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🦞👀 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. What this changesDoctor and triage snapshots reuse their installation’s existing SQLite cache namespace so Gateway maintenance can reclaim abandoned copies. Example: Two triage runs inspect private state copies inside sqlite-9565507d… on macOS.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this focused fix addresses a current snapshot leak without introducing a runtime defect; exact-head CI remains pending. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe SQLite staging resolver receives the active state directory and cache environment, then supplies private snapshot destinations to database inspection and reclamation. flowchart TD
A[Doctor or triage] --> B[Private state copy]
B --> C[SQLite staging resolver]
C --> D[Installation cache namespace]
D --> E[Gateway maintenance]
E --> F[Lifetime token checks]
F --> G[Reclaim abandoned snapshots]
Technical reviewBest possible solution: Keep namespace selection in the shared staging resolver while preserving existing reclamation safeguards and handling historical leftovers in the separate repair. Do we have a high-confidence way to reproduce the issue? The source establishes the failure: Doctor substitutes a temporary state directory, the base resolver hashes that path, and Gateway reclamation scans a different namespace; the body also reports before-and-after CLI runs. Is this the best way to solve the issue? This is the smallest complete producer-side fix: reuse the enclosing admitted namespace without changing snapshot lifetime ownership or broadening the reclamation scan. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 566559c6bd3c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +8, Tests +25, Other +2. Total +35 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
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 HistoryReview history (1 earlier review cycle)
Reviewed November 5, 2026, 1:18 PM ET / 18:18 UTC (Revision 2). |
A state dir that is itself a namespace, or sits in a snapshot directory outside one, must keep its own hashed namespace. Move the new assertions into their own case.
…rivate-state-namespace
…rivate-state-namespace
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
… reclaimed (openclaw#193229) * fix: keep Doctor's snapshot copies in the installation's swept namespace Doctor lint inspects a private copy of the state directory, staged inside the installation's SQLite snapshot namespace, and points OPENCLAW_STATE_DIR at it. Every snapshot taken in that context was staged under a namespace hashed from that throwaway path, so each run created a new ~/Library/Caches/openclaw/sqlite-<hash>/ that the Gateway's reclamation never visits. Any copy left there, by a crash, a kill or a failed cleanup, stayed forever, and each run also left an empty namespace directory. When the resolved state directory lies inside an existing snapshot namespace, reuse that namespace. * test(sqlite): add negative controls for the enclosing snapshot namespace A state dir that is itself a namespace, or sits in a snapshot directory outside one, must keep its own hashed namespace. Move the new assertions into their own case. * test(sqlite): type the snapshot directory names as a tuple
… reclaimed (openclaw#193229) * fix: keep Doctor's snapshot copies in the installation's swept namespace Doctor lint inspects a private copy of the state directory, staged inside the installation's SQLite snapshot namespace, and points OPENCLAW_STATE_DIR at it. Every snapshot taken in that context was staged under a namespace hashed from that throwaway path, so each run created a new ~/Library/Caches/openclaw/sqlite-<hash>/ that the Gateway's reclamation never visits. Any copy left there, by a crash, a kill or a failed cleanup, stayed forever, and each run also left an empty namespace directory. When the resolved state directory lies inside an existing snapshot namespace, reuse that namespace. * test(sqlite): add negative controls for the enclosing snapshot namespace A state dir that is itself a namespace, or sits in a snapshot directory outside one, must keep its own hashed namespace. Move the new assertions into their own case. * test(sqlite): type the snapshot directory names as a tuple
Related: #193174, #193652
What Problem This Solves
Fixes: SQLite snapshot copies that Doctor or
openclaw triagefail to remove are never reclaimed. On top of that, every run leaves a new empty~/Library/Caches/openclaw/sqlite-<hash>/directory.On one Mac host, 49 GB of leftover copies from two triage runs sat in
sqlite-0e5d8581…andsqlite-ac549b06…. The installation's own namespace (sqlite-9565507d…, the one its Gateway sweeps) was empty.User Impact
Snapshot copies taken during Doctor and triage now live in the installation's own namespace. If one is left behind by a crash, a kill or a failed cleanup, the Gateway's existing snapshot reclamation removes it after its usual grace period. Runs no longer add an empty namespace directory each time.
This PR does not remove copies that are already on disk in older per-run namespaces. #193652 does that: the Gateway sweep also reclaims day-old copies in sibling namespaces and directly under the cache parent.
Why This Change Was Made
Doctor lint inspects a private copy of the state directory. That copy is a snapshot staged inside the installation's namespace, and Doctor points
OPENCLAW_STATE_DIRat it. The snapshot namespace is a hash of the resolved state directory, so every snapshot taken in that context went into a namespace hashed from the throwaway path. That's a new one per run, and the Gateway's sweep (reclaimAbandonedSqliteSnapshots) only looks in the installation's namespace.resolveSnapshotStagingRootnow reuses the enclosing namespace when the resolved state directory is strictly inside an existingsqlite-<24 hex>namespace under the admitted cache root. Any other state directory, including a different installation sharing the cache, keeps its own hashed namespace. Reclamation still takes each snapshot's lifetime token before deleting it, so copies that are in use stay fenced.This is independent of PR #193174, which fixes the cleanup failure when an inspection task is cancelled. This PR makes sure anything that still escapes cleanup can be reclaimed.
Evidence
Head
064f66db2bc2, which containsorigin/main2c04aec4eb6f. The latest main merge doesn't touch the SQLite staging, temp-root or state-dir paths.Reproduction in a disposable HOME and state dir, logging every
sqlite-<hash>namespace created and theOPENCLAW_STATE_DIRat that moment:ca81928c…,5c9aaece…,afc816a0…,b976225e…across runs). ItsOPENCLAW_STATE_DIRwas…/sqlite-<install>/openclaw-sqlite-readonly-v2-*/openclaw-sqlite-readonly-v2-*/openclaw-state.triage --runruns left only the installation's namespace.Regression test in
src/infra/sqlite-private-directory.test.ts: "keeps a private state copy in its enclosing namespace but hashes any other cache path". A private state copy at<namespace>/openclaw-sqlite-readonly-v2-*/openclaw-sqlite-readonly-v2-*/openclaw-stateresolves to that namespace.Negative controls in the same case: a state dir equal to the namespace itself, and one at
<cache>/openclaw-sqlite-readonly-v2-*/openclaw-state(outside any namespace), each get their own hashedsqlite-<24 hex>namespace. The cache root holds exactly those three namespaces. The unchanged case "isolates installations sharing a cache and keeps each namespace stable" still covers separate installations.inside.length >= 0): fails (expected 2 to be 3)sqlite-<24 hex>: fails (the outside path resolves toopenclaw-sqlite-readonly-v2-aB3dE6)Commands:
pnpm teston the 31 files touching the staging root, reclamation, retirement, read-only location cleanup, update-candidate state and Doctor lint state: 220 passed (first revision).vitest runon every test file that callsresolvePrivateSqliteSnapshotStagingRootor Doctor's lint state snapshot. One case failed under load: "preserves cold DB and sidecar names and bytes through full authority (profile=true)" insrc/gateway/server-methods/sessions-github-readiness.test.ts. It passed when rerun alone, both on this branch and with this PR's source reverted. After the last main merge, which changedtmp-openclaw-dir.ts,sqlite-private-directory,tmp-openclaw-diranddoctor-session-archive-cache-checktests: 42 passed.pnpm check:changed: lint, format and import-cycle guards pass. Madge: 0 cycles. The local tsgo typecheck can't run on this machine because the checkout uses the shared pnpm store, which its graph boundary refuses. CI's typecheck is the gate for that: on007d709c2f58it caught an unchecked tuple index in the new test (check-test-types-core-3), fixed in064f66db2bc2by typing the namesas const.config/test-lines-allocations/sqlite-snapshot-private-state-namespace.txt. The check passes (slack 11).origin/main, P0–P2): scoped-clean on96d0ecc8bfa3(before the last main merge).Test file audit (
src/infra/sqlite-private-directory.test.ts, read in full): the new case reuses the existing temp-dir tracker and owns its cache root. The earlier revision's assertions moved out of "isolates installations…", which is back to its original form. Nothing was pruned.