Skip to content

fix: reclaim abandoned archive backup scratch - #154199

Merged
steipete merged 5 commits into
mainfrom
upd/unattended-restart-backup-retention
Sep 21, 2026
Merged

steipete merged 5 commits into
mainfrom
upd/unattended-restart-backup-retention

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Related: #154114 (part B). Thanks @agebreak0083 for the report.

What Problem This Solves

Interrupted archive backups can leave large temporary config and database captures behind, and failed cleanup was silently swallowed, consuming space needed by later updates.

User Impact

New archive backups report cleanup failures with the scratch path. The next backup run and openclaw doctor --fix reclaim abandoned scratch while preserving scratch held by a live transaction. Ordinary Doctor reports candidates without opening or changing their tokens.

If a scanned scratch directory disappears before reclamation, the lifecycle owner records alreadyReclaimed and reports “Backup scratch already reclaimed.” It neither emits a warning nor claims that this pass removed the directory. Every such candidate was previously observed, so this is an already-reclaimed outcome, not a never-created claim. A missing child file alone does not qualify.

Legacy tokenless directories are reported for manual inspection, not automatically deleted: older backup writers have no lifetime records that can distinguish them from abandoned scratch. Stop older backup processes before removing those reported directories. Published archives and package rollback backups remain outside this cleanup.

Why This Change Was Made

Archive scratch uses the existing SQLite staging transaction primitive shared with private snapshots. Reclamation requires exclusive transaction custody and validates the scratch layout and filesystem identity. Retirement is committed before deleting payloads. A retired scratch name survives partial cleanup, allowing a later pass to retry even after the token is removed. Recorded archive destinations locate fallback scratch roots; completed outcome records do not grant cleanup authority.

The r3 correction uses the shared missing-path classifier for both Node errors and fs-safe’s not-found result, then confirms the scratch root itself is absent. Cleanup records removed, already-reclaimed, and failed outcomes separately. Genuine cleanup failures, live transactions, unknown contents, and substituted paths retain their existing protections.

There are no new options, dependencies, or canonical database schemas. Candidate Doctor uses its existing repair flow; an already-running older backup is not retrofitted with a token. The separate unattended update authorization fix is outside this PR.

Evidence

  • Deterministic regressions failed against the preceding implementation, including the exact root dir not found false warning. They cover disappearance before lstat, before the real fs-safe root boundary, and at removal, plus a vanished child whose scratch root remains.
  • The local scratch suite passed all 10 tests in 1.87 s wrapper wall (0.887 s Vitest wall). Doctor’s existing lifecycle test also checks the visible already-reclaimed outcome.
  • Rebased without conflicts onto cc93169068686341dc173960a9020fc2cda45013, including the canonical native-process fixture admission-clock fix 9247701e7ae351dc71e81e51d6628b49e2e13dee. The rebase preserved production behavior.
  • Blacksmith Testbox tbx_01m31s6cae5rspn22kx9a4vpkt passed all 34 tests across scratch retention, archive publication, vanished-file backup/restore, Doctor, and native-process authority in 121.63 s. Infrastructure tests took 42.86 s; Doctor took 3.07 s (208 ms test time); native-process authority took 70.24 s. The formerly failing replace-around-open case passed in 447 ms. Testbox run.
  • After the mock typing correction, the same Testbox verified the final scratch file: all 10 tests passed in 4.44 s wrapper wall (2.67 s Vitest wall). The owned lease was stopped after proof.
  • Selected changed-file gates passed after correcting mock typing: core and test typechecks, lint, formatting, schema, storage, dependency, boundary, deprecation, dead-export, runtime-loader, and import-cycle checks. Previously passing checks were reused and the remaining native commands completed successfully.
  • Final P1 autoreview is scoped-clean. The initial regression mock had a strict-TypeScript overload error; separate lstat/rmdir mocks correct it without changing the production fix.
  • Earlier isolated macOS proof invoked the production Doctor scratch handler with two real scratch-owning processes. After SIGKILL of one owner, read-only inspection preserved both directories; repair reclaimed 1,048,576 payload bytes from the dead owner, preserved the live owner, and preserved a package rollback sentinel. The surviving owner completed normal cleanup.
  • R3 own production interdiff versus f540823810d: +51/-16 (net +35); tests +77/-0; docs +2/-0. Whole PR: production +566/-74, tooling +2/-0, tests +356/-0, docs +18/-0.

