Skip to content

fix(kuna): report output beyond REA's buffer as deterministic and final - #4098

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/kuna-output-limit-not-retryable
Oct 15, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/kuna-output-limit-not-retryable

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

When Kuna's output overflowed REA's fixed buffer for a command (graph 32 MiB, xrefs and single-function text 16 MiB, inventory 128 MiB), REA reported a capacity resource constraint. MCP/CLI project capacity as retryable: true with "Wait for an active analysis to complete, then retry within the reported admission limits." That advice is wrong: the same target and Kuna executable produce the same output, so every retry overflows again. For call queries, each retry also repeats the whole-program kuna decompile-graph walk, and the error carried about 4 KB of the cut-off JSON document. Refs #1957.

Problem and expected behavior

Smallest real trigger: Kuna 1.833 on macOS arm64, lipo -thin arm64 of /Applications/Firefox.app/Contents/MacOS/XUL (169 MB Mach-O, 403,795 inventory entries), then MCP procedure_callers for any function (0x46e5d4):

procedure_callers  113489 ms  6306 bytes  code=resource_constraint retryable=true
  "kuna decompile-graph wrote more than 33554432 bytes of output."
  remediation: "Wait for an active analysis to complete, then retry within the reported admission limits."
  details.captured_output.stdout: 4096 chars from the middle of the graph JSON
procedure_callers (again)  113115 ms  same error

For scale, a 14 MB Sublime Text arm64 binary produces a 31.8 MB graph (41,773 functions, 139,662 edges), just under the budget.

Expected: a non-retryable error that says why repeating cannot help, and no second whole-program walk in the same session.

Change and scope

  • KunaCommand: an output-limit failure becomes AnalysisResourceConstraintError with resource memory, as the WABT and pcap adapters already classify their fixed output budgets. Its remediation reads "REA buffers at most N bytes of kuna output, so repeating this request for this target fails the same way. Use another provider for it." memory projects as retryable: false.
  • The same branch no longer returns the overflowed stdout tail (captured_output.stdout: "", truncated: true); stderr, exit status and signal remain.
  • KunaReferenceQueries remembers a graph that overflowed (#graphFailure, cleared on close), so later call queries in the session return that failure at once.
  • docs/kuna-provider.md: the graph budget paragraph names a real image that exceeds it and states the error behavior.

Not included: raising the 32 MiB graph budget or parsing the graph as a stream. The budget bounds REA's memory (raw JSON plus materialized indexes) and was chosen with the call-relationship feature; changing it is a design decision with its own memory measurements. XUL's call relationships therefore remain unavailable from Kuna. Per-address xref overflows are not memoized.

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

Contract and boundary impact

  • Semantic owner and earliest changed stage: KunaCommand.commandFailure (the classifier for every Kuna run); KunaReferenceQueries (graph reuse).
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. An output overflow's details.resource changes from capacity to memory, and retryable from true to false.
  • Provider, bridge, target-format, or platform compatibility: Kuna only.
  • Evidence, artifact, provenance, or reconstruction contract: reported_limits.output_limit_bytes is unchanged. The overflowed stdout fragment is dropped; nothing else from the failure is.
  • Target selection, authority, upstream behavior, and cleanup details: fewer repeated Kuna runs; cleanup is unchanged.
  • 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.

(Existing kuna decompile-graph runs; this change runs fewer of them.)

Evidence and regression coverage

  • Tests added or updated: new kunaCommandFailures.test.ts:

    • KunaTargetCommands.run with a 100-byte buffer over the fake inventory gives a memory constraint, retryable: false, the exact remediation, and an empty, truncated stdout capture;
    • with a new oversized fake graph mode (33 MiB of output), two procedure_callers calls both fail as memory/not retryable after a single decompile-graph run.
  • Base reproduction: both tests fail on the base revision (git stash of src/kuna).

  • Real Kuna 1.833, XUL arm64 slice as above, after the fix:

    procedure_callers  115322 ms  813 bytes  retryable=false
      remediation: "REA buffers at most 33554432 bytes of kuna decompile-graph output, so repeating this request for this target fails the same way. Use another provider for it."
      captured_output: {stdout: "", stderr: "", truncated: true, exit_code: 0, signal: null}
    procedure_callers (again)  2 ms  same error
    procedure_callees          3 ms  same error
    

    Each error response drops from 6306–6383 to 813 bytes. Model tokens were not measured.

  • Remaining proof gaps: no Linux run; the overflow is exercised for the graph and inventory paths, while single-function and xref overflows go through the same classifier without their own tests.

  • 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: 136 passed, two consecutive runs on the final change.
  • New tests on the base revision: 2 failed.
  • npm run check:fast: typecheck and lint passed.
  • npm run docs:check: passed.
  • REA_KUNA_COMMAND=… npm run verify:kuna (real Kuna 1.833, darwin/arm64): passed, cleanup: "complete" (run before the stdout change, which affects only output-limit failures).
  • Real XUL runs before and after, above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Only how an output overflow is classified and repeated changes.
  • Real Hopper/Ghidra, browser, or OS coverage: real Kuna on macOS arm64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new side effects; fewer repeated Kuna processes.

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

Kuna output that overflowed REA's fixed buffer was a `capacity` constraint,
which projects as `retryable: true` with "wait for an active analysis to
complete, then retry". The same target and executable overflow the same
buffer every time; on a 169 MB Mach-O, each retry of a call query repeated a
113 s whole-program graph walk and failed again. The overflow is now a
`memory` constraint whose remediation says repeating fails the same way, a
session answers later call queries from a graph overflow it already saw, and
the cut-off document's stdout tail is no longer returned.

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-15T12:06:44.096196Z cb702ea PR opened
ℹ️ 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: 4/5

[Medium impact] Changes how the Kuna provider handles output buffer overflows.

The PR appears safe to merge, with a non-blocking memory-retention issue in the saved graph failure.

Findings

  1. P2 Discarded graphs stay in memory ▶
Fix with agent prompt
### Issue 1
src/kuna/KunaReferenceQueries.ts:144-149
Caching `run.error` also keeps the full overflowed output alive. `commandFailure` clears `capturedOutput.stdout`, but passes the original `OwnedCommandFailure` as `cause`; its `snapshot.stdout.text` still holds up to 32 MiB. Each session that hits this limit keeps that unused graph until close, so several open sessions multiply the memory cost. Cache a compact failure without the output-bearing cause instead.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR makes Kuna output overflows final rather than retryable.

  • Kuna output overflows now produce a non-retryable memory error.
  • Call queries reuse graph-overflow failures for the session.

The saved graph failure still retains the full output through its cause; caching a compact error would avoid that extra memory cost.

Review checks were source-only; tests were not run. Whether this PR has been superseded could not be checked because GitHub access required authentication.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Call query] --> B{Saved graph failure?}
  B -->|Yes| C[Return saved failure]
  B -->|No| D[Run Kuna graph command]
  D --> E{Output exceeds budget?}
  E -->|No| F[Parse and cache graph]
  E -->|Yes| G[Return non-retryable memory error]
  G --> H[Save error for later queries]
  H --> I[Original cause still retains output]
Loading

Reviews (1) · Last reviewed commit: "fix(kuna): report output beyond REA's bu..." · Reviewed by Greptile

Comment on lines +144 to +149
if (!run.ok) {
if (
run.error instanceof AnalysisResourceConstraintError &&
run.error.resource === "memory"
)
this.#graphFailure = run.error;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Discarded graphs stay in memory

Caching run.error also keeps the full overflowed output alive. commandFailure clears capturedOutput.stdout, but passes the original OwnedCommandFailure as cause; its snapshot.stdout.text still holds up to 32 MiB. Each session that hits this limit keeps that unused graph until close, so several open sessions multiply the memory cost. Cache a compact failure without the output-bearing cause instead.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/kuna/KunaReferenceQueries.ts
Line: 144-149

Comment:
**Discarded graphs stay in memory**

Caching `run.error` also keeps the full overflowed output alive. `commandFailure` clears `capturedOutput.stdout`, but passes the original `OwnedCommandFailure` as `cause`; its `snapshot.stdout.text` still holds up to 32 MiB. Each session that hits this limit keeps that unused graph until close, so several open sessions multiply the memory cost. Cache a compact failure without the output-bearing cause instead.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb702ea528

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/kuna/KunaCommand.ts
Comment on lines +213 to +215
cause.reason === "output-limit"
? ""
: snapshot.stdout.text.slice(-4096),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain a bounded overflow-output excerpt

When a Kuna command crosses outputBytes, the supervisor has already retained the bounded prefix in snapshot.stdout, but this branch replaces it with an empty string. The resulting error therefore has no source output at all—even though it is marked truncated—so analysts cannot inspect the local evidence that distinguishes a large normal document from malformed or unexpected provider output. Keep a bounded, explicitly truncated (and appropriately redacted) excerpt instead.

AGENTS.md reference: AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit b3b5c8b into main Oct 15, 2026
34 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/kuna-output-limit-not-retryable branch October 15, 2026 12:23
@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