Skip to content

fix: SQLite snapshot reads fail on Windows EFS-encrypted profile directories - #169159

Closed
JasonBuildAI wants to merge 5 commits into
openclaw:mainfrom
JasonBuildAI:fix/windows-efs-sqlite-snapshot-rename-jbai-x7q4
Closed

JasonBuildAI wants to merge 5 commits into
openclaw:mainfrom
JasonBuildAI:fix/windows-efs-sqlite-snapshot-rename-jbai-x7q4

Conversation

@JasonBuildAI

Copy link
Copy Markdown
Contributor

Related: #169157

What Problem This Solves

Fixes: read-only SQLite snapshot publication fails with EXDEV: cross-device link not permitted when the private staging directory inherits the EFS Encrypted attribute (for example %LOCALAPPDATA%\openclaw under a corporate encryption policy), which makes openclaw doctor stop at state-migration detection and block every later migration step.

User Impact

User impact: on affected Windows machines, read-only state inspection and openclaw doctor now complete instead of refusing to continue with "check filesystem health and write permissions or set XDG_CACHE_HOME to a writable filesystem". No user action or data migration is required, and behavior on unencrypted filesystems is unchanged (the rename fast path is still used).

Why This Change Was Made

Node's Windows rename path reports same-directory moves as a cross-device error on EFS-encrypted directories even though both paths are on one volume. That made the two publication renames inside the private staging directory (first -> database.sqlite.partial, and the database.sqlite.partial* -> database.sqlite* loop) abort every snapshot. The publication helper now falls back to copying the already-verified staged bytes (descriptor copy + fsync) and removing the staged file only when the rename is rejected with EXDEV; other rename failures still fail closed. The staged files are closed private copies in a single-process staging directory, so the rename's atomicity is not load-bearing here. The helper lives in a small sibling module because sqlite-readonly-location.ts is at the repo's 700-line cap.

Evidence

Before the fix (2026.9.9, commit 3258dd8, Windows 11 build 26200, EFS-encrypted %LOCALAPPDATA%), minimal reproduction calling the snapshot API on a plain SQLite source:

FAILED: Error: SQLite read-only worker failed while creating its private snapshot: EXDEV: cross-device link not permitted, rename 'C:\Users\Jason\AppData\Local\openclaw\openclaw-sqlite-readonly-v2-43361feb-...\openclaw-sqlite-readonly-v2-7d621f7e-...\first' -> 'C:\Users\Jason\AppData\Local\openclaw\openclaw-sqlite-readonly-v2-43361feb-...\openclaw-sqlite-readonly-v2-7d621f7e-...\database.sqlite.partial'; snapshot staging root ...: check filesystem health and write permissions or set XDG_CACHE_HOME to a writable filesystem (code=EXDEV)

openclaw doctor with a fresh state home stopped at migration detection:

Doctor stopped because a state migration refused to continue. Resolve the reported migration failure before retrying. Later repairs were not run.
Failing check migration-detection (step-refused): Failed detecting Codex native pending assignments: Error: SQLite read-only worker failed while creating its private snapshot: EXDEV: cross-device link not permitted, rename [redacted-path]
Failing check device-auth (blocked-by-prior-refusal): Migration step "device-auth" was not run because prior step "migration-detection" refused execution.
Failing check device-identity (blocked-by-prior-refusal): ...
Failing check meeting-transcripts (blocked-by-prior-refusal): ...
Failing check managed-worktrees (blocked-by-prior-refusal): ...

After the fix, the same reproduction and the same doctor command on the same machine:

prepared: C:\Users\Jason\AppData\Local\openclaw\openclaw-sqlite-readonly-v2-...\database.sqlite
cleanup: ok
—  Doctor complete.

with no step-refused or blocked-by-prior-refusal failures in the output.

Trigger characterization on the affected machine: cipher /c C:\Users\Jason\AppData\Local reports "New files added to this directory will be encrypted" and dir /a shows E on AppData\Local\openclaw; fs.renameSync within one directory fails with EXDEV under %LOCALAPPDATA% and %APPDATA% (file and directory renames), while cmd move, PowerShell Rename-Item, and [System.IO.File]::Move succeed in the same directory, and the same Node rename succeeds under %LOCALAPPDATA%\Temp, the profile root, and D:\Temp.

Checks run locally:

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.infra.config.ts src/infra/sqlite-readonly-location.test.ts -t "EXDEV" -> 2 passed. Without the fix, the new EXDEV test fails at src/infra/sqlite-readonly-location.ts:370 with EXDEV: cross-device link not permitted, so the regression test demonstrably detects the defect.
  • pnpm tsgo:core -> exit 0.
  • pnpm exec oxfmt --check on the changed files -> clean.
  • node --import ./scripts/tsx.mjs scripts/check-line-cap-ratchet.mts --base upstream/main -> OK. check-assertion-safety-ratchet.mts --base upstream/main -> OK.
  • node --import ./scripts/tsx.mjs scripts/run-lint.mts --base upstream/main -> Control UI Lit ratchet OK; the plugin-sdk boundary dts generation step then timed out after 300 s on this machine (load/network-bound, unrelated to this change).

Known gaps: the regression test simulates the EXDEV rejection so it runs deterministically on every OS; the EFS reproduction itself is Windows-only. Repo-wide pnpm check fails on this base commit before this change as well (line-cap, database-worker, assertion-safety, and changelog-attribution ratchet failures reproduce with a pristine checkout); the two ratchets that this change can affect now pass. The background reclamation claim rename in src/infra/sqlite-snapshot-staging.ts shares the same failure mode but only degrades cleanup logging, so it is intentionally out of scope for this minimal fix (noted in the issue).

AI disclosure: this change was drafted with AI assistance at my request, under my direction and review.

… with EXDEV

Windows profile directories encrypted with EFS reject same-directory renames with a false cross-device error, which aborted every private SQLite read-only snapshot publication and stopped doctor state migrations. Keep the rename as the primary path and fall back to copying the verified staged bytes.
@clawsweeper

clawsweeper Bot commented Oct 11, 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.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR falls back to copying private SQLite snapshot files when publication renames fail with EXDEV.

Example: Run openclaw doctor on Windows 11 with EFS encryption inherited by LOCALAPPDATA/openclaw.

  • Before: Snapshot publication throws EXDEV and Doctor stops before later migration steps.
  • After: The private snapshot is copied into place and Doctor completes.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, useful repair with shipped CLI behavior evidence, meaningful regression coverage, and no actionable findings; latest-head CI is still pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Contributor terminal output exercises the real snapshot API and openclaw doctor on the affected Windows 11 EFS filesystem, showing publication and cleanup success and Doctor completion after the fix; the production patch is unchanged from the proof-bearing revision.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Doctor stops on EFS-encrypted Windows cache directories because private SQLite snapshots cannot be published.
Reason: The change restores an existing inspection contract with a small shared repair; background reclamation warnings remain a separately documented concern.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a concrete Windows snapshot failure, and the prior wrapper-inventory and CI-attribution blockers are resolved.

Priority: P1
Reviewed head: 47a71dab834180eb8c1a2f0a0dbe42bc30224d2f

Before merge

None.

Findings

None.

Agent review details

How this fits together

Doctor and other SQLite inspection callers request a consistent private snapshot; the snapshot owner prepares and publishes database files, then returns a location with cleanup operations.

flowchart TD
  A[Doctor or inspection caller] --> B[Snapshot source owner]
  B --> C[Isolated snapshot worker]
  C --> D[Verified private staging files]
  D --> E[Rename or EXDEV copy]
  E --> F[Private reader and cleanup]
Loading

Technical review

Best possible solution:

Land the focused EXDEV fallback through the normal merge gates without requiring cache relocation or new configuration.

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

Current-main source shows the unhandled EXDEV path, and the reporter supplies concrete Windows EFS failures and filesystem controls; this review did not run a Windows reproduction.

Is this the best way to solve the issue?

The fallback repairs the shared publication owner after source verification, preserves fatal non-EXDEV errors, and relies on existing private-directory ownership and cleanup rather than adding migration or configuration machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Private SQLite snapshot publication keeps the original intent (497d4ff: Publication and staging lifecycle changes supported consistent private snapshots and safe reclamation while preserving active owners and source artifacts.)
  • Verified no-sidecar copy promotion keeps the original intent (140b602: The infrastructure simplification retained filesystem safety and persistent-state semantics; the new fallback retains verified bytes and changes only EXDEV handling.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 497d4ff adds src/infra/sqlite-readonly-location.ts:330 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 497d4ff3d24d; files: src/infra/sqlite-readonly-location.ts)
  • Vincent Koc: Raw commit ec7f8e9 adds src/infra/sqlite-readonly-location.ts:331 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ec7f8e9dd1c3; files: src/infra/sqlite-readonly-location.ts)

PR surface

Source +34, Tests +35, Other +1. Total +70 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 36 2 +34
Tests 1 35 0 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 4 72 2 +70

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The deterministic publication failure blocks Doctor and SQLite inspection on affected Windows installations.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (4 earlier review cycles)
  • reviewed 2026-10-11T14:47:39.703Z sha 14d7075 :: needs changes before merge. :: [P2] Add the new helper to the trusted wrapper inventory
  • reviewed 2026-10-11T15:03:15.285Z sha 7198975 :: needs changes before merge. :: none
  • reviewed 2026-10-11T15:41:55.124Z sha bc0b7ee :: needs changes before merge. :: none
  • reviewed 2026-10-11T15:56:41.868Z sha bc0b7ee :: needs changes before merge. :: none

Reviewed October 11, 2026, 1:41 PM ET / 17:41 UTC (Revision 5).

The trusted-anchor PR wrapper inventory must stay closed over runtime imports; add the new src/infra/sqlite-snapshot-rename.ts entry so eager-import-closure tests resolve ./sqlite-snapshot-rename.js.
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Oct 11, 2026
@JasonBuildAI

Copy link
Copy Markdown
Contributor Author

