Skip to content

fix(agent): enforce tool timeouts and abort signals across background grace, approval resume, and MCP wrappers - #178

Merged
alexb-openrouter merged 2 commits into
mainfrom
devin/1796091622-fix-tool-timeout-signals
Dec 1, 2026
Merged

alexb-openrouter merged 2 commits into
mainfrom
devin/1796091622-fix-tool-timeout-signals

Conversation

@alexb-openrouter

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

Copy link
Copy Markdown
Contributor

Summary

Fixes three tool-timeout and abort-signal gaps in @openrouter/agent:

  1. Background tool timeoutMs suppressed during graceMs (ModelResult.handleAsyncInvocation)

    • Previously, the per-tool timeoutMs timer was only armed when AsyncToolRegistry.trackBackground ran after graceMs elapsed, so background tools with timeoutMs < graceMs (including the default 250ms graceMs) ran past timeoutMs without aborting ctx.signal.
    • Now arms the timeoutMs timer alongside the grace-window race immediately when the background work starts, aborting controller and settling with a timeout error at timeoutMs (and clearing both timers on settle so handoff to trackBackground when graceMs < timeoutMs remains single-timer).
  2. Approval-resume and auto-approve paths dropped timeoutMs / toolTimeoutMs and ctx.signal (ModelResult.processApprovalDecisions, executeAutoApproveTools, settleAsyncInvocationAsUnsent)

    • Previously, approved tools resumed via approveToolCalls (and auto-approved tools in mixed approval rounds) called runToolWithHooks without composeToolSignal, execution extras (signal, callId, conversationId, client, runExtras), or raceToolDeadline.
    • Now composes the per-call signal and deadline on both paths and races execution (including background invocations settled via settleAsyncInvocationAsUnsent) against raceToolDeadline, cleaning up inflightToolControllers in finally.
  3. MCP tool wrapper dropped per-execution ctx.signal (wrapMcpTool / invokeTool)

    • Previously, invokeTool only forwarded wrapper-level options.signal to client.callTool, ignoring ctx.signal carrying timeoutMs and run cancellation.
    • Now composes options.signal and ctx?.signal via AbortSignal.any (preserving direct reference when only one is set) for both regular and emitProgress generator MCP tools.

Testing

  • Added unit tests covering:
    • Background tools with timeoutMs < graceMs (signal-aware and signal-ignoring callbacks) and timeoutMs > graceMs in packages/agent/tests/unit/async-tool-background.test.ts.
    • Approval-resume with per-tool timeoutMs, run-level toolTimeoutMs, approved background tools, and end-to-end MCP toolTimeoutMs abort propagation in packages/agent/tests/unit/tool-cancellation.test.ts.
    • Per-execution ctx.signal forwarding and composition with wrapper options.signal for both regular and generator MCP tools in packages/agent/tests/unit/mcp/call-tool-shape.test.ts.
  • Ran pnpm lint, pnpm typecheck, pnpm verify:packages, and pnpm test (all green).

@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 bd1c358 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