Skip to content

fix(kuna): report a failed export as not retryable in its session - #4070

Merged
kaoru0822-kitauji merged 4 commits into
mainfrom
fix/kuna-failed-export-not-retryable
Oct 15, 2026
Merged

kaoru0822-kitauji merged 4 commits into
mainfrom
fix/kuna-failed-export-not-retryable

Conversation

@kaoru0822-kitauji

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

Copy link
Copy Markdown
Collaborator

Summary

A Kuna session builds its project export at most once. When the export fails, every later request that needs it (procedure_assembly, analyze_function, data-name address_name) got the stored failure back unchanged. For a timeout, MCP projected that as retryable: true with "Analysis took too long. Try a smaller request…". Repeating the request, or trying a smaller function, returned the same stored failure in about 1 ms, so an agent following the hint loops without any chance of success. Refs #1957.

Problem and expected behavior

Smallest trigger: REA_KUNA_PROJECT_TIMEOUT_MS=2000, cold cache, real Kuna 1.833, MCP on zip (arm64e):

procedure_assembly main  2592 ms  code=timeout retryable=true  "Analysis took too long. Try a smaller request, then run `rea doctor` if it continues."
procedure_pseudo_code main  ok (single-function), project_export.state = "failed"
procedure_assembly main     1 ms  identical timeout error, retryable=true

Expected: the error says the export failed for this session, is not retryable as-is, and names what must change before reopening the target.

Change and scope

#awaitProject passes a failed build through exportUnavailable(operation, failure). It returns an AnalysisCapabilityUnavailableError with retryable: false that keeps:

  • cause: the original export error;
  • diagnostics.export_error, export_code and export_details: the cause's tag and its own projected code and details, carried whole. That covers captured Kuna output, resource limits, artifact-change path and reason, and the cause's diagnostics. The MCP/CLI projection does not recurse into cause, so hand-copying fields kept dropping some; that is what three review findings reported;
  • a user message: Kuna's project export failed, so <operation> is unavailable in this session: <reason>. <next step>

For a timeout, the next step is to set REA_KUNA_PROJECT_TIMEOUT_MS above N ms or raise REA_KUNA_JOBS in the environment that starts REA, then restart REA, because KunaProvider snapshots its environment at startup, and reopen the target. For a resource constraint (for example, an export larger than the cache cap), it is the cause's own remediation plus the same restart. For other failures, it is to resolve the failure and reopen the target. AnalysisCancelledError and errors with incomplete cleanup pass through unchanged, so cancellation and retained-cleanup reporting still work. Pseudocode is unaffected: it already falls back to single-function runs and reports the export failure in its limitations. docs/kuna-provider.md documents the behavior.

Not included: rebuilding a failed export within the same session. A deterministic timeout would just burn the same deadline again; reopening the target already starts a fresh build. Generic timeout retryability is unchanged for other providers.

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: KunaSessionClient, the owner of "a session never rebuilds a failed export".
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. For these requests after a failed export, the error code changes from the cause's (timeout, resource_constraint, adapter failure) to capability_unavailable with retryable: false; the cause's tag stays in details.diagnostics.export_error.
  • Provider, bridge, target-format, or platform compatibility: Kuna only.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged. The failure stays visible in raw_result.project_export of pseudocode answers.
  • Target selection, authority, upstream behavior, and cleanup details: no process or file change. Unproven-cleanup errors are not rewrapped.
  • 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.

Evidence and regression coverage

  • Tests added or updated: kunaProvider.test.ts gets "reports a failed export as not retryable in its session". It covers a timed-out export (fake hangs, 300 ms deadline), a failed export (exit-failure) and an export larger than a 1 MiB REA_KUNA_CACHE_MAX_BYTES. For both procedure_assembly and analyze_function it checks retryable: false, the exact next-step text, the cause's tag, and that the wrapper's projected diagnostics.export_details equals the cause's own projected details. It also spot-checks the limits or captured output. Every review fix fails this test on its previous head.

  • Base reproduction: both cases fail on the base revision (git stash of src/kuna).

  • Real Kuna 1.833, same trigger as above, after the fix:

    procedure_assembly main  2311 ms  code=capability_unavailable retryable=false
      "Kuna's project export failed, so procedure_assembly is unavailable in this session: Analysis operation timed out after 2000ms: kuna:decompile-project. To retry, set REA_KUNA_PROJECT_TIMEOUT_MS above 2000 ms or raise REA_KUNA_JOBS in the environment that starts REA. REA reads Kuna settings when it starts, so restart REA, then reopen the target."
      details.diagnostics: {export_error: "AnalysisTimeoutError", export_code: "provider_timeout",
                            export_details: {operation: "kuna:decompile-project", timeout_ms: 2000,
                                             captured_output: {stdout: "", stderr: "", exit_code: null, signal: "SIGKILL"}}}
    

    analyze_function returns the same shape in about 3 ms.

  • Cost: one error is larger (1431 vs 630 serialized bytes, including the cause's projected details) because it names the cause and the fix. In exchange, an agent following the old retryable: true hint repeated a request that could not succeed. Model tokens were not measured.

  • Remaining proof gaps: no Linux run; the resource-constraint branch (export larger than the cache cap) is source-derived, not exercised by a test.

  • 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: on the latest head, rebased onto main with the Kuna xrefs feature, 137 passed twice. One earlier full run hit a single failure in the untouched cache test "preserves concurrent results and reclaims capacity (pin: true)"; that file then passed 6/6 on its own. I did not establish the cause.
  • 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, process lineage verified, cleanup: "complete".
  • Real MCP timeout reproduction before and after, above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Error codes change only for Kuna requests after a failed export, and the cause stays in diagnostics.
  • 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.

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

@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-15T11:20:15.865029Z d8c0b6d 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; no blocking issues were found.

Summary

Kuna requests that need a failed project export now return capability_unavailable with retryable: false.

  • Kuna export failures now stop dependent requests from retrying in the same session.

The previous and current commits have different merge bases, so this review used the full PR diff. Live supersession status could not be checked because GitHub access was not authenticated.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Request needs project export] --> B{Export succeeded?}
  B -->|Yes| C[Read export]
  B -->|No| D{Cancelled or cleanup incomplete?}
  D -->|Yes| E[Return original error]
  D -->|No| F[Return capability_unavailable]
  F --> G[Keep cause and export details]
  G --> H[Explain changes needed before reopening]
Loading

Reviews (4) · Last reviewed commit: "refactor(kuna): carry a failed export's ..." · Reviewed by Greptile

Comment thread src/kuna/KunaSessionClient.ts Resolved

@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: 2aab43a1d4

ℹ️ 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/KunaSessionClient.ts Outdated
Comment on lines +178 to +182
cause: failure,
diagnostics: {
...failure.diagnostics,
export_error: failure._tag,
...(failure instanceof AnalysisTimeoutError

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 Preserve the failed export's captured output

When kuna decompile-project exits unsuccessfully or times out cleanly, its typed failure can contain capturedOutput, but this wrapper copies only diagnostics into the new capability error. projectAnalysisError exposes captured output only from the top-level error, not its cause, so callers lose the export's stdout/stderr precisely when the session disallows a retry. Forward failure.capturedOutput to the wrapper (and preserve any other projected failure context).

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

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Valid, fixed in 988b50e. Root cause: the wrapper rebuilt the error from diagnostics only, while projectAnalysisError reads capturedOutput (and partialObservation) from the top-level error, not its cause. Fix: exportUnavailable forwards both from the export failure; diagnostics and cause were already kept, and cleanup-incomplete failures still pass through unwrapped. Validation: the test now requires the wrapper's capturedOutput to equal the cause's and the projection to include details.captured_output. It fails on the previous head. With real Kuna, the timed-out export now projects captured_output: {stdout: \"\", stderr: \"\", exit_code: null, signal: \"SIGKILL\"}.

@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: 988b50eb3f

ℹ️ 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/KunaSessionClient.ts Outdated
Comment on lines +184 to +188
diagnostics: {
...failure.diagnostics,
export_error: failure._tag,
...(failure instanceof AnalysisTimeoutError
? { timeout_ms: failure.timeoutMs }

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 Preserve resource details when wrapping an export failure

When a project export exceeds REA_KUNA_CACHE_MAX_BYTES (or a Kuna command reaches its output cap), the failure is an AnalysisResourceConstraintError carrying resource and reportedLimits; projectAnalysisError exposes those only when that typed error is top-level. This wrapper retains only its tag (and timeout metadata), so the projected MCP/CLI error no longer includes the cache/output limits needed to act on the remediation; copy the resource fields into the wrapper diagnostics (or preserve the typed projection) as well.

AGENTS.md reference: AGENTS.md:L29-L29

Useful? React with 👍 / 👎.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Valid, fixed in 0fde460 (rebased onto main after #4049/#4052 merged). Root cause: the wrapper kept the cause's tag and timeout but not the fields projectAnalysisError renders only for a top-level AnalysisResourceConstraintError. Fix: for a resource-constraint cause, diagnostics now also carry resource and reported_limits, with the same names as that projection. Validation: the provider test gets a third case, an export larger than a 1 MiB REA_KUNA_CACHE_MAX_BYTES (it was only source-derived before). It checks resource: \"capacity\", reported_limits.cache_max_bytes/export_bytes, the remediation plus the restart sentence, and retryable: false. That case fails on the previous head and passes now. Kuna suite 98 ×2, check:fast and docs:check pass.

@kaoru0822-kitauji
kaoru0822-kitauji force-pushed the fix/kuna-failed-export-not-retryable branch from 988b50e to 0fde460 Compare October 15, 2026 10:52

@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: 0fde460e6a

ℹ️ 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 on lines +184 to +186
diagnostics: {
...failure.diagnostics,
export_error: failure._tag,

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 Preserve artifact-change fields when wrapping export failures

When a session already has a valid single-function workspace but the separate project export observes that the selected target changed, the export produces AnalysisArtifactChangedError. This wrapper forwards only base diagnostics and export_error, so projectAnalysisError projects the outer capability error and drops the original structured path and boundary fields; the cause is not recursively projected to CLI/MCP callers. Copy the artifact-change fields (or preserve its projection) into the wrapper diagnostics so callers retain the selected-target evidence.

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

Useful? React with 👍 / 👎.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Valid, fixed in d8c0b6d (rebased onto main with the new Kuna xrefs feature; Kuna suite 137 ×2), structurally this time. Root cause: the wrapper rebuilt the cause's projection by hand (captured output, then resource limits), so each typed error with other fields, here AnalysisArtifactChangedError's path and reason, lost them, because the projection never recurses into cause. Fix: exportUnavailable calls projectAnalysisError(failure) once and carries the result in diagnostics as export_error (tag), export_code and export_details. Every type keeps the fields and shape its own projection gives it. The hand-written copies, including the top-level capturedOutput/partialObservation forwarding from the earlier review, are removed; captured output now appears once, under export_details.captured_output. Validation: for the timeout, adapter-failure and cache-capacity cases, the provider test requires the wrapper's projected diagnostics.export_details to equal the cause's own projected details, plus spot checks for limits and captured output; all three fail on the previous head. With real Kuna, a 2 s deadline on zip projects export_code: provider_timeout and export_details: {operation, timeout_ms: 2000, captured_output: {…, signal: SIGKILL}}. The artifact-changed case is not exercised here: on this branch the session's own inventory run sees the change first and reports it directly. It is covered by the same mechanism rather than by a dedicated test.

kaoru0822-kitauji and others added 4 commits October 15, 2026 11:13
A session never rebuilds a failed project export, yet requests that need it
returned the export's raw failure. For a timeout that projected as
`retryable: true` with "Try a smaller request", and every retry returned the
same stored failure. Those requests now fail with a non-retryable
capability error that keeps the export failure as its cause and diagnostics
and names what to change (the deadline or jobs for a timeout) before
reopening the target. Cancellation and unproven cleanup keep their own
errors.

Refs #1957

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The capability error for a failed export dropped the export's captured Kuna
output, which the MCP projection only reads from the top-level error. It
also told callers to change a setting and reopen the target, but REA reads
Kuna settings once at startup. The error now carries the captured output
and partial observation, and its recovery text says to change the setting
where REA starts and restart REA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An export larger than REA_KUNA_CACHE_MAX_BYTES, or a Kuna command at its
output cap, fails with a resource constraint whose resource and reported
limits the projection exposes only on the top-level error. The wrapper now
copies them into its diagnostics under the same names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The capability error for a failed export copied the cause's facts field by
field (captured output, resource limits), and each missing field, such as an
artifact change's path and boundary, dropped evidence callers could not
reach through `cause`. The wrapper now carries the export failure's own
projected code and details in its diagnostics, so every typed field survives
in the shape its own projection gives it, and the duplicated top-level
copies are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji
kaoru0822-kitauji force-pushed the fix/kuna-failed-export-not-retryable branch from 0fde460 to d8c0b6d Compare October 15, 2026 11:16
@kaoru0822-kitauji
kaoru0822-kitauji merged commit a5024a9 into main Oct 15, 2026
33 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/kuna-failed-export-not-retryable branch October 15, 2026 12:20
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction provider: kuna Analysis provider / engine: kuna labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction 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