Skip to content

fix: recovery originals stay retirable after a doctor NOCOW rewrite - #169893

Merged
steipete merged 7 commits into
openclaw:mainfrom
xydigitLybnnnn:fix/169674-nocow-recovery-identity
Oct 13, 2026
Merged

steipete merged 7 commits into
openclaw:mainfrom
xydigitLybnnnn:fix/169674-nocow-recovery-identity

Conversation

@xydigitLybnnnn

@xydigitLybnnnn xydigitLybnnnn commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #169674

What Problem This Solves

Fixes openclaw update cleanup permanently blocking verified pre-migration recovery originals after openclaw doctor --fix rewrites their btrfs store with NOCOW.

User Impact

Recovery originals remain eligible for the existing cleanup process after a verified NOCOW rewrite and a later successful update. Unproven or replaced originals and destination databases remain protected. Cleanup still requires offline ownership, verified migration completion, a later completed update, content verification, and consent.

Why This Change Was Made

The directory exchange changes file identities. Doctor now updates the existing migration manifest only when its pre-rewrite inventory matches the recorded generation. Backups must also match their recorded pre-copy timestamp/size and copied SHA-256. Destination databases retain their generation binding while allowing normal in-place migration. Reconciliation failures produce warnings and leave cleanup conservative; the original directory and WAL-aware snapshots remain retained.

Original fix by @xydigitLybnnnn; maintainer cleanup consolidates identity reconciliation, removes duplicate helper-only tests, and exercises actual retirement and refusal through the existing owners. No schema, persisted format, configuration, retention policy, or cleanup safety change. No new state store.

Evidence

  • Source/history confirmation: main's NOCOW copy/exchange replaces inode and mtime without updating recovery records; inventory rejects changed metadata and retirement independently verifies the destination generation. The original NOCOW owner was introduced in perf(sqlite): prepare NOCOW stores and add offline btrfs repair #160877; recovery registration and destination binding in fix(doctor): retire deferred receipts and track migration backups #162771.
  • CI is the test/typecheck gate. doctor-sqlite-nocow.recovery-identity.test.ts covers retires a recorded recovery original after a NOCOW rewrite without changing live data and keeps the original protected after changing %s for destination replacement, backup replacement, changed backup metadata, and corrupted copied bytes. Existing NOCOW/Doctor/cleanup tests run in the applicable CI shards.
  • Local changed-file core oxlint passed. The normal wrapper could not load the parent install's missing eslint-plugin-solid; the static fallback retained the root lint rules and removed only the unrelated ui/**/*.tsx plugin override. Changed-file oxfmt and git diff --check passed. No dependency installation or shared-install changes.
  • Deslop: removed verbose reconciliation narration and repeated guards; replaced 178 lines of duplicate helper tests with stronger owner-boundary coverage.
  • Codex autoreview: scoped-clean at P0–P2. The initial review flagged pre-copy metadata continuity in the old index; the committed revision fixes it, and the final branch review found no actionable findings. The subsequent test-only subprocess correction also passed P0–P2 autoreview.
  • Live Gateway/btrfs, stable-to-candidate execution, local tests/typechecks, and negative-control execution were intentionally skipped per the maintainer proof policy of 2026-10-13. PR CI is the proof gate. The previous ClawSweeper requests for live and compatibility execution are proof-only requests under that policy; its prior P1 destination-binding finding remains covered, and the latest review reports no code findings.
  • Exact-head CI: passed for 8d810fa7117dbd4e0fc939cb782dfa0e03e8b326: run 38404907293, 41 successful jobs and 28 skipped, including production/test typechecks, lint, tests, and openclaw/ci-gate. Current origin/main was merged immediately before pushing. The first attempt on this head hit a 300-second plugin-SDK declaration-preparation timeout after core lint had passed; one retry of only the failed jobs succeeded. This was not classified as inherited: the latest scheduled main run passed the corresponding lint job. First run 38403059533, job 115316218790, exposed a test-fixture defect: its subprocess mock rejected the real ownership-inspection Node worker. The fixture now delegates Node calls while keeping btrfs tools mocked. The existing NOCOW suite passed 26/26 on that first run. This was introduced test setup, not an inherited failure.
  • Test cost: the new regression file passed 5/5 in CI job 115322908327: 16.41 s including the wrapper (14.49 s Vitest duration). These tests exercise real snapshot, ownership, and retirement boundaries; no local timing because local test execution was intentionally skipped.

