Skip to content

[AUTOMATED] fix(cli): handle closed output — a broken pipe suppresses the diagnostic, not the verdict (DIV-89) - #336

Merged
mahaloz merged 2 commits into
Noelo-Lab:mainfrom
phix33:fix/cli-output-errors
Aug 27, 2026
Merged

mahaloz merged 2 commits into
Noelo-Lab:mainfrom
phix33:fix/cli-output-errors

Conversation

@phix33

@phix33 phix33 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Treat broken pipes as clean CLI termination.
  • Preserve errors for other output failures.
  • Add integration coverage and documentation.

Tests

  • Added CLI integration coverage for broken pipes and other output failures.

- Treat broken pipes as clean termination.
- Keep other output failures visible.
@mahaloz

mahaloz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

@phix33, after a quick review (human), this looks good. Thanks for the contribution (and donated tokens of effort)!

…e verdict (DIV-89)

Review amendments to the broken-pipe fix. The core of it is right and verified:
every stdout print site in kuna-cli now renders into a string and goes through
the fallible boundary, and across 24 command invocations the output is
byte-identical to the parent commit in stdout, stderr AND exit code. Three
things needed correcting before it lands.

1. A broken pipe was collapsing every exit code to 0, which converts a false red
   into a false green. `kuna test` against a REGRESSED baseline exited 0 once its
   reader closed, and `kuna decompile` lost both the exit 1 and the `error: ...`
   line of the DIV-45 failure contract. The write failed because nobody was
   reading, which is orthogonal to whether the work succeeded, and stderr is
   still open -- so `error_status(err)` becomes `status_after(err, status)`:
   BrokenPipe keeps the verdict the command reached, anything else still reports
   and forces 1. decompile.rs reports and returns its failure whether or not
   stdout survived, emitting first so the stdout-then-stderr order is unchanged.

2. `kuna specs` had been switched from `.status()` to `.output()`, which turned
   a streaming passthrough into a captured one: a 148-spec run went silent for
   17.2s and then printed all 1004 stderr lines ahead of all 149 stdout lines --
   detaching 615 warnings that carry no filename from the `Compiling <spec>:`
   line that was their only attribution. It now streams the child's stdout
   through the same boundary with stderr left inherited, so the interleaving
   matches the old passthrough (time-to-first-line 17.2s -> 0.01s) and
   `kuna specs | head` still exits quietly. Past a write failure the reads
   continue to EOF so slacomp finishes its .sla files instead of dying on EPIPE.

