fix(runtime): surface API errors instead of returning them as successful results - #58
Merged
Conversation
…ful results The runtime returned `await response.json()` with no status check, so a non-2xx response (401/403/422/5xx) was handed back as a successful tool result — the model saw an error payload as if the call succeeded (worst for promptAgent, whose normalizer says "this is the agent's reply"). Now: gate on `response.ok`, throw on non-2xx, and have executeToolCall return an `isError` CallToolResult (also covering network failures). - Fix in the shared packages/openapi-codegen/src/runtime.ts → regenerated into both tools.generated.ts and tools.v2.generated.ts (runtime block only; 0 per-tool changes). - The 2xx path and all 15 normalizeResponse handlers are unchanged (they only run on 2xx). - Adds runtime tests for 2xx / 401 / 500 / network-failure (17 tests pass). Benefits all 62 tools.
🦋 Changeset detectedLatest commit: 2771bb2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The runtime did
return await response.json()with no status check (runtime.ts:129). A non-2xx response (401/403/422/5xx) with a JSON body was returned as a successfulCallToolResult— the model saw the error payload as a valid result. It's worst forpromptAgent, whose normalizer literally appends "This is the agent's reply" — so an auth error gets relayed to the user as the agent's answer.Fix (shared runtime → all 62 tools)
defaultExecuteToolCall: gate onresponse.ok; on a non-2xx read the body as text and throw with status + body.executeToolCall: thecatchnow returns{ isError: true, content: [...] }instead of rethrowing — covering both HTTP errors and network/transport failures with a clear, model-actionable message.packages/openapi-codegen/src/runtime.ts; regenerated intotools.generated.ts+tools.v2.generated.ts.Zero-regression evidence
server.tool()lines changed (verified). Tool counts hold: 57 v1 + 5 v2 = 62.normalizeResponsehandlers only run on 2xx, so none are affected.executeToolCallruntime tests (2xx / 401 / 500 / network failure). 17 tests pass, lint clean.cc @deanzaka @lxcid