Exact diff versus merged main: production +106 / -0, tests +180 / -0, docs +4 / -0; total +290 / -0 across six files (down from +484 across seven). The remaining positive production delta is the required producer-side identity bookkeeping; eliminating it would leave stale identities or weaken cleanup. No unrelated safety code was removed to meet a line target.

Doctor's btrfs NOCOW repair copies every store file into a fresh directory, so
the inode and mtime recorded in the migration manifest no longer match the live
file. `update cleanup` then classifies a verified recovery original as
blocked/artifact-metadata-changed, and its destination-database check rejects
the rewritten database, permanently disabling a documented retirement path for
operators who followed the NOCOW guidance.

After a successful directory exchange the rewrite now re-records the relocated
identity of the recovery originals and destination databases it exchanged,
only after proving the copy still carries the recorded content (size and
sha256). Anything that cannot be proven keeps its original record and stays
protected, so no cleanup safeguard is weakened.

Fixes openclaw#169674
@clawsweeper

clawsweeper Bot commented Oct 12, 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: M labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Doctor refreshes recorded recovery-original and destination-database identities after a verified NOCOW rewrite.

Example: Doctor rewrites a btrfs store containing a recorded 10,076,160-byte migration backup, followed by a successful update.

  • Before: The backup receives a new inode and update cleanup blocks it with artifact-metadata-changed.
  • After: Doctor transfers verified identity evidence so the existing cleanup process can retire the backup with consent.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and has no identified correctness blocker, but required behavior and existing-state compatibility proof are absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot reclaim verified migration backups through update cleanup after Doctor rewrites their store with NOCOW.
Reason: The change restores an existing documented retirement contract and retains conservative protection for unmatched originals and destinations.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR addresses a reported current-main cleanup defect with a focused producer-side fix, and no actionable code finding remains.

Priority: P2
Reviewed head: 8d810fa7117dbd4e0fc939cb782dfa0e03e8b326

Before merge

  • Add real behavior proof - Supplied evidence exercises repair and retirement functions through Vitest with substituted btrfs tools and later-update history, rather than the shipped CLI. Provide redacted terminal output or logs showing Doctor NOCOW repair on btrfs, a later successful update, actual retirement, and refusal after destination replacement. Because this rewrites persisted identity evidence, also show a v2026.10.2-to-candidate upgrade preserving settings, database contents, and recovery records; unchanged manifest schemas alone do not establish compatibility. Redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: The shipped btrfs CLI repair-to-update-to-retirement sequence, replacement refusal, and a base-fails/head-passes regression execution are not shown.
Agent review details

How this fits together

Offline Doctor maintenance copies and exchanges SQLite store directories; recovery manifests carry their identity evidence into update cleanup, which verifies ownership, destination generation, content, and consent before deleting originals.

flowchart TD
  A[Offline Doctor ownership] --> B[Store inventory]
  B --> C[Verified NOCOW rewrite]
  C --> D[Recovery manifest reconciliation]
  D --> E[Later successful update]
  E --> F[Cleanup verification and consent]
  F --> G[Retire eligible originals]
Loading

Technical review

Best possible solution:

Refresh only verified rewritten generations in Doctor while preserving the existing cleanup ownership, consent, and content checks.

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

The linked report supplies an official affected version and cleanup output, and current source confirms that NOCOW copying changes identities rejected by recovery inventory; no runtime reproduction was executed during this review.

Is this the best way to solve the issue?

