Skip to content

fix(doctor): fall back to a guarded hard-link move when RENAME_NOREPLACE is rejected - #164748

Merged
steipete merged 1 commit into
mainfrom
upd/upd-doctor-audit-log-rename-noreplace-einval
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-doctor-audit-log-rename-noreplace-einval

Conversation

@steipete

@steipete steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Closes #164703

What Problem This Solves

Fixes Doctor's legacy config audit-log migration on filesystems that reject native no-replace rename, as reported on a QNAP ZFS-backed Docker bind mount.

Why This Change Was Made

Audit migration bypassed the guarded fallback already used by other Doctor source claims. Share that implementation at OpenClaw's fs-safe call boundary and route all seven audit moves through it. Keep native rename first, then publish an exclusive hard link, verify inode ownership, sync, and remove the old name.

Copying would lose later appends through a predecessor CLI's open descriptor. Recovery therefore recognizes only the exact two-link source/claim/archive/journal/quarantine pairs. Backup capture sanitizes one destination snapshot without mutating the live pair. Existing source-claim migrations use the same helper; fs-safe remains unchanged.

User Impact

Doctor can complete the migration while preserving late appends and never overwriting an existing destination. If hard links are also unavailable, it preserves the audit inode, emits a visible warning with the file, filesystem limitation, and state-specific openclaw doctor --fix command, and lets independent repairs and update finalization continue.

Unsupported files remain for a later repair. Operator guidance requires stopping the Gateway and CLI writers before relocating state to a compatible filesystem. Collision, identity, authority, and post-publication failures retain their safety checks. No config, CLI, dependency, or database schema changes.

Evidence

Regression and recovery proof

  • Reproduced the original refusal by injecting EINVAL at fs-safe's native renameNoReplace primitive. Regression coverage now also exercises ENOSYS and EOPNOTSUPP.
  • Kept a predecessor append descriptor open across migration, verified the same archive inode and the later row, then imported it exactly once on retry.
  • Injected EPERM, EXDEV, and EMLINK at hard-link publication: the original bytes/inode remain, a warning names the targeted repair command, and independent migration continues. Archive/journal-stage deferral and deduplicated retry also pass.
  • Exercised interrupted claim, raw archive, restoration, journal, and quarantine pairs; competing destinations, unrelated hardlinks, third links, and revoked authority remain protected.
  • The Doctor receipt regression verifies skipped, no refusal exception, preserved bytes, and completion of the later exec-approvals repair.
  • Backup tests verify one sanitized capture, retained live names, unchanged inode/link count, and rejection of unrelated aliases.

Validation

Local macOS, Node 26.10.0. Tests use real isolated filesystem/SQLite state with native primitive fault injection; no QNAP device or Windows runtime proof is claimed.

  • Four affected suites, 3 runs × 86 passing tests: audit logs, audit backup, audit skips, and source snapshots. Wrapper wall times: 184.25 s, 215.45 s, and 215.14 s.
  • Remaining importers and bounded sibling checks: 25 Gateway tests passed; 21 infra tests passed, with the existing Windows-only case skipped on macOS. This includes backup create/lease, commitments, and workspace portable-move recovery.
  • ci-changed-node-test-plan.selection.test.ts: 15 passed.
  • Required eager-import, PR-wrapper-source, and PR-worktree-provision closure suites: 36 passed, one existing platform-specific skip; 405.47 s wall time.
  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 CI=1 node scripts/check-changed.mjs --base 12c5644ad78f4a3b3882cb7e10aaf8f49bbeb3d0 --timed: all selected gates passed locally, including core/test types, lint, documentation, unused exports, and structural guards.
  • node --import ./scripts/tsx.mjs scripts/check-export-name-collisions.mts and node scripts/tests/update-restart-swap-fixture.mjs: passed.
  • Independent direct-route Codex P1 review: scoped-clean, no accepted/actionable findings. Formatting and git diff --check passed.

Test cost

Measured with the repository Vitest wrapper and --maxWorkers=1 (the same test entry point used by pnpm test). Hosted CI timing is pending; the table reports local serial test seconds across the three final repetitions:

Suite Run 1 Run 2 Run 3
Audit logs 48.61 82.35 59.61
Audit backup 0.68 0.68 0.99
Audit skips 101.98 113.31 133.92
Source snapshots 0.29 0.32 0.32

The audit boundary uses real durable file operations and SQLite to prove inode retention, safe publication, interrupted recovery, and Doctor receipt continuation. No Gateway boots, sleeps, retries, or timeout increases were added.

Slow pre-existing suites (waived)

state-migrations.audit-skips.test.ts reached 171.99 s of test time during initial validation and 133.92 s in the final repetitions. pr-worktree-provision.test.ts took 348.84 s; its existing APFS cold/warm/sparse scenario took 105.43 s and passed its unchanged deadline. These pre-existing costs are covered by the maintainer's slow-suite waiver.

Inherited gate and tooling recovery

