Repository navigation
Open
Description
Scope
Follow-up from the CodeRabbit review of #1408 (S4b, epic #1375 file-safety series). The review finding (comment on src/core/tools/ReadFileTool.ts:238) points out that read completeness is not tracked:
processTextFile()is slice-based by default: even aread_filewithout explicitoffset/limitreturns at mostDEFAULT_LINE_LIMITlines (truncated, with a warning), andindentationmode returns only a semantic block.- The observation registered after such a read is file-level only —
FileObservation = { version, observedAt }(src/core/task/observationRegistry.ts), with the version token derived from on-diskfs.stat. - So
fs.readFilecan complete successfully, the version tokens can match, and a laterwrite_to_filefull-file replacement still passes theguardedWrite()updatepath — even though the model only ever saw a slice of the file.
Proposed behavior
- Extend
FileObservationwith read scope (S2 registry, feat(task): per-task file observation registry (A2, #1375) Zoo-Code-Org/Zoo-Code#1394): e.g.complete: booleanplus the observed line range / total line count (fromprocessTextFile's result:returnedLines,totalLines,includedRanges). - Registration records the scope (ReadFileTool): a read that delivered the whole file (or an explicit full-file read) marks the observation complete; slice/indentation/truncated reads mark it partial with the delivered range.
guardedWrite()requires a complete observation for theupdatekind (full-file replacement): a partial observation rejects the update with the standard stale/guard rejection (re-read remediation), while theeditkind keeps working on any prior observation (optionally, a later step could also scopeeditto the observed range).- Re-reading the file extends/refreshes the observation as today; a complete read supersedes a partial one.
Acceptance criteria
- Regression test: file read through a truncated slice →
write_to_filefull replacement → rejected with the standard guard error; after a complete read → allowed. - Regression test:
editkind still permitted after a slice read (no behavior change for scoped edits in this step). FileObservationscope fields round-trip through the registry semantics (re-observe replaces the entry).
References
- feat(tools): wire guarded writes into the diff-view save paths (S4b, #1375) Zoo-Code-Org/Zoo-Code#1408 (S4b diff-view wiring) — review finding thread on
ReadFileTool.ts:238. - [EPIC] File Write Safety Prevent Concurrent Write Races Data Corruption Zoo-Code-Org/Zoo-Code#1375 (epic) — A1 version tokens / A2 observation registry / A3 CAS guard.
- feat(task): per-task file observation registry (A2, #1375) Zoo-Code-Org/Zoo-Code#1394 (S2) — observation registry; feat(tools): guarded write CAS core with per-path FIFO chain (S4a, #1375) Zoo-Code-Org/Zoo-Code#1405 (S4a) —
guardedWrite()core; feat(tools): wire guarded writes into the diff-view save paths (S4b, #1375) Zoo-Code-Org/Zoo-Code#1408 (S4b) — tool wiring. - Fork sibling issue #44 — the other 1408 follow-up (diff-view user-accept save path).
Metadata
Metadata
Assignees
Labels
No labels
Activity