Updating evidence at the verified rewrite producer addresses the cause without weakening retirement checks or introducing a competing cleanup policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 79e11a6b4b1b.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 302dbad adds src/commands/doctor-sqlite-nocow.ts:167 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 302dbadcb82a; files: src/commands/doctor-sqlite-nocow.ts)
  • Dallin Romney: Raw commit 93e8737 adds src/commands/doctor-maintenance-state.ts:68 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 93e87378063a; files: src/commands/doctor-maintenance-state.ts)

PR surface

Source +106, Tests +180, Docs +4. Total +290 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 106 0 +106
Tests 2 180 0 +180
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 290 0 +290

Review metrics

Metric Value Why it matters
Production versus test LOC Production +106/-0; tests +180/-0 Production growth supplies identity reconciliation at the rewrite producer; tests cover retirement and four distinct refusal inputs through existing owners.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #169674
Summary: This PR is the open fixing candidate for the reported NOCOW-to-cleanup identity mismatch.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The defect prevents supported disk reclamation after explicit btrfs maintenance without establishing data loss or a broken core runtime.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 (3 earlier review cycles)
  • reviewed 2026-10-12T12:54:26.856Z sha 4825b20 :: needs real behavior proof before merge. :: [P1] Match the recorded destination to the pre-rewrite database
  • reviewed 2026-10-13T01:21:08.686Z sha 40e7d4d :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T13:20:07.158Z sha c776dea :: needs real behavior proof before merge. :: none

Reviewed October 13, 2026, 9:38 AM ET / 13:38 UTC (Revision 4).

…generation

The earlier reconciliation refreshed whichever file occupied a recorded path, so
a valid database that replaced the recorded destination before the rewrite was
adopted and cleanup could then retire the original against the wrong generation.
Bind each refresh to the rewrite's pre-exchange dev/ino: an artifact must still
match its recorded identity and carry the recorded size and sha256, and a
destination must still be the generation whose migration was verified. Mismatches
stay protected and are reported, preserving PR openclaw#162771's destination binding.

Fixes the P1 review finding on openclaw#169893.
@xydigitLybnnnn

Copy link
Copy Markdown
Contributor Author

Addressed the review on head 40e7d4d5211.

  • P1 (destination binding) fixed — reconciliation now refreshes a record only when the file being rewritten still matches the recorded pre-exchange dev/ino (carried from the rewrite's own inventory); a recovery original must additionally keep its recorded size + sha256. A database that merely replaced the recorded path is no longer adopted, so cleanup keeps rejecting it. Regression: doctor-sqlite-nocow.recovery-identity.test.ts → "does not rebind a destination database that was replaced before the rewrite".
  • Stored-data compatibility — no schema or persisted-field change; manifests are still read as v1–v4, and an unmatched manifest is left byte-identical (unit test added).
  • Real behavior proof — this host has no btrfs support: no btrfs in /proc/filesystems, no kernel module, no root, and GNU mv 8.30 without --exchange/--no-copy; a privileged container cannot add btrfs because the host kernel lacks it. So the live btrfs doctor --fix → update → update cleanup sequence cannot run here. The strongest available proof is at the real repair + cleanup code boundary (real repairDoctorSqliteNoCow and recovery inventory, with only the btrfs/root filesystem tools substituted through the repo's existing NOCOW fixture). The PR body now states this limitation and includes a btrfs-host runbook.
  • CI — checks-node-changed-compact-small-1 fails on src/gateway/server-methods/agents-delete.upgrade.test.ts ("SQLite session reclamation database owner is no longer current"). It reproduces identically on pristine upstream/main (e550cd44d2f) with this branch absent, so it is inherited red, not caused by this change; openclaw/ci-gate only aggregates it.

Local gates on main @ e550cd44d2f: 6 related files / 61 tests pass, tsgo:core exit 0, oxlint 0/0, oxfmt clean, line-cap + max-lines ratchets OK.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Oct 13, 2026
@steipete
steipete merged commit 29fb33a into openclaw:main Oct 13, 2026
200 of 204 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…penclaw#169893)

* fix(doctor): keep recovery originals retirable across a NOCOW rewrite

Doctor's btrfs NOCOW repair copies every store file into a fresh directory, so
the inode and mtime recorded in the migration manifest no longer match the live
file. `update cleanup` then classifies a verified recovery original as
blocked/artifact-metadata-changed, and its destination-database check rejects
the rewritten database, permanently disabling a documented retirement path for
operators who followed the NOCOW guidance.

After a successful directory exchange the rewrite now re-records the relocated
identity of the recovery originals and destination databases it exchanged,
only after proving the copy still carries the recorded content (size and
sha256). Anything that cannot be proven keeps its original record and stays
protected, so no cleanup safeguard is weakened.

Fixes openclaw#169674

* fix(doctor): refresh NOCOW recovery identities only for the recorded generation

The earlier reconciliation refreshed whichever file occupied a recorded path, so
a valid database that replaced the recorded destination before the rewrite was
adopted and cleanup could then retire the original against the wrong generation.
Bind each refresh to the rewrite's pre-exchange dev/ino: an artifact must still
match its recorded identity and carry the recorded size and sha256, and a
destination must still be the generation whose migration was verified. Mismatches
stay protected and are reported, preserving PR openclaw#162771's destination binding.

Fixes the P1 review finding on openclaw#169893.

* fix(doctor): preserve exact recovery identity across NOCOW rewrites

Consolidate the verified rewrite identity handoff and preserve the pre-copy metadata check. Exercise actual cleanup and refusal for replaced destinations, originals, metadata, and changed bytes.

Co-authored-by: xydigitLybnnnn <[email protected]>

* test(doctor): allow cleanup ownership workers in NOCOW fixture

---------

Co-authored-by: xydigitLybnnnn <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
hilsbos pushed a commit to hilsbos/openclaw that referenced this pull request Oct 22, 2026
…penclaw#169893)

* fix(doctor): keep recovery originals retirable across a NOCOW rewrite

Doctor's btrfs NOCOW repair copies every store file into a fresh directory, so
the inode and mtime recorded in the migration manifest no longer match the live
file. `update cleanup` then classifies a verified recovery original as
blocked/artifact-metadata-changed, and its destination-database check rejects
the rewritten database, permanently disabling a documented retirement path for
operators who followed the NOCOW guidance.

After a successful directory exchange the rewrite now re-records the relocated
identity of the recovery originals and destination databases it exchanged,
only after proving the copy still carries the recorded content (size and
sha256). Anything that cannot be proven keeps its original record and stays
protected, so no cleanup safeguard is weakened.

Fixes openclaw#169674

* fix(doctor): refresh NOCOW recovery identities only for the recorded generation

The earlier reconciliation refreshed whichever file occupied a recorded path, so
a valid database that replaced the recorded destination before the rewrite was
adopted and cleanup could then retire the original against the wrong generation.
Bind each refresh to the rewrite's pre-exchange dev/ino: an artifact must still
match its recorded identity and carry the recorded size and sha256, and a
destination must still be the generation whose migration was verified. Mismatches
stay protected and are reported, preserving PR openclaw#162771's destination binding.

Fixes the P1 review finding on openclaw#169893.

* fix(doctor): preserve exact recovery identity across NOCOW rewrites

Consolidate the verified rewrite identity handoff and preserve the pre-copy metadata check. Exercise actual cleanup and refusal for replaced destinations, originals, metadata, and changed bytes.

Co-authored-by: xydigitLybnnnn <[email protected]>

* test(doctor): allow cleanup ownership workers in NOCOW fixture

---------

Co-authored-by: xydigitLybnnnn <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit 29fb33a)
Co-authored-by: RomneyDa <[email protected]>
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 P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: doctor --fix NOCOW rewrite makes pre-startup-migration .bak originals permanently non-retirable by update cleanup (artifact-metadata-changed)

2 participants