[PR #4098] [MERGED] fix(kuna): report output beyond REA's buffer as deterministic and final #6057

Closed
opened 2026-10-31 01:11:31 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4098
Author: @kaoru0822-kitauji
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/kuna-output-limit-not-retryable


📝 Commits (1)

  • cb702ea fix(kuna): report output beyond REA's buffer as deterministic and final

📊 Changes

5 files changed (+122 additions, -7 deletions)

View changed files

📝 docs/kuna-provider.md (+1 -1)
📝 src/kuna/KunaCommand.ts (+14 -4)
📝 src/kuna/KunaReferenceQueries.ts (+16 -1)
📝 tests/boundary/providers/kuna/fakeKuna.ts (+9 -1)
➕ tests/boundary/providers/kuna/kunaCommandFailures.test.ts (+82 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4098 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/kuna-output-limit-not-retryable` --- ### 📝 Commits (1) - [`cb702ea`](https://github.com/morluto/rea/commit/cb702ea52814491506d590dd96a1543917b97927) fix(kuna): report output beyond REA's buffer as deterministic and final ### 📊 Changes **5 files changed** (+122 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `docs/kuna-provider.md` (+1 -1) 📝 `src/kuna/KunaCommand.ts` (+14 -4) 📝 `src/kuna/KunaReferenceQueries.ts` (+16 -1) 📝 `tests/boundary/providers/kuna/fakeKuna.ts` (+9 -1) ➕ `tests/boundary/providers/kuna/kunaCommandFailures.test.ts` (+82 -0) </details> ### 📄 Description ## 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 <subcommand> 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: - [x] Read existing files or captured data. - [x] 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. - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] 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: <!-- @GitHub-handle --> - [ ] 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:11:31 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6057
No description provided.