SDK SSE client ignores custom fetch - blocks containerized/sandboxed environments #7232

Open
opened 2026-02-16 18:06:31 -05:00 by yindo · 5 comments
Owner

Originally created by @kalepail on GitHub (Jan 22, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

The @opencode-ai/sdk SSE client in serverSentEvents.gen.js calls the global fetch() instead of options.fetch, which means custom fetch implementations are ignored for SSE subscriptions. This blocks usage in containerized environments (like Cloudflare Sandbox) that require custom fetch adapters.

Bug Location:

  • File: node_modules/@opencode-ai/sdk/dist/gen/core/serverSentEvents.gen.js
  • Line 20:
const response = await fetch(url, { ...options, headers, signal });

This calls the global fetch() directly instead of using options.fetch.

Expected Behavior:
The SSE client should use the custom fetch if provided:

const _fetch = options.fetch ?? globalThis.fetch;
const response = await _fetch(request);

Root Cause: The SDK's client architecture correctly supports custom fetch (client.gen.js:16 merges it, client.gen.js:137-146 passes it to createSseClient), but serverSentEvents.gen.js:20 ignores it.

Upstream Fix Available: This is fixed in @hey-api/openapi-ts:
https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/serverSentEvents.ts#L111-L113

Request: Please regenerate the SDK with the latest @hey-api/openapi-ts version.

Related: https://github.com/hey-api/openapi-ts/issues/772

Plugins

N/A - using SDK programmatically in Cloudflare Workers

OpenCode version

@opencode-ai/sdk: 1.1.31

Steps to reproduce

  1. Create OpenCode client with custom fetch: createOpencodeClient({ fetch: customFetch })
  2. Call client.event.subscribe()
  3. Observe that customFetch is never called - global fetch() is used instead

Screenshot and/or share link

N/A - SDK bug, not UI issue

Operating System

Cloudflare Workers + Sandbox runtime

Terminal

N/A - headless/programmatic usage

Originally created by @kalepail on GitHub (Jan 22, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description The `@opencode-ai/sdk` SSE client in `serverSentEvents.gen.js` calls the global `fetch()` instead of `options.fetch`, which means custom fetch implementations are ignored for SSE subscriptions. This blocks usage in containerized environments (like Cloudflare Sandbox) that require custom fetch adapters. **Bug Location:** - **File:** `node_modules/@opencode-ai/sdk/dist/gen/core/serverSentEvents.gen.js` - **Line 20:** ```javascript const response = await fetch(url, { ...options, headers, signal }); ``` This calls the **global `fetch()`** directly instead of using `options.fetch`. **Expected Behavior:** The SSE client should use the custom fetch if provided: ```javascript const _fetch = options.fetch ?? globalThis.fetch; const response = await _fetch(request); ``` **Root Cause:** The SDK's client architecture correctly supports custom fetch (`client.gen.js:16` merges it, `client.gen.js:137-146` passes it to `createSseClient`), but `serverSentEvents.gen.js:20` ignores it. **Upstream Fix Available:** This is fixed in `@hey-api/openapi-ts`: https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@hey-api/client-core/bundle/serverSentEvents.ts#L111-L113 **Request:** Please regenerate the SDK with the latest `@hey-api/openapi-ts` version. **Related:** https://github.com/hey-api/openapi-ts/issues/772 ### Plugins N/A - using SDK programmatically in Cloudflare Workers ### OpenCode version @opencode-ai/sdk: 1.1.31 ### Steps to reproduce 1. Create OpenCode client with custom fetch: `createOpencodeClient({ fetch: customFetch })` 2. Call `client.event.subscribe()` 3. Observe that `customFetch` is never called - global `fetch()` is used instead ### Screenshot and/or share link N/A - SDK bug, not UI issue ### Operating System Cloudflare Workers + Sandbox runtime ### Terminal N/A - headless/programmatic usage
Author
Owner

@github-actions[bot] commented on GitHub (Jan 22, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #2840: Empty SSE Events Leak Through Opencode Stream Processor - Related to SSE client behavior and event processing in serverSentEvents.gen.ts

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 22, 2026): This issue might be a duplicate of existing issues. Please check: - #2840: Empty SSE Events Leak Through Opencode Stream Processor - Related to SSE client behavior and event processing in serverSentEvents.gen.ts Feel free to ignore if none of these address your specific case.
Author
Owner

@mrlubos commented on GitHub (Jan 24, 2026):

@kalepail I'm pretty sure OpenCode is using the version with the code you shared, are you sure that's where the issue is? You could also open an issue upstream if it's broken in https://github.com/hey-api/openapi-ts

@mrlubos commented on GitHub (Jan 24, 2026): @kalepail I'm pretty sure OpenCode is using the version with the code you shared, are you sure that's where the issue is? You could also open an issue upstream if it's broken in https://github.com/hey-api/openapi-ts
Author
Owner

@kalepail commented on GitHub (Jan 26, 2026):

Any time I've tried to use the events streaming at least with Cloudflare Workers it doesn't work. When I set to consuming events myself with my own interpreter it does. I don't know much about the project but whenever I point any LLM at it they all agree and can confirm by looking at the underlying compiled code that it's using the wrong fetch for event streaming

@kalepail commented on GitHub (Jan 26, 2026): Any time I've tried to use the events streaming at least with Cloudflare Workers it doesn't work. When I set to consuming events myself with my own interpreter it does. I don't know much about the project but whenever I point any LLM at it they all agree and can confirm by looking at the underlying compiled code that it's using the wrong `fetch` for event streaming
Author
Owner

@mrlubos commented on GitHub (Jan 26, 2026):

Do let me know if this is an issue in Hey API, I'd look into it

@mrlubos commented on GitHub (Jan 26, 2026): Do let me know if this is an issue in Hey API, I'd look into it
Author
Owner

@goleary commented on GitHub (Feb 5, 2026):

Same here. We can't subscribe to events through the sdk (from a cloudflare worker/DO) when we are running opencode on a cloudflare sandbox (because @cloudflare/sandbox passes containerFetch which is not honored when using client.event.subscribe)

For now we're working around it by using sandbox.containerFetch directly for the SSE /event endpoint and parsing the stream manually.

@goleary commented on GitHub (Feb 5, 2026): Same here. We can't subscribe to events through the sdk (from a cloudflare worker/DO) when we are running opencode on a cloudflare sandbox (because [`@cloudflare/sandbox` passes containerFetch](https://github.com/cloudflare/sandbox-sdk/blob/d6d346059582f40d90c8c3f55c40a276b54352ec/packages/sandbox/src/opencode/opencode.ts#L374) which is not honored when using `client.event.subscribe`) For now we're working around it by using sandbox.containerFetch directly for the SSE /event endpoint and parsing the stream manually.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7232