3. The repo requires a DIV row and owning-spec prose for a driver-tier behavior
   change (cf. DIV-66 Noelo-Lab#270, DIV-68 Noelo-Lab#277): adds DIV-89, the stdout-boundary
   section in docs/spec/00-overview.md beside the DIV-45 arm it qualifies, and
   reconciles the docs/cli.md paragraph with the exit-code contract 60 lines
   below it.

Tests: broken_pipe.rs gains the immediate-close case pinning that a REGRESSED
parity run still exits 1 (exit 0 before this commit, 1 after), plus unit
coverage of status_after; both file headers added. The two tests already here
fail on main with exit 101, so the suite is a real regression net in both
directions. All four gates green: make test PARITY OK, make test-stages PARITY
OK, make check-spec OK (strict too), make rust-test green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GgH79MoS51D7LX3J5WpoRd
@mahaloz mahaloz changed the title [AUTOMATED] fix(cli): handle closed output [AUTOMATED] fix(cli): handle closed output — a broken pipe suppresses the diagnostic, not the verdict (DIV-89) Aug 27, 2026
@mahaloz

mahaloz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Reviewed and amended in ae1fcb98 before merge. The core of this is right, and it verifies well: across 24 command invocations the output is byte-identical to the parent commit in stdout, stderr and exit code, and the two tests here fail on main with exit 101, so they are a real regression net. Three things needed correcting.

1. A broken pipe was collapsing every exit code to 0. That converts a false red into a false green:

$ kuna test --datatests --datatests-dir tests/stages --baseline docs/baseline.json --name kuna-catalog
                                       # 675 REGRESSED -> exit 1
$ ...same run, reader closes early     # exit 0   <-- gate goes green by losing its audience

kuna decompile lost both halves of the DIV-45 failure contract the same way — the exit 1 and the error: decompilation failed ... line, which docs/cli.md promises 60 lines below the paragraph this PR added. The write failed because nobody was reading, which is orthogonal to whether the work succeeded, and stderr is still open. So error_status(err) became status_after(err, status): BrokenPipe keeps the verdict the command reached, anything else still reports and forces 1. decompile.rs now emits first (preserving stdout-then-stderr order), then reports and returns its failure regardless.

2. kuna specs lost streaming and stream interleaving — .status() → .output() turned an inherited-stdio passthrough into a captured one. On the full 148-spec tree:

before this PR amended
time to first line 0.01s 17.2s (total silence) 0.01s
ordering interleaved all 1004 stderr, then all 149 stdout interleaved

615 of those 1004 warnings (WARN 1 NOP constructors found, WARN Use -n switch…) carry no filename — the Compiling <spec>: line above them was their only attribution, and capturing detached it. It now streams the child's stdout through the same boundary with stderr left inherited. kuna specs | head still exits quietly; past a write failure the reads continue to EOF so slacomp finishes its .sla files rather than dying on EPIPE.

3. Driver-tier conventions. A behavior change at this tier takes a DIV row and prose in the owning spec chapter (cf. DIV-66 #270, DIV-68 #277). Added DIV-89, the stdout-boundary section in docs/spec/00-overview.md beside the DIV-45 arm it qualifies, and reconciled the docs/cli.md paragraph with the exit-code contract below it. Note make check-spec runs lenient, so it would not have caught this.

Tests gained the immediate-close case pinning that a REGRESSED parity run still exits 1 (exit 0 before ae1fcb98, 1 after — it closes the read end before the child's first write, so it does not depend on the payload outgrowing the pipe buffer), plus unit coverage of status_after, plus the //! headers.

All four gates green locally on the amended branch: make test PARITY OK, make test-stages PARITY OK, make check-spec OK (strict too), make rust-test green.

Thanks for the fix — every kuna ... | head was a panic trace before this.

@mahaloz
mahaloz merged commit 76ea31b into Noelo-Lab:main Aug 27, 2026
2 checks passed
mahaloz added a commit that referenced this pull request Aug 27, 2026
…IV-90) (#341)

[AUTOMATED]

`kuna decompile` is the only surface that drives `decomp_dbg` as a subprocess,
so it holds no error object and has to recover what failed from the transcript.
`kuna-cli/src/decompile.rs (check_errors)` threw that away twice over.

1. GH-337 — the binary-load failure. The arm matched the trigger line
   `Could not create architecture` and answered
   `could not build an architecture for <binary> (unsupported/!recognized
   binary)` no matter what had actually happened, while the three in-process
   surfaces formatted the escaped `LowlevelError`. Sometimes that is an actively
   wrong diagnosis: `--sleighpath /nonexistent` masked `No sleigh specification
   for x86:LE:64:default`, a specs problem reported as a problem with the user's
   binary. It also made DIV-88's `symbolnamerepair` symptom — the exact string
   `docs/options.md` publishes as the flip trigger — unmatchable from this
   surface. `IfcLoadFile`'s error arm prints `{e.explain()}` and then the
   trigger on the next line, both to stdout, so `arch_failure_reason` reads the
   preceding line and the four surfaces now converge byte for byte. The generic
   wording survives only as the fallback for a transcript that printed no reason
   (the command echo is not a reason).

2. GH-339's silent half — the analysis commit. A failed `read symbols` is an
   `Execution error:` the console prints while keeping the session alive, so
   `print C` still rendered C, the out-file was non-empty, and `kuna decompile`
   printed quietly degraded output and exited 0 — while `functions`,
   `decompile-all` and `decompile-project` exited 1 with `read symbols (analysis
   commit) failed: <reason>`. The commit is not transactional and is
   unretryable, so a partial commit is a failed load, not a degraded one; exit 0
   there is indistinguishable from a binary that simply has no symbols.
   `read_symbols_failure` attributes each console diagnostic to the command echo
   above it and reports a `read symbols` failure with the in-process surfaces'
   message and exit code.

Driver tier, the DIV-89/#336 precedent: no option, no stages XML, no catalog
counts. `scripts/decompile.py (_check_errors)`, the Python library shim that
mirrors this function for `scripts/pipeline/`, carries both recoveries so the
two drivers do not disagree again (new `AnalysisCommitError`, a `DecompileError`
subclass every pipeline caller already catches).


Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@phix33
phix33 deleted the fix/cli-output-errors branch September 6, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants