Repository navigation
fix(kuna): report a failed export as not retryable in its session - #4070
Conversation
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] The PR appears safe to merge; no blocking issues were found. SummaryKuna requests that need a failed project export now return
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]
Reviews (4) · Last reviewed commit: "refactor(kuna): carry a failed export's ..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 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".
| cause: failure, | ||
| diagnostics: { | ||
| ...failure.diagnostics, | ||
| export_error: failure._tag, | ||
| ...(failure instanceof AnalysisTimeoutError |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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\"}.
There was a problem hiding this comment.
💡 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".
| diagnostics: { | ||
| ...failure.diagnostics, | ||
| export_error: failure._tag, | ||
| ...(failure instanceof AnalysisTimeoutError | ||
| ? { timeout_ms: failure.timeoutMs } |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
988b50e to
0fde460
Compare
There was a problem hiding this comment.
💡 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".
| diagnostics: { | ||
| ...failure.diagnostics, | ||
| export_error: failure._tag, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
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]>
0fde460 to
d8c0b6d
Compare
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-nameaddress_name) got the stored failure back unchanged. For a timeout, MCP projected that asretryable: truewith "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 onzip(arm64e):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
#awaitProjectpasses a failed build throughexportUnavailable(operation, failure). It returns anAnalysisCapabilityUnavailableErrorwithretryable: falsethat keeps:cause: the original export error;diagnostics.export_error,export_codeandexport_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 intocause, so hand-copying fields kept dropping some; that is what three review findings reported;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_MSabove N ms or raiseREA_KUNA_JOBSin the environment that starts REA, then restart REA, becauseKunaProvidersnapshots 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.AnalysisCancelledErrorand 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.mddocuments 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
KunaSessionClient, the owner of "a session never rebuilds a failed export".timeout,resource_constraint, adapter failure) tocapability_unavailablewithretryable: false; the cause's tag stays indetails.diagnostics.export_error.raw_result.project_exportof pseudocode answers.Expected effects:
Evidence and regression coverage
Tests added or updated:
kunaProvider.test.tsgets "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 MiBREA_KUNA_CACHE_MAX_BYTES. For bothprocedure_assemblyandanalyze_functionit checksretryable: false, the exact next-step text, the cause's tag, and that the wrapper's projecteddiagnostics.export_detailsequals 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 stashofsrc/kuna).Real Kuna 1.833, same trigger as above, after the fix:
analyze_functionreturns 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: truehint 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.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".Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code