[PR #4103] [MERGED] fix(providers): report provider-selection diagnostics when the selected provider refuses its profile #6059

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4103
Author: @pablodiazjorge
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @morluto

Base: main ← Head: fix/explicit-profile-refusal-selection-details


📝 Commits (8)

  • 6c61693 fix(providers): report provider-selection diagnostics when the selected provider refuses its profile
  • 4539a85 fix(providers): keep refusal evidence and cleanup ownership on selection failures
  • 43cec3c Merge upstream main into fix/explicit-profile-refusal-selection-details
  • 67cb026 Merge upstream main into fix/explicit-profile-refusal-selection-details
  • 4a1103e Merge upstream main into fix/explicit-profile-refusal-selection-details
  • dda7972 Merge upstream main into fix/explicit-profile-refusal-selection-details
  • a765200 Merge upstream main into fix/explicit-profile-refusal-selection-details
  • 8db415f Merge upstream main into fix/explicit-profile-refusal-selection-details

📊 Changes

6 files changed (+248 additions, -11 deletions)

View changed files

📝 src/application/binary/AnalysisProviderRegistry.test.ts (+68 -0)
📝 src/application/binary/AnalysisProviderRegistry.ts (+37 -3)
📝 src/domain/analysisErrorPresentation.ts (+5 -0)
📝 src/domain/analysisErrorProjection.test.ts (+26 -0)
📝 src/domain/providerSelectionError.ts (+16 -8)
➕ tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts (+96 -0)

📄 Description

Summary

Fixes #3930. When a provider is selected explicitly and then refuses the target while resolving its analysis profile, open_binary returned the raw refusal (unsupported_target, operation resolve_analysis_profile) and dropped the provider-selection diagnostics that every other unsupported selection carries: selection_reason, requested_provider_id, candidate_ids and rejections. The evaluation already records that refusal as the candidate's target rejection (AnalysisProviderEvaluation.ts), but #selectConcrete returned the profile error before building the selection error (AnalysisProviderRegistry.ts). Now an unsupported-target refusal becomes the target_unsupported selection error with the updated candidate statuses, and it keeps the refusal's own message and, when the provider gives one, its specific recovery.

Problem and expected behavior

Smallest trigger, from the issue: explicit provider_id: "ghidra" with REA_GHIDRA_LANGUAGE_ID set, opening a raw ARM binary. On main the MCP error is unsupported_target with reason REA_GHIDRA_LANGUAGE_ID cannot override the admitted raw-binary import. and no selection details. Expected, as the issue asks: capability_unavailable with details.selection_reason: "target_unsupported", requested_provider_id: "ghidra", the candidate IDs and the provider's rejection, with the refusal reason still visible.

Change and scope

  • src/application/binary/AnalysisProviderRegistry.ts: in explicit selection, an AnalysisUnsupportedTargetError from profile resolution returns selectionError("target_unsupported", …) built from the evaluated statuses, whose rejection already holds the refusal reason (code: "target_format_unsupported"). Its userMessage is the refusal's message, so callers read the same text as before; its recovery is the refusal's remediationAction when there is one; and it carries the refusal's captured output, diagnostics and partial observation, with the refusal as its cause. A refusal with unconfirmed cleanup is returned unchanged, so it still projects as cleanup_incomplete with its resources, as automatic selection already does. Other profile errors (adapter errors) are returned unchanged.
  • src/domain/providerSelectionError.ts: an optional remediationAction, as AnalysisUnsupportedTargetError already has, and the shared cause, diagnostics and partialObservation options passed to the base error alongside capturedOutput.
  • src/domain/analysisErrorPresentation.ts: a selection error with remediationAction uses it as remediation.action; without it, the action stays the user message, as before.

Keeping the refusal's recovery matters for the refusals that know a specific fix: for example, the NativeAOT extension refusals tell the caller to omit REA_GHIDRA_NATIVEAOT_JAR, and the generic "choose another provider" guidance alone would point the wrong way.

Automatic selection is unchanged; it already folds profile refusals into its selection result.

Contribution scope: not applicable (error reporting of an existing selection path).

Contract and boundary impact

  • Semantic owner and earliest changed stage: explicit provider selection in AnalysisProviderRegistry.
  • CLI and MCP/tool-catalog contract: no schema change. An explicit selection refused during profile resolution now reports capability_unavailable with selection details instead of unsupported_target; the message is unchanged.
  • Provider, bridge, target-format, or platform compatibility: provider-neutral; no provider changes.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Generated metadata (docs/public/product-catalog.json), 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:
    • tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts: the issue's case through the public open_binary MCP tool with the production Ghidra provider and a simulated installation. The refusal returns capability_unavailable with selection_reason, requested_provider_id, candidate_ids and a rejection whose reason is the refusal text, without starting an engine; the same raw input without the override still opens. With main's registry the first test fails with unsupported_target.
    • src/application/binary/AnalysisProviderRegistry.test.ts, in its own block: an explicit refusal with a recovery, captured output and diagnostics keeps all three, its reason and the refusal as cause on the selection failure; a refusal with unconfirmed cleanup is returned unchanged and projects cleanup_incomplete. Removing the recovery copy or the cleanup guard makes the matching test fail.
    • src/domain/analysisErrorProjection.test.ts: a selection error keeps a supplied recovery as remediation.action and otherwise falls back to its message.
  • Remaining proof gaps: no real Ghidra installation was used; the installation is the existing simulated host, as in the issue.

For evidence-bearing changes:

  • 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

Windows 11 x64 (10.0.26300), Node 24.18.0, branch based on 8ed3d1df7.

  • npx vitest run src/application/binary/AnalysisProviderRegistry.test.ts tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts src/domain/analysisErrorProjection.test.ts: 68 passed.
  • The registry tests with the recovery copy removed, and with the cleanup guard removed: each fails its own test.
  • The MCP test with main's AnalysisProviderRegistry.ts: the refusal case failed with unsupported_target, as expected.
  • After npm run build:cached and npm run test:prepare, the 20 test files that reference provider selection or its errors: 124 passed, 2 failures, ghidraInventoryMcp (byte search) and BinarySessionLiveness (cancelled-switch restoration, 30 s timeout). Both fail identically with main's code on this host.
  • npm run check:fast: passed.
  • npx oxfmt --check on the changed files: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: callers that matched unsupported_target for an explicitly selected provider's profile refusal now receive capability_unavailable with selection details, the same code other unsupported selections already use.
  • Real Hopper/Ghidra, browser, or OS coverage: none; simulated installation only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new input is read and nothing runs; the rejection diagnostics are the ones the evaluation already recorded, and cleanup ownership is never moved to the selection error.

Author readiness

Human owner: @pablodiazjorge

  • 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.

🔄 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/4103 **Author:** [@pablodiazjorge](https://github.com/pablodiazjorge) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/explicit-profile-refusal-selection-details` --- ### 📝 Commits (8) - [`6c61693`](https://github.com/morluto/rea/commit/6c61693e70fb121a2783b3b2ef6836aa98417b0f) fix(providers): report provider-selection diagnostics when the selected provider refuses its profile - [`4539a85`](https://github.com/morluto/rea/commit/4539a85499fea437c344baf7d1c9bd821da9cff2) fix(providers): keep refusal evidence and cleanup ownership on selection failures - [`43cec3c`](https://github.com/morluto/rea/commit/43cec3c40c81f7d387a2b094e1a893241da59783) Merge upstream main into fix/explicit-profile-refusal-selection-details - [`67cb026`](https://github.com/morluto/rea/commit/67cb026efcfbfefb4cd7e7a4dfbe196cc5e2e42e) Merge upstream main into fix/explicit-profile-refusal-selection-details - [`4a1103e`](https://github.com/morluto/rea/commit/4a1103e8adf0c0068b94a778acc8c812a5e5db4f) Merge upstream main into fix/explicit-profile-refusal-selection-details - [`dda7972`](https://github.com/morluto/rea/commit/dda7972fbeaa0ffcf90e61ae80a65138db438e80) Merge upstream main into fix/explicit-profile-refusal-selection-details - [`a765200`](https://github.com/morluto/rea/commit/a765200bd63fbb357719c74b87f80997cb4c41b4) Merge upstream main into fix/explicit-profile-refusal-selection-details - [`8db415f`](https://github.com/morluto/rea/commit/8db415f836a7b9500278de79e3a1ea7408ba1758) Merge upstream main into fix/explicit-profile-refusal-selection-details ### 📊 Changes **6 files changed** (+248 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `src/application/binary/AnalysisProviderRegistry.test.ts` (+68 -0) 📝 `src/application/binary/AnalysisProviderRegistry.ts` (+37 -3) 📝 `src/domain/analysisErrorPresentation.ts` (+5 -0) 📝 `src/domain/analysisErrorProjection.test.ts` (+26 -0) 📝 `src/domain/providerSelectionError.ts` (+16 -8) ➕ `tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts` (+96 -0) </details> ### 📄 Description ## Summary Fixes #3930. When a provider is selected explicitly and then refuses the target while resolving its analysis profile, `open_binary` returned the raw refusal (`unsupported_target`, operation `resolve_analysis_profile`) and dropped the provider-selection diagnostics that every other unsupported selection carries: `selection_reason`, `requested_provider_id`, `candidate_ids` and `rejections`. The evaluation already records that refusal as the candidate's target rejection (`AnalysisProviderEvaluation.ts`), but `#selectConcrete` returned the profile error before building the selection error (`AnalysisProviderRegistry.ts`). Now an unsupported-target refusal becomes the `target_unsupported` selection error with the updated candidate statuses, and it keeps the refusal's own message and, when the provider gives one, its specific recovery. ## Problem and expected behavior Smallest trigger, from the issue: explicit `provider_id: "ghidra"` with `REA_GHIDRA_LANGUAGE_ID` set, opening a raw ARM binary. On main the MCP error is `unsupported_target` with reason `REA_GHIDRA_LANGUAGE_ID cannot override the admitted raw-binary import.` and no selection details. Expected, as the issue asks: `capability_unavailable` with `details.selection_reason: "target_unsupported"`, `requested_provider_id: "ghidra"`, the candidate IDs and the provider's rejection, with the refusal reason still visible. ## Change and scope - `src/application/binary/AnalysisProviderRegistry.ts`: in explicit selection, an `AnalysisUnsupportedTargetError` from profile resolution returns `selectionError("target_unsupported", …)` built from the evaluated statuses, whose rejection already holds the refusal reason (`code: "target_format_unsupported"`). Its `userMessage` is the refusal's message, so callers read the same text as before; its recovery is the refusal's `remediationAction` when there is one; and it carries the refusal's captured output, diagnostics and partial observation, with the refusal as its `cause`. A refusal with unconfirmed cleanup is returned unchanged, so it still projects as `cleanup_incomplete` with its resources, as automatic selection already does. Other profile errors (adapter errors) are returned unchanged. - `src/domain/providerSelectionError.ts`: an optional `remediationAction`, as `AnalysisUnsupportedTargetError` already has, and the shared `cause`, `diagnostics` and `partialObservation` options passed to the base error alongside `capturedOutput`. - `src/domain/analysisErrorPresentation.ts`: a selection error with `remediationAction` uses it as `remediation.action`; without it, the action stays the user message, as before. Keeping the refusal's recovery matters for the refusals that know a specific fix: for example, the NativeAOT extension refusals tell the caller to omit `REA_GHIDRA_NATIVEAOT_JAR`, and the generic "choose another provider" guidance alone would point the wrong way. Automatic selection is unchanged; it already folds profile refusals into its selection result. Contribution scope: not applicable (error reporting of an existing selection path). ## Contract and boundary impact - Semantic owner and earliest changed stage: explicit provider selection in `AnalysisProviderRegistry`. - CLI and MCP/tool-catalog contract: no schema change. An explicit selection refused during profile resolution now reports `capability_unavailable` with selection details instead of `unsupported_target`; the message is unchanged. - Provider, bridge, target-format, or platform compatibility: provider-neutral; no provider changes. - Evidence, artifact, provenance, or reconstruction contract: none. - Generated metadata (`docs/public/product-catalog.json`), 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. - [x] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: - `tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts`: the issue's case through the public `open_binary` MCP tool with the production Ghidra provider and a simulated installation. The refusal returns `capability_unavailable` with `selection_reason`, `requested_provider_id`, `candidate_ids` and a rejection whose reason is the refusal text, without starting an engine; the same raw input without the override still opens. With main's registry the first test fails with `unsupported_target`. - `src/application/binary/AnalysisProviderRegistry.test.ts`, in its own block: an explicit refusal with a recovery, captured output and diagnostics keeps all three, its reason and the refusal as `cause` on the selection failure; a refusal with unconfirmed cleanup is returned unchanged and projects `cleanup_incomplete`. Removing the recovery copy or the cleanup guard makes the matching test fail. - `src/domain/analysisErrorProjection.test.ts`: a selection error keeps a supplied recovery as `remediation.action` and otherwise falls back to its message. - Remaining proof gaps: no real Ghidra installation was used; the installation is the existing simulated host, as in the issue. For evidence-bearing changes: - [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 Windows 11 x64 (10.0.26300), Node 24.18.0, branch based on `8ed3d1df7`. - `npx vitest run src/application/binary/AnalysisProviderRegistry.test.ts tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts src/domain/analysisErrorProjection.test.ts`: 68 passed. - The registry tests with the recovery copy removed, and with the cleanup guard removed: each fails its own test. - The MCP test with main's `AnalysisProviderRegistry.ts`: the refusal case failed with `unsupported_target`, as expected. - After `npm run build:cached` and `npm run test:prepare`, the 20 test files that reference provider selection or its errors: 124 passed, 2 failures, `ghidraInventoryMcp` (byte search) and `BinarySessionLiveness` (cancelled-switch restoration, 30 s timeout). Both fail identically with main's code on this host. - `npm run check:fast`: passed. - `npx oxfmt --check` on the changed files: passed. ## Compatibility, safety, and release - Breaking changes or migration steps: callers that matched `unsupported_target` for an explicitly selected provider's profile refusal now receive `capability_unavailable` with selection details, the same code other unsupported selections already use. - Real Hopper/Ghidra, browser, or OS coverage: none; simulated installation only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new input is read and nothing runs; the rejection diagnostics are the ones the evaluation already recorded, and cleanup ownership is never moved to the selection error. ## Author readiness Human owner: @pablodiazjorge - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <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:32 +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#6059
No description provided.