Repository navigation
[AUTOMATED] fix(driver): surface pipeline panics instead of reporting success (DIV-45) - #225
Merged
Merged
Conversation
… 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
…panics # Conflicts: # docs/history.md
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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":
decompile_drive.rscalledpanic_message(&payload)withpayload: Box<dyn Any + Send>.&Box<dyn Any + Send>unsize-coerces to the box itself as theAny, so bothdowncast_ref::<&str>()anddowncast_ref::<String>()always failed — everyLOSS-131error record in the wild readpanic with non-string payload.kuna decompileexited 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-decompiledFuncdataas a brace-matched shell, so the file was never empty.structuring declined at a stubwas emitted for every no-sblocksrender. 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)
Before
exit=0, stderr empty.After
stderr:
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_messagenow takes thecatch_unwindpayload 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&strpayload, aStringpayload, anunwrap-on-Nonepayload, and the genuinely-non-string fallback.funcdata.rs—Funcdata::set_kuna_pipeline_failure/kuna_pipeline_failure: the reason for an abort, stamped on theFuncdatathat survives the unwind (newlines folded,*/neutralized so it can never break out of the emitted comment).ifacedecomp.rs— theLOSS-131swallow arm stamps that reason onto the retainedFuncdata(guarded on the entry address) before printing its existingSkipping <fn>: <reason>line. Console/datatest behavior is otherwise byte-identical.printc.rs— the no-sblocksshell 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.xmldocuments a restart-budget exhaustion that reached it).kuna-cli/src/decompile.rs— recognizes the console notice (find_pipeline_failure), reportserror: decompilation failed for <fn> in <binary>: <reason>+ the forwardeddecomp_dbgstderr, and exits 1. The recovered shell still goes to stdout.The contract (documented in
docs/cli.md, DIV-45)error: …+note: decomp_dbg stderr:(panic line + source location, 2000-char cap)error: …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-functionerrorrecord and never aborts the batch (that record now carries the real panic text instead ofpanic with non-string payload).Downstream callers checked
scripts/decbench/triage.py,rescore.py,showcase.pykuna decompile-all(+--addr)decbench/decompilers/raw/kuna_raw.pykuna decompile-all --jsonscripts/pipeline/timeit.py,prdemo.pyscripts/decompile.py(its owndecomp_dbgsubprocess, not the Rust CLI)kuna-ghidra(process.rs,decompileAt)decompile_funccould not decompile the function at <addr> (<reason>)message now carries the real panic textkuna-wasm/integrations/webkuna_console::project::decompile_targetserrorfield pathintegrations/ghidra(Java plugin)Verified after the change:
python3 -m scripts.decbench.triage --case O0-coreutils-factor-factorrenders its kuna(fresh) pane as before;kuna decompile-all comm --jsonexits 0 with 194 functions and exactly oneerrorrecord — now reading... (LOSS-131): called \Option::unwrap()` on a `None` value;kuna functions ls --json` unchanged.Gates
make testmake test-stagesmake rust-testpanic_messageunit tests, 4 newfind_pipeline_failureunit tests, 3 newkuna decompileCLI integration tests)make check-spec--strict)kuna catalog --checkTests are hermetic: the CLI gate points
--decomp-dbgat 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