Skip to content

fix(opencode): apply provider timeouts to Cloudflare AI Gateway models - #51549

Open
danlapid wants to merge 1 commit into
anomalyco:devfrom
danlapid:ai-gateway-timeouts
Open

danlapid wants to merge 1 commit into
anomalyco:devfrom
danlapid:ai-gateway-timeouts

Conversation

@danlapid

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #51545

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

headerTimeout, chunkTimeout and timeout live in the fetch wrapper that resolveSDK adds, but the cloudflare-ai-gateway loader ignores that SDK and ai-gateway-provider calls the global fetch. A stalled stream through AI Gateway therefore never aborts; we saw opencode github run hang until CI killed the job.

The wrapper moves into a timeoutFetch(options) helper, unchanged. The gateway loader uses it for both of its routes: through createAiGateway's binding.run hook (it has no fetch option), sending the same request as its REST path, and as fetch for the createOpenAICompatible catalog route.

Gateway models now get the default 300s header/chunk timeouts, where before they had none.

How did you verify your code works?

  • Three new tests in test/provider/header-timeout.test.ts (chunk stall on both routes, header stall). They fail without the change.
  • bun test test/provider/ test/session/ and bun typecheck in packages/opencode pass.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

headerTimeout, chunkTimeout and timeout are enforced by the fetch wrapper
resolveSDK installs on the provider SDK. The cloudflare-ai-gateway loader
ignores that SDK and builds its own clients, and ai-gateway-provider's REST
path calls the global fetch, so none of these options applied: a stalled
gateway stream was never aborted and hung the session indefinitely.

Extract the wrapper into timeoutFetch and use it in the gateway loader.
Gateway requests go through ai-gateway-provider's binding hook, which
sends the same POST (options as request-level cf-aig-* headers) the REST
path does, and the REST catalog client receives it as its fetch.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provider timeouts (chunkTimeout/headerTimeout) are ignored for cloudflare-ai-gateway models

1 participant