Skip to content

[AUTOMATED] fix(driver): surface pipeline panics instead of reporting success (DIV-45) - #225

Merged
mahaloz merged 2 commits into
mainfrom
fix/surface-pipeline-panics
Aug 1, 2026
Merged

mahaloz merged 2 commits into
mainfrom
fix/surface-pipeline-panics

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

The bug

When the decompile pipeline panics for a function, kuna threw away the reason and reported success. Three defects compounded into "a function silently produces nothing and no one can find out why":

  1. The panic message was always discarded. decompile_drive.rs called panic_message(&payload) with payload: Box<dyn Any + Send>. &Box<dyn Any + Send> unsize-coerces to the box itself as the Any, so both downcast_ref::<&str>() and downcast_ref::<String>() always failed — every LOSS-131 error record in the wild read panic with non-string payload.
  2. kuna decompile exited 0 with empty stdout/stderr. The CLI surfaced the subprocess output only when the emitted C file was empty — but a caught abort still renders the previous, un-decompiled Funcdata as a brace-matched shell, so the file was never empty.
  3. The warning text named the wrong thing. structuring declined at a stub was emitted for every no-sblocks render. A 20,246-function corpus sweep found zero cases where it came from an actual structuring decline; it cost one investigation a wrong first hypothesis.

Before / after (the reproducer)

kuna decompile $R/O0/coreutils/stripped/comm --addr 0x3994 --mode reliable

Before

void sub_3994(void)
{
  /* WARNING: structured blocks unavailable (structuring declined at a stub) */
}

exit=0, stderr empty.

After

void sub_3994(void)
{
  /* WARNING: decompilation failed: decompile pipeline reached an un-ported seam (LOSS-131): called `Option::unwrap()` on a `None` value */
}

stderr:

error: decompilation failed for sub_3994 in .../O0/coreutils/stripped/comm: decompile pipeline reached an un-ported seam (LOSS-131): called `Option::unwrap()` on a `None` value
note: decomp_dbg stderr:
thread 'main' panicked at crates/kuna-decomp/src/p2_lift/jumptable.rs:1811:76:
called `Option::unwrap()` on a `None` value

exit=1.

The function still fails — that is deliberate. The underlying panics (the P3 opcode whitelist gaps, and the stale jump-table / destroyed BRANCHIND at p2_lift/jumptable.rs:1811) are owned by two other PRs. This PR is about surfacing failures, not removing them.

What changed

  • decompile_drive.rs — panic_message now takes the catch_unwind payload by value and downcasts it, so the old (broken) call site cannot be re-written. All three call sites updated (jumptable sub-pipeline, the main drive, the named-variant drive). New unit tests round-trip a &str payload, a String payload, an unwrap-on-None payload, and the genuinely-non-string fallback.
  • funcdata.rs — Funcdata::set_kuna_pipeline_failure / kuna_pipeline_failure: the reason for an abort, stamped on the Funcdata that survives the unwind (newlines folded, */ neutralized so it can never break out of the emitted comment).
  • ifacedecomp.rs — the LOSS-131 swallow arm stamps that reason onto the retained Funcdata (guarded on the entry address) before printing its existing Skipping <fn>: <reason> line. Console/datatest behavior is otherwise byte-identical.
  • printc.rs — the no-sblocks shell now says /* WARNING: decompilation failed: <reason> */ when the drive recorded one, and keeps a (de-fibbed) /* WARNING: structured blocks unavailable (structuring declined) */ for a genuine no-blocks render (that path is real: tests/stages/gh8500-stackalias.xml documents a restart-budget exhaustion that reached it).
  • kuna-cli/src/decompile.rs — recognizes the console notice (find_pipeline_failure), reports error: decompilation failed for <fn> in <binary>: <reason> + the forwarded decomp_dbg stderr, and exits 1. The recovered shell still goes to stdout.

The contract (documented in docs/cli.md, DIV-45)

stdout stderr exit
success the C — 0
pipeline abort the recovered shell, its comment naming the reason error: … + note: decomp_dbg stderr: (panic line + source location, 2000-char cap) 1
run-level error (no such function, no architecture, no C at all) — error: … 1 (unchanged)

stdout keeps the shell deliberately: an agent that ignores the exit code still reads the reason in the comment, and an agent that checks it now can. decompile-all / decompile-project / wasm are unchanged — a failed function stays a per-function error record and never aborts the batch (that record now carries the real panic text instead of panic with non-string payload).

Downstream callers checked

caller drives affected
scripts/decbench/triage.py, rescore.py, showcase.py kuna decompile-all (+ --addr) no — batch surface unchanged
decbench/decompilers/raw/kuna_raw.py kuna decompile-all --json no
scripts/pipeline/timeit.py, prdemo.py the Python shim scripts/decompile.py (its own decomp_dbg subprocess, not the Rust CLI) no — left deliberately untouched, out of scope
kuna-ghidra (process.rs, decompileAt) in-process decompile_func behavior unchanged; its could not decompile the function at <addr> (<reason>) message now carries the real panic text
kuna-wasm / integrations/web kuna_console::project::decompile_targets no — error field path
integrations/ghidra (Java plugin) the wire protocol, not the CLI no

Verified after the change: python3 -m scripts.decbench.triage --case O0-coreutils-factor-factor renders its kuna(fresh) pane as before; kuna decompile-all comm --json exits 0 with 194 functions and exactly one error record — now reading ... (LOSS-131): called \Option::unwrap()` on a `None` value; kuna functions ls --json` unchanged.

Gates

gate result
make test PARITY OK (675/675) — baseline untouched
make test-stages PARITY OK (305/305)
make rust-test green (workspace suite, incl. the 4 new panic_message unit tests, 4 new find_pipeline_failure unit tests, 3 new kuna decompile CLI integration tests)
make check-spec OK (also --strict)
kuna catalog --check OK — no option added (driver/diagnostics tier)

Tests are hermetic: the CLI gate points --decomp-dbg at a stub replaying a real console transcript, so it does not depend on which corpus functions currently panic.

inspiration = "decbench:cases-missing pool; coreutils comm main LOSS-131"

🤖 Generated with Claude Code

https://claude.ai/code/session_011RXVU58TKJxb518oViChwo

mahaloz and others added 2 commits August 1, 2026 18:38
… success

A function whose decompile pipeline aborts used to look like a success: `kuna
decompile` exited 0 with an empty stderr, and the C it printed blamed
structuring. Three compounding defects, fixed together:

1. The panic message was always discarded. `panic_message` was called as
   `panic_message(&payload)` with `payload: Box<dyn Any + Send>`; the reference
   unsize-coerces to the *box itself* as the `Any`, so `downcast_ref::<&str>()`
   and `downcast_ref::<String>()` both always failed and every LOSS-131 error
   record read "panic with non-string payload". The function now takes the
   payload BY VALUE (a signature the old call cannot be written against) and
   downcasts it, so the real text round-trips. Four unit tests cover the &str,
   String, unwrap-on-None and non-string payload shapes.

2. `kuna decompile` swallowed the failure. It surfaced the console's output only
   when the emitted C file was empty — but a caught abort still renders the
   previous, un-decompiled Funcdata as a brace-matched shell, so the file was
   never empty. The CLI now recognizes the console's `Skipping <fn>: <reason>`
   notice, prints `error: decompilation failed for <fn> in <binary>: <reason>`
   plus the forwarded `decomp_dbg` stderr (the panic line and its source
   location), and exits 1. The recovered shell still goes to stdout.

3. The warning text named the wrong thing. `/* WARNING: structured blocks
   unavailable (structuring declined at a stub) */` was emitted for every
   no-sblocks render; a 20,246-function corpus sweep found zero cases where it
   came from an actual structuring decline. The console now stamps the abort
   reason onto the retained Funcdata and the printer emits
   `/* WARNING: decompilation failed: <reason> */` for it, keeping the generic
   (now honest) "structuring declined" text for a genuine no-sblocks render.

This is about SURFACING failures, not removing them: the panics themselves (the
P3 opcode whitelist gaps and the stale jump-table BRANCHIND in
p2_lift/jumptable.rs:1811) are owned by other PRs, and the reproducer below
still fails - now loudly and accurately.

Reproducer (coreutils comm, sub_3994 @ 0x3994, --mode reliable):
  before: exit 0, empty stderr,
          /* WARNING: structured blocks unavailable (structuring declined at a stub) */
  after:  exit 1,
          /* WARNING: decompilation failed: decompile pipeline reached an
             un-ported seam (LOSS-131): called `Option::unwrap()` on a `None` value */
          error: decompilation failed for sub_3994 in .../comm: ... Option::unwrap() ...
          note: decomp_dbg stderr:
          thread 'main' panicked at crates/kuna-decomp/src/p2_lift/jumptable.rs:1811:76

Batch surfaces are unchanged by design: decompile-all / decompile-project / wasm
still isolate a failed function as its per-function `error` record and continue
(that record now carries the real message). Driver/diagnostics tier, so no
option: DIV-45 records the CLI contract change, documented in docs/cli.md, with
the spec prose in docs/spec/00-overview.md §0.2 and docs/spec/09-emission.md.

Gates: make test PARITY OK (675/675), make test-stages PARITY OK (305/305),
make rust-test green, make check-spec OK, kuna catalog --check OK.

inspiration = "decbench:cases-missing pool; coreutils comm main LOSS-131"

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011RXVU58TKJxb518oViChwo
@mahaloz
mahaloz merged commit 1362430 into main Aug 1, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/surface-pipeline-panics branch August 1, 2026 18:48
mahaloz added a commit that referenced this pull request Aug 1, 2026
Two P6 cover-extension steps were dropped in the merge port, and each made
kuna emit C that computes a DIFFERENT VALUE than the binary.

1. `Funcdata::build_copy_pair_range` built `Merge::checkCopyPair`'s dominance
   range from the dominant COPY's def point alone, omitting upstream's
   `range.addRefPoint(subOp, subOp->getIn(0))` (merge.cc:1121). A def-point-only
   Cover is a point, not a range, so no intervening write to the HighVariable was
   ever found inside it, `checkCopyPair` called every dominated COPY redundant,
   and `markRedundantCopies` marked load-bearing restores non-printing. At -O0 a
   guard-clause function whose `return param;` paths share one epilogue then
   returns a failed call's NULL instead of the parameter, and `for` loops lose
   their initializer. The sibling `build_single_read_cover` records the identical
   omission as LOSS-229 and had already been fixed; this is the second site.

2. `ActionMarkImplied` set the implied flag directly instead of going through
   `Merge::markImplied` (merge.cc:1595-1605), dropping the operand cover-dirtying,
   and `MergeContext::vn_set_cover_dirty` did not forward a Varnode `coverdirty`
   to the owning HighVariable the way `Varnode::setFlags` does
   (varnode.cc:377-378). `Cover::rebuild` walks forward through implied consumers,
   so an operand's live range only reaches the point where the inlined expression
   is printed once it is recomputed — and `HighIntersectTest::update_high`
   short-circuits on a high it believes is clean. Without both halves the
   speculative merges saw pre-inlining Covers and folded two values that are live
   at the same printed expression into one variable, so the emitted C read the
   later value where the binary reads the earlier one.

Both are upstream-faithful restorations, not new policy, so neither ships behind
an option: a default-off flag would leave kuna miscompiling by default.

Gates: make test PARITY OK (675/675), make test-stages PARITY OK (314/314),
make rust-test green, make check-spec green, kuna catalog --check OK. No baseline
re-pin and no per-test opt-out.

Regression: new fixture `covercopy_x86_64` (+ source) and
`kuna-console/tests/verify_cover_miscompile.rs`, one test per root cause,
asserting the VALUE-carrying statement (the `vN = a0;` restore after the
clobbering call; the two selects staying two variables and both being read by the
call argument). Each test fails on the pre-fix tree.