The initial PR-provisioning gate failed because the extracted wrapper lacked the application runtime that template operations were trying to load. Integrated the already-landed fix b97d4c03f364d244db687b372930c29759a45cc9 (#164706), which gives templates a narrow worker entry while keeping the broad runtime absent. All ten lane files were byte-identical across that rebase; all three closure suites then passed.

The combined importer JSON reporter rejected Gateway's inline simple project before running those tests. Split the configurations and used the normal reporter for Gateway; all remaining tests passed. No assertions or product guards were weakened.

Change size

Production: +506 / -224. Tests: +421 / -32. Docs: +15 / -0. Total: +942 / -256 across 10 files.

Thanks to @bbs2i58 for the isolated filesystem probe and report.

Share the guarded hard-link move with audit claim, archive, restore, quarantine, and journal publication. Recover known interrupted inode pairs, preserve read-only backup capture, and defer unsupported hard links with a warning so independent repairs and updates continue.

Preserve open predecessor append descriptors and never overwrite an existing destination. Closes #164703. Thanks to @bbs2i58 for the filesystem probe.
@clawsweeper

clawsweeper Bot commented Oct 4, 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 size: XL labels Oct 4, 2026
@steipete
steipete marked this pull request as ready for review October 4, 2026 03:47
@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 11:53 PM ET / October 4, 2026, 03:53 UTC.

ClawSweeper review

What this changes

Doctor shares a guarded hard-link fallback across legacy audit migrations, recovers interrupted moves, and preserves unsupported files with actionable warnings.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful fix for an established filesystem compatibility failure. No concrete introduced correctness defect was found, and current main still uses direct native moves for audit migration.

Priority: P2
Reviewed head: d52742d0b56cd01dbbdd44c24923e650ba20313f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is coherent and supported by meaningful production-boundary evidence, with one required upgrade integration case outstanding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Reported macOS runs exercise the production Doctor migration with real filesystem/SQLite state and native fault injection, observing preserved append descriptors, exactly-once recovery, safe collisions, and sanitized backups. Existing journal/checkpoint formats and legacy-state recovery remain compatible; published-updater integration is a separate outstanding repository gate.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Reported macOS runs exercise the production Doctor migration with real filesystem/SQLite state and native fault injection, observing preserved append descriptors, exactly-once recovery, safe collisions, and sanitized backups. Existing journal/checkpoint formats and legacy-state recovery remain compatible; published-updater integration is a separate outstanding repository gate.
Evidence reviewed 8 items Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduced hunks. The verified test merge records the pinned base followed by the exact PR head, and its result contains only the same migration changes; endpoint drift was not attributed to this PR.
Current main still needs the fix: Fetched main directly moves audit claims, archives, restorations, and quarantine files through Root.move. The released v2026.9.8 source independently shows the same direct moves. The linked report describes an observed QNAP filesystem failure: #164703.
Fallback and dependency boundary: The helper directly imports fs-safe and its native configuration, establishing the dependency contract. It retains native moves first, rejects fallback for guarded mutation policies or required-native mode, pins the parent, publishes an exclusive link, and verifies the exact inode pair before removal.
Findings None None.
Security None None.

How this fits together

Doctor imports legacy audit files into OpenClaw’s shared SQLite state and preserves sanitized recovery archives. Filesystem failures affect migration receipts, subsequent repairs, and update completion.

flowchart TD
  A[Legacy audit files] --> B[Doctor migration]
  B --> C[Native no-replace move]
  C -->|Unsupported| D[Guarded exclusive hard link]
  D -->|Supported| E[Import and recover archives]
  C -->|Supported| E
  D -->|Unsupported| F[Preserve files and warn]
  E --> G[SQLite history and repair receipts]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The supplied evidence does not establish that a published installed updater completes candidate finalization when legacy audit moves are deferred; the repository explicitly requires that integration case.
  • Complete next step (P2) - Add the repository-required published-driver × candidate evidence showing update finalization continues when unsupported audit moves produce recoverable warnings.
Agent review details

Security

None.

PR surface

Source +282, Tests +389, Docs +15. Total +686 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 506 224 +282
Tests 3 421 32 +389
Docs 1 15 0 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 942 256 +686

Review metrics

Metric Value Why it matters
Production versus regression growth Production net +282 lines; tests net +389 lines The growth has a stated purpose: share the existing fallback and cover audit-specific recovery, preservation, and backup behavior.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/state-migrations.no-replace-move.ts, migration/backfill/repair: src/infra/state-migrations.source-snapshot.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Complete installed-updater coverage (recommended)
    Provide the required published-driver × candidate result showing preserved audit inputs and successful update finalization after recoverable deferral.

Technical review

Best possible solution:

Keep one guarded migration move owner that preserves legacy inodes, sanitized backups, and repair continuation, with verified compatibility through the installed updater.

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

Yes, from source: current-main audit moves propagate fs-safe’s helper-unavailable result for native EINVAL, matching the reporter’s isolated filesystem observation. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: sharing the established guarded move implementation preserves open-descriptor appends and avoids a competing copy-based migration path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 06131c40d09f.

Labels

Label changes:

  • add P2: This repairs a reported migration failure on a specific filesystem without evidence of data loss or a whole-Gateway outage.
  • add merge-risk: 🚨 compatibility: Doctor warning semantics affect upgrade continuation, and compatibility through the published installed updater remains unverified.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Reported macOS runs exercise the production Doctor migration with real filesystem/SQLite state and native fault injection, observing preserved append descriptors, exactly-once recovery, safe collisions, and sanitized backups. Existing journal/checkpoint formats and legacy-state recovery remain compatible; published-updater integration is a separate outstanding repository gate.
  • 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. Sufficient (live_output): Reported macOS runs exercise the production Doctor migration with real filesystem/SQLite state and native fault injection, observing preserved append descriptors, exactly-once recovery, safe collisions, and sanitized backups. Existing journal/checkpoint formats and legacy-state recovery remain compatible; published-updater integration is a separate outstanding repository gate.

Label justifications:

  • P2: This repairs a reported migration failure on a specific filesystem without evidence of data loss or a whole-Gateway outage.
  • merge-risk: 🚨 compatibility: Doctor warning semantics affect upgrade continuation, and compatibility through the published installed updater remains unverified.
  • 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. Sufficient (live_output): Reported macOS runs exercise the production Doctor migration with real filesystem/SQLite state and native fault injection, observing preserved append descriptors, exactly-once recovery, safe collisions, and sanitized backups. Existing journal/checkpoint formats and legacy-state recovery remain compatible; published-updater integration is a separate outstanding repository gate.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported macOS runs exercise the production Doctor migration with real filesystem/SQLite state and native fault injection, observing preserved append descriptors, exactly-once recovery, safe collisions, and sanitized backups. Existing journal/checkpoint formats and legacy-state recovery remain compatible; published-updater integration is a separate outstanding repository gate.

Evidence

What I checked:

  • Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduced hunks. The verified test merge records the pinned base followed by the exact PR head, and its result contains only the same migration changes; endpoint drift was not attributed to this PR. (76a68482214d)
  • Current main still needs the fix: Fetched main directly moves audit claims, archives, restorations, and quarantine files through Root.move. The released v2026.9.8 source independently shows the same direct moves. The linked report describes an observed QNAP filesystem failure: [Bug]: Doctor audit-log migration fails on QNAP ZFS bind mount when RENAME_NOREPLACE returns EINVAL #164703. (src/infra/state-migrations.audit-logs.ts:312, 06131c40d09f)
  • Fallback and dependency boundary: The helper directly imports fs-safe and its native configuration, establishing the dependency contract. It retains native moves first, rejects fallback for guarded mutation policies or required-native mode, pins the parent, publishes an exclusive link, and verifies the exact inode pair before removal. (src/infra/state-migrations.no-replace-move.ts:78, d52742d0b56c)
  • Verified native error and publication contracts: Inspected v0.21.1 native move normalization and exclusive publication. EINVAL becomes helper-unavailable; link-required never copies; failures after target creation receive a wrapped publication error. The tag resolves to the listed dependency commit. (src/root-move-noreplace.ts:68, 305ff575ce13)
  • After-fix production filesystem evidence: The captured PR body reports three successful runs of the affected suites on macOS with real isolated filesystem and SQLite state. Inspected regressions inject native syscall failures while exercising the production migration, retain an open append descriptor, verify archive inode identity, recover the later row exactly once, and preserve competing destinations and unrelated links. QNAP and Windows execution are expressly not claimed. (src/infra/state-migrations.audit-logs.test.ts:58, d52742d0b56c)
  • Existing-state and authority safeguards: Backup capture verifies and sanitizes one known destination without unlinking live names. Existing journal and checkpoint formats remain unchanged. The retained source-claim suite exercises revoked Root authority, required-native refusal, third-link rejection, and root rebinding; the extracted helper continues to use Root.remove at the final mutation boundary. (src/infra/state-migrations.source-snapshot.test.ts:249, d52742d0b56c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • MasterSwords1: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Record published installed-updater × candidate evidence for audit deferral and successful finalization.

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.

@steipete
steipete merged commit db01dc3 into main Oct 4, 2026
165 of 204 checks passed
@steipete
steipete deleted the upd/upd-doctor-audit-log-rename-noreplace-einval branch October 4, 2026 03:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…ACE is rejected (openclaw#164748)

Doctor's legacy config audit-log migration failed on filesystems where renameat2(RENAME_NOREPLACE) returns EINVAL (QNAP ZFS bind mount), stopping the migration at its exclusive source-claim move. The guarded hard-link no-replace move already used by the source claim is now the shared helper for every audit move site: it keeps the destination exclusive, preserves late appends from a still-open predecessor descriptor (same inode), and recovers interrupted link pairs; when hard links are also unavailable it leaves the files intact, warns with the manual command, and lets the migration continue. A copy-based fallback was rejected because it would drop late appends and trip Doctor's inode-change refusal. Closes openclaw#164703.
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 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Bug]: Doctor audit-log migration fails on QNAP ZFS bind mount when RENAME_NOREPLACE returns EINVAL

1 participant