Repository navigation
fix(bed): write summary.yml atomically so a partial write cannot destroy the verdict - #159
Conversation
…roy the verdict writeBedSummary used a plain os.WriteFile: a short write (full filesystem, killed process) leaves a TRUNCATED summary.yml that no YAML reader can parse, and the error was only printed while the caller believed a summary existed (opencharly/charly#1308: a run whose summary ended mid-scalar at line 218 could not be graded at all). Now: temp file in the same directory, fsync, rename - all-or-nothing, real error returned. The test reproduces the post-open short write via RLIMIT_FSIZE and FAILS on the old writer. *Agent: `jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5` · OpenCode session `ses_de3fa473bffeFiBo62whHxDPE5`* *Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)*
Review — BLOCKHead SHA: Change class: code/config — Go change in Blocks
Notes (non-blocking)
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — BLOCKHead SHA: Change class: code/config — Go change in Blocks
Comment dispositions
The atomic-write implementation (temp-in-same-dir → Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — PASSHead SHA: Security screen: PASS — no secrets/egress, no guardrail weakening, no supply-chain or scope mismatch; the change strengthens the write path (temp-same-dir → Checklist: All applicable rules PASS or NA. Placement: Comment dispositions:
Non-blocking notes: R11 is not addressed in the body — genuinely N/A (internal write helper, no DESIGN field/mechanism touched), but a one-line Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Summary
writeBedSummarywrote the run's verdict with a plainos.WriteFile, and the error was only printed to stderr while the caller carried on believing a summary existed. A short write — a full filesystem, a killed process — therefore leaves a truncatedsummary.ymlthat no YAML reader can parse, destroying the run's machine-readable verdict and taking the failing step's stderr with it.Measured (opencharly/charly#1308):
yamlScalaris correct (strconv.Quote), so this was never an escaping bug: the file simply ends mid-write.Now the write is atomic — temp file in the SAME directory (rename(2) is only atomic within one filesystem),
fsync,rename— so the target is either the complete new document or the previous one, and the real error is returned rather than swallowed.How tested
TestWriteFileAtomic_CompletesOrRefusespins the invariants the bug violated: a successful write is byte-complete and leaves no temp residue, and a refused write (unwritable directory) returns the error and leaves no partial document at the target.TestWriteFileAtomic_SurvivesAShortWritereproduces the PRODUCTION failure: a child process raisesRLIMIT_FSIZEto one block and then writes 8 KiB, so the write fails after the file is open (the field's ENOSPC; EFBIG here). The parent asserts the PREVIOUS document is intact. Red arm — the child using the oldos.WriteFile:So the change is now distinguished by a test that FAILS on the unmodified code:
os.WriteFiletruncates the target, the atomic path leaves the previous document intact.Spike
RCA claim: the summary was cut off in the WRITE, not mis-quoted.
A. Atomic temp+fsync+rename (chosen). Proven by the test: complete content, no temp residue, error surfaced.
B. Escape/quote the scalar harder. Spiked with the artifact:
yamlScalaralready usesstrconv.Quote, and the file does not end at a broken quote — it ends mid-document, so there are no bytes to escape:An unterminated
"fromstrconv.Quoteis impossible (it always closes); a file that stops after 218 lines is a short WRITE. Eliminated by measurement.C. Keep
os.WriteFilebut checklen(written). Spiked with the new regression instrument — the child process writing through the OLD call underRLIMIT_FSIZE:os.WriteFileopens the target with O_TRUNC, so the short write leaves a destroyed document in place — checkinglen(written)afterwards cannot restore it. Eliminated by measurement.Winner: A.
Exemption named (R12, spike-equivalent): candidate A is proved by a regression instrument that fails on the UNMODIFIED tree and passes with the fix —
TestWriteFileAtomic_SurvivesAShortWritere-execs itself withRLIMIT_FSIZE, writes 8 KiB through the oldos.WriteFile, and the parent asserts the previous document survived:That is the spike-equivalent case R12 accepts: the candidate's success IS the proof, and the failure of the alternative is measured on the same instrument rather than argued.
Rulebook compliance
R0 —
check/strict-policy/git-workflowloaded before the work.R1 — the defect is check run writes an INVALID summary.yml when a check's text exceeds the writer's budget (unterminated YAML scalar) charly#1308, reproduced live; this PR fixes it.
R2 — one write path: the call site is replaced, and
writeFileAtomicis the single implementation.R3 — no workaround: the atomicity is real, not a retry or a sleep.
R4 — product fixed before the prose.
R5 — the old call is gone; no second writer.
R6 —
fix/branch off freshmain; no destructive action.R7 — the test pins the invariants; its red is stated honestly above.
R8 — no live service involved (pure file I/O).
R9 — module gate run on this tree.
R10 — the changed path IS the bed runner, so the binary was built from THIS PR's tree and run against a
disposable: truebed (check-pod-overlayis declareddisposable: trueincharly/charly.yml). The binary is a two-module workspace: THIS plugin-check at the PR head, plus thecharlymodule whosemain.BuildCalVerit stamps.Three numbers, three different facts — all measured from the run: the workspace's plugin-check head is the tree under review; the binary stamp comes from the
charlymodule's HEAD commit (that is wherescripts/calver.shreads it: "the build clock is never consulted"); the run directory carries the run's own wall clock.The complete 16-step run it produced (all steps, in order — no excerpt):
and the artifact this PR exists to protect, read from THAT run's directory:
What the change proves, precisely:
writeBedSummaryis called ONCE, to emit the final summary for a run — it is not invoked per step. The 16 steps are pasted to show the run completed under the changed binary; the change itself is proved by the artifact those steps produced: the summary exists, parses, and carries all 16 steps with no temp residue. (The earlier phrasing "on the path of every one of those 16 steps" overstated it and is corrected here.)The pre-fix artifact from this same bed raised
yaml.scanner.ScannerError: found unexpected end of stream (line 217); this one parses. The changed call site (writeBedSummary→writeFileAtomic) is what emitted this summary, so it ran.Change classification
A write-path fix: the summary is now written atomically. Breaking change + rollback: none — same path, same bytes on success.
Filed issues
None: this fixes opencharly/charly#1308.
Agent:
jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5· OpenCode sessionses_de3fa473bffeFiBo62whHxDPE5Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)