CI attribution for the current head (bc0b7ee0c, run 38151272834), addressing the pending review item.

  1. check-test-types-core-* (previous head): transient window while main renamed testing.stopGatewayProcess -> testing.stopWindowsGatewayProcess in test/helpers/openclaw-test-instance.ts (callers updated in the same series). The PR merge tree at that moment combined the renamed helper with this branch's pre-rename copy of test/scripts/managed-child-process.windows.test.ts. Merging current main (this head) makes both sides consistent, and the job no longer fails.

  2. Trusted wrapper inventory (previous head): fixed in 719897591 by registering src/infra/sqlite-snapshot-rename.ts. Verified locally after the fix: test/scripts/eager-import-closure.test.ts (12 passed) and test/scripts/pr-wrapper-source-closure.test.ts (3 passed).

  3. checks-ui-e2e (6/7) - ui/src/e2e/chat-panel-layout.e2e.test.ts > Control UI chat panel layout > preserves live content and saved geometry across main, dock, focus, and narrow layouts: terminal canvas stays hidden (61 x locator resolved to hidden <canvas width="560" height="312">, locator.waitFor timeout 30000ms). Same test and signature fail on unrelated PRs in the same window (fix(mcp): tool results are duplicated when a server mirrors structuredContent as compact JSON #169180, refactor(sessions): move title reads off main and drop redundant SQL #169177, fix(sessions): avoid turn errors when write receipts overtake reads #169174), and open PR fix(ui): terminal and browser panels render with hidden content #169182 ("fix(ui): terminal and browser panels render with hidden content") targets exactly this symptom.

  4. checks-ui-e2e (3/7) - ui/src/e2e/chat-flow.navigation-presentation.e2e.test.ts > keeps derived sidebar titles and accessible state after session patch refreshes: accessible name mismatch, expected link "Readable planning title", received link "Unread Readable planning title". UI sidebar rendering; this PR changes only src/infra and scripts/pr-lib/wrapper-components.txt. UI E2E jobs are currently red on several unrelated PRs (refactor(storage): reduce SQLite bookkeeping per turn #169173, fix(sessions): avoid turn errors when write receipts overtake reads #169174, refactor(sessions): move title reads off main and drop redundant SQL #169177, perf(worktrees): publish reserved checkouts without allocation waits #169178, fix(mcp): tool results are duplicated when a server mirrors structuredContent as compact JSON #169180).

  5. checks-node-changed-compact-large-32 - src/state/github-publication.worker.test.ts > revokes prepared sources when canonical deletion commits before its ordinary reply: a race-timing assertion (expect(() => bindGitHubPublicationSource(source)).toThrow(...)). The same file passes locally on this head (11/11), and this shard passed in the previous run of this PR; treating it as flaky.

Local verification on this head: EXDEV snapshot repro publishes and cleans up for both plain and WAL sources; the two focused EXDEV regression tests pass; the two wrapper-closure tests above pass; github-publication.worker.test.ts passes.

@JasonBuildAI

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

JasonBuildAI added a commit to JasonBuildAI/openclaw that referenced this pull request Oct 11, 2026
@JasonBuildAI

Copy link
Copy Markdown
Contributor Author

CI attribution for the outstanding review item - the github-publication.worker.test.ts:603 failure in run 38151272834 is now established with matching-base evidence, and it is not caused by this diff.

Matching-base failure evidence (the same assertion failed on main):

  • Main's own CI failed the same revocation assertion ~50 minutes before this run: run 38147604740 (main, head 6233a19ea7), failed job 114494372711 (checks-node-compact-small-10, 14:33-14:41 UTC).
  • Upstream repaired exactly that failure with the test-only commit d7e26112cc ("test(state): wait for publication deletion receipt installation", 16:50 UTC). Its message states it "Repairs main CI run 38147604740, job 114494372711" and describes the same race this run hit: the revocation fixture intercepted the ordinary worker reply before the broker drained the separate admission receipt, so expect(() => bindGitHubPublicationSource(source)).toThrow("source authority changed") raced. A later stabilization landed in #169220 (17:15 UTC). Both are test-only changes; no production behavior changed.
  • This head (bc0b7ee0) predates both: it was created at 15:26 UTC. Its failing job 114505307168 (15:27-15:32 UTC) shows the identical signature - same file, same test ("revokes prepared sources when canonical deletion commits before its ordinary reply"), same AssertionError: expected [Function] to throw an error at 603:57.
  • The previous head of this branch (71989759, run 38149174434) ran every checks-node-* job green (14:57-15:10 UTC). This head then merged main@3529142c, which included aec89935b8 (refactor(plugin-sdk): complete awaited GitHub publication migration #168954) - the refactor of the very publication worker surface this fixture exercises.

Why this diff cannot be the cause: its only behavioral delta is the Windows EXDEV fallback in renameStagedSnapshotFile (identical to fs.renameSync unless rename throws EXDEV, which cannot occur on Linux CI runners), plus the wrapper-inventory registration and two infra tests. It touches no src/state/github-publication* file.

Repair: merged current upstream/main into the branch (47a71dab834180eb8c1a2f0a0dbe42bc30224d2f), which imports d7e26112cc and 0e9917f514, so CI now runs the repaired fixture. No repair to this branch's functional diff was needed; the diff is unchanged.

@JasonBuildAI

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
…ite-snapshot-rename-jbai-x7q4

# Conflicts:
#	src/infra/sqlite-readonly-location.test.ts
#	src/infra/sqlite-readonly-location.ts
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @JasonBuildAI for the EFS characterization and fix. Landed a smaller credited replacement in #190087 (8662c66): removed the intermediate rename and added the EXDEV-only fallback at final snapshot publication. The three regressions fail on main before the fix and pass afterward; CI is green. Your Co-authored-by credit is preserved in the merged commit. Closing this as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: S 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.

2 participants