Skip to content

file.writeWholeFile append flag TRUNCATES instead of appending; silent data loss #888

Open

Description

@jsavin

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

  1. Fix file.writeWholeFile() to actually append when flag=true
  2. Add regression test: verify both append=false (truncate) and append=true (append)
  3. Audit ODB for scripts calling writeWholeFile with append=true
  4. Verify census tools and log-writers use correct flag

Recommendation

  1. Trace the bug: Headless file.writeWholeFile implementation + verb glue
  2. Check flag handling: append flag propagation to fopen/write calls (should use "a" mode, not "w")
  3. Implement fix: Correct flag handling or mode selection
  4. 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.

Activity

  1. added
    priority/p1High priority - address soon
    type/bugDefect in existing functionality, needs fix
    workstream/runtime-coreRuntime architecture, memory, lifecycle, and global context
    on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1High priority - address soonscope/quick-win< 4 hours, obvious solutiontype/bugDefect in existing functionality, needs fixworkstream/runtime-coreRuntime architecture, memory, lifecycle, and global context

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions