Skip to content

fix(agent): refuse to execute tool calls from non-completed responses - #177

Merged
alexb-openrouter merged 1 commit into
mainfrom
devin/1796091638-refuse-non-completed-tool-calls
Dec 1, 2026
Merged

alexb-openrouter merged 1 commit into
mainfrom
devin/1796091638-refuse-non-completed-tool-calls

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Previously, responseHasToolCalls and extractToolCallsFromResponse in packages/agent/src/lib/stream-transformers.ts only refused tool execution when response.status === 'incomplete' and response.incompleteDetails?.reason === 'max_output_tokens'. Responses with any other non-completed status — failed, cancelled, in_progress, queued, or incomplete due to content_filter (or missing details) — could still execute local tools if their output contained function_call items.

Changes

  • packages/agent/src/lib/stream-transformers.ts: Replace isTruncatedAtMaxOutputTokens with isResponseCompleted (response.status === 'completed'). Both responseHasToolCalls and extractToolCallsFromResponse now return false / [] for any response whose status is not 'completed'.
  • packages/agent/src/lib/conversation-state.ts: Guard extractToolCallsFromResponse with response.status !== 'completed' for parity with the stream-transformer extractor.
  • packages/agent/tests/unit/non-completed-response-tool-calls.test.ts: Add unit tests covering failed, cancelled, incomplete (content_filter, max_output_tokens, and null details), in_progress, and queued responses across the extractors, callModel (initial turn, streaming response.incomplete and mismatched response.completed, and follow-up turn with stopWhen + allowFinalResponse), and executeToolLoop, plus a completed control case.
  • Existing test fixtures: Add status: 'completed' to five unit test fixture helpers that previously omitted status via as unknown as models.OpenResponsesResult.

Testing

  • pnpm test (@openrouter/agent: 113 files, 1318 tests; @openrouter/mcp: all unit tests passing)
  • pnpm typecheck
  • pnpm lint
  • pnpm build
  • pnpm verify:packages

@devin-ai-integration

devin-ai-integration Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@alexb-openrouter
alexb-openrouter merged commit 37a2aa0 into main Dec 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant