Skip to content

fix(ai-gateway-provider): isolate per-request fetch via Proxy - #635

Open
edenbuilds wants to merge 3 commits into
cloudflare:mainfrom
edenbuilds:fix/gateway-concurrent-fetch-isolation
Open

fix(ai-gateway-provider): isolate per-request fetch via Proxy#635
edenbuilds wants to merge 3 commits into
cloudflare:mainfrom
edenbuilds:fix/gateway-concurrent-fetch-isolation

Conversation

@edenbuilds

Copy link
Copy Markdown

Summary

  • processModelRequest mutated shared model.config.fetch when capturing provider requests and when replaying the gateway response.
  • Concurrent generateText calls on one gateway-wrapped model could cross-wire bodies/responses (one caller saw ANSWER:undefined, the other got the wrong prompt).
  • Wrap each model in a Proxy that overrides config.fetch per call instead of mutating the shared config.

Test plan

  • Concurrent generateText isolation regression (issue reproduction)
  • Proven to fail without the fix (ANSWER:undefined cross-wire)

Fixes #620

Made with Cursor

processModelRequest mutated shared model.config.fetch for both capture
and response replay. Concurrent calls on one gateway-wrapped model
cross-wired bodies/responses. Use a Proxy so each call gets its own
fetch without mutating the shared model.

Fixes cloudflare#620
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8bc6132

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

This PR includes changesets to release 1 package
Name Type
ai-gateway-provider 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

Required so the concurrent-fetch Proxy fix bumps @cloudflare/ai-gateway-provider.
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.

[ai-gateway-provider] Concurrent requests can receive each other's responses

1 participant