Skip to content

fix(tools): extend the transport-deadline disarm to the Node workers - #7124

Merged
icecrasher321 merged 1 commit into
stagingfrom
fix/node-worker-transport-timeout
Aug 26, 2026
Merged

fix(tools): extend the transport-deadline disarm to the Node workers#7124
icecrasher321 merged 1 commit into
stagingfrom
fix/node-worker-transport-timeout

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

  • Async executions run in Trigger.dev workers (runtime: 'node-24'), where Node's fetch is undici — its default dispatcher arms headersTimeout/bodyTimeout at 300s, so internal-route tool calls (sandbox function runs, custom tools) died at exactly five minutes with TypeError: fetch failed (cause HeadersTimeoutError) no matter what plan deadline the executor armed
  • The existing disarm (timeout: false) is a Bun-only fetch option and is silently ignored on Node — the module's doc claimed undici had no equivalent default, which was wrong
  • withCallerOwnedDeadline now also attaches a shared undici Agent({ headersTimeout: 0, bodyTimeout: 0 }) as the request dispatcher: Node's fetch honors it, Bun ignores it and keeps the existing disarm, so the caller's armed AbortController (the plan deadline) stays the single enforcement point on both runtimes
  • Corrected the module docs with measured numbers and extended the unit tests (dispatcher attached off-Bun, one shared instance, caller init untouched)

Type of Change

  • Bug fix

Testing

  • Measured against a local server that withholds response headers with all server-side timers disabled: the pre-fix init dies at 300996ms with fetch failed / HeadersTimeoutError (UND_ERR_HEADERS_TIMEOUT), the fixed helper resolves at 310016ms, and a 3s caller abort still fires at 3006ms — so the transport disarm does not remove the in-process deadline
  • Cross-copy dispatcher handoff verified with the bundled undici 6.21.2 driving the npm undici 7.29.0 Agent — a wider version split than the node-24 workers run
  • fetch-deadline and tools/index test suites pass; lint, type-check, block-registry audit, and check:audits pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

The internal-route transport fix disarmed Bun's 300s fetch idle timer with
`timeout: false`, on the recorded claim that Node's undici had no equivalent
default. It does: undici arms `headersTimeout` and `bodyTimeout` at 300e3 on
its default dispatcher, and the Bun-only option is silently ignored there. Async
executions run in Trigger.dev workers on `runtime: 'node-24'`, so every sandbox
run longer than five minutes still died at the default with
`TypeError: fetch failed` (cause `HeadersTimeoutError`) despite a plan
deadline of up to seven days.

withCallerOwnedDeadline now also attaches a shared undici Agent with both
timers disarmed as the request dispatcher. Bun ignores `dispatcher` and keeps
the existing `timeout: false` disarm; Node's fetch honors it, leaving the
caller's armed AbortController as the single enforcement point on both
runtimes. Measured against a server that withholds response headers: the
pre-fix init dies at 300996ms with the headers-timeout cause, the disarmed
init resolves at 310016ms, and a 3s caller abort still fires at 3006ms.
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 26, 2026 8:29pm

Request Review

@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR extends caller-owned fetch deadline handling to Node workers by attaching a shared undici Agent with transport header and body timers disabled.

  • Preserves Bun’s existing timeout: false behavior while adding Node-compatible dispatcher handling.
  • Reuses one dispatcher across internal-route requests for connection pooling.
  • Adds Node-focused tests covering dispatcher attachment, reuse, and caller-init immutability.
  • Updates internal tool-call documentation to describe both runtime paths.

Confidence Score: 5/5

The PR appears safe to merge, with internal requests still bounded by the existing caller-owned AbortController on both supported runtimes.

The Node-specific dispatcher is available as a direct dependency, the Bun path avoids constructing it, and the only production caller applies a timed signal to both header acquisition and response-body reading.

Important Files Changed

Filename Overview
apps/sim/lib/core/utils/fetch-deadline.ts Adds a lazily initialized shared undici Agent for Node while retaining Bun’s transport-timeout disarm; no actionable defect was established.
apps/sim/lib/core/utils/fetch-deadline.test.ts Extends Node-environment coverage for dispatcher attachment, singleton reuse, and non-mutation of caller initialization.
apps/sim/tools/index.ts Documents that internal-route fetches disarm runtime transport timers while retaining the existing locally armed cancellation deadline.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Internal tool request] --> B[Create timed AbortController]
  B --> C[withCallerOwnedDeadline]
  C --> D{Runtime}
  D -->|Bun| E["timeout: false"]
  D -->|Node worker| F["Shared undici Agent<br/>headersTimeout: 0<br/>bodyTimeout: 0"]
  E --> G[fetch internal route]
  F --> G
  B --> G
  G --> H[Caller deadline remains enforcement point]
Loading

Reviews (1): Last reviewed commit: "fix(tools): extend the transport-deadlin..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@icecrasher321
icecrasher321 merged commit 9c88845 into staging Aug 26, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/node-worker-transport-timeout branch August 27, 2026 01:24
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