Focused Testbox command: node scripts/run-vitest.mjs src/infra/backup-scratch.test.ts src/infra/backup-create.publication.test.ts src/infra/backup-create.vanished.test.ts src/commands/doctor-backup-scratch.test.ts extensions/codex/src/app-server/run-attempt-native-process-authority.test.ts --maxWorkers=1.

No end-to-end package installation or Gateway restart was performed for this correction. Auto-merge remains disabled; this revision is for r3 review.

@clawsweeper

clawsweeper Bot commented Sep 21, 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 commands Command implementations size: L maintainer Maintainer-authored PR labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 00:21
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 21, 2026, 7:09 AM ET / 11:09 UTC (Revision 5).

ClawSweeper review

What this changes

Archive backups gain transaction-protected scratch cleanup, abandoned-directory recovery through subsequent backups and Doctor, and explicit cleanup outcomes.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 5 items remain

The cleanup work remains useful and is absent from current main. The already-reclaimed correction is sound, but the previously reported Windows retirement defect remains unresolved.

Priority: P2
Reviewed head: 8c7f9c93a0df985a55af9d8e660efd75152bbb40

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful lifecycle design and real macOS observations are limited by the unresolved Windows defect and update compatibility gap.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured macOS production-Doctor observations demonstrate dead-owner reclamation while preserving a live owner and rollback sentinel. This remains valid bounded lifecycle proof; Windows retirement and the published-updater compatibility check remain separate unresolved merge requirements.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured macOS production-Doctor observations demonstrate dead-owner reclamation while preserving a live owner and rollback sentinel. This remains valid bounded lifecycle proof; Windows retirement and the published-updater compatibility check remain separate unresolved merge requirements.
Evidence reviewed 11 items Introduced cleanup operation: The pinned merge-base-to-head diff introduces a pre-created retirement directory followed by an overwrite move. Normal completion and abandoned-directory reclamation both use this operation before deleting payloads.
Verified filesystem dependency contract: The target pins @openclaw/fs-safe 0.17.0 and its filesystem facade delegates Root.move to this dependency. Inspection of the verified dependency repository and release tag shows overwrite moves reach fs.rename without removing the existing destination directory.
Windows rename implementation: Node 24.16.0's bundled libuv implements rename using MoveFileExW with MOVEFILE_REPLACE_EXISTING.
Findings 1 actionable finding [P2] Avoid renaming onto an existing directory on Windows
Security None None.

How this fits together

Archive creation stages configuration and database copies before publishing a backup. The scratch lifecycle owner coordinates writers and cleanup, while Doctor discovers abandoned directories and reports or repairs them.

flowchart TD
  A[Backup creation] --> B[Private scratch directory]
  B --> C[SQLite lifetime transaction]
  D[Next backup or Doctor] --> E[Inspect layout and acquire custody]
  C --> E
  E --> F[Preserve live or unknown scratch]
  E --> G[Retire and remove abandoned scratch]
  G --> H[Report cleanup outcome]
Loading

Before merge

  • Avoid renaming onto an existing directory on Windows (P2) - The retirement destination is created immediately before this overwrite move. Pinned fs-safe 0.17.0 delegates it to fs.rename, whose Windows implementation rejects an existing directory destination. Consequently normal backup completion and abandoned-scratch reclamation stop before payload deletion, leaving captures behind; Doctor retries hit the same failure. This previously reported blocker remains present. Use a portable retirement operation while retaining identity and collision safeguards.
  • Resolve merge risk (P1) - Windows backup completion and reclamation cannot retire scratch through the existing-directory overwrite move, so payloads accumulate despite repeated Doctor repair.
  • Resolve merge risk (P1) - The published-updater × candidate Doctor compatibility check requested in the prior review remains unrecorded; standalone macOS handler proof does not establish preservation of existing scratch and rollback material through that update entrypoint.
  • Complete next step (P2) - Repair portable scratch retirement, demonstrate Windows cleanup and retry, and record the published-updater × candidate Doctor compatibility result.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P2] Avoid renaming onto an existing directory on Windows — src/infra/backup-scratch.ts:153-159
Agent review details

Security

None.

PR surface

Source +492, Tests +356, Docs +18, Other +2. Total +868 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 8 566 74 +492
Tests 3 356 0 +356
Docs 1 18 0 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 13 942 74 +868

Review metrics

Metric Value Why it matters
Lifecycle implementation growth Production +566/-74 (net +492); tests +356/-0 The stated growth implements transaction custody, guarded reclamation, recovery outcomes, and Doctor integration while sharing the existing staging primitive.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-backup-scratch.ts, migration/backfill/repair: src/flows/doctor-health-contribution-runners.state.ts, migration/backfill/repair: src/infra/backup-create.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Make retirement portable (recommended)
    Repair the Windows retirement operation without weakening identity or collision checks, then verify normal cleanup, abandoned cleanup, retry, and the published-updater boundary.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Replace the existing-directory overwrite retirement with a portable operation that preserves source identity, destination collision protection, committed retirement, and partial-cleanup recovery; validate Windows cleanup and the published-updater-to-candidate Doctor path with existing scratch and rollback material.

Technical review

Best possible solution:

Use portable, identity-checked retirement within the shared scratch owner, with Windows recovery and published-updater compatibility demonstrated before landing.

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

Yes, from source: a Windows backup reaches a rename onto an existing directory, which the pinned dependency and Windows API reject. This review did not execute a Windows reproduction.

Is this the best way to solve the issue?

The shared lifetime owner is appropriate, but the retirement operation must be portable; the already-reclaimed correction does not address that failure.

Full review comments:

  • [P2] Avoid renaming onto an existing directory on Windows — src/infra/backup-scratch.ts:153-159
    The retirement destination is created immediately before this overwrite move. Pinned fs-safe 0.17.0 delegates it to fs.rename, whose Windows implementation rejects an existing directory destination. Consequently normal backup completion and abandoned-scratch reclamation stop before payload deletion, leaving captures behind; Doctor retries hit the same failure. This previously reported blocker remains present. Use a portable retirement operation while retaining identity and collision safeguards.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6e70aff09276.

Labels

Label justifications:

  • P2: This is a bounded backup-maintenance repair for abandoned disk usage, with a concrete Windows cleanup defect remaining.
  • merge-risk: 🚨 compatibility: Merging replaces working normal scratch deletion with a retirement operation Windows rejects, and update-entrypoint compatibility proof remains outstanding.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The captured macOS production-Doctor observations demonstrate dead-owner reclamation while preserving a live owner and rollback sentinel. This remains valid bounded lifecycle proof; Windows retirement and the published-updater compatibility check remain separate unresolved merge requirements.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured macOS production-Doctor observations demonstrate dead-owner reclamation while preserving a live owner and rollback sentinel. This remains valid bounded lifecycle proof; Windows retirement and the published-updater compatibility check remain separate unresolved merge requirements.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/infra/backup-scratch.test.ts src/infra/backup-create.publication.test.ts src/commands/doctor-backup-scratch.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs --dry-run -- src/infra/backup-scratch.ts src/infra/backup-scratch.test.ts src/infra/backup-create.publication.test.ts src/commands/doctor-backup-scratch.test.ts.
  • [P1] git diff --check.
  • [P1] On Windows, exercise normal backup cleanup, dead-owner reclamation, live-owner preservation, and retry after partial deletion through the production owners.
  • [P1] Exercise a published updater against the candidate Doctor with existing legacy/new scratch and package rollback material; record the observed preservation and cleanup outcomes.

