Skip to content

fix(memory-wiki): retry transient source-page rewrite race instead of aborting wiki_status - #94443

Merged
openclaw-clownfish[bot] merged 1 commit into
openclaw:mainfrom
ZengWen-DT:fix/wiki-source-page-rename-race-92134
Jun 22, 2026
Merged

openclaw-clownfish[bot] merged 1 commit into
openclaw:mainfrom
ZengWen-DT:fix/wiki-source-page-rename-race-92134

Conversation

@ZengWen-DT

Copy link
Copy Markdown
Contributor

Summary

  • Fixes wiki_status (and bridge source sync) intermittently aborting with Refusing to write imported source page (path-mismatch) when the memory-wiki bridge re-exports a source page at the same instant the sync writes it.
  • The page write now retries briefly on the transient path-mismatch race (a concurrent atomic write-temp + rename replacing the file mid-operation) instead of treating it as fatal. Persistent guard failures (directory collision, not-file, not-empty) and symlink/path-alias swaps still hard-fail exactly as before.
  • Extracts the duplicated guarded-write logic shared by source-page-shared.ts and okf.ts into one helper (writeGuardedVaultPage), so the fix covers both write paths and removes the copy.

Linked context

Closes #92134

Real behavior proof

  • Behavior or issue addressed: a transient concurrent atomic rewrite of a memory-wiki source page made the whole wiki_status / bridge source-sync call abort with path-mismatch, dropping the status card; re-running a moment later succeeded.
  • Real environment tested: real filesystem repro driving the real @openclaw/fs-safe vault root (openclaw/plugin-sdk/security-runtime) with a real write-temp + rename burst; the "old" arm runs the verbatim origin/main single-write code path, the "new" arm runs the shipped writeGuardedVaultPage. Not a stub of the failing component.
  • Root cause / premise evidence: path-mismatch here comes from @openclaw/fs-safe opened-realpath (resolveOpenedFileRealPathForHandle, node_modules/@openclaw/fs-safe/dist/opened-realpath.js:41 → throw new FsSafeError("path-mismatch", "unable to resolve opened file path")): the opened fd's inode can no longer be found by path after a concurrent atomic rename. Symlink/hardlink swaps surface on distinct codes (symlink/path-alias/hardlink) and are rejected earlier via O_NOFOLLOW, so retrying only path-mismatch does not weaken the identity guard. The sibling memory read path already treats path-mismatch as transient (packages/memory-host-sdk/src/host/read-file.ts:54 isFileDisappearedDuringReadError); only the write path was the outlier.
  • Before evidence (bug reproduced on main): the origin/main single-write path aborts on every write that lands inside the rewrite window.
  • Exact steps or command run after this patch: node --import tsx /tmp/repro-92134.ts (bounded concurrent rename burst per trial, single write landing inside the window).
  • Evidence after fix: terminal output below — the new retry path recovers every write while the old path aborts every write on the same real-filesystem workload.
OLD (origin/main single write): 0/60 writes ok, 60 path-mismatch aborts
NEW (writeGuardedVaultPage retry): 60/60 writes ok, 0 path-mismatch aborts

result: old aborts=60, new aborts=0
REPRODUCED + FIXED
  • Observed result after fix: with a real concurrent atomic-rename burst, the old single-write behavior aborts 60/60 with path-mismatch, while writeGuardedVaultPage completes 60/60 with 0 aborts. Result was stable across repeated runs.
  • What was not tested: not exercised against a live multi-process gateway with a real bridge export daemon; the concurrent rewrite is reproduced with a real-filesystem rename burst rather than a second OpenClaw process.
  • Proof limitations or environment constraints: the race is timing-dependent; the repro uses a bounded rewrite window shorter than the retry span so the window settles before retries exhaust, matching the reported "burst of a few seconds" shape.

Tests and validation

  • git diff --check
  • node scripts/run-vitest.mjs extensions/memory-wiki (174 passed, including new vault-page-write.test.ts and the existing directory-collision / symlink guard tests)
  • pnpm tsgo:extensions

