Skip to content

[AUTOMATED] fix(cli): kuna decompile reports the console's real failure reason, for the load AND the analysis commit (DIV-90) - #341

Merged
mahaloz merged 1 commit into
mainfrom
fix/clidiag
Aug 27, 2026
Merged

mahaloz merged 1 commit into
mainfrom
fix/clidiag

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Closes #337. Also fixes the silent half of #339 — the driver half. #339's engine half (the
st_size clamp and the two typecache index panics it reaches) ships in the sibling
fix/symbolsizeclamp PR; this PR touches only kuna-cli.

kuna decompile is the one surface that drives decomp_dbg as a subprocess, so it holds no error
object and has to recover what failed from the console transcript. kuna-cli/src/decompile.rs (check_errors) threw that away twice over. The other three surfaces load in-process and format the
real LowlevelError (decompile_all.rs (load_program)). This makes the fourth agree — byte for
byte, message and exit code.

Driver tier, the DIV-89/#336 precedent: no option, no tests/stages XML, no catalog counts.

1. The architecture error (#337)

The arm matched the trigger line Could not create architecture and answered a fixed string
regardless of what happened:

$ kuna decompile   hostile_scope_x86_64 main --option symbolnamerepair off
error: could not build an architecture for …/hostile_scope_x86_64 (unsupported/!recognized binary)
$ kuna functions   hostile_scope_x86_64      --option symbolnamerepair off
error: could not build an architecture for …/hostile_scope_x86_64: Non-global scope has empty name

That is not merely less informative. --sleighpath /nonexistent masked No sleigh specification for x86:LE:64:default — a specs problem reported as a problem with the user's binary, which sends
them at the file instead of their install. And it made DIV-88's symbolnamerepair symptom
(could not build an architecture for <binary>: Non-global scope has empty name, the exact string
docs/options.md publishes as the flip trigger) unmatchable from the surface an agent is most likely
driving. The DIV-88 row names this defect verbatim as "a separate driver-tier defect this row does
not fix".

The transcript always carried the reason: IfcLoadFile's error arm prints {e.explain()} and then
the trigger on the next line, both to stdout. arch_failure_reason reads the preceding line and
formats it in load_program's wording, so the four surfaces converge on one string. The generic
(unsupported/!recognized binary) text survives only as the fallback for a transcript that
printed no reason at all (a [decomp]>-prefixed predecessor is the command echo, not a reason).

After:

$ kuna decompile / functions / decompile-all / decompile-project   (all four, exit 1)
error: could not build an architecture for …/hostile_scope_x86_64: Non-global scope has empty name

2. The analysis-commit failure (#339's silent half)

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 functions    sz.elf     error: read symbols (analysis commit) failed: g_a symbol created with zero size type   [exit 1]
$ kuna decompile-all sz.elf    error: read symbols (analysis commit) failed: g_a symbol created with zero size type   [exit 1]
$ kuna decompile    sz.elf main
unsigned int main(void) { return dat_402000; }                                                       [exit 0]   <-- silent

read_symbols_failure attributes each console diagnostic to the command echo above it and reports a
read symbols failure verbatim, in the in-process surfaces' wording.

Hard error or stderr warning? — hard error (exit 1, no C)

Both forms would let an agent notice. Three things decide it the other way:

  1. The state is not "degraded", it is broken. commit_analysis_output mutates the architecture
    in place, arm by arm, so an abort leaves the early arms applied and abandons library prototypes,
    cppsig/DWARF prototypes, ARM/MIPS context paints, tracked register values, call-fixups, DWARF
    stack locals and line comments — and it is unretryable (std::mem::take already drained both the
    pending stash and loader_data_objects). Nothing about which arms survived is visible in the C.
    The three in-process surfaces refuse to emit anything for exactly that reason; printing that C
    under a warning would keep this one surface disagreeing with them about what the run was.
  2. Exit 0 is the actual defect being reported. [AUTOMATED] A symbol whose st_size has zero low 32 bits kills the analysis commit — loudly on three surfaces, silently on kuna decompile #339's complaint is that the surface cannot be
    told apart from a binary with no symbols. A message on stderr is lost by any caller that captures
    stdout only; the status code is the part that cannot be dropped.
  3. No caller depends on exit 0 there. I grepped for every consumer:
    • scripts/decbench/{triage,rescore,optsweep,showcase,mine}.py and scripts/pipeline/status.py
      shell out to kuna decompile-all, never kuna decompile — that surface already exits 1
      here, so their behavior is unchanged. (optsweep.py:146 even treats a non-zero exit with
      non-empty stdout as ok, and it is on decompile-all anyway.)
    • scripts/pipeline/{compare,prdemo,timeit}.py and reference/kuna_adapter.py go through the
      Python scripts/decompile.py shim, not the kuna binary; all four catch the base
      kdecompile.DecompileError, so the new AnalysisCommitError subclass is already handled.
    • tests/datatests + tests/stages run decomp_test_dbg; they never reach kuna-cli, and both
      corpora are symbol-less bytechunks that cannot commit analysis at all.
    • integrations/web drives kuna_wasm, whose lib.rs:380 already fails loudly with this
      exact message (the 5th surface, untouched and already in agreement); integrations/ghidra
      drives kuna_ghidra, its own binary.
    • grep -rn "unsupported/!recognized" finds two producers (this file + the Python shim) and
      zero consumers; the three CLI skip-helpers (decompile_all_cli.rs (is_specs_skip),
      decompile_project_cli.rs, ctypes_per_arch.rs) key on the unchanged
      could not build an architecture prefix and are untouched.

scripts/decompile.py

It is the Python library shim scripts/pipeline/ still imports, and its _check_errors mirrored the
masked arm line for line. Both recoveries are ported there, plus a new
AnalysisCommitError(DecompileError) (exported from scripts/__init__.py), so fixing only the Rust
side does not leave the two drivers disagreeing again.

Tests

  • Recorded-transcript unit tests in decompile.rs, over transcripts captured from real
    decomp_dbg runs: reason present (empty scope / missing .sla / junk file), reason absent
    (fallback), a [decomp]>-prefixed predecessor (fallback, not a bogus reason), the read symbols
    failure, a diagnostic belonging to another command (not misattributed), and a clean transcript.
  • One real end-to-end test, decompile_cli.rs (every_surface_reports_the_same_load_failure):
    drives the actual engine over the checked-in kuna-analysis/tests/fixtures/hostile_scope_x86_64
    with --option symbolnamerepair off and asserts all four surfaces produce the same string and
    exit 1. This is the part that would catch a console-side print reorder; the stub tests would not.
    Its skip predicate is deliberately narrower than decompile_all_cli.rs (is_specs_skip), which
    treats any could not build an architecture as a missing-.sla skip and would have swallowed
    the very assertion.
  • Three more stub-driven CLI tests for the commit failure, the misattribution guard, and the
    preserved generic fallback. The commit-failure test is stubbed on purpose: the sibling engine fix
    removes the st_size repro, and the driver must keep reporting any commit failure after it lands.

Measurements

  • Collateral: 0 differing / 171 real kuna decompile invocations (stdout, stderr and exit
    code compared) across tests/bug-repro/{grep,sort,faillog,libselinux.so.1}, fauxware,
    /usr/bin/ls, /usr/bin/id — pre-change binary vs post-change. Expected by construction (both
    recoveries only fire on failure paths), and stated as such rather than as evidence of anything
    else. The real evidence is the failing-path A/B above.
  • Speed: interleaved, alternating arms, min-of-12 on grep/main — -2.15 % (0.5286 s ->
    0.5173 s), i.e. noise. Only two line scans of a transcript already in memory were added.
  • Parity: 675/675 and 538/538 unchanged, structurally — both corpora are symbol-less bytechunks
    driven by decomp_test_dbg, which never reaches kuna-cli.

Known limits (stated, not fixed)

  • The recovered reason is whatever the console said, and for a non-object file the console's
    own dispatch differs from the in-process loader's: 200 bytes of junk gets syntax error from
    decompile (the <binaryimage> XML branch) versus not in recognized object file format: Unknown file magic from functions. That is a pre-existing bootstrap_from_file vs bootstrap_from_object
    divergence, not a check_errors one; the reported text is still strictly more than the fixed string.
  • Scoped to read symbols, as decided. --option nosuchoption on still exits 0 on decompile and 1
    on functions — an option-command diagnostic, one line of the same helper away, left for its own
    change rather than smuggled in here.
  • DIV-90 is the number claimed; DIV-89 is the highest on main, and sibling PRs may take 90/91/92.
    Renumber the row and its four in-tree references (docs/history.md, docs/cli.md,
    docs/spec/00-overview.md ×2) on rebase.

🤖 Generated with Claude Code

https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

…IV-90)

[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).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1
@mahaloz
mahaloz merged commit f882494 into main Aug 27, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/clidiag branch August 27, 2026 19:16
mahaloz added a commit that referenced this pull request Aug 27, 2026
[AUTOMATED] DIV-90/91/92 were claimed by #341/#342/#344 while this branch was
in flight; the row and every reference move to DIV-93.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1
mahaloz added a commit that referenced this pull request Aug 27, 2026
…e aggressive preset (DIV-93) (#345)

* feat(modes): the four ARM entry-discovery options join the aggressive preset (DIV-90)

cortexmvectors (#248), ptrentry (#255), tailcallentry (#259) and poolentry (#278)
all shipped default-OFF and sat on the UNEVALUATED list in modes.rs, so they were
absent from AGGRESSIVE_OVERRIDES. `auto` resolves to `aggressive` under 500 KiB,
and the preset is what the whole-binary surfaces actually run, so all four were
INERT on every default path -- the DIV-64 itaniumrtti trap, four times over. The
default path's stripped-ARM entry recall had not moved since they merged.

They are flipped jointly because they compose, which is exactly what the
UNEVALUATED comment demanded before any flip.

Measured over the 110 stripped non-x86-64 decbench twins against their unstripped
twins' symbol tables (50,724 ground-truth function starts), --mode aggressive:

  arm       entries   exact   midbody   recall     added  added_exact  lost_exact
  base        55006   44957      8333   88.63%         -            -           -
  cortexm     55142   45093      8333   88.90%       136          136           0
  ptr         56594   46522      8333   91.72%      1588         1565           0
  tail        55655   45602      8337   89.90%       649          645           0
  pool        53956   45122      7116   88.96%       167          165           0
  all4        56188   47330      7117   93.31%      2402         2373           0

Recall and precision improve together: +2,373 real entries (98.8% of everything
added is a real function start) while mid-body false entries FALL 8,333 -> 7,117.
No ground-truth entry is lost by any arm -- poolentry's 1,217 removals contain
zero ground-truth addresses. 0 of 110 binaries lose recall.

Restricted to the 105 binaries `auto` actually sends to `aggressive` (< 500 KiB),
the default-path number is 90.92% -> 96.06%. The 5 images at/over the threshold
resolve to `reliable` and are disclosed in the DIV row rather than papered over.

Non-ARM inertness is measured: identical entry sets over 90 x86-64 twins and the
12 i386 PE images in the ARM corpus, byte-identical emitted C over 8 x86-64
binaries. Speed, interleaved min-of-4: decompile-all cf2.elf -5.8% (a speedup),
nuttx +3.5%, x86-64 controls at noise; discovery-only `kuna functions` +6.2%,
which is more work for more output on the one surface that only does discovery.

The 0/675 ablation is proven, not asserted: a throwaway build with all four forced
ON as engine defaults -- strictly stronger than preset membership, which the XML
harness never applies -- still reports 675/675 and 538/538 PARITY OK.

Also lands PR #239's two doc corrections, repointed at the shipped feature docs
rather than at its unshipped-proposal directory: the recall-measurement.md
mechanism/noise correction and the missing-ghidra-analyses.md
OperandReferenceAnalyzer row (its "function creation is subsumed by entry-disc"
claim is what ptrentry disproved).

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs(decbench): retire the two round-ledger claims DIV-90 falsifies

features-round4.md Rank 6 was a filed, still-open recommendation to flip
`tailcallentry` into the preset ("aggressive does not carry it"); DIV-90 does
exactly that, so it is marked SHIPPED with the sweep it asked for. features.md
still called step 3 "in flight" and did not know about step 5 (`poolentry`, #278).

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs: state the ARM restriction precisely -- poolentry has no arch gate

cortexmvectors/ptrentry/tailcallentry each early-return on
`object::Architecture::Arm`; poolentry does not, and is ARM-only in EFFECT
because it keys on PC-relative literal pools. The measured inertness is the same
either way (identical entry sets on 90 x86-64 twins and 12 i386 PE images), but
"all four are ARM-gated" overstated the mechanism for one of them.

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs(history): add the leave-one-out direction to the DIV-90 evidence

Dropping each option from the combination loses 27 / 1427 / 645 / 136 ground-truth
entries respectively, and dropping poolentry is the only one that also raises
mid-body false entries (7117 -> 8337). No option is redundant given the others.

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs: renumber the ARM-preset divergence to DIV-93

[AUTOMATED] DIV-90/91/92 were claimed by #341/#342/#344 while this branch was
in flight; the row and every reference move to DIV-93.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

---------

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.

[AUTOMATED] kuna decompile masks every load failure behind "(unsupported/!recognized binary)"

1 participant