`verify_declared_vars`' sanity floor moves 5 -> 4: with Covers recomputed at the
right points the `make_dir_clone` size phi finally coalesces with the `strlen`
result the way upstream does, so the un-coalesced `v5` is gone. The
undeclared-variable gate itself is unchanged and still passes.

Rebased onto origin/main after #227 (the P3 opcode -> TypeOp seam totalisation)
and re-verified end to end on that base; the root causes here are Cover
construction and Cover invalidation, not op property bits. DIV-44..46 were taken
by #224/#225/#226 while this was in flight, so this claims DIV-47.

Docs: DIV-47 in docs/history.md; docs/spec/06-variables-and-merge.md gains the
prose for both cover extensions (the two-point Cover construction and the
implied-consumer walk).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011RXVU58TKJxb518oViChwo
mahaloz added a commit that referenced this pull request Aug 1, 2026
#228)

Two P6 cover-extension steps were dropped in the merge port, and each made
kuna emit C that computes a DIFFERENT VALUE than the binary.

1. `Funcdata::build_copy_pair_range` built `Merge::checkCopyPair`'s dominance
   range from the dominant COPY's def point alone, omitting upstream's
   `range.addRefPoint(subOp, subOp->getIn(0))` (merge.cc:1121). A def-point-only
   Cover is a point, not a range, so no intervening write to the HighVariable was
   ever found inside it, `checkCopyPair` called every dominated COPY redundant,
   and `markRedundantCopies` marked load-bearing restores non-printing. At -O0 a
   guard-clause function whose `return param;` paths share one epilogue then
   returns a failed call's NULL instead of the parameter, and `for` loops lose
   their initializer. The sibling `build_single_read_cover` records the identical
   omission as LOSS-229 and had already been fixed; this is the second site.

2. `ActionMarkImplied` set the implied flag directly instead of going through
   `Merge::markImplied` (merge.cc:1595-1605), dropping the operand cover-dirtying,
   and `MergeContext::vn_set_cover_dirty` did not forward a Varnode `coverdirty`
   to the owning HighVariable the way `Varnode::setFlags` does
   (varnode.cc:377-378). `Cover::rebuild` walks forward through implied consumers,
   so an operand's live range only reaches the point where the inlined expression
   is printed once it is recomputed — and `HighIntersectTest::update_high`
   short-circuits on a high it believes is clean. Without both halves the
   speculative merges saw pre-inlining Covers and folded two values that are live
   at the same printed expression into one variable, so the emitted C read the
   later value where the binary reads the earlier one.

Both are upstream-faithful restorations, not new policy, so neither ships behind
an option: a default-off flag would leave kuna miscompiling by default.

Gates: make test PARITY OK (675/675), make test-stages PARITY OK (314/314),
make rust-test green, make check-spec green, kuna catalog --check OK. No baseline
re-pin and no per-test opt-out.

Regression: new fixture `covercopy_x86_64` (+ source) and
`kuna-console/tests/verify_cover_miscompile.rs`, one test per root cause,
asserting the VALUE-carrying statement (the `vN = a0;` restore after the
clobbering call; the two selects staying two variables and both being read by the
call argument). Each test fails on the pre-fix tree.

`verify_declared_vars`' sanity floor moves 5 -> 4: with Covers recomputed at the
right points the `make_dir_clone` size phi finally coalesces with the `strlen`
result the way upstream does, so the un-coalesced `v5` is gone. The
undeclared-variable gate itself is unchanged and still passes.

Rebased onto origin/main after #227 (the P3 opcode -> TypeOp seam totalisation)
and re-verified end to end on that base; the root causes here are Cover
construction and Cover invalidation, not op property bits. DIV-44..46 were taken
by #224/#225/#226 while this was in flight, so this claims DIV-47.

Docs: DIV-47 in docs/history.md; docs/spec/06-variables-and-merge.md gains the
prose for both cover extensions (the two-point Cover construction and the
implied-consumer walk).


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

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant