Skip to content

fix(aistudio): reassemble SSE frames across relay chunks - #7095

Merged
hkfires merged 2 commits into
router-for-me:devfrom
wozhenbang2004:fix/aistudio-fragmented-sse-7093
Oct 29, 2026
Merged

hkfires merged 2 commits into
router-for-me:devfrom
wozhenbang2004:fix/aistudio-fragmented-sse-7093

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Fixes #7093.

AI Studio can split a single SSE frame across several websocket relay chunks. Translating each chunk independently then loses the final JSON fields, including the finish reason and usage, even though the upstream request completed.

This change buffers incomplete SSE frames before the existing per-frame model/usage/translation path. It handles splits inside data prefixes, large thought signatures, and CRLF separators; a final frame without a trailing blank line is flushed on stream end. Bare and pretty-printed JSON relay messages keep their existing behavior. No protocol translators or request payload construction are changed.

Validation (Linux amd64, Go 1.27.3, based on dev 56efc81fa5246277cda95ca6f9d190719ed166e3):

  • The new websocket regression failed against the unmodified executor and passed with this change, covering OpenAI Chat Completions, Responses, and Anthropic Messages.
  • go test -p 2 ./internal/runtime/executor/helps ./internal/runtime/executor -run 'TestRelaySSEBuffer|TestSplitRelayFrames|TestAIStudio|TestApplyPatchAIStudio' -count=1 passed.
  • go build -buildvcs=false -p 1 -o /dev/shm/cpa-test-output ./cmd/server passed. -buildvcs=false is used because validation used an upstream source archive; TMPDIR and GOTMPDIR were redirected to writable temporary storage.
  • gofmt -l is empty for all four changed files. The patch also passed git apply --check against a clean copy of the changed baseline file.

Not run: the full repository test suite or a live AI Studio browser relay. The websocket tests use the real local relay manager with synthetic responses and do not make paid model calls.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T04:41:41.708984Z
We couldn’t complete this review. Comment @codex review to try again.
498170a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@hkfires
hkfires merged commit 265ca17 into router-for-me:dev Oct 29, 2026
3 checks passed
github-actions Bot added a commit to omarcresp/cliproxyapi-flake that referenced this pull request Oct 30, 2026
## server 8.0.48

<!-- cliproxyapi-linux-release-assets:start -->
## Linux release assets

- `CLIProxyAPI_<version>_linux_<arch>.tar.gz` is the default Linux build. It supports dynamic library plugins and is built against a GLIBC 2.17 baseline.
- `CLIProxyAPI_<version>_linux_<arch>_no-plugin.tar.gz` is the portable Linux build for musl-based or older systems such as OpenWrt. It does not support dynamic library plugins.

## FreeBSD release assets

- `CLIProxyAPI_<version>_freebsd_aarch64_no-plugin.tar.gz` is the FreeBSD arm64 build. It is built without CGO and does not support dynamic library plugins.

<!-- cliproxyapi-linux-release-assets:end -->

## Changelog

- test(openai): assert websocket disconnect error event (fa42f390)
- fix(devin): classify JSON control character errors (02ee3139)
- Merge pull request #7092 from sususu98/fix/slow-test-disconnect (56efc81f)
- fix(aistudio): buffer fragmented relay SSE frames (7df437c8)
- fix(aistudio): add relay SSE frame reassembly helper (498170a4)
- feat(usage): capture structured Anthropic Messages upstream usage details (89e472f3)
- feat(usage): capture structured xAI usage across chat, responses, and media (24840fdd)
- feat(usage): capture structured OpenAI and Codex usage across responses, chat, and images (01551f5f)
- feat(usage): capture structured Gemini, Vertex, AI Studio, and Antigravity usage (bd5ec531)
- perf(usage): optimize stream usage observation and large payload parsing (d5eb4ca1)
- fix(usage): preserve stream failure usage, multipart image params, and provisional zero search counters (97dd3a4a)
- fix(home): restrict websocket access in home mode (a6b4477b)
- fix(usage): preserve output_item.done tool counts and multiline SSE usage (82deffb9)
- Merge pull request #7074 from sususu98/feat/structured-usage-7054 (eabcb1b7)
- Merge pull request #7095: reassemble AI Studio SSE frames (265ca179)
- Merge pull request #7102 from router-for-me/aistudio (d30edd7f)
- fix(logging): prevent deferred request retention on Responses WebSockets (4cb98e3c)
- Merge pull request #7106 from router-for-me/fix/responses-ws-deferred-logging (8dfb45d2)
- fix(auth): write the cooldown state next to the auth file when auth-dir is relative (43068c86)
- fix(openai): keep incomplete streams without [DONE] out of credential cooldown (f013eb66)
- feat(codex): guide recovery when automatic credential renewal becomes impossible (514d09f7)
- fix(translator): translate mid-conversation Claude tool_addition blocks (12d97cfe)
- Merge pull request #7109 from eaxeax/fix/cooldown-state-relative-auth-dir (67beb7a6)
- feat(pluginhost): allow model registrars to publish models for multiple providers (bc81923b)
- fix(gemini): preserve Claude tool-result error semantics (#6838) (81de4b9c)
- fix(antigravity): preserve Claude tool-result error semantics (068fe153)
- fix(codex): expand recognized CPA compaction capsules before forwarding to OpenAI (dbb70621)


## What's Changed
* Fix WebSocket disconnect test and Devin diagnostics by @sususu98 in router-for-me/CLIProxyAPI#7092
* feat(usage): capture structured upstream usage details across Anthropic, xAI, OpenAI/Codex, and Gemini by @sususu98 in router-for-me/CLIProxyAPI#7074
* fix(aistudio): reassemble SSE frames across relay chunks by @wozhenbang2004 in router-for-me/CLIProxyAPI#7095
* fix(home): restrict websocket access in home mode by @hkfires in router-for-me/CLIProxyAPI#7102
* fix(logging): prevent deferred request retention on Responses WebSockets by @GavinKung in router-for-me/CLIProxyAPI#7106
* fix(auth): write the cooldown state next to the auth file when auth-dir is relative by @eaxeax in router-for-me/CLIProxyAPI#7109
* fix(gemini): preserve Claude tool-result error semantics by @GavinKung in router-for-me/CLIProxyAPI#6838

## New Contributors
* @wozhenbang2004 made their first contribution in router-for-me/CLIProxyAPI#7095
* @eaxeax made their first contribution in router-for-me/CLIProxyAPI#7109

**Full Changelog**: router-for-me/CLIProxyAPI@v8.0.47...v8.0.48


Upstream release: https://github.com/router-for-me/CLIProxyAPI/releases/tag/v8.0.48
xiaoran7 added a commit to xiaoran7/CLIProxyAPI that referenced this pull request Nov 2, 2026
…ation, and expand opencode catalog

- Sync upstream router-for-me/CLIProxyAPI v8.0.43 through v8.0.51 (PRs router-for-me#7010, router-for-me#7016, router-for-me#7042, router-for-me#7057, router-for-me#7074, router-for-me#7092, router-for-me#7095, router-for-me#7101, router-for-me#7102, router-for-me#7106, router-for-me#7109, router-for-me#7113, router-for-me#7141, router-for-me#7142, router-for-me#7143, router-for-me#7149, router-for-me#7154)
- Port WorkBuddy reference updates (ardeyouxipianyi/workbuddy2api-hub v1.10.1): DSH file reference WAF 11-128 neutralization and tool name/type sanitization
- Expand OpenCode Zen model catalog with flint-40b-free (262k context, full thinking level suite)
- Preserve fork invariants across force-model-prefix routing, plugin/native OAuth priority, redactor payload masking, and dual management.html MD5 parity

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

2 participants