Repository navigation
file.writeWholeFile append flag TRUNCATES instead of appending; silent data loss #888
Copy link
Copy link
Open
Labels
priority/p1High priority - address soonHigh priority - address soonscope/quick-win< 4 hours, obvious solution< 4 hours, obvious solutiontype/bugDefect in existing functionality, needs fixDefect in existing functionality, needs fixworkstream/runtime-coreRuntime architecture, memory, lifecycle, and global contextRuntime architecture, memory, lifecycle, and global context
Description
Rationale
file.writeWholeFile(path, data, true) does NOT append — the append flag TRUNCATES and overwrites instead. Silent data loss for any caller relying on append semantics. Destroyed two full census walks before being caught (silent overwriting of accumulated output). Needs: fix the headless implementation, behavioral test for both flag values, audit for in-ODB callers relying on append.
Current State
Verified bug (2026-08-11):
file.writeWholeFile(path, "", true) // write empty, append flag=true
file.writeWholeFile(path, "AAA", true) // append "AAA", flag=true
file.writeWholeFile(path, "BBB", true) // append "BBB", flag=true
// Expected: "AAABBB"
// Actual: "BBB" (3 bytes)
Root cause: append flag either not honored in headless implementation or incorrect flag handling in verb glue
Impact:
- Silent data loss: no error, no warning, file is just truncated
- Destroyed two full census walks (expensive diagnostic work lost)
- Any caller relying on append semantics gets truncation instead
Severity: High (data loss)
Desired Outcome
- Fix file.writeWholeFile() to actually append when flag=true
- Add regression test: verify both append=false (truncate) and append=true (append)
- Audit ODB for scripts calling writeWholeFile with append=true
- Verify census tools and log-writers use correct flag
Recommendation
- Trace the bug: Headless file.writeWholeFile implementation + verb glue
- Check flag handling: append flag propagation to fopen/write calls (should use "a" mode, not "w")
- Implement fix: Correct flag handling or mode selection
- Test: Both truncate and append modes must work correctly
Exit Criteria
- file.writeWholeFile(path, data, false) truncates (current behavior correct)
- file.writeWholeFile(path, data, true) appends without truncation
- Regression test covers both flag values
- ODB scripts audited for append-mode calls (verify they work after fix)
- Census tools verified with fix in place
Related Context
- Found by: ODB census 2026-08-11 (file truncation destroyed two census runs)
- Code: Headless file.writeWholeFile implementation, verb glue flag handling
- Impact: Silent data loss, breaks append-based logging/accumulation
- Regression impact: Any script writing multiple times to same file with append=true
- Severity: P1 (data loss bug)
Note
This bug was not caught earlier because tests likely use temporary files and don't verify both flag modes. The silent truncation (no error, no warning) is the worst-case behavior.
Metadata
Metadata
Assignees
Labels
priority/p1High priority - address soonHigh priority - address soonscope/quick-win< 4 hours, obvious solution< 4 hours, obvious solutiontype/bugDefect in existing functionality, needs fixDefect in existing functionality, needs fixworkstream/runtime-coreRuntime architecture, memory, lifecycle, and global contextRuntime architecture, memory, lifecycle, and global context
Activity