Risk checklist

Did user-visible behavior change? Yes — a transient concurrent-rewrite no longer aborts wiki_status; persistent failures still error.

Did config, environment, or migration behavior change? No

Did security, auth, secrets, network, or tool execution behavior change? No — the fs-safe identity guard is unchanged; only path-mismatch (a benign rename race, distinct from symlink/path-alias/hardlink) is retried, then rethrown unchanged on exhaustion.

Highest-risk area: masking a genuine persistent guard failure as transient.

How is that risk mitigated? Only path-mismatch is retried, with a small bounded backoff; on exhaustion the original labeled error is rethrown, so persistent directory/not-file collisions still fail exactly as before (covered by existing tests that still pass).

Current review state: maintainer review and CI.

AI-assisted (Claude). Proof above was run manually.

A concurrent atomic rewrite (write-temp + rename) of a memory-wiki source
page by the bridge re-export made fs-safe's opened-fd identity check fail
with `path-mismatch`, which the page write rethrew as a fatal "Refusing to
write" error and aborted the whole wiki_status / source-sync call. The race
is transient and benign: the file is replaced under the open handle and the
concurrent writer lands equivalent content.

Retry briefly on `path-mismatch` (the rename window closes sub-ms) and
rethrow unchanged on exhaustion, so persistent failures (directory
collision, not-file) and symlink/path-alias swaps still hard-fail exactly
as before. The identity guard is untouched; only the benign rename race is
retried, matching the sibling read path that already treats path-mismatch
as transient.

Extracts the guarded-write logic duplicated by source-page-shared.ts and
okf.ts into one writeGuardedVaultPage helper so both write paths get the
fix and the copy is removed.

Closes openclaw#92134

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-wiki size: M proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 18, 2026
@clawsweeper

clawsweeper Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 21, 2026, 1:40 PM ET / 17:40 UTC.

Summary
This PR extracts memory-wiki guarded vault page writes into a shared helper, retries bounded path-mismatch write races for imported-source and OKF pages, and adds helper regression tests.

PR surface: Source +21, Tests +94. Total +115 across 4 files.

Reproducibility: yes. at source level: current main routes wiki_status through imported-source sync, where path-mismatch from vault.write is fatal. I did not rerun the timing-dependent live bridge race, but the PR supplies old/new real-filesystem terminal proof.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: unknown-data-model-change: extensions/memory-wiki/src/okf.ts, unknown-data-model-change: extensions/memory-wiki/src/source-page-shared.ts, unknown-data-model-change: extensions/memory-wiki/src/vault-page-write.test.ts, unknown-data-model-change: extensions/memory-wiki/src/vault-page-write.ts, vector/embedding metadata: extensions/memory-wiki/src/okf.ts, vector/embedding metadata: extensions/memory-wiki/src/source-page-shared.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #92134
Summary: This PR is the focused candidate fix for the wiki_status source-page rewrite race; a broader open PR covers overlapping bridge reliability and a closed earlier PR was superseded by this branch.

Members:

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

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] The focused retry overlaps fix(memory-wiki): stop duplicate bridge imports under polling #91828, which also changes memory-wiki bridge retry and coalescing behavior; maintainers should choose one canonical landing path before the implementations diverge.
  • [P1] The supplied real behavior proof uses a real filesystem rename-burst harness rather than a live multi-process gateway with the actual bridge export daemon, so reporter-scale load behavior remains outside this PR's proof.

Maintainer options:

  1. Choose the canonical memory-wiki fix (recommended)
    Before merge, decide whether this focused retry PR or the broader bridge-hardening PR owns the retry/coalescing landing path.
  2. Land the focused mitigation first
    Maintainers may merge this narrow retry and handle bridge coalescing separately, accepting the follow-up integration work with the broader PR.
  3. Pause behind the broader PR
    If the broader coalescing PR is the intended reliability fix, pause or close this PR after its useful shared-helper behavior is folded there.

