Repository navigation
fix(sqlite): Gateway never frees snapshot copies left in other cache namespaces - #193652
Conversation
… namespace Doctor's private state copy and older releases staged SQLite snapshots in sibling sqlite-<hash> namespaces or directly under the shared cache parent. The Gateway sweep only looked in its own namespace, so those copies stayed forever. Sweep them too after a day of inactivity, using the same lifetime tokens that fence live creators and readers.
…tranded-namespace-sweep
|
🦞👀 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 changesExtend Gateway snapshot cleanup to abandoned token-bearing copies in sibling cache namespaces and the shared cache parent after 24 hours. Example: A killed v2026.11.1 process leaves a nested snapshot directly under the shared cache parent, idle for 25 hours.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a storage leak that remains on current main; the previous documentation finding is fixed, and no actionable introduced defect remains. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway maintenance discovers cached SQLite snapshots, delegates reclamation to the existing native worker, and records removed bytes and retained directories. flowchart TD
A[Gateway maintenance] --> B[Discover eligible cache roots]
B --> C[Native staging sweep worker]
C --> D[Check age ownership and nested tokens]
D --> E[Retain live or unknown copies]
D --> F[Retire abandoned snapshot payloads]
F --> G[Report reclaimed bytes]
Technical reviewBest possible solution: Use the existing retirement worker to reclaim eligible abandoned copies while preserving live tokens, unknown layouts, primary databases, and backups. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the missed-root path, and the supplied base/head results demonstrate stranded copies surviving before the change; this review ran no reproduction. Is this the best way to solve the issue? The change is focused: discovery stays with Gateway maintenance, deletion stays with the existing retirement owner, and both new test groups protect distinct observable failures. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 00d9c69743b2. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +45, Tests +105, Docs +8, Other +2. Total +160 across 5 files. Added test files: 1. 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, 2:31 PM ET / 19:31 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…namespaces (openclaw#193652) * fix(sqlite): reclaim snapshot copies stranded beside the installation namespace Doctor's private state copy and older releases staged SQLite snapshots in sibling sqlite-<hash> namespaces or directly under the shared cache parent. The Gateway sweep only looked in its own namespace, so those copies stayed forever. Sweep them too after a day of inactivity, using the same lifetime tokens that fence live creators and readers. * docs: describe the cross-namespace snapshot sweep in the recovery guide
…namespaces (openclaw#193652) * fix(sqlite): reclaim snapshot copies stranded beside the installation namespace Doctor's private state copy and older releases staged SQLite snapshots in sibling sqlite-<hash> namespaces or directly under the shared cache parent. The Gateway sweep only looked in its own namespace, so those copies stayed forever. Sweep them too after a day of inactivity, using the same lifetime tokens that fence live creators and readers. * docs: describe the cross-namespace snapshot sweep in the recovery guide
Related: #193174, #193229
What Problem This Solves
Fixes: SQLite snapshot copies already left under
~/Library/Caches/openclaw/by earlier Doctor oropenclaw triageruns are never deleted, because they sit outside the namespace the Gateway sweeps.On one Mac host, two triage runs left 49 GB of copies in
sqlite-0e5d8581…andsqlite-ac549b06…, beside the installation's ownsqlite-9565507d…namespace. Older releases also left flatopenclaw-sqlite-readonly-v2-*directories directly under the cache parent.User Impact
The Gateway's existing maintenance sweep now also frees snapshot copies stranded in sibling
sqlite-<hash>namespaces and directly under the shared cache parent, once they have been idle for a day. Copies that a live process still owns or reads are kept, as before.Why This Change Was Made
PR #193229 stops new copies from landing in per-run namespaces, and #193174 fixes the cleanup failure on cancellation. Neither one removes copies that are already on disk.
After the pass over its own namespace,
reclaimAbandonedSqliteSnapshotsnow lists the cache parent. It runs the same staging-sweep worker on each siblingsqlite-<24 hex>namespace and on the parent itself, which holds the flatopenclaw-sqlite-readonly-v2-*entries. The worker accepts exactly those roots: its own namespace, a sibling namespace, or their shared parent.Liveness is unchanged:
owner.sqlitemust be taken withBEGIN EXCLUSIVEandtimeout: 0.allowLegacy: falsestill rejects pre-token layouts.Copies outside this installation's namespace must be idle for 24 hours across the whole tree (reusing
SQLITE_SNAPSHOT_LEGACY_AGE_MS), because another installation may be between allocation and first use. The installation's own namespace keeps its 15-minute grace.The sweep is best-effort. Errors on a sibling root, including an unreadable one, are counted as
skippedand never thrown, and empty namespace directories are left in place. The own-namespace pass behaves as before.Evidence
Compatibility with copies left by the latest stable release (v2026.11.1,
4ffdd2047d19). In a disposable HOME, cache and state dir, that tag's own staging code made two nested copies directly under<cache>/openclaw/, which is where v2026.11.1 stages them (it has nosqlite-<hash>namespaces):owner.sqliteand a 512-byte-journalat each level, as on the affected host;The directory also held a tokenless
openclaw-sqlite-readonly-v2-*directory, a pre-tokenopenclaw-sqlite-readonly-<pid>-*directory, and a nested copy outside the sweep roots. Everything was aged to 25 hours, then swept:origin/main{ removed: 0, bytes: 0, skipped: 0 }{ removed: 1, bytes: 73728, skipped: 2 }{ removed: 1, bytes: 73728, skipped: 1 }Head
d4b60a86e0c0, which containsorigin/main8eb01599c83a. The red/green runs below used basee0466ffe4d11; after merging main (whose only change on these paths adds a read-only lookup totmp-openclaw-dir.ts), the reclamation and temp-root tests were rerun: 29 passed.Regression tests in the new
src/infra/sqlite-snapshot-reclamation.test.tsdrivereclaimAbandonedSqliteSnapshotsthrough the real staging-sweep worker process, with real staging tokens and nested copies whose child creator has exited:removed: 1; only the own-namespace copy)openclaw-sqlite-readonly-v2-*directory, and an unreadable sibling namespace give{ removed: 0, bytes: 0, skipped: 5 }, and every directory stays. After the creator and reader release, the same two copies are reclaimed.skipped: 0; siblings are never inspected)Commands:
vitest run src/infra/sqlite-snapshot-reclamation.test.ts src/infra/sqlite-snapshot-reclamation.process.test.ts: 3 passed. The existing process test (a killed byte-copy creator in the own namespace) is unchanged.pnpm check:changed: format, lint (core and scripts), runtime import cycles and the other guards pass. Two steps fail for reasons outside this change. The dead-export scan reports existing unused exports insrc/gateway/auth.ts,src/gateway/github-publication-workflows.tsand a cron test-support file, none of them touched here. The local tsgo typecheck refuses this checkout's shared pnpm store ("Declaration input escapes checkout"), so CI's typecheck is the gate for that.config/test-lines-allocations/sqlite-snapshot-stranded-namespace-sweep.txt. The check passes (slack 11).vitest runon the 26 test files that import reclamation, retirement, the read-only worker or Gateway maintenance: 435 passed, 1 skipped. One suite,src/cli/update-cli/update-command-post-core-admission.process.test.ts, fails at setup because it expects a built candidatedistworker. It fails the same way in a checkout without this change.origin/main, P0–P2): scoped-clean on0701b48827cc.Docs:
docs/reference/database-schemas/integrity-and-recovery.mdnow describes the sibling-namespace and cache-parent sweep, its 24-hour grace beside the own namespace's 15 minutes, and the layouts that still need offline cleanup.Test file audit:
src/infra/sqlite-snapshot-reclamation.test.tsis new. It owns its temp root through the shared tracker, stubs onlyXDG_CACHE_HOMEandOPENCLAW_STATE_DIR(restored after each test), restores the unreadable directory's mode before cleanup, and releases every token it takes.src/infra/sqlite-snapshot-reclamation.process.test.tswas read and is unchanged.