refactor(memory-core): use replaceFileAtomic for dreaming file writes#96734
refactor(memory-core): use replaceFileAtomic for dreaming file writes#96734SunnyShu0925 wants to merge 1 commit into
Conversation
Align with the sibling dreaming-dreams-file.ts which already uses replaceFileAtomic from openclaw/plugin-sdk/security-runtime. Replaces three fs.writeFile calls (inline daily, separate report, deep report) with replaceFileAtomic for consistent file I/O patterns within the dreaming module. Test: existing 9 tests pass unchanged, no behavioral change.
|
Codex review: needs real behavior proof before merge. Reviewed June 25, 2026, 6:08 AM ET / 10:08 UTC. Summary PR surface: Source +20. Total +20 across 1 file. Reproducibility: yes. for the PR defect by source inspection: the PR calls Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Keep atomic replacement, but preserve existing file and directory permission behavior unless maintainers explicitly approve and test a private artifact contract, then require redacted real run proof. Do we have a high-confidence way to reproduce the issue? Yes for the PR defect by source inspection: the PR calls Is this the best way to solve the issue? No. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4ecb45bf7729. Label changesLabel justifications:
Evidence reviewedPR surface: Source +20. Total +20 across 1 file. View PR surface stats
Security concerns:
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
|
What Problem This Solves
dreaming-markdown.tsusesfs.writeFilefor three dreaming write paths (inline daily, separate report, deep report).fs.writeFileis non-atomic on Linux—a process crash mid-write can leave the target file truncated or empty. The sibling moduledreaming-dreams-file.tsalready avoids this by usingreplaceFileAtomicfromopenclaw/plugin-sdk/security-runtime.This PR aligns the two modules so all dreaming file writes in memory-core use the same safe atomic write pattern.
Why This Change Was Made
replaceFileAtomicwrites to a temp file then renames atomically, so a crash during write never corrupts the target file. The same tool and pattern is already used indreaming-dreams-file.ts—this is a consistency refactor that also brings the crash-safety benefit to the remaining write paths.No new dependencies or behavioral changes. Temp cleanup is handled by
replaceFileAtomicinternally.User Impact
None visible. Dreaming output is identical. The only difference is that a process crash during a dreaming phase write will no longer risk truncating daily memory or dreaming report files.
Evidence
replaceFileAtomicimport and usage pattern already exists inextensions/memory-core/src/dreaming-dreams-file.ts:84-91extensions/memory-core/src/dreaming-markdown.ts