Skip to content

fix(kuna): answer a repeated single-function request without re-running Kuna - #4169

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/kuna-reuse-single-function-answers
Oct 15, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/kuna-reuse-single-function-answers

Conversation

@kaoru0822-kitauji

@kaoru0822-kitauji kaoru0822-kitauji commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

While a Kuna session has no export reader, each procedure_pseudo_code request for a procedure starts a kuna decompile --addr run, which analyzes the whole image again. Concurrent requests share one run (#4045), but the session dropped the run as soon as it settled. A repeat request for the same procedure therefore paid for a full new analysis, and got back the same text with the same evidence ID. After a failed export this applies to every pseudocode request for the rest of the session. Refs #1957.

Problem and expected behavior

Observed on main, real Kuna 1.833, macOS arm64, /usr/bin/zip (arm64e slice). REA_KUNA_PROJECT_TIMEOUT_MS=2000 makes the export fail, and main is then requested three times over MCP:

procedure_assembly      2280 ms  capability_unavailable (export failed, retryable: false)
procedure_pseudo_code   7674 ms  193297 bytes  single-function
procedure_pseudo_code   7702 ms  193297 bytes  single-function   ← same evidence_id
procedure_pseudo_code   7732 ms  193297 bytes  single-function   ← same evidence_id
total 25.4 s, user CPU 25.3 s

The same happens while an export is still building. On Debian trixie linux/arm64, /usr/bin/bash's export takes about 40 s, and each repeat of main re-ran Kuna for about 1.5 s.

Expected: a completed single-function answer depends only on the session's target, its committed Kuna executable and the entry address. Within the session it is reusable work, and it remains so until the export can answer.

Change and scope

KunaSessionClient keeps each successful single-function text by entry address:

  • Bound: 16 MiB of UTF-8 text in all, plus a fixed per-entry charge, dropping the least recently used. This mirrors the session's exact-address xref memo.
  • Lookup: a request by name or by address resolves to the same entry, so both reuse one text.
  • What isn't kept: failed or cancelled runs, a run whose waiters all left, a run finishing after the export reader was adopted, or one finishing during close.
  • Lifetime: the kept texts are dropped when the export reader is adopted, so the export's text supersedes them exactly as before. They are also dropped on close.
  • Limitations unchanged: each answer still carries the single-function limitation, and the export-failure note when it applies. The project_export status is computed per request.

The fake Kuna gains decompilePadding so the budget can be tested. docs/kuna-provider.md describes the retention.

Not included: sharing these texts across sessions or servers. The export cache already does that once it finishes.

Scope: performance fix within the existing Kuna provider boundary; no maintainer scope decision applies.

Contract and boundary impact

  • Semantic owner and earliest changed stage: KunaSessionClient, which owns single-function runs.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: unchanged. Answers are byte-identical; only their latency changes.
  • Provider, bridge, target-format, or platform compatibility: unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged. A kept answer still reports raw_result.source.kind: "single-function" and its limitation.
  • Target selection, authority, upstream behavior, and cleanup details: no new processes or files. Kept texts are released on close.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

(These are the existing effects of a Kuna decompile; the change removes repeated launches.)

Evidence and regression coverage

  • Tests added in kunaSingleFunctionRuns.test.ts:
    • a repeat by name or by address while the export builds runs Kuna once;
    • repeats after a failed export run once and keep the export-failure limitation;
    • a failed run is not kept;
    • past the 16 MiB budget the least recently used text is dropped, and a hit refreshes recency. With three 6 MiB texts (two fit), main, parse, main, broken, main, parse runs 0x1000, 0x1040, 0x1080, 0x1040. The test fails when the refresh on a hit is removed.
  • Base reproduction: with main's KunaSessionClient.ts, the three retention tests fail. The "failed run is not kept" test passes on both; it guards against keeping errors.
  • Real provider, after the fix:
Scenario Before After
zip, macOS, export failed: 3 × main 7674 / 7702 / 7732 ms 8630 / 3 / 5 ms
zip, macOS: whole run 25.4 s, 25.3 s user CPU 11.1 s, 11.0 s user CPU
zip, macOS: peak RSS 650 MB 648 MB (largest process: Kuna)
bash, Linux, export building: 3 × main ~1.5 s each 2500 / 2 / 2 ms
  • Answers match: the three zip answers are identical (193297 bytes each, same result SHA-256 prefix 74234e98afe7, source single-function).

  • Handoff to the export on bash: the repeats while building kept the same evidence ID and project_export.state: "building". After procedure_assembly waited 39.8 s for the export, main came from project-export, with its own text and no single-function limitation.

  • Tokens: response sizes are unchanged. The saving is time, CPU and Kuna processes (each run held about 360 MiB on a 200 KiB image in earlier measurements).

  • Remaining proof gaps:

    • Eviction is covered by the fake only; no real target produced texts near 16 MiB.
    • The Linux run used a copy of the change applied to an earlier main (40f73f6), built in the container.
  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/providers/kuna/*.test.ts (20 files) — 194 passed.
  • npm run test:focused -- tests/boundary/filesystem/directAnalysisPermissions.test.ts — 2 passed.
  • npm run check:fast — passed.
  • npm run docs:check — passed.
  • Real Kuna 1.833 over MCP, macOS arm64 (zip): table above.
  • Real Kuna 1.833 over MCP, Debian trixie linux/arm64 in Colima (bash): table above.
  • kunaProjectConcurrency.test.ts > preserves concurrent results and reclaims capacity (pin: true) failed under CPU stress (9 × yes), with main's KunaSessionClient.ts as well (3 of 3). It passes on an idle host. This is pre-existing flakiness, not caused by this change.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: real Kuna on macOS arm64 and linux/arm64.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: memory retained per session is bounded at 16 MiB of text plus entry charges and released on close. Fewer Kuna processes are launched.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

…ng Kuna

A session dropped each single-function run once it settled, so a repeat
request for the same procedure re-ran `kuna decompile --addr`, which
analyzes the whole image again. After a failed export every pseudocode
request uses that path for the rest of the session.

Keep each completed text by entry address, within a 16 MiB least recently
used budget, until the export's reader is adopted or the session closes.
Failed and cancelled runs are not kept. The export's text still supersedes
a kept one.

Refs #1957

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added bug Something isn't working track:kuna Kuna decompiler provider series (#1957) labels Oct 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T16:17:03.555857Z 814525c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the revised test addresses the previous finding.

Summary

KunaSessionClient keeps successful single-function answers within a 16 MiB session budget and clears them when the export takes over or the session closes.

  • Repeated pseudocode requests reuse the saved Kuna result.

Reviews (2) · Last reviewed commit: "test(kuna): pin that a kept text's hit r..." · Reviewed by Greptile

With two 9 MiB texts only one fit the budget, so a repeated lookup could
not change which entry was dropped. Use three 6 MiB texts: re-reading main
leaves parse least recently used, so keeping broken must drop parse.

Refs #1957

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji
kaoru0822-kitauji merged commit 62bf098 into main Oct 15, 2026
33 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/kuna-reuse-single-function-answers branch October 15, 2026 16:36
@morluto morluto added the provider: kuna Analysis provider / engine: kuna label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: kuna Analysis provider / engine: kuna track:kuna Kuna decompiler provider series (#1957)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants