Repository navigation
Conversation
The legacy root memory merge archived the legacy file but overwrote the canonical MEMORY.md with a truncate-in-place writeFile and no copy of the pre-merge bytes. A crash or ENOSPC mid-write tore or emptied the only durable memory file, and the failure surfaced only as a doctor note. Copy the canonical file beside the legacy archive before the merge and publish through the repo's atomic text writer with the original file mode, so a failed or interrupted merge leaves the live file intact and the pre-merge bytes recoverable.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesDoctor backs up canonical memory and publishes merged legacy memory through the existing atomic file writer. Example: Doctor merges MEMORY.md containing "# Canonical\n" with memory.md containing "# Legacy\n", but publication fails with EPERM.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete memory-loss path still present on current main; earlier findings are resolved, and no remaining actionable defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherDoctor receives configured agent workspace paths, detects split root memory, obtains repair confirmation, and archives legacy content before publishing canonical memory. flowchart TD
A[Doctor CLI] --> B[Memory recall health]
B --> C[Workspace memory repair]
C --> D[Legacy archive and canonical backup]
D --> E[Atomic file writer]
E --> F[Canonical MEMORY.md]
C --> G[Doctor result note]
Technical reviewBest possible solution: Retain the focused backup-and-atomic-publication fix and land it after required CI passes. Do we have a high-confidence way to reproduce the issue? Current-main source exposes truncation before a failed write can complete; contributor evidence exercises failed publication through the shipped CLI, while this review ran no target code. Is this the best way to solve the issue? Backing up canonical bytes and reusing the existing atomic writer directly fixes the destructive write without changing merge semantics or adding a competing owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f810bb4eede7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +32, Tests +94. Total +126 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 27, 2026, 10:52 AM ET / 14:52 UTC (Revision 5). |
… memory merge Review findings on 065aa40: writeTextAtomic defaults dirMode to 0755 and chmods the existing parent directory, widening a private 0700 workspace, and its unconditional copy fallback unlinks the live MEMORY.md when rename fails with EPERM/EEXIST, reintroducing the tear this fix removes. Publish through replaceFileAtomic directly, matching the existing memory writer: pass the workspace's actual mode back as dirMode, keep the original file mode via preserveExistingMode, and leave the copy fallback disabled so a denied rename fails the repair with the live file untouched. Cover EPERM publication failures and workspace-mode preservation in tests.
|
@clawsweeper re-review Pushed
PR body updated with all of the above. |
|
🦞👀 Re-review progress:
|
Review finding on 84ddf27: replaceFileAtomic rejects a symlinked parent directory on POSIX, so a configured workspace alias (a supported setup) made the merged memory publication fail after the legacy file had already been archived. The in-place write it replaces followed the alias. Resolve the workspace directory with realpath for publication only. The final-file symlink rejection is unaffected: earlier bounded reads already verified the canonical file as a regular file, and the destination inside the resolved directory is that same file. Cover the alias case in tests.
|
@clawsweeper re-review Pushed
PR body updated with all evidence. |
|
🦞👀 Re-review progress:
|
The publication-failure tests intercept renames by comparing against the fixture path, but the repair now publishes to the realpath-resolved workspace. On hosts whose temporary root is a symlink (macOS /var -> /private/var), the fixture and the destination differ, the fault is never injected, and the test fails on its error-note assertion. Canonicalize the fixture path like the shared temp-dir helpers do.
|
@clawsweeper re-review Pushed
Checks: |
|
🦞👀 Re-review progress:
|
What Problem This Solves
Fixes:
openclaw doctor's legacy root memory merge can leaveMEMORY.mdempty or torn when the merge write fails (crash, Ctrl-C, ENOSPC/EPERM mid-write), silently destroying the agent's durable memory.The merge archived only the legacy
memory.mdbefore overwriting the canonicalMEMORY.mdwith a truncate-in-placewriteFile— the pre-merge canonical bytes existed nowhere else. The truncated file is also what the doctor note reports as a completed repair when the error is caught upstream, so the loss is silent.User Impact
User impact: a failed or interrupted doctor memory merge now leaves the live
MEMORY.mdbyte-for-byte intact, and the pre-merge canonical content is preserved asMEMORY.md.pre-mergebeside the existing legacy archive for recovery. The merge success note reports the new backup path.The publication matches the existing memory writer (
extensions/memory-core/src/dreaming-markdown.ts):replaceFileAtomicwithpreserveExistingMode, the workspace's actual directory mode passed back asdirMode(publication can no longer widen a private0700workspace to0755), the permission-error copy fallback left disabled (its unlink-then-recreate path would reintroduce the tear), durable temp+fsync+rename semantics, and the workspace directory resolved throughrealpathbefore publication so configured workspace aliases keep working (the atomic writer rejects symlinked parents by design; the alias is resolved for publication only, and the final-file symlink rejection is unaffected because earlier bounded reads already verified the canonical file as a regular file).Why This Change Was Made
The same function already treats atomicity as a requirement one step earlier (the legacy archive move is an atomic rename, and the archive is re-read "after the atomic move"), but the canonical overwrite — the one mutation with no recovery copy — bypassed that. The fix reuses the existing atomic-replace owner (
@openclaw/fs-safe/atomic) and the existing timestamped repair archive directory, rather than adding new state or helpers.Evidence
Shipped CLI, successful merge through a workspace directory alias (
openclaw doctor --fix, workspace configured as a junction alias to a case-sensitive directory):Verified through the junction's real target afterwards:
MEMORY.mdholds the merged content in the exact byte formatmainproduces, the repair directory holds bothmemory.mdandMEMORY.md.pre-merge, andmemory.mdis gone from the live path.Shipped CLI, failed publication (
MEMORY.mdmarked read-only, so the publication rename fails withEPERM):Completed upgrade from latest stable (stable
2026.10.7viapnpm dlx, then this build, both through the shipped Doctor CLI on the same isolated case-sensitive workspace + state dir):[email protected] doctor --fixon the split workspace: merges with its own note format and no canonical backup (exit 0).openclaw doctor --fixon the same state dir: completes the shared-state-DB migration custody and finishes with "Doctor complete" (exit 0, zero split/shadow findings).MEMORY.mdis preserved byte-for-byte, no re-merge or rewrite occurred, and the workspace holds only the merged file.Data-model compatibility: the merge output format is byte-identical across stable
2026.10.7,main, and this head — existing data loads and works unchanged, andopenclaw memory statuson a merged workspace reports the memory file with normal dreaming path resolution.Regression tests (
src/commands/doctor-workspace.test.ts; red onmain, green on this head; verified executing locally on a case-sensitive NTFS scratch dir since the canonical/legacy pair requires one):preserves canonical memory when publication fails with ENOSPC/with EPERM: a failed publication leaves the live file intact, no fallback recreates it, the pre-merge backup holds the original bytes. The fixture path is canonicalized (realpath) like the shared temp-dir helpers, so the rename interception matches the resolved publication destination on hosts whose tmpdir sits behind a symlink (macOS).preserves the workspace mode across a successful merge: a0700workspace stays0700(POSIX-checked in CI; Windows chmod is a no-op).merges through a symlinked workspace directory alias: a configured alias is followed for publication and the merged file lands in the same canonical file (POSIX red on head, green with the fix, via CI; on Windows the junction variant executes green — the fs-safe parent rejection it fixes is POSIX-only, so Windows cannot reproduce the red).Checks per the review acceptance list:
pnpm vitest run src/commands/doctor-workspace.test.ts src/commands/doctor-memory-recall.test.ts— 19/19 pass; oxlint clean on both touched files;git diff --checkclean;pnpm tsgo:prodall lanes pass.Test environment notes and gaps
The canonical/legacy pair (
MEMORY.md+memory.md) can only coexist on a case-sensitive filesystem, so this repair suite no-ops on case-insensitive hosts (existing tests in this file already guard withif (!(await seedMemory())) return;). Local verification used a per-directory case-sensitive NTFS scratch dir (NTFSsetCaseSensitiveInfo); CI runs the suite on Linux, where the alias test also reproduces the POSIX red/green for the parent-rejection fix.Upgrade note: stable
2026.10.8was published today and is correctly refused by this repo's pnpmminimumReleaseAgesupply-chain policy, so the upgrade run uses2026.10.7, the newest installable stable.Not covered: an injected publication failure during a full interactive
openclaw doctorrun (the CLI failure above uses a read-only canonical file, a real OS-level denial through the shipped CLI). The repository-wide lint shard crashes on this Windows box from memory pressure; the changed files are oxlint-clean directly and CI runs the full lint on the exact head.