Next step before merge

  • [P2] No repair lane is needed because there are no concrete line-level findings; maintainers should choose this focused PR versus the broader overlapping PR and complete exact-head review.

Security
Cleared: No concrete security or supply-chain concern was found; the diff is plugin-local, adds no dependency/workflow surface, and preserves fs-safe hard failures outside bounded path-mismatch retry.

Review details

Best possible solution:

Land one canonical memory-wiki reliability fix: either this focused shared-helper retry, or a deliberate fold into the broader bridge-coalescing PR, while preserving fs-safe hard failures.

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

Yes at source level: current main routes wiki_status through imported-source sync, where path-mismatch from vault.write is fatal. I did not rerun the timing-dependent live bridge race, but the PR supplies old/new real-filesystem terminal proof.

Is this the best way to solve the issue?

Yes for the narrow bug: putting bounded retry in the shared guarded vault-page writer is the narrowest maintainable fix and keeps fs-safe hard failures fail-closed. For the broader load/coalescing issue, maintainers still need to choose against #91828.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against eea777c9fc9c.

Label changes

Label justifications:

  • P2: This is a bounded memory-wiki reliability fix for a shipped tool abort with limited plugin scope and no reported data loss.
  • merge-risk: 🚨 other: The PR overlaps an open broader bridge-hardening PR, and CI cannot decide which memory-wiki reliability implementation should become canonical.
  • 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. Sufficient (terminal): The PR body includes after-fix terminal output from a real filesystem rename-burst repro showing old single-write behavior aborting 60/60 and the new retry path succeeding 60/60.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from a real filesystem rename-burst repro showing old single-write behavior aborting 60/60 and the new retry path succeeding 60/60.
Evidence reviewed

PR surface:

Source +21, Tests +94. Total +115 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 99 78 +21
Tests 1 94 0 +94
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 193 78 +115

What I checked:

Likely related people:

  • vincentkoc: GitHub history shows this handle introduced or maintained the memory-wiki bridge/status surfaces and added OKF import behavior touched by the shared writer. (role: feature owner and recent area contributor; confidence: high; commits: e2f3044b8fb7, 4cf4e5417938, ffea7fa6479c; files: extensions/memory-wiki/src/bridge.ts, extensions/memory-wiki/src/tool.ts, extensions/memory-wiki/src/okf.ts)
  • steipete: GitHub history shows this handle deduped the imported source-page writer and worked on adjacent fs-safe integration surfaces. (role: shared writer refactor author and fs-safe adjacent contributor; confidence: high; commits: efd9aaea3f3e, f5bb8cbb98aa, 538605ff44d2; files: extensions/memory-wiki/src/source-page-shared.ts, extensions/memory-wiki/src/bridge.ts, extensions/memory-wiki/src/unsafe-local.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 18, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Jun 21, 2026
@openclaw-clownfish
openclaw-clownfish Bot merged commit f3d9293 into openclaw:main Jun 22, 2026
233 of 241 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 23, 2026
…94443)

A concurrent atomic rewrite (write-temp + rename) of a memory-wiki source
page by the bridge re-export made fs-safe's opened-fd identity check fail
with `path-mismatch`, which the page write rethrew as a fatal "Refusing to
write" error and aborted the whole wiki_status / source-sync call. The race
is transient and benign: the file is replaced under the open handle and the
concurrent writer lands equivalent content.

Retry briefly on `path-mismatch` (the rename window closes sub-ms) and
rethrow unchanged on exhaustion, so persistent failures (directory
collision, not-file) and symlink/path-alias swaps still hard-fail exactly
as before. The identity guard is untouched; only the benign rename race is
retried, matching the sibling read path that already treats path-mismatch
as transient.

Extracts the guarded-write logic duplicated by source-page-shared.ts and
okf.ts into one writeGuardedVaultPage helper so both write paths get the
fix and the copy is removed.

Closes openclaw#92134

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-wiki merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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.

wiki_status intermittently aborts with path-mismatch when bridge re-exports source pages concurrently

1 participant