Repository navigation
fix(kuna): report output beyond REA's buffer as deterministic and final - #4098
Conversation
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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[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
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.SummaryThis PR makes Kuna output overflows final rather than retryable.
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]
Reviews (1) · Last reviewed commit: "fix(kuna): report output beyond REA's bu..." · Reviewed by Greptile |
| if (!run.ok) { | ||
| if ( | ||
| run.error instanceof AnalysisResourceConstraintError && | ||
| run.error.resource === "memory" | ||
| ) | ||
| this.#graphFailure = run.error; |
There was a problem hiding this 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.
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.There was a problem hiding this comment.
💡 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".
| cause.reason === "output-limit" | ||
| ? "" | ||
| : snapshot.stdout.text.slice(-4096), |
There was a problem hiding this comment.
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 👍 / 👎.
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
capacityresource constraint. MCP/CLI projectcapacityasretryable: truewith "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-programkuna decompile-graphwalk, 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 arm64of/Applications/Firefox.app/Contents/MacOS/XUL(169 MB Mach-O, 403,795 inventory entries), then MCPprocedure_callersfor any function (0x46e5d4):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: anoutput-limitfailure becomesAnalysisResourceConstraintErrorwith resourcememory, 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."memoryprojects asretryable: false.captured_output.stdout: "",truncated: true); stderr, exit status and signal remain.KunaReferenceQueriesremembers 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
KunaCommand.commandFailure(the classifier for every Kuna run);KunaReferenceQueries(graph reuse).details.resourcechanges fromcapacitytomemory, andretryablefrom true to false.reported_limits.output_limit_bytesis unchanged. The overflowed stdout fragment is dropped; nothing else from the failure is.Expected effects:
(Existing
kuna decompile-graphruns; this change runs fewer of them.)Evidence and regression coverage
Tests added or updated: new
kunaCommandFailures.test.ts:KunaTargetCommands.runwith a 100-byte buffer over the fake inventory gives amemoryconstraint,retryable: false, the exact remediation, and an empty, truncated stdout capture;oversizedfake graph mode (33 MiB of output), twoprocedure_callerscalls both fail asmemory/not retryable after a singledecompile-graphrun.Base reproduction: both tests fail on the base revision (
git stashofsrc/kuna).Real Kuna 1.833, XUL arm64 slice as above, after the fix:
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.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).Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code