Repository navigation
fix(save-user-section): atomic temp+rename write (profile Phase 2 hardening) - #66
Conversation
The agent writer did fs.readFile then fs.writeFile with no atomicity and no lock, so a concurrent reader (the dashboard section reader) or the app_profile seed's CAS read could observe a half-written file -> torn markers -> the reader fails closed with a 500. Write to a temp file in the same dir then rename(2) over the target (atomic on one filesystem). Flagged by the Phase 2 adversarial review. Unifying the lock domain with the dashboard flock CAS so the two writers serialise is a tracked follow-up. vitest 13/13. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@codex review — small Phase 2 hardening: the openclaw agent writer ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8711b73c2f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| usersDir, | ||
| `.${appUserId}.md.tmp.${crypto.randomBytes(6).toString("hex")}`, | ||
| ); | ||
| await fs.writeFile(tmpPath, next, "utf-8"); |
There was a problem hiding this comment.
Clean up temp files when the write fails
When fs.writeFile(tmpPath, ...) fails after creating/truncating the temp file (for example ENOSPC/EIO or a short partial write), execution never reaches the rename catch, so .user.md.tmp.* files are left behind in users/. Repeated failed saves can accumulate partial temp files and further consume the workspace disk, so the write and rename should share a cleanup path (e.g. try around both steps, skipping rm only after a successful rename).
Useful? React with 👍 / 👎.
cryptolir
left a comment
There was a problem hiding this comment.
Follow-up review finding for PR #66:
- [P2] Temp files are not cleaned up if
writeFilefails.
The cleanup only wrapsfs.rename. Iffs.writeFile(tmpPath, next, "utf-8")creates/truncates the temp file and then fails (ENOSPC/EIO/partial write), the temp file remains inusers/. Please wrap bothwriteFileandrenamein one cleanup path, skippingrmonly after rename succeeds.
Everything else looks reasonable. Temp+rename fixes torn reads; the remaining lost-update race is accurately called out as a follow-up for shared locking.
… review 4510329796) Wrap both fs.writeFile and fs.rename in one try so the temp file is removed if writeFile creates/truncates it and then fails (ENOSPC/EIO); only a successful rename leaves no temp behind. vitest 13/13. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed in the latest push: both fs.writeFile and fs.rename are now wrapped in one try, so the temp file is cleaned up if writeFile creates/truncates it and then fails (ENOSPC/EIO) — only a successful rename leaves no temp behind. vitest 13/13. |
…oad_skill #74) (#75) Record the load_skill roll: #74 merged, gateway v2026.06.18.1 (sourceSha 09a99e4) pinned to life only — ships the full per-user stack to prod (writer #65/#66 + injection #68 + first-turn #71 + load_skill #74). Bump the INFRASTRUCTURE life-ahead tag to v2026.06.18.1 and note the US-host disk cleanup (97% to 67%, removed 8 unused/unreferenced gateway tags). Co-authored-by: Liran Peretz <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
Phase 2 hardening (per the adversarial review on the per-user-profile plan #64). The agent writer did
fs.readFilethenfs.writeFilewith no atomicity and no lock, while the dashboard side uses flock+temp+rename CAS. A concurrent reader (the dashboard section reader) or the newapp_profileseed's CAS read could observe a half-written file → torn markers → the reader fails closed with a 500. This writes to a temp file in the same dir thenrename(2)over the target (atomic on one filesystem), so readers only ever see a complete file.Follow-up (tracked): unify the lock domain so the agent writer and the dashboard CAS serialise (the agent writer should also flock the same
<file>.lock), closing the remaining lost-update race. Atomic rename alone fixes the corruption/torn-read case; the lost-update self-heals (the seed is idempotent + best-effort; the agent re-writes its block next turn).Gate: vitest
save-user-section13/13; file oxfmt-clean. (Reaches the livelifeagent on the next gateway image roll — Phase 3.)🤖 Generated with Claude Code