Skip to content

fix: reclaim abandoned read-only database snapshots - #192368

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-abandoned-readonly-staging-reclamation-20260919
Nov 4, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-abandoned-readonly-staging-reclamation-20260919

Conversation

@steipete

@steipete steipete commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: read-only database copies accumulate after a creator is killed, and plain openclaw status can unnecessarily copy the entire state database when reading update history.

User Impact

New abandoned snapshots are reclaimed by Gateway maintenance after a 15-minute grace period, without deleting copies held by live creators, nested workers, or inspection workers. Plain status reads avoid an unnecessary snapshot. Existing flat shared-cache snapshots remain explicit offline cleanup because their installation cannot be identified safely.

Why This Change Was Made

Stage new copies under a private namespace derived from the installation's state directory. The existing delayed startup/hourly maintenance owner runs a streaming scan with bounded memory and the native worker deadline through the existing native SQLite worker, using the existing lifetime-token retirement protocol. Inspection workers retain their own read token through result publication, so killing their launcher cannot expose a live snapshot to reclamation. Explicit artifact-preserving update diagnostics retain their existing behavior.

No new configuration, SQLite schema, survivor process, or cleanup IPC. Production growth is 164 lines for the deferred reclamation owner and complete lifetime coverage; removing the redundant status scope is a net deletion. Related: #191639, #191782.

Evidence

Focused regressions fail on exact parent 073498226768e62d6ee0232b4e196cb487fc56cc and pass on this change: unnecessary update-history snapshot; inspection-worker lifetime after launcher release; Gateway maintenance leaving an aged abandoned copy. Real native byte-copy SIGSTOP/SIGKILL proof covers abandoned journal files, live parent ownership, live nested ownership, and subsequent reclamation. Relevant read-only, update, cancellation, cleanup, and Gateway maintenance tests pass. pnpm build:ci-artifacts passes. Independent Codex autoreview: no actionable findings.

Synthetic btrfs workload: 35.03 GiB database, 4,000 sessions, 62,000 workspace files / 1.10 GB. A/A controls and five interleaved A/B pairs: all unchanged-owner samples retain the abandoned copy; all reclamation samples remove it; live owners remain. Median copied bytes at kill: 596 MiB. Reclamation median/p95: 45.47/59.14 ms wall, 10.76/11.47 ms owner CPU, 364/446 KB sampled allocation. This measures a byte copy; it does not assert a production-matched fragmentation ratio.

Rerunnable workloads: scripts/perf/sqlite-staging-reclamation-measure.mts, scripts/perf/sqlite-staging-maintenance-measure.mts, and scripts/perf/gateway-status-read-measure.mts. Acceptance: zero unnecessary status snapshots; dead copies reclaimed with live copies retained; five paired fresh-process measurements plus A/A controls; maintenance/rollback wall, CPU, allocation and tails must not materially regress (20% is a stop). Final status-owner results on a synthetic 12.03-GiB shared state database (five counterbalanced pairs):

Median / p95 Before After
Staged directories 1 / 1 0 / 0
Wall 34.448 / 55.121 s 3.654 / 3.802 s
Owner CPU 4.872 / 7.567 s 3.064 / 3.169 s
Total process CPU 12.90 / 15.24 s 10.22 / 10.72 s
Instrumented allocation 13.11 / 20.63 MB 1.89 / 2.05 MB
Peak RSS 756 / 760 MB 679 / 687 MB

A/A wall controls were 44.78/26.51 s. Allocation includes the staging observer, so longer copies incur more observer allocation. Endpoint RSS increased 467→677 MB at substantially different process ages; peak RSS is the one-shot process maximum and improved. This measures the update-history owner, not every possible diagnostic read.

Quiet fresh-maintenance/rollback qualification (A/A controls and five counterbalanced pairs):

Median / p95 Before After
Maintenance wall 13.825 / 16.955 s 14.076 / 15.186 s
Maintenance CPU 627 / 855 ms 630 / 674 ms
Maintenance allocation 162.294 / 166.591 MB 161.080 / 163.947 MB
Rollback wall 8.202 / 10.705 s 8.271 / 9.271 s
Rollback CPU 1,373 / 1,595 ms 1,398 / 1,555 ms
Rollback allocation 14.259 / 15.370 MB 14.191 / 14.631 MB
Total process CPU 61.89 / 69.06 s 62.63 / 69.94 s

Median wall/CPU changes are at most +1.82%, below A/A variation (about 2–6%); allocations decrease slightly. Loads were 7.42–12.98. An earlier campaign overlapped builds/checks and regressed maintenance/rollback timing tails by 52.5%/73.5%; those raw results were retained and a serial repeat resolved the qualification gap. No speedup is claimed from baseline tail variation.

