Repository navigation
Keep rollback prompt writes inside the prompts directory - #150
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
50c1a10 to
c202224
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b9dd24e2c5
ℹ️ 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".
Rollback write-back only checked the leaf of each prompt path for a symlink, so a symlinked prompts directory or subdirectory could redirect writes and the orphan sweep outside the prompts root. It now refuses to run when prompts or any existing parent directory below the repo is a symlink, checked before and after creating directories, and the sweep refuses a symlinked root. The temp file used for atomic replacement is now created exclusively with a unique name that tree entries cannot use, so entries such as a.tmp and a.txt no longer collide and a planted link is never followed.
A symlinked prompts directory or an invalid tree entry name used to be rejected only after reverse migrations and memory restore had committed, leaving a torn rollback. Rollback now validates the target prompts tree and checks for symlinked directories first, including on dry runs, and keeps the write-time checks. The temp file now has a short name independent of the prompt name. It is created exclusively, retried on a name clash up to 16 times, and removed only after the exclusive open succeeded, so a pre-existing file is never deleted. The reserved temp-name restriction on tree entries is dropped so rollback to existing commits keeps working.
A tree with both a and a/b passed the preflight and failed halfway through the write, after the database had changed. A temp name equal to the destination would also expose a partial write, so skip it.
Raw string comparison let p//a and a case-folded name slip past p/a/b.
Temp files used for atomic prompt replacement lived next to the destination, so a committed tree that named every candidate temp file could make the write fail after the database had already changed. They are now created exclusively in the state directory's tmp folder, which no prompt entry can name, and renamed into place. A rename across filesystems fails with an error saying the state directory and prompts must share a filesystem. The write-back comment now describes the residual race for a same-uid worker sharing the volume and why it is accepted.
A symlinked or loosened .agentic/tmp is refused or tightened, and a prompts path on another filesystem than the temp directory now fails in preflight instead of at rename, after the database changed.
b9dd24e to
d0e9097
Compare
The pairwise scan was quadratic in the number of tree entries, which a socket client controls. Sorted component paths place every extension of a key right after it, so comparing neighbours is enough.
Rollback restores prompt files into
<repo>/prompts. It only checked whether the final file was a symlink, so a symlinked directory insideprompts/, orprompts/itself being a symlink, sent writes and the orphan sweep outside that directory. The temp file name was derived from the prompt name, so entries such asa.tmpanda.mdoverwrote each other's contents. A tree that write-back would refuse also failed only after reverse migrations and memory restore had already run.Now:
prompts/or ancestor directory..agentic-tmp-<pid>-<n>), are created exclusively, and skip names that are taken.Out of scope: a concurrent directory swap between check and write would need an
openat-style walk and a new daemon dependency (an ADR). It only matters when another uid can writeprompts/, which the separate state-directory change makes the daemon refuse. Names that differ only by Unicode normalization on APFS remain the existing TM-008 gap.Proof: new unit tests cover symlinked roots and subdirectories, sibling temp names, planted temp files and symlinks, the retry limit, and file/directory conflicts. Two integration tests show that a rejected tree leaves the schema, memory rows and branch tip unchanged. They fail without the fix.
cargo fmtandcargo test --workspacepass.Reviewed with sol-loop: 4 rounds with gpt-6.2-sol. Sol verdict: one finding declined (Unicode normalization on APFS, pre-existing TM-008); all others resolved.
Created with Claude Opus 5.5 and Claude Sonnet 5.5 in Claude Code.