Repository navigation
fix(memory-wiki): retry transient source-page rewrite race instead of aborting wiki_status - #94443
Conversation
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]>
|
Codex review: needs maintainer review before merge. Reviewed June 21, 2026, 1:40 PM ET / 17:40 UTC. Summary PR surface: Source +21, Tests +94. Total +115 across 4 files. Reproducibility: yes. at source level: current main routes Review metrics: none identified. Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest 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 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 changesLabel justifications:
Evidence reviewedPR surface: Source +21, Tests +94. Total +115 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
f3d9293
into
openclaw:main
…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]>
Summary
wiki_status(and bridge source sync) intermittently aborting withRefusing 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.path-mismatchrace (a concurrent atomicwrite-temp + renamereplacing 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.source-page-shared.tsandokf.tsinto one helper (writeGuardedVaultPage), so the fix covers both write paths and removes the copy.Linked context
Closes #92134
Real behavior proof
wiki_status/ bridge source-sync call abort withpath-mismatch, dropping the status card; re-running a moment later succeeded.@openclaw/fs-safevault root (openclaw/plugin-sdk/security-runtime) with a realwrite-temp + renameburst; the "old" arm runs the verbatim origin/main single-write code path, the "new" arm runs the shippedwriteGuardedVaultPage. Not a stub of the failing component.path-mismatchhere comes from@openclaw/fs-safeopened-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 viaO_NOFOLLOW, so retrying onlypath-mismatchdoes not weaken the identity guard. The sibling memory read path already treatspath-mismatchas transient (packages/memory-host-sdk/src/host/read-file.ts:54isFileDisappearedDuringReadError); only the write path was the outlier.node --import tsx /tmp/repro-92134.ts(bounded concurrent rename burst per trial, single write landing inside the window).path-mismatch, whilewriteGuardedVaultPagecompletes 60/60 with 0 aborts. Result was stable across repeated runs.Tests and validation
git diff --checknode scripts/run-vitest.mjs extensions/memory-wiki(174 passed, including newvault-page-write.test.tsand the existing directory-collision / symlink guard tests)pnpm tsgo:extensionsRisk checklist
Did user-visible behavior change?
Yes— a transient concurrent-rewrite no longer abortswiki_status; persistent failures still error.Did config, environment, or migration behavior change?
NoDid security, auth, secrets, network, or tool execution behavior change?
No— the fs-safe identity guard is unchanged; onlypath-mismatch(a benign rename race, distinct fromsymlink/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-mismatchis retried, with a small bounded backoff; on exhaustion the original labeled error is rethrown, so persistent directory/not-filecollisions 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.