Summary
Multiple confirmed cases of file corruption and lost writes across the ZOO codebase due to lack of atomic file writes, version guards, and cross-process locking. This epic coordinates fixing all known issues and implementing a robust filesystem safety layer.
Impact
Known Issues
| # |
Title |
Status |
Severity |
| #1371 |
MCP settings wiped by concurrent windows |
Open |
High |
| #920 |
Concurrent task history updates cause lost entries |
Open |
Medium |
| #1221 |
Truncated tool-call args silently written to disk |
Open |
Medium |
| #1021 |
Race in abandonSubtask for saveClineMessages |
Open |
Medium |
| #1231 |
Global _index.json full rewrite unsafe (corruption confirmed) |
Closed |
- |
Related stories (pending):
- #376 File-level write serialization
- #370 Extension-side task-scoping guard
Current State: Three-Layer Defense Gap
| DSH Layer |
ZOO Status |
Details |
| Policy CAS (observed version -> replaceIfVersion) |
Nonexistent |
No read-version record, no write-time check |
| Per-target FIFO lock |
Dead code |
safeWriteJson.ts uses proper-lockfile but zero importers |
| Atomic publish (staging + fsync + rename) |
Half |
Main paths use raw fs.writeFile() |
Unsafe Paths Currently Used
DiffViewProvider.saveDirectly() -> fs.writeFile(absolutePath, content) NO GUARD
McpHub.initializeMcpServers() -> fs.writeFile direct overwrite NO GUARD
Reference: DSH Implementation
DSH handles this with three orthogonal layers:
- Policy CAS -- FsObservation records presence+version on read; FsWriteIntent.replaceIfVersion(version) gates writes
- Per-target FIFO lock -- Map tail-promise chain serializes all mutations per target
- Atomic publish -- staging dir + temp file (0o600) + fsync + rename/hardlink/ReplaceFile
Proposed Plan
Phase 1 (1-2w): Make safeWriteJson sole JSON entry point; fix #1371,#920,#1221,#1021
Phase 2 (2-3w): Implement Observation Gate + guarded intent into Write/Edit tools
Phase 3 (1w): Port DSH tail-promise FIFO chain to DiffViewProvider/safeWriteJson
Phase 4 (1w): Replace all bare fs.writeFile/fs.appendFile with atomic paths
Acceptance Criteria
Summary
Multiple confirmed cases of file corruption and lost writes across the ZOO codebase due to lack of atomic file writes, version guards, and cross-process locking. This epic coordinates fixing all known issues and implementing a robust filesystem safety layer.
Impact
Known Issues
Related stories (pending):
Current State: Three-Layer Defense Gap
Unsafe Paths Currently Used
DiffViewProvider.saveDirectly() -> fs.writeFile(absolutePath, content) NO GUARD
McpHub.initializeMcpServers() -> fs.writeFile direct overwrite NO GUARD
Reference: DSH Implementation
DSH handles this with three orthogonal layers:
Proposed Plan
Phase 1 (1-2w): Make safeWriteJson sole JSON entry point; fix #1371,#920,#1221,#1021
Phase 2 (2-3w): Implement Observation Gate + guarded intent into Write/Edit tools
Phase 3 (1w): Port DSH tail-promise FIFO chain to DiffViewProvider/safeWriteJson
Phase 4 (1w): Replace all bare fs.writeFile/fs.appendFile with atomic paths
Acceptance Criteria