fix(sdk): honor caller abort signals

LU
2mo ago
+216-7

PR Checklist

  • The commit message follows the contribution guidelines.

Bugs / Features

  • Related issue linked: #1443
  • Tests for the changes have been added
  • Docs have been added / updated. N/A: restores the existing RequestInit.signal behavior without changing the API.
  • A patch changeset for @voltagent/sdk has been added

What is the current behavior?

sendRequest replaces the caller's RequestInit.signal with its internal timeout signal. A pre-aborted POST is still sent, cancelling an in-flight request has no effect, and cancellation cannot stop reading a streamed response body.

What is the new behavior?

Compose the caller signal with the SDK deadline using AbortSignal.any. Caller cancellation reaches native fetch and its response body. SDK timeouts remain VoltAgentAPIError with status 408; competing aborts retain the first signal's reason. Clear the deadline timer in finally on every fetch outcome.

Before response headers, caller abort reasons propagate unchanged. Body reads retain the runtime's native fetch semantics, which differ between Node 20 and Node 24.

Fixes #1443.

Notes for reviewers

Validation against 72a46c7 in the actual workspace:

  • SDK tests on Node 20.20.2 and Node 24.19: 31 passed each, including 14 new cancellation, timeout and cleanup cases. Most cases use a real local HTTP server; deterministic competing-abort tests defer only the fetch rejection.
  • pnpm build:all: passed for 29 projects.
  • pnpm lint:ci: passed for 1,785 files, with 5 existing warnings.
  • pnpm sp lint and pnpm publint:all: passed; publint covered 14 projects.
  • Original pre-commit and commit-msg hooks: passed.
  • Additional SDK tsc --noEmit reports four diagnostics in the unchanged src/evals/index.spec.ts; all four also occur on the exact base.

Workspace dependencies and lifecycle scripts were installed with frozen pnpm 8.10.5. Playwright browser downloads were not provisioned. The full monorepo suite, including Docker E2E, was not run; the SDK package suite above was run explicitly.

AI assistance: OpenAI Codex helped reproduce, implement, test and review this change. An independent review checked the public API behavior and Node 20/24 cancellation differences.


Summary by cubic

Fixes the SDK's handling of caller abort signals so that pre-aborted requests are not sent and in-flight requests and response bodies can be cancelled. Combines the caller's signal with an internal timeout signal via AbortSignal.any instead of replacing it. Preserves caller abort reasons before response headers and native fetch behavior during body reads. Keeps SDK timeouts reported as HTTP 408 and clears the deadline timer on every outcome. Fixes #1443.

Summary by CodeRabbit

  • Bug Fixes
    • Requests now respect caller-provided cancellation signals alongside SDK timeouts. Caller-triggered cancellations preserve their original errors, while SDK-triggered timeouts continue to report a timeout.