Skip to content

feat(agents): resume dropped /run streams in createAI - #2589

Merged
mattzcarey merged 2 commits into
feat/createai-run-transportfrom
feat/createai-stream-resume
Oct 14, 2026
Merged

mattzcarey merged 2 commits into
feat/createai-run-transportfrom
feat/createai-stream-resume

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

createAI (agents/models/ai-sdk and agents/models/pi-ai) now resumes a streamed answer from AI Gateway's /run when the connection drops mid-stream. It reconnects through the binding and replays from the last complete event, so the consumer's stream keeps going with nothing lost or repeated. Stacked on #2576.

A streamed /run answer names its run in cf-aig-run-id, and the Run Durable Object keeps the run's events. The binding replays them from an event index, through a route aig-entry serves for it:

env.AI.fetch(`https://workers-binding.ai/ai-gateway/gateways/${id}/run/${runId}/resume?from=${n}`)
  • The core transport's run() wraps a streamed /run body that carries a run id. Every caller gets resume with nothing to configure: AI SDK catalog models and dynamic routes, pi-ai catalog models, and agents/models/opencode, which wraps the AI SDK provider. Workers AI streams and provider-native requests have no run id and are returned as they are.
  • core/resume.ts passes on only complete SSE events and holds back a trailing partial one. from counts complete events, so after a drop the replay starts on the boundary: nothing duplicated, nothing cut.
  • It stops with a CloudflareAIError after five drops, or on a 404 once the gateway no longer holds the run. An abort or a cancel never reconnects, and an abort reaches the consumer as the error it is.

Checked live on the agents account's default gateway. To get a real drop, a test Worker wrapped the real AI binding and cut the first /run stream partway through an event, as a dropped connection would. createAI then resumed against the real gateway buffer. Each answer came back complete: one to forty in order, nothing repeated or missing.

Provider and model Cut after Resumed from
AI SDK anthropic/claude-haiku-4.5 600 / 2,500 bytes event 1 / 15
AI SDK openai/gpt-5-mini 600 / 2,500 / 5,000 bytes event 1 / 8 / 16
pi-ai anthropic/claude-haiku-4.5 600 / 2,500 bytes event 1 / 15
AI SDK dynamic/<route> (served by openai/gpt-5-mini) 1,500 bytes event 4
pi-ai dynamic/<route> 1,500 bytes event 4

The resume route also returns 404 {"error":"Request not found"} for an unknown run. pnpm run check and the model tests pass.

@changeset-bot

changeset-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c3216f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

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

@agent-think

agent-think Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🟡 agents import sizes: 1 entry point grew

Entry point Exports Largest gzip change Size now
🟡 agents/models/ai-sdk 1 resized +815 B (+3.92%) 21.1 KiB
Changed exports (1)
Import Gzip change Size now
🟡 agents/models/ai-sdk#createAI +815 B (+3.92%) 21.1 KiB
How this works

Each runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement.

Compared fda892f8 → c3216f85 · workflow run · reported by agent-think[bot]

@pkg-pr-new

pkg-pr-new Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2589

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2589

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2589

hono-agents

npm i https://pkg.pr.new/hono-agents@2589

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2589

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2589

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2589

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2589

commit: c3216f8

@mattzcarey
mattzcarey force-pushed the feat/createai-stream-resume branch from 600a620 to 1cc5c84 Compare October 14, 2026 14:31
@mattzcarey
mattzcarey force-pushed the feat/createai-stream-resume branch from 1cc5c84 to c3216f8 Compare October 14, 2026 15:18
@mattzcarey
mattzcarey merged commit 841cc18 into main Oct 14, 2026
16 checks passed
@mattzcarey
mattzcarey deleted the feat/createai-stream-resume branch October 14, 2026 15:42
@github-actions github-actions Bot mentioned this pull request Oct 14, 2026
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