Commands: node --import ./scripts/tsx.mjs scripts/perf/sqlite-staging-reclamation-measure.mts --root <synthetic-root>; node --import ./scripts/tsx.mjs scripts/perf/sqlite-staging-maintenance-measure.mts --base <parent> --candidate <candidate> --out <new-output>; and node --import ./scripts/tsx.mjs scripts/perf/gateway-status-read-measure.mts --subject src/infra/update-run-reader.ts --export getUpdateRunHistoryStatusAsync with isolated synthetic state/cache environment.

Hosted review found fixed-prefix scan starvation; the corrected streaming scan is covered by 257 reclaimable copies mixed with 256 missing-token directories. The regression fails before that correction and passes afterward. Initial CI also caught the omitted wrapper inventory entry and a proof byte-count race before SIGSTOP delivery; both are repaired, with the exact byte-count assertion retained. Focused wrapper, Gateway maintenance, and real SIGKILL tests pass.

pnpm check:changed exposes a main regression: four unused exports in src/gateway/node-plugin-tool-snapshot.ts, reproduced on the exact parent and introduced by e0ac3370bbe37d73abc057bc8bd4dd32670c8e97 (#191589). This PR does not modify that owner; the failure is retained for attribution rather than hidden with a baseline change.

The exact parent also exceeds the test-line ceiling by 53 (6,443,949 versus 6,443,896). Commit 073498226768 (#192297) added 65 lines with only 12 slack and no allocation. The exact-parent staged ratchet against its predecessor reproduces the failure. This is a second inherited main regression; this PR adds only its own 282-line justified allocation and does not alter the baseline.

Final CI checks out merge f185cb0d5e7f34143c148f1b2b40f3bb22e1e7a7 of this head into main 70f04d86b7c52c5948d50c0593745d9fdd99c8b5. That actual main parent has 47 lines of inherited budget debt: #192302 removed six lines from the original 53-line overrun.

A newly introduced main type regression also appears in final CI: f32ee258e30983f699abbe4fd3c4d3ad0114f563 (#192302) moved McpCatalogTool to agent-bundle-mcp-catalog.types.ts without updating the import in mcp-metadata.ts. The repository core typecheck on exact main parent 70f04d86 exits 2 with all five diagnostics identical to CI. The owner sources, configuration, package manifest and lockfile are identical between that parent and the tested merge. SDK declaration emission fails on the same missing type; the later missing-full-receipt publication error is downstream. This is a main regression requiring repair, not noise or a PR-caused failure. Final CI run 41739591548, attempt 1, completed with exactly nine inherited root failures plus the aggregate: the budget ratchet, seven typecheck jobs, and SDK declaration/publication. All selected test jobs, including PostgreSQL conformance, passed; security-fast passed. Extension lint was selected but skipped because the failed SDK declaration job emitted no artifact, and its job condition requires that artifact. This downstream skip is included explicitly in the aggregate attribution. Native admission uses the explicitly authorized pinned-head inherited-failure route and retains failed CI rather than relabeling it green.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: XL labels Nov 3, 2026
@steipete
steipete marked this pull request as ready for review November 3, 2026 23:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-11-03T23:32:18.724219Z 81087a9 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b57a3a744

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reclaims abandoned installation-scoped database snapshots and avoids unnecessary copies during ordinary status reads.

Example: A snapshot creator is killed after copying 596 MiB.

  • Before: The abandoned copy remains without automatic Gateway reclamation.
  • After: Delayed maintenance can reclaim it after 15 minutes of inactivity, while live tokens prevent deletion.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused repair with native fault evidence and no concrete introduced defect; broad CI attribution remains unresolved.
Proof confidence 🐚 platinum hermit (4/6) The maintainer-authored proof exemption applies; supplied production-owner measurements cover interrupted native copies, live custody, reclamation, and zero unnecessary status snapshots.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Killed readers leave large disposable copies behind, and ordinary status can unnecessarily copy the shared database.
Reason: The maintainer-authored direction addresses demonstrated waste while deliberately retaining offline ownership of historical shared-cache copies.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses concrete snapshot leaks and unnecessary status copies using existing owners; no introduced correctness defect was found, but failing CI checks remain unattributed.

Priority: P2
Reviewed head: 81087a9ae3f82c244f00060d9a74d921ac37cc99

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supplied measurements exercise production owners and native processes, rather than a complete plain-status CLI and scheduled Gateway lifecycle.
Agent review details

How this fits together

Status and update inspection use the shared SQLite read infrastructure; Gateway maintenance sends abandoned snapshot directories through the existing native worker and token-protected retirement owner.

flowchart TD
  A[Status request] --> B[Shared state read owner]
  B --> C[Native read connection]
  D[Gateway maintenance] --> E[Installation snapshot namespace]
  E --> F[Native cleanup worker]
  F --> G[Token protected retirement]
Loading

Technical review

Best possible solution:

Keep the installation-scoped sweep in the existing maintenance worker and preserve explicit inspection custody and legacy-cache boundaries.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes both paths, and the supplied evidence reports parent-failing regressions and real interrupted-copy measurements; this review executed no target code.

Is this the best way to solve the issue?

The change uses the existing read, maintenance, worker, and retirement owners, with necessary namespace isolation and inspection custody rather than a competing cleanup system.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 003f1f6ed569.

Provenance checked

  • Gateway abandoned-snapshot maintenance changes intended behavior with a stated reason (e68dfaf: Removed shared-cache scanning because cleanup can stall the filesystem and copies span independently owned installations.)
  • Status artifact-preserving reads changes intended behavior with a stated reason (5ff5fb2: Moved history reads into workers while preserving cold-read artifacts and warm polling behavior.)
  • Nested snapshot retirement keeps the original intent (b25f3d8: Reclaim disposable bytes under exclusive parent and descendant custody before allocating retirement markers.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit b25f3d8 adds src/infra/sqlite-snapshot-retirement.ts:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b25f3d82963c; files: src/infra/sqlite-snapshot-retirement.ts)

PR surface

Source +164, Tests +282, Docs +14, Other +570. Total +1030 across 31 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 10 180 16 +164
Tests 13 315 33 +282
Docs 3 25 11 +14
Config 0 0 0 0
Generated 0 0 0 0
Other 5 570 0 +570
Total 31 1090 60 +1030

Labels

Label changes:

  • add P2: Abandoned copies waste disk space and ordinary status can copy a large database; this is a focused storage and responsiveness repair.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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: Abandoned copies waste disk space and ordinary status can copy a large database; this is a focused storage and responsiveness repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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.

Reviewed November 3, 2026, 6:47 PM ET / 23:47 UTC.

@steipete
steipete merged commit c16858b into main Nov 4, 2026
167 of 182 checks passed
@steipete
steipete deleted the steipete/perf-micro-abandoned-readonly-staging-reclamation-20260919 branch November 4, 2026 00:04
@steipete

steipete commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
* fix: reclaim abandoned read-only database snapshots

* fix: let snapshot reclamation progress past retained copies
vincentkoc added a commit that referenced this pull request Nov 4, 2026
* commit 'b4ebd3673fea4932296b92bbc07b7abc4bdc792d':
  fix(ci): allow serial SDK API reports to finish (#192196)
  fix(ci): run PostgreSQL checks when its shard planner changes (#191963)
  fix(ci): model native Linux updater asset entry
  improve(test): speed up config and device binding browser tests (#192404)
  improve(ui): show arrivals top right with a contextual session status (#192016)
  improve(ui): mark error toasts and split two-sentence copy (#192015)
  fix(sandbox): give dependency builders a writable home (#192390)
  fix(worktrees): keep archive manifest checks off the main thread (#192358)
  fix(cron): preserve admitted runs and pacing across unrelated MCP reloads (#192399)
  improve(ui): stack toasts in a center lane and an arrivals lane (#192014)
  fix: reclaim abandoned read-only database snapshots (#192368)
  improve(ui): rebuild the toast on one component with variants and a hover dismiss (#192013)
  docs: consolidate team server and team setup into one Multiplayer page
  fix(ci): reconcile remaining unallocated test lines
  feat: run admitted MCP tools on the worker node that hosts them (#191387)
brandon-julio-t added a commit to brandon-julio-t/openclaw that referenced this pull request Nov 5, 2026
The browser CI bundle fails its invalid-database and WAL-cookie import cleanup controls because they expect the entire cache root to disappear. Upstream c16858b intentionally introduced a retained per-installation SQLite namespace. The fixture now checks the correct cleanup boundary: exactly one recognized namespace remains, and it is empty. Extra root entries and leftover scratch files or directories still fail.

Related: openclaw#192368
Validation: the original fixture reproduces both CI failures locally (2 failed, 24 passed). The repaired browser/identity/early-exit/system-profile group passes all 26 cases on pinned Bun in 12.80 seconds. No runtime SQLite behavior changes. Independent P0-P2 review reports no findings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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