What I checked:

  • Introduced cleanup operation: The pinned merge-base-to-head diff introduces a pre-created retirement directory followed by an overwrite move. Normal completion and abandoned-directory reclamation both use this operation before deleting payloads. (src/infra/backup-scratch.ts:153, 8c7f9c93a0df)
  • Verified filesystem dependency contract: The target pins @openclaw/fs-safe 0.17.0 and its filesystem facade delegates Root.move to this dependency. Inspection of the verified dependency repository and release tag shows overwrite moves reach fs.rename without removing the existing destination directory. (src/root-impl.ts:1498, 38b312a51900)
  • Windows rename implementation: Node 24.16.0's bundled libuv implements rename using MoveFileExW with MOVEFILE_REPLACE_EXISTING. (deps/uv/src/win/fs.c:2333, c7d10158bc31)
  • Windows destination restriction: Microsoft documents that MOVEFILE_REPLACE_EXISTING reports an error when the destination names an existing directory: MoveFileExW contract. This applies to the empty reservation created by the patch.
  • Prior finding remains applicable: The previous completed review reported the Windows overwrite-directory defect. Reading the earlier reviewed file through GitHub confirms that the current retirement operation retains that implementation. The latest correction instead adds missing-root classification and separate already-reclaimed reporting. Local comparison of the older head was unavailable; GitHub supplied the original file. (src/infra/backup-scratch.ts:158, f540823810d7)
  • Current main still needs scratch recovery: Fetched main still allocates scratch with mkdtemp and silently catches recursive cleanup failures; it has no backup-scratch module. The central recovery behavior therefore remains necessary. (src/infra/backup-create.ts:702, 6e70aff09276)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Repair retirement and demonstrate normal cleanup, abandoned-scratch reclamation, and partial-cleanup retry on Windows.
  • Record the published-updater × candidate Doctor result with existing scratch and package rollback material.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-21T00:29:27.733Z sha e3baac3 :: blocked before merge. :: [P2] Avoid renaming onto an existing directory on Windows
  • reviewed 2026-09-21T01:51:13.027Z sha fc98de4 :: blocked before merge. :: [P2] Avoid renaming onto an existing directory on Windows
  • reviewed 2026-09-21T02:41:54.196Z sha 33d98e3 :: blocked before merge. :: [P2] Avoid renaming onto an existing directory on Windows
  • reviewed 2026-09-21T08:57:09.002Z sha f540823 :: blocked before merge. :: [P2] Avoid renaming onto an existing directory on Windows

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 21, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 21, 2026
@steipete
steipete enabled auto-merge (squash) September 21, 2026 04:41
@steipete
steipete force-pushed the upd/unattended-restart-backup-retention branch from 33d98e3 to f540823 Compare September 21, 2026 08:47
@steipete
steipete disabled auto-merge September 21, 2026 10:37
Record scratch cleanup warnings and protect live archive scratch with the existing SQLite staging lifetime primitive. Reclaim retired scratch through the backup and Doctor owners, preserving package rollback material and tokenless legacy directories.

Related: #154114 (part B). Thanks @agebreak0083 for the report.
Add the new backup scratch and SQLite staging token modules to the curated wrapper source set so extracted wrapper processes resolve their eager imports. The three requested wrapper test files pass on Blacksmith Testbox (95 passed, one platform skip).
The staging-token extraction introduced six direct SQLite calls outside the approved execution boundary, failing lint:kysely in check:architecture. Compile the fixed statements through Kysely and execute synchronously on the same connection, preserving transaction admission and retirement.

Testbox reproduced the six violations before the fix. Afterward, check:architecture, 52 selected scratch/lifetime/Kysely/wrapper tests, core typecheck, and targeted lint passed. Independent review found no actionable issues. No guard policy or baseline changes.
@steipete
steipete force-pushed the upd/unattended-restart-backup-retention branch from f540823 to 8c7f9c9 Compare September 21, 2026 11:01
@steipete
steipete enabled auto-merge (squash) September 21, 2026 11:05
@steipete
steipete merged commit 0e4f556 into main Sep 21, 2026
218 checks passed
@steipete
steipete deleted the upd/unattended-restart-backup-retention branch September 21, 2026 11:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
* fix: reclaim abandoned archive backup scratch

Record scratch cleanup warnings and protect live archive scratch with the existing SQLite staging lifetime primitive. Reclaim retired scratch through the backup and Doctor owners, preserving package rollback material and tokenless legacy directories.

Related: openclaw#154114 (part B). Thanks @agebreak0083 for the report.

* style: avoid reassigning scratch cleanup parameters

* fix(ci): include backup modules in PR wrapper inventory

Add the new backup scratch and SQLite staging token modules to the curated wrapper source set so extracted wrapper processes resolve their eager imports. The three requested wrapper test files pass on Blacksmith Testbox (95 passed, one platform skip).

* fix(infra): execute staging tokens through Kysely

The staging-token extraction introduced six direct SQLite calls outside the approved execution boundary, failing lint:kysely in check:architecture. Compile the fixed statements through Kysely and execute synchronously on the same connection, preserving transaction admission and retirement.

Testbox reproduced the six violations before the fix. Afterward, check:architecture, 52 selected scratch/lifetime/Kysely/wrapper tests, core typecheck, and targeted lint passed. Independent review found no actionable issues. No guard policy or baseline changes.

* fix: avoid warnings for already reclaimed backup scratch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant