[GH-ISSUE #154] runDerivedOperation does not catch synchronous compute exceptions in derived MCP tools #102

Closed
opened 2026-10-15 18:21:11 +00:00 by bsakaguchi · 0 comments
Owner

Originally created by @morluto on GitHub (Jul 14, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/154

Problem

The runDerivedOperation helper executes the compute callback directly and returns an uncaught rejection when that callback throws. Several MCP handlers rely on runDerivedOperation to return a Result, but thrown values bypass toCallToolResult and surface as transport errors instead of structured MCP error content.

Evidence

Uncaught sync throw path

  • src/server/runDerivedOperation.ts:39

Call sites without local try/catch

  • src/server/registerArtifactComparisonTool.ts:34-36 (compareArtifacts)
  • src/server/registerBundleComparisonTool.ts:67-75 (compareBundles)
  • src/server/registerFunctionComparisonTool.ts:36-37 (compareFunctions)
  • src/server/registerInvestigationTools.ts:201-203 (findChangedBehavior)
  • src/server/registerInvestigationTools.ts:263-265 (buildCallPath)
  • src/server/registerInvestigationTools.ts:329-331 (correlateStaticAndRuntime)
  • src/server/registerInvestigationTools.ts:408-414 (verifyReconstruction)

Throwing comparators/parsers used in these flows

  • src/domain/changedBehavior.ts throws in parseComparisonEvidence and parseResult (TypeError) for invalid evidence contracts and malformed payloads.
  • src/domain/functionComparison.ts calls parseFunctionEvidence, which throws TypeError on malformed function Evidence.
  • src/domain/artifactComparison.ts and src/domain/artifactInventoryEvidence.ts throw for malformed artifact Evidence and pagination/graph mismatch cases.
  • src/domain/bundleComparison.ts throws for invalid explicit pair references and entity bounds via TypeError.

Impact

Malformed user-provided Evidence or edge-case comparison input can crash the tool handler path instead of producing a deterministic MCP tool error, reducing diagnosability and resilience of MCP/CLI behavior.

Repro sketch

  1. Supply invalid comparison Evidence to a derive tool such as compare_artifacts or compare_functions (e.g., mismatched provider/predicate or malformed evidence structure).
  2. The comparison callback may throw and the request is handled through an unguarded runDerivedOperation call.

Proposed outcome

  • Ensure synchronous compute exceptions are converted to error Results and then translated through toCallToolResult, or catch in each affected handler.
  • Keep cancellation semantics from AnalysisCancelledError unchanged.

Notes

  • registerProcessComparisonTool currently wraps runDerivedOperation in try/catch; this issue is specifically for the non-protected derived-tool paths above.
Originally created by @morluto on GitHub (Jul 14, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/154 ## Problem The runDerivedOperation helper executes the compute callback directly and returns an uncaught rejection when that callback throws. Several MCP handlers rely on runDerivedOperation to return a `Result`, but thrown values bypass toCallToolResult and surface as transport errors instead of structured MCP error content. ## Evidence ### Uncaught sync throw path - src/server/runDerivedOperation.ts:39 ### Call sites without local try/catch - src/server/registerArtifactComparisonTool.ts:34-36 (compareArtifacts) - src/server/registerBundleComparisonTool.ts:67-75 (compareBundles) - src/server/registerFunctionComparisonTool.ts:36-37 (compareFunctions) - src/server/registerInvestigationTools.ts:201-203 (findChangedBehavior) - src/server/registerInvestigationTools.ts:263-265 (buildCallPath) - src/server/registerInvestigationTools.ts:329-331 (correlateStaticAndRuntime) - src/server/registerInvestigationTools.ts:408-414 (verifyReconstruction) ### Throwing comparators/parsers used in these flows - src/domain/changedBehavior.ts throws in parseComparisonEvidence and parseResult (TypeError) for invalid evidence contracts and malformed payloads. - src/domain/functionComparison.ts calls parseFunctionEvidence, which throws TypeError on malformed function Evidence. - src/domain/artifactComparison.ts and src/domain/artifactInventoryEvidence.ts throw for malformed artifact Evidence and pagination/graph mismatch cases. - src/domain/bundleComparison.ts throws for invalid explicit pair references and entity bounds via TypeError. ## Impact Malformed user-provided Evidence or edge-case comparison input can crash the tool handler path instead of producing a deterministic MCP tool error, reducing diagnosability and resilience of MCP/CLI behavior. ## Repro sketch 1. Supply invalid comparison Evidence to a derive tool such as compare_artifacts or compare_functions (e.g., mismatched provider/predicate or malformed evidence structure). 2. The comparison callback may throw and the request is handled through an unguarded runDerivedOperation call. ## Proposed outcome - Ensure synchronous compute exceptions are converted to error Results and then translated through toCallToolResult, or catch in each affected handler. - Keep cancellation semantics from AnalysisCancelledError unchanged. ## Notes - registerProcessComparisonTool currently wraps runDerivedOperation in try/catch; this issue is specifically for the non-protected derived-tool paths above.
bsakaguchi 2026-10-15 18:21:11 +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#102
No description provided.