Repository navigation
Description
read_file conflates directories, errors, and empty files: all read as "".
Spec reference
Audit target 2 (call/return correctness) and target 18 (artifact
provenance). Found during the build-graph audit; retained as BGO-002 in
.audit/modules/src__BuildGraphOps.w.md with confined -O1 fixtures, and
re-observed on the current revision. The forwarding branch is
src/BuildGraphRuntime.w:88-89.
Minimal reproduction
use BuildGraphRuntime
let sandbox = ".audit/probes/build_graph_runtime_sandbox"
let _ = build_graph_rt_mkdir_p(sandbox)
let _ = build_graph_rt_write_file(sandbox ++ "/empty.txt", "")
print(f"dir={build_graph_rt_read_file(sandbox).len()}")
print(f"missing={build_graph_rt_read_file(sandbox ++ "/missing").len()}")
print(f"empty={build_graph_rt_read_file(sandbox ++ "/empty.txt").len()}")
Output: dir=0 missing=0 empty=0 — the three cases are indistinguishable.
The retained fixtures go further: :compare-directories -O1 exits 0 with a
green survey verdict for two directories containing different files, and
:copy-directory -O1 exits 0 while replacing the destination with a
zero-byte regular file.
Expected vs actual
Expected: a read failure (directory, missing, permission) is
distinguishable from a successful empty read. Actual: all three yield "",
so build_graph_compare_files and build_graph_copy_file_to_path treat
unreadable inputs as empty files. Because fixpoint comparison shares this
function, a malformed or unreadable stage-input pair can be reported
byte-identical — a false-green integrity failure, not a poor diagnostic.
Root cause
with_fs_read_file (rt/rt_core.w:3277-3300) returns the same empty
string for a directory, for open failure, and when size-seek yields <= 0;
operations then treat the convenience string as proof bytes were read
(src/BuildGraphOps.w:31-38, :511-525).
Workaround
Check existence and file type before reading (still racy against
disappearing files and says nothing about short reads).
Suggested repair boundary
Introduce a status-bearing exact-read result distinguishing empty success
from every failure, validate regular-file inputs where operations require
files, make all consumers handle the error before comparing or writing, and
make fixpoint fail closed on any non-regular or unreadable stage input.
Artifact writes must likewise surface short writes (see the write_file
short-write issue).
Activity
std.fs: read_file returns Result[str, IoError]; ToolFs.read_text pani…
build/: the zlib helpers read their input through Result; a build-hel…
ehartford commentedon Sep 14, 2026
Independently reproduced the legacy read ambiguity. The tested public API and build-graph consumers are already repaired. This is a valid report with a subsequent fix, rather than an invalid report.
Reproduction and current controls
Environment: Darwin arm64;
/Users/eric/.local/bin/withreportsv0.15.2.1; runtime probes compiled at-O1. Current source reviewed and imported:5809ac10aee5033d4811a9f023dae7282e4ef500. I also importedBuildGraphRuntimefrom an isolated worktree at the reported revision450733e58a1a7cce14f9cb2084943fc178815111. That historical-source probe still used the installed compiler/runtime, not a compiler rebuilt from the historical revision.Minimal probe, after creating a directory containing an empty file and an eight-byte file:
with run -O1 repro.wprintsdir=0,missing=0,empty=0,full=8, exit 0. I observed this with both current and historical wrapper source. My executed fixtures used an isolated directory outside the repository; the path above is shortened for readability.The repaired
std.fs.read_filegives distinct results:Err(IoError.Os(21, path))Err(IoError.Os(2, path))Ok("")Ok, length 8Direct probes of current
BuildGraphOpsalso passed the relevant controls:KEEPbytes.with run -O1 test/behavior/behav_fs_read_file_io_error.wadditionally printedok, exit 0, covering the error payload/message, directory rejection, empty success, and?propagation.Source, specification, and history
The historical runtime implementation explicitly returns the same empty string for directory, open-failure, and nonpositive-size paths. That is source evidence for the reported mechanism, not a claim of historical instruction-level debugger proof.
Repair commit 08f87b6c adds status-bearing reads, changes
std.fs.read_filetoResult[str, IoError], makesToolFs.read_textreport errors, and routes compare/copy/promote/install through checked reads. It references this issue and closes the overlapping #909. The current checked graph read and public API preserve the distinction. The legacy runtime helper intentionally retains the empty-on-failure contract for internal probes; observing it alone no longer demonstrates that comparison/copy is broken.Specification §10.2 shows
read_file(path)?propagatingIoError. The decision log supplies no exception authorizing failed artifact reads to count as successful empty reads. D20's spec-leads rule and the mission's guardrails support the implemented repair.I checked relevant merged history and open PRs. The repair landed as the commit above; GitHub's commit-to-PR lookup returned no associated PR. Subsequent changes to these graph files are path/platform work, and the open audit PR #1078 records the older findings rather than supplying a competing fix.
Assessment and limits
I would champion this failure-handling requirement: an unreadable artifact must never become evidence of byte equality or silently overwrite a valid destination. The existing fix addresses the independently tested cases, so I would prioritize retaining regression coverage and reviewing any remaining consumers over reimplementing that fix.
I could not independently execute the historical comparison/copy paths: their old dependencies fail checking on retired
Vec.set_i32calls with both available local binaries. I did not alter them to manufacture a passing reproduction. I also did not inject permission races, short reads, devices, or platform-specific failures, nor run a full stage fixpoint. The current operation probes therefore establish the cases above, not complete closure of every proposed acceptance criterion. The historical false-green comparison remains supported by the reporter's evidence and source review, not a new historical execution claim.ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): does not reproduce; the fix landed.validate-all-tests: a batch that never spawns reports instead of pani…