Skip to content

fix: preserve MEMORY.md when Doctor merges fail - #190497

Merged
roboclaw-bot merged 1 commit into
mainfrom
roboclaw/doctor-memory-merge-atomic
Nov 1, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
roboclaw/doctor-memory-merge-atomic

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #187291 by @syxscott.

What Problem This Solves

Doctor can truncate or tear MEMORY.md when a legacy root-memory merge write fails. The existing repair archives only memory.md, leaving the original canonical memory without a recovery copy.

User Impact

Failed writes preserve the live canonical memory, and each merge keeps MEMORY.md.pre-merge beside the legacy archive. Earlier backups remain intact and a second Doctor run after a completed merge leaves the file unchanged. Workspace directory aliases and existing file/directory permissions remain supported.

Why This Change Was Made

This takes over #187291 with Syxscott's atomic publication fix and one small correction: allocate a unique repair directory with mkdtemp, because timestamp-only recursive mkdir can reuse a directory and overwrite its backups. Publication uses the existing atomic writer with the actual directory mode, preserved file mode, synced temporary file/parent, and its permission-error copy fallback disabled. Doctor documentation includes the backup location and recovery step.

Syxscott is retained as the source commit author and co-author; Peter Steinberger receives the requested co-author credit. No new abstraction or compatibility path is introduced. Production source grows by 23 lines and tests by 129 lines; the separate test-line allocation covers publication failures, aliases/modes, and the backup collision/idempotency regression.

Evidence

  • Personally inspected current main, the complete contributor diff/history, the dreaming writer, callers, and fs-safe's publication implementation.
  • Secretless Crabbox reproduction: publication regressions are red against the main writer; same-timestamp backup preservation is red on the contributor head (earlier legacy archive overwritten); four original failure/alias/mode cases pass on that head.
  • Candidate proof: all 60 tests passed in doctor-workspace.test.ts, doctor-memory-recall.test.ts, and doctor-memory-search.test.ts, with source hashes matching this commit. Command wall time 51.49 s including compilation (Vitest 46.20 s); workspace test bodies take under 0.2 s. This focused pre-PR proof uses the contributor checkout's frozen dependency set; exact-head PR CI supplies current-main dependency, lint, and type proof.
  • Independent local autoreview: P0–P3, scoped-clean, no findings. Source snapshot verification passed; reviewer did not execute repository code.
  • Pinned oxfmt 0.74.0 and git diff --check pass. Local lint could not start without this worktree's dependencies; no local installation or broad suite was run.
  • Real Doctor CLI on a 2 MiB tmpfs: the current-main writer (substituted into the contributor checkout) hit real ENOSPC and left live memory torn at 786,432 bytes; the repaired writer in the same setup left canonical bytes intact and preserved both backups. The linked candidate run completed successfully. This is an OS failure through the CLI, not just a mocked rename.
  • Published-head proof: all 16 workspace tests pass with current dependencies (55.37 s command wall, 47.95 s Vitest including compilation); targeted lint passes on both files in 4.00 s. The later CLI setup initially refused group-writable synthetic state; the corrected private-fixture run passed actual ENOSPC through the exact published-head CLI and preserved canonical bytes and both backups.
  • Exact-head CI is SUCCESS on 8910404: 36 successful jobs, 27 planned skips, zero failures; 504 s wall.
  • Latest-stable upgrade proof is not applicable to this local MEMORY.md merge-write fix, per the loop owner. The red/green reproduction, 60 named tests, actual ENOSPC CLI proof, and exact published-head tests/lint are sufficient. No package-manager swap, policy override, or extra installation was needed.

Keep the pre-merge canonical memory beside the legacy archive and publish
through the existing atomic writer without its destructive copy fallback.
Use a unique repair directory so later repairs cannot overwrite recovery
copies. Preserve workspace aliases and modes and leave completed merges
unchanged on subsequent Doctor runs.

The 129-line test allocation covers failed publication, alias and mode
preservation, and the backup collision/idempotency regression.

Co-authored-by: Syxscott <[email protected]>
Co-authored-by: steipete <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 1, 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 gateway Gateway runtime commands Command implementations size: S labels Nov 1, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 1, 2026 16:09
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Doctor preserves canonical memory before atomically publishing a legacy-memory merge and allocates unique recovery directories.

Example: Doctor merges MEMORY.md containing "# Canonical\n" with memory.md containing "# Legacy\n" and publication encounters ENOSPC.

  • Before: The in-place write can truncate canonical memory without preserving its original bytes.
  • After: Canonical memory remains intact, and the recovery directory retains the legacy archive and canonical backup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, useful repair with meaningful filesystem regressions and passing exact-head CI; persisted-state validation remains incomplete.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied Doctor CLI evidence exercises successful alias publication and real publication failure with canonical bytes preserved; this PR additionally reports a real tmpfs ENOSPC comparison, although its Crabbox artifacts were inaccessible from this review environment.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A failed Doctor merge can damage the agent's canonical durable memory without retaining its original contents.
Reason: Preventing durable-memory corruption has clear user value, and the maintainer-authored direction retains the established repair workflow.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it repairs a concrete canonical-memory corruption path still present on main, and no actionable patch defect was found.

Priority: P2
Reviewed head: 8910404ddfcbbe2e9b2d8c060a6bc8c58384ac8e

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: The promised exact-head upgrade from latest stable 2026.10.9 has no completed result in the supplied evidence.
Agent review details

How this fits together

Doctor receives configured workspace paths and repair confirmation, archives legacy memory, publishes the merged canonical file, and reports the result.

flowchart TD
  A[Doctor CLI] --> B[Memory health checks]
  B --> C[Workspace memory repair]
  C --> D[Unique recovery directory]
  D --> E[Legacy archive and canonical backup]
  C --> F[Existing atomic writer]
  F --> G[Canonical MEMORY.md]
  C --> H[Doctor result note]
Loading

Technical review

Best possible solution:

Use the existing atomic-publication owner with independent recovery copies and unique archive directories.

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

Current-main source establishes truncate-in-place publication, and supplied CLI evidence demonstrates real filesystem failures; this read-only review executed no target code.

Is this the best way to solve the issue?

This is a focused repair at the existing migration owner: it preserves archive ordering and merge semantics while replacing destructive publication with the established atomic writer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Archive ordering and merge format keeps the original intent (10a9acb: Archive shadowed legacy memory before merging so subsequent Doctor runs do not duplicate imported content.)
  • Canonical publication changes intended behavior with a stated reason (10a9acb: The original repair published merged content with writeFile; this PR explains the resulting truncation risk and replaces that operation.)
  • Timestamped recovery directories changes intended behavior with a stated reason (10a9acb: Keep legacy recovery copies under the workspace repair directory; unique allocation now prevents a later repair from overwriting earlier copies.)
  • Bounded reads and UTF-8 preservation keeps the original intent (ce5b795: Reject malformed UTF-8 before rewriting memory and retain independent recovery archives after post-archive read failures.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ce5b795 adds src/commands/doctor-workspace.ts:203 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ce5b795128e3; files: src/commands/doctor-workspace.ts)
  • Mariano: Raw commit 10a9acb adds src/commands/doctor-workspace.ts:226 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 10a9acbf2936; files: src/commands/doctor-workspace.ts)
  • cxbAsDev: Raw commit 881b0a6 adds src/commands/doctor-workspace.ts:258 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 881b0a619f56; files: src/commands/doctor-workspace.ts)

PR surface

Source +23, Tests +129, Docs +2, Other +2. Total +156 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 28 5 +23
Tests 1 130 1 +129
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 162 6 +156

Review metrics

Metric Value Why it matters
Production versus test growth Production +28/-5; tests +130/-1 Growth protects distinct publication-failure, workspace-alias, mode-preservation, backup-collision, and completed-repair idempotency contracts.

Root-cause cluster

Relationship: canonical
Canonical: #190497
Summary: This PR takes over the contributor's atomic-memory repair and adds unique recovery directories.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Protects durable memory from corruption during the limited split-root-memory Doctor repair workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

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

  • Complete the recorded stable-to-head upgrade and show that existing memory, settings, and earlier recovery copies remain intact.

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.

Reviewed November 1, 2026, 11:26 AM ET / 16:26 UTC.

@roboclaw-bot
roboclaw-bot merged commit 1b92282 into main Nov 1, 2026
248 of 250 checks passed
@roboclaw-bot
roboclaw-bot deleted the roboclaw/doctor-memory-merge-atomic branch November 1, 2026 16:44
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
Keep the pre-merge canonical memory beside the legacy archive and publish
through the existing atomic writer without its destructive copy fallback.
Use a unique repair directory so later repairs cannot overwrite recovery
copies. Preserve workspace aliases and modes and leave completed merges
unchanged on subsequent Doctor runs.

The 129-line test allocation covers failed publication, alias and mode
preservation, and the backup collision/idempotency regression.

Co-authored-by: Syxscott <[email protected]>
Co-authored-by: steipete <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 10, 2026
Keep the pre-merge canonical memory beside the legacy archive and publish
through the existing atomic writer without its destructive copy fallback.
Use a unique repair directory so later repairs cannot overwrite recovery
copies. Preserve workspace aliases and modes and leave completed merges
unchanged on subsequent Doctor runs.

Adapt the regression fixtures to the stable branch while preserving its
bounded-read and UTF-8 repairs. Inject torn direct writes for the real
Doctor entry-point red proof; cover atomic publication failures, workspace
aliases/modes, and unique backups/idempotency without a dependency change.

Co-authored-by: Syxscott <[email protected]>
Co-authored-by: steipete <[email protected]>

(cherry picked from commit 1b92282)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit bf293d0942920e55eefb2a4b594d7397e9442e33)
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport scoped #190497 from 1b92282.

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

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants