Skip to content

fix: leftover SQLite snapshot copies from Doctor and triage are never reclaimed - #193229

Merged
fuller-stack-dev merged 6 commits into
openclaw:mainfrom
fuller-stack-dev:fix/sqlite-snapshot-private-state-namespace
Nov 5, 2026
Merged

fuller-stack-dev merged 6 commits into
openclaw:mainfrom
fuller-stack-dev:fix/sqlite-snapshot-private-state-namespace

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Related: #193174, #193652

What Problem This Solves

Fixes: SQLite snapshot copies that Doctor or openclaw triage fail 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… and sqlite-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_DIR at 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.

resolveSnapshotStagingRoot now reuses the enclosing namespace when the resolved state directory is strictly inside an existing sqlite-<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 contains origin/main 2c04aec4eb6f. 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 the OPENCLAW_STATE_DIR at that moment:

  • Base: each triage or Doctor run created a fresh namespace (ca81928c…, 5c9aaece…, afc816a0…, b976225e… across runs). Its OPENCLAW_STATE_DIR was …/sqlite-<install>/openclaw-sqlite-readonly-v2-*/openclaw-sqlite-readonly-v2-*/openclaw-state.
  • This branch: two triage --run runs 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-state resolves 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 hashed sqlite-<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.

  • base: fails (the private state copy gets a new hashed namespace)
  • accepting the namespace itself (inside.length >= 0): fails (expected 2 to be 3)
  • accepting any enclosing directory, not just sqlite-<24 hex>: fails (the outside path resolves to openclaw-sqlite-readonly-v2-aB3dE6)
  • this branch: passes

Commands:

  • pnpm test on the 31 files touching the staging root, reclamation, retirement, read-only location cleanup, update-candidate state and Doctor lint state: 220 passed (first revision).
  • After adding the controls and merging main: vitest run on every test file that calls resolvePrivateSqliteSnapshotStagingRoot or Doctor's lint state snapshot. One case failed under load: "preserves cold DB and sidecar names and bytes through full authority (profile=true)" in src/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 changed tmp-openclaw-dir.ts, sqlite-private-directory, tmp-openclaw-dir and doctor-session-archive-cache-check tests: 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: on 007d709c2f58 it caught an unchecked tuple index in the new test (check-test-types-core-3), fixed in 064f66db2bc2 by typing the names as const.
  • Test-lines ratchet: net growth +25, recorded exactly in config/test-lines-allocations/sqlite-snapshot-private-state-namespace.txt. The check passes (slack 11).
  • Autoreview (Codex, branch mode against origin/main, P0–P2): scoped-clean on 96d0ecc8bfa3 (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.

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

clawsweeper Bot commented Nov 5, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: Each temporary state path produces another namespace that the installation’s Gateway never sweeps.
  • After: Both runs reuse sqlite-9565507d…, where existing maintenance can reclaim abandoned snapshots.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is narrow and source-supported; shipped CLI results are reported in prose rather than attached runtime traces, and current-head CI is unfinished.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports disposable-HOME triage runs retaining only the installation namespace, supported by source-reviewed regression controls.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Doctor and triage can leave large snapshot copies outside the Gateway’s automatic cleanup namespace.
Reason: The maintainer-authored change restores the existing cleanup design with a narrow shared-owner correction and explicitly separates historical leftovers.

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
Reviewed head: 064f66db2bc21852a05b791998e5407e7aac99bc

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Private cache staging keeps the original intent (c7f70f3: Avoid shared temporary-filesystem quota failures while preserving private-directory admission.)
  • Installation-scoped snapshot reclamation keeps the original intent (c16858b: Reclaim abandoned installation-owned copies without deleting snapshots held by live creators or readers.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c16858b adds src/infra/sqlite-private-directory.ts:45 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c16858baa256; files: src/infra/sqlite-private-directory.ts)
  • Vincent Koc: Raw commit ec7f8e9 adds src/infra/sqlite-private-directory.ts:142 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ec7f8e9dd1c3; files: src/infra/sqlite-private-directory.ts)

PR surface

Source +8, Tests +25, Other +2. Total +35 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 10 2 +8
Tests 1 25 0 +25
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 37 2 +35

Preflight source

Source 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

Metric Value Why it matters
Production and regression coverage Production +10/-2; tests +25/-0 The growth implements one shared namespace decision and tests the reported failure plus distinct boundary controls.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The report identifies 49 GB of stranded diagnostic snapshots, making repeated runs a material disk-exhaustion risk.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-05T05:50:35.239Z sha a8f78d5 :: needs changes before merge. :: [P3] Remove agent-attribution text from the public submission

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.
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@fuller-stack-dev
fuller-stack-dev merged commit 34bc643 into openclaw:main Nov 5, 2026
136 of 137 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/sqlite-snapshot-private-state-namespace branch November 5, 2026 19:07
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
… 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
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 6, 2026
… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant