Repository navigation
fix: interrupted triage leaves full-size SQLite snapshot copies in the cache - #193174
Conversation
When `openclaw triage` (or Doctor's in-process collection) is interrupted, the database-engine inspection worker task is cancelled while it holds a private read-only snapshot. Its cleanup runs, but every SQLite statement on the staging token, and the retirement of the copy's admission facts, goes through the worker's admission exchange. That exchange checks the task's cancellation first, so cleanup failed with "SQLite admission facts exchange cancelled by its caller" and the multi-gigabyte copy stayed under ~/Library/Caches/openclaw/sqlite-<hash>/ after the process exited. Add a settlement scope to the admission relay that keeps the caller's deadline but not its cancellation, and use it in the two cleanup primitives: the staging token's lock operations and admission-fact retirement for a removed path. Live readers still fence retirement through their own disk tokens. 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 changesThis PR lets cancelled inspection workers release SQLite staging locks and retire snapshot admission facts while preserving deadlines and live-reader protection. Example: Interrupt triage with SIGINT while inspecting a disposable 3.1 GB database.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete cancellation cleanup failure still present on main. No actionable code finding remains; the verified squash workflow resolves the earlier attribution concern. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherDoctor and triage run database inspections in served workers; snapshot cleanup uses staging locks and host admission exchanges before removing private database copies. flowchart TD
A[Triage or Doctor] --> B[Inspection worker]
B --> C[Private SQLite snapshot]
B --> D[Cancellation and cleanup]
D --> E[Admission settlement scope]
E --> F[Staging locks and admission retirement]
F --> G[Remove unheld snapshot]
Technical reviewBest possible solution: Land the focused cancellation settlement repair through the native squash workflow, keeping deadline-expiry and hangup repairs separately scoped. Do we have a high-confidence way to reproduce the issue? Source confirms cancellation rejects cleanup admission exchanges, and the author supplies repeated real-command red/green reproduction; this read-only review ran no target code, and the original non-interrupted host incidents remain unexplained. Is this the best way to solve the issue? The patch repairs the existing cleanup primitives, retains their lock checks, and extracts the existing wait scope into a leaf to avoid an import cycle; each added component serves the cancellation fix. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 474592cc2b42. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +55, Tests +58, Other +3. Total +116 across 7 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. 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 (2 earlier review cycles)
Reviewed November 5, 2026, 2:15 PM ET / 19:15 UTC (Revision 3). |
Move the admission-wait scope (its store, deadline reader, cancellation check and the new settlement scope) into a leaf module. The staging token and admission-fact retirement import it there instead of through the worker relay, which closed a madge type-import cycle. The relay re-exports the helpers its existing importers use. Record the regression test's exact net test-line growth. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ancelled-retirement
The PR wrapper extracts its import closure from scripts/pr-lib/wrapper-components.txt. The new src/infra/sqlite-database-admission-wait.ts is in that closure, so wrapper bootstrap and PR worktree provisioning failed to resolve it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ancelled-retirement
Cancelled cleanup only needs reclaim, release and retirement, so leave create-mode token acquisition outside the settlement scope. The regression test now stages the copy in a nested child directory whose creator exits first, so retiring the parent must reclaim the child after cancellation.
…ancelled-retirement
…ancelled-retirement
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
On the remaining P3 about agent-attribution trailers: The branch commits are not what gets published. This PR lands through #193134, #193622, #193626, #193132, #193229 and #193648 all landed today the same way: their branches had these trailers, and their squash commits on main have none. Removing the trailers from the branch would need a force-push to an open PR, and that wouldn't change what lands. No commits added since the review carry the trailer, and the PR body has no generated footer. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…e cache (openclaw#193174) * fix: retire cancelled workers' SQLite snapshot copies When `openclaw triage` (or Doctor's in-process collection) is interrupted, the database-engine inspection worker task is cancelled while it holds a private read-only snapshot. Its cleanup runs, but every SQLite statement on the staging token, and the retirement of the copy's admission facts, goes through the worker's admission exchange. That exchange checks the task's cancellation first, so cleanup failed with "SQLite admission facts exchange cancelled by its caller" and the multi-gigabyte copy stayed under ~/Library/Caches/openclaw/sqlite-<hash>/ after the process exited. Add a settlement scope to the admission relay that keeps the caller's deadline but not its cancellation, and use it in the two cleanup primitives: the staging token's lock operations and admission-fact retirement for a removed path. Live readers still fence retirement through their own disk tokens. * fix: keep the admission-wait scope out of the worker relay import cycle Move the admission-wait scope (its store, deadline reader, cancellation check and the new settlement scope) into a leaf module. The staging token and admission-fact retirement import it there instead of through the worker relay, which closed a madge type-import cycle. The relay re-exports the helpers its existing importers use. Record the regression test's exact net test-line growth. * fix: list the admission-wait leaf in the PR wrapper inventory The PR wrapper extracts its import closure from scripts/pr-lib/wrapper-components.txt. The new src/infra/sqlite-database-admission-wait.ts is in that closure, so wrapper bootstrap and PR worktree provisioning failed to resolve it. * fix(sqlite): keep cancelled tasks from minting snapshot staging owners Cancelled cleanup only needs reclaim, release and retirement, so leave create-mode token acquisition outside the settlement scope. The regression test now stages the copy in a nested child directory whose creator exits first, so retiring the parent must reclaim the child after cancellation.
…e cache (openclaw#193174) * fix: retire cancelled workers' SQLite snapshot copies When `openclaw triage` (or Doctor's in-process collection) is interrupted, the database-engine inspection worker task is cancelled while it holds a private read-only snapshot. Its cleanup runs, but every SQLite statement on the staging token, and the retirement of the copy's admission facts, goes through the worker's admission exchange. That exchange checks the task's cancellation first, so cleanup failed with "SQLite admission facts exchange cancelled by its caller" and the multi-gigabyte copy stayed under ~/Library/Caches/openclaw/sqlite-<hash>/ after the process exited. Add a settlement scope to the admission relay that keeps the caller's deadline but not its cancellation, and use it in the two cleanup primitives: the staging token's lock operations and admission-fact retirement for a removed path. Live readers still fence retirement through their own disk tokens. * fix: keep the admission-wait scope out of the worker relay import cycle Move the admission-wait scope (its store, deadline reader, cancellation check and the new settlement scope) into a leaf module. The staging token and admission-fact retirement import it there instead of through the worker relay, which closed a madge type-import cycle. The relay re-exports the helpers its existing importers use. Record the regression test's exact net test-line growth. * fix: list the admission-wait leaf in the PR wrapper inventory The PR wrapper extracts its import closure from scripts/pr-lib/wrapper-components.txt. The new src/infra/sqlite-database-admission-wait.ts is in that closure, so wrapper bootstrap and PR worktree provisioning failed to resolve it. * fix(sqlite): keep cancelled tasks from minting snapshot staging owners Cancelled cleanup only needs reclaim, release and retirement, so leave create-mode token acquisition outside the settlement scope. The regression test now stages the copy in a nested child directory whose creator exits first, so retiring the parent must reclaim the child after cancellation.
What Problem This Solves
Fixes: interrupting
openclaw triage(Ctrl-C or SIGTERM) while Doctor's database inspection is copying a database leaves the full-size read-only copy under~/Library/Caches/openclaw/sqlite-<hash>/openclaw-sqlite-readonly-v2-*/openclaw-sqlite-readonly-v2-*/database.sqliteafter the process exits.On one Mac host, two triage runs left four nested copies of the agent and state databases (13, 15, 6.2 and 15 GB), and free disk fell from 87 GiB to 38 GiB. Every leftover
owner.sqlitewas empty with a 512-byte-journal, and no process held the files afterwards. Those two runs were not interrupted: one was refused late for an oversized--update-resultfile, the other was a non-TTY--runrefusal, and both exited 1. This PR fixes the leak mechanism I can reproduce, which is cancellation of the inspection task while it holds a copy. I have not reproduced that host's exact trigger; see Evidence.User Impact
An interrupted triage or Doctor inspection now removes its private snapshot copy before it exits. A copy that a live reader still holds is kept until that reader releases it, as before.
Why This Change Was Made
Doctor's database-engine inspection runs as a served worker task. When triage is interrupted, the task is cancelled, and its cleanup does start. But each SQLite statement on the private staging token, and the retirement of the copy's admission facts, goes through the worker's admission-facts exchange. That exchange checks the task's cancellation first. So cleanup failed with
SQLite admission facts exchange cancelled by its caller, and the worker thread was torn down with the copy still on disk.This adds
withSqliteDatabaseAdmissionSettlementto the admission-wait scope. The scope now lives in a leaf module,sqlite-database-admission-wait.ts, so the staging token and the admission store can import it without a madge cycle through the worker relay; the relay re-exports the helpers its existing importers use. The settlement scope stops outer cancellation from failing the exchange but keeps outer deadlines. Two cleanup primitives use it: the staging token's reclaim and read opens, release and retirement, andretireSqliteDatabaseAdmissionForPath. Creating a new staging owner is not settled, so a cancelled task still cannot allocate another copy. Every retirement path goes through those two. Live readers still fence retirement with their own disk tokens, and cancelled admission waits outside these two primitives behave as before. Each half alone still leaks; both are required.Ruled out:
beginSqliteSnapshotRetirementwith the gateway sweep's cutoff removed both nested and flat leftovers, including the stale-journal.owner.sqlitewith a 512-byte-journalis what a creator token holdingBEGIN IMMEDIATEleaves when its process ends without releasing. It's a live lock, not a failed commit.triage --json --update-result <9 KB file>(refused withFile exceeds 8192 bytesafter 237 s) removed every copy before it exited 1. Head behaves the same, as does the non-TTYtriage --runrefusal (exit 1 after writing the bundle).healthanddiagnostics.capabilitiescalls.Not fixed here: when the host dies, the spawn broker's SQLite native resource deliberately keeps creator custody of its own session-allocated snapshot (covered by the existing "refuses cleanup after losing its host fence port" test). The orphaned broker then keeps one flat copy alive. That fail-closed behaviour needs a maintainer decision, so it belongs in a separate PR.
Evidence
Head
67fb70d48f3f, which containsorigin/main480d50305383. The end-to-end red reproduction ran onffbbb514ba3b. The unit red/green below ran against merge base341f69b93d2d; after merging main to9f07ae4789dc, the focused tests were rerun. The last main merge (480d50305383) touches only Doctor's Codex route warnings, outside these paths, so the tests were not rerun for it.Reproduction, in a disposable HOME and state dir with a 3.1 GB state database owned by a disposable Gateway, then SIGINT to the
openclaw triage --non-interactive --jsonprocess group as soon as the nested copy appears:owner.sqlitewith a 512-byte-journal)Instrumenting base showed the worker calling
removeTempDirectoryAsync10 ms after cancellation, then failing atBEGINon the staging token (getSqliteDatabaseSchemaRevision→ admission exchange →worker task cancelled). With only the token change, it failed next atretireSqliteDatabaseAdmissionForPath.Regression test in
src/infra/worker-task-server.test.ts: "retires a cancelled task's snapshot copy unless a live reader still holds it". It drives the real task server, cancellation word, admission relay, staging tokens and real SQLite copies. Each copy sits in a nested staging directory, as Doctor's inspection leaves it: the child that wrote it releases its creator token first, so removing the parent after cancellation must takereclaimon the child. The test also checks that the host admission exchange was used and awaits the task's result.41e89ee105b4, which also settledcreate: fails the new control belowNegative controls in the same test:
falseand the nested copy stays. After the reader releases, the same removal succeeds.Commands:
vitest run src/infra/worker-task-server.test.ts test/scripts/eager-import-closure.test.tson the head: 29 passed.vitest runon the 209 test files that import the staging token, admission store or relay, snapshot staging, read-only location cleanup, retirement, reclamation or the worker task server: 4 failures in 3 files, and each fails identically with this PR's source reverted to the merge base:src/state/openclaw-state-db-readonly.test.ts("reads only active disposable scopes…", a/private/varvs/vartemp-path alias on macOS),src/config/sessions/session-transcript-reconcile.lease.test.ts(claim-before and claim-after cases) andsrc/cli/update-cli/update-command-failure-recovery.test.ts("settles a headless package rollback…").pnpm check:changed: lint, format, import-cycle and boundary guards pass. 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.origin/main, P0–P2): scoped-clean on389bc572e467(the head before that last main merge).scripts/check-madge-import-cycles.ts: 0 cycles (the first push had 1, fixed by the leaf module). Runtime import cycles: 0.scripts/pr-lib/wrapper-components.txt, the PR wrapper's import-closure inventory; CI's wrapper bootstrap and PR worktree provisioning tests failed without it.test/scripts/eager-import-closure.test.tspasses locally (36/36). The cases fromtest/scripts/pr-worktree-provision.test.tsthat failed in CI now pass locally; one other case there times out locally (178 s against a 120 s limit while materializing full clones) and did not fail in CI.config/test-lines-allocations/sqlite-snapshot-cancelled-retirement.txt. With current main the check passes (slack 30).Test file audit (
src/infra/worker-task-server.test.ts, read in full): the fixture's syntheticnode:worker_threadsmock now reports a workerthreadId, so fact retirement takes the cross-thread path a real served worker takes. The other six tests pass unchanged. The newnativeSectionsfixture parameter and the temp-dir tracker are used only by the new test, which owns and removes its temp root and awaits its task. Nothing was pruned: every existing case covers distinct behaviour.