Repository navigation
fix(mcp): name the close_binary retry for retained cleanup - #8329
Conversation
A close_binary that retired its target but could not confirm cleanup returned cleanup_incomplete with retryable: false and only the generic "Review the reported local resources" remediation, although the session keeps every failed owner and the next close_binary on the same connection retries them. Agents could abandon the connection that owns the only retry. The MCP close tool now passes its retry operation to the session. The session binds that typed AnalysisCleanupRetry to a failed retirement only while it retains the cleanup for its next close; the close tool binds it to process-capture failures its own scope retains and to compositions whose session part was offered. Projection then reports recovery.kind=retry_cleanup and appends a conditional instruction: keep the connection, let the condition settle or resolve it, call close_binary without snapshot_path and check the result. The hint disappears once that cleanup resolves. retryable keeps describing the failed operation. One-shot CLI closes, open_binary, analysis tools and failed snapshot saves (which keep the target open) offer no retry. Cleanup composition copies the owner's remediation without a retry offer, so the text appears once. Fixes #8211 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. |
[Low impact] This PR appears safe to merge; no actionable new issues were found. SummaryAdds
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["MCP close_binary"] --> B{"Snapshot requested?"}
B -->|Yes| C{"Save succeeded?"}
C -->|No| D["Return save error without retry offer"]
C -->|Yes| E["Retire target and close owned resources"]
B -->|No| E
E --> F{"Cleanup failed and remains retained?"}
F -->|Yes| G["Bind retry_cleanup and append guidance"]
F -->|No| H["Return normal close result"]
G --> I["Next same-connection close retries cleanup"]
Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
The new close_binary retry assertions froze ProviderCleanupError's explanatory sentence, so a harmless wording edit would break them. The MCP test now compares delivered remediation with analysisErrorRemediationAction applied to the delivered typed error plus cleanupRetryRemediation. The domain tests use the same formatters, check that unbound and released errors carry no retry text, and check that a bound composition adds the offer once. Recovery fields, cleanup state and retry behavior keep separate assertions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Independent real-Kuna cleanup-retry check after mergeOn REA main
Both owned target hashes were unchanged and neither target was executed. Successful MCP replies used fetched compact tool definitions; I separately validated the two close errors and the blocked-open error against One separate status-discoverability observation: while cleanup was pending, the |
) * fix(mcp): name the close_binary retry for retained cleanup A close_binary that retired its target but could not confirm cleanup returned cleanup_incomplete with retryable: false and only the generic "Review the reported local resources" remediation, although the session keeps every failed owner and the next close_binary on the same connection retries them. Agents could abandon the connection that owns the only retry. The MCP close tool now passes its retry operation to the session. The session binds that typed AnalysisCleanupRetry to a failed retirement only while it retains the cleanup for its next close; the close tool binds it to process-capture failures its own scope retains and to compositions whose session part was offered. Projection then reports recovery.kind=retry_cleanup and appends a conditional instruction: keep the connection, let the condition settle or resolve it, call close_binary without snapshot_path and check the result. The hint disappears once that cleanup resolves. retryable keeps describing the failed operation. One-shot CLI closes, open_binary, analysis tools and failed snapshot saves (which keep the target open) offer no retry. Cleanup composition copies the owner's remediation without a retry offer, so the text appears once. Fixes morluto#8211 Co-Authored-By: Claude Opus 5.5 <[email protected]> * test: derive close retry guidance from its owning formatters The new close_binary retry assertions froze ProviderCleanupError's explanatory sentence, so a harmless wording edit would break them. The MCP test now compares delivered remediation with analysisErrorRemediationAction applied to the delivered typed error plus cleanupRetryRemediation. The domain tests use the same formatters, check that unbound and released errors carry no retry text, and check that a bound composition adds the offer once. Recovery fields, cleanup state and retry behavior keep separate assertions. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
What broke:
close_binaryreturnedcleanup_incompletewithretryable: false, norecovery, and only "Review the reported local resources before opening another target." The session kept the failed owners, and the nextclose_binaryon the same connection retried them, but the error never said so (observed with Kuna's unproven export stop).Fix: The MCP close tool passes its retry operation to the session. The session binds a typed
AnalysisCleanupRetryto a failed close only when it retired the target and still holds that cleanup. The projection then addsrecovery.kind=retry_cleanupand a retry instruction that does not promise success.Risk: Low, but the contract changes: the error schema gains one recovery kind, and remediation text grows only on those errors. One-shot CLI,
open_binary, analysis tools and failed snapshot saves are unchanged.Summary
Fixes #8211.
A failed
close_binaryretires the target and keeps every owner whose cleanup failed. The nextclose_binaryon the same connection retries them; the Kuna guide already documented this. The error did not name that recovery, so an agent could drop the connection that owns the only retry.After a failed
close_binary, the error now carriesrecovery: {"kind": "retry_cleanup", "operation": "close_binary"}and adds this to the owner's remediation:The hint disappears once that cleanup resolves.
retryablestill describes the failed operation and staysfalse.Problem and expected behavior
close_binary.close_binaryretry of the retained cleanup. It must stay distinct from rerunning the analysis, must not promise success, and must not suggest terminating processes. Owners that cannot offer the retry must not advertise it.Change and scope
The fact is owned by the component that retains the cleanup, and it is never derived from message text.
Domain (
analysisErrorBase.ts,analysisErrorRecovery.ts):AnalysisError.bindCleanupRetry()records a frozen{ operation: "close_binary" }.cleanupRetryreturns that value only whilecleanupIncompleteis live.retry_cleanupjoins the recovery union and its zod schema.Projection (
analysisErrorProjection.ts): a small, localized change outsideerrorRecovery. A live bound retry takes precedence over the class-derived hint and appends the instruction to the owner's remediation.Composition (
analysisErrorCleanup.ts):analysisErrorWithCleanupFailurecopies the cleanup owner's remediation without any retry offer. A composed error therefore shows the retry text once, and only when its own owner binds it.Session (
BinarySession.ts,BinarySessionPort.ts):closeandcloseWithSnapshotaccept an optionalcleanupRetry. The session binds it only when all three hold:#closeActive) failed with incomplete cleanup;cleanup_pendinguses the same predicate,#retainsCloseCleanup, plus the external-mutation owner, whichclose_binarydoes not retry. A failed export or save returns before retirement and gets no offer.MCP adapter (
registerCloseLifecycleTool.ts):CLOSE_RETRYto the session;Provider audit (source-read only, no real-provider runs). A second
close()retries the remaining cleanup and never reportsokbefore confirmation in all of the following:IDA retries cannot reconnect a dead transport, so they keep failing. The retry text already allows for that by saying it can report
cleanup_incompleteagain. The Hopper document text and the Kuna published-staging text already mentionclose_binary, so they now repeat that advice once.Not included:
open_binary: it gets no hint. Its cleanup failures can leave a previous target active, and recommendingclose_binarythere would clear its records.Contribution scope: an ordinary fix within existing boundaries; no maintainer scope decision is needed.
Contract and boundary impact
BinarySessionowns the retained close cleanup, and the MCP close tool owns the process-capture scope and the retry operation.cleanup_pendingexpression was replaced by the shared predicate.recovery.kind=retry_cleanupvariant;docs/error-contract.schema.jsonwas regenerated.close_binary'scleanup_incompleteremediation text grows.Expected effects:
Evidence and regression coverage
tests/boundary/mcp/kunaCloseRetryMcp.test.ts(new) runs a real public MCP workflow with the productionKunaProvider, a fake Kuna and a launcher whosedecompile-projectstop stays unproven:open_binary→procedure_pseudo_code→close_binaryreportscleanup_incomplete,retryable: false,recoveryretry_cleanup/close_binary, and a remediation equal to the owning formatters' output (analysisErrorRemediationActionon the delivered error pluscleanupRetryRemediation), so prose is never frozen;binary_sessionshowsopen: false, cleanup_pending: true;open_binaryis blocked with no hint;close_binarysucceeds,cleanup_pendingbecomes false, staging is empty, and the target bytes are unchanged.processCleanupRetryMcp.test.ts:binarySessionCleanupRetry.test.ts:close()withoutcleanupRetrygets no hint, the offered close gets it, and it disappears after release;saved_snapshot.providerCleanupError.test.ts:idaRetainedCleanupCli.test.ts: the built one-shot CLI output contains noretry_cleanup.src/changes removed) failed only on the missingrecovery. Its first close returned{"code":"cleanup_incomplete","retryable":false,"remediation":{"action":"Provider cleanup could not be fully confirmed. Review the reported local resources before opening another target."},"recovery":null}, which matches the issue.recoveryobject above.close_binarytakes no cancellation signal, and this change does not touch cleanup ordering.close_binarycalls are not tested.For evidence-bearing changes:
Validation performed
All commands ran with Node 24.22.1 on macOS arm64.
node scripts/run-exact-tests.mjs run tests/boundary/mcp/kunaCloseRetryMcp.test.tsrecovery(reproduction above);npm run test:focused --with idaRetainedCleanupCli, kunaCloseRetryMcp, processCleanupRetryMcp, selectedSnapshotCleanupMcp, cleanupPrimaryProjection, sessionFixtureCleanup, createServerCleanup, finishAnalysisCommand, kunaProvider, kunaPublicationCleanup, hopperLaunchFailureCli and captureCleanup — 12 files, 66 tests passed.npm run test:local -- src/domain/providerCleanupError.test.ts tests/composition/analysis-sessions/binarySessionCleanupRetry.test.ts— passed (7 + 12 tests).npm run test:changed -- --base origin/main— 12545 passed, 23 skipped, 1 failed.src/inspector/JavaScriptRuntimeScope.cancellation.test.ts("stops Inspector target authorization after the current stat settles"), in code this PR does not touch.npm run check:fast— passed.npm run format:check— passed.Review follow-up (533e76a): guidance assertions now come from the owning formatters, and the controls behaved as intended:
test:focusedon the 5 touched or added test files passed (25 tests);check:fast,format:checkanddocs:checkpassed.npm run docs:error-schema— regenerateddocs/error-contract.schema.json.npm run docs:check— passed; it includesgenerate-error-schema --checkand package metadata checks.After merging
origin/main(a989c0e), these were rerun:npm run check:fast— passed;npm run format:check— passed;npm run docs:check— passed;npm run test:focused --with kunaCloseRetryMcp, processCleanupRetryMcp, selectedSnapshotCleanupMcp, idaRetainedCleanupCli, binarySessionCleanupRetry, providerCleanupError, analysisErrorProjection, analysisErrorCleanup, cleanupPrimaryProjection and kunaProvider — 10 files, 151 tests passed.Compatibility, safety, and release
recoveryis optional, and the new kind is additive. Strict clients that enumeraterecovery.kindshould acceptretry_cleanup.Author readiness
Human owner: @kaoru0822-kitauji
Before merge
type(scope): outcome.🤖 Generated with Claude Code