Skip to content

fix(deepseek): transport-neutral bounded-JSON policy with terminal SSE synthesis (#875) - #1026

Merged
lidge-jun merged 3 commits into
devfrom
codex/stack-04-deepseek-bounded-json
Aug 5, 2026
Merged

fix(deepseek): transport-neutral bounded-JSON policy with terminal SSE synthesis (#875)#1026
lidge-jun merged 3 commits into
devfrom
codex/stack-04-deepseek-bounded-json

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

Stack 04 of the bug-stack campaign (devlog/_plan/260805_bug_stack_campaign/050), stacked on #1025. Fixes #875.

The registry's upstream-streaming hint was WS-scoped: ordinary HTTP turns kept stream:true into DeepSeek's terminal-less SSE and stalled after tool calls (reporter reproduced at e44d234 with websockets:false, bodyKind:sse).

  • modelResponsesUpstreamStreaming (renamed, transport-neutral) applies after final wire resolution for openai-responses adapters — DeepSeek Flash now uses bounded JSON upstream on every transport.
  • Shared bounded-JSON event sequence (src/server/responses-json-events.ts): the WS bridge and the new HTTP synthesis emit the same canonical frames — response.created → one response.output_item.done per item → status-preserving terminal; HTTP streaming clients get SSE with exactly one [DONE].Non-streaming clients and WS turns keep plain JSON (gate excludesinboundTransport: "websocket"`).
  • Supersedes PR fix(deepseek): apply bounded JSON policy on HTTP SSE for Flash #1006's mechanism with the contributor's core policy retained (attribution) — its duplicated event algorithm, missing [DONE] trailer, and bypass of the SSE item-ID repair branch are avoided.

Tests

  • Stall activation: fake upstream fails loudly if stream:true is ever sent (the old hang), and the client receives the full synthesized sequence with [DONE]; function_call id/call_id byte-identical.
  • WS/HTTP serializer parity + status preservation (failed/incomplete) in tests/responses-json-events.test.ts and tests/ws-endpoint.test.ts.
  • Independent review: GO-WITH-FIXES(1) folded (WS transport exclusion).
  • bun run typecheck 0 errors; bun run privacy:scan pass.
  • Full bun run test on Linux (ssh lidge): 8288 pass / 0 fail (baseline 8222).

Limitations

DeepSeek Flash loses progressive token delivery — the intended provider-specific reliability tradeoff. structure/04 documents the transport-neutral policy.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • ^dev$
  • ^preview$

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e7938d5e-fd76-431d-a35d-beda3aed50db

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Aug 4, 2026
@lidge-jun
lidge-jun force-pushed the codex/stack-04-deepseek-bounded-json branch from a3dd247 to ec5e666 Compare August 5, 2026 00:08
@lidge-jun
lidge-jun force-pushed the codex/stack-03-sparse-snapshot-repair branch from 45eb5b8 to 681f2e4 Compare August 5, 2026 00:08
…E synthesis (#875)

The registry's upstream-streaming hint was WS-scoped, so ordinary HTTP
turns kept stream:true into DeepSeek's terminal-less SSE and stalled
after tool calls. The policy is now transport-neutral:

- registry hint renamed modelResponsesUpstreamStreaming, applied after
  final wire resolution for openai-responses adapters
- shared bounded-JSON event sequence (responses-json-events.ts) used by
  both the WS bridge and a new HTTP SSE synthesis (created ->
  output_item.done -> terminal -> [DONE]) for streaming clients
- stall activation test: terminal-less fake SSE proves the old hang;
  the client now gets the full synthesized sequence
- structure/04 updated

Supersedes PR #1006's mechanism with the contributor's core policy
retained (attribution); avoids its duplicated event algorithm and adds
the missing [DONE] trailer.
#1026 review blocker 3. The bounded-JSON policy answers a streaming client by
synthesizing SSE from a completed JSON body, and reframes the same body into
events for WS turns. Neither path goes through the SSE relay, so neither
picked up the relay's item-id rewrite: enabling this reliability policy would
silently DISABLE id repair for a provider that has it configured — canonical
ids while streaming, placeholder ids the moment the policy engaged.

Adds repairResponsesJsonItemIds for whole-object normalization and applies it
to the synthesized-SSE and WS-reframe paths, after the raw recording. This
layer no longer depends on the later #938 work to be safe on its own.

Tests: repaired ids on both bounded-JSON paths, and a provider without repair
keeps the body byte-identical.
@lidge-jun
lidge-jun force-pushed the codex/stack-04-deepseek-bounded-json branch from ec5e666 to 710492c Compare August 5, 2026 00:25
@lidge-jun
lidge-jun force-pushed the codex/stack-03-sparse-snapshot-repair branch from 681f2e4 to 62a5ee6 Compare August 5, 2026 00:25
@lidge-jun

Copy link
Copy Markdown
Owner Author

Rebased onto the current stack head, with a review blocker folded in.

Blocker: this layer was not independently safe with item-id repair.

The bounded-JSON policy answers a streaming client by synthesizing SSE from a completed JSON body, and reframes the same body into events for WS turns. Neither path goes through the SSE relay, so neither picked up the relay's item-id rewrite. The consequence is worse than a missing feature: for a provider that has id repair configured, enabling this reliability policy would silently disable it — canonical ids while streaming, raw upstream ids the moment the policy engaged. The later #938 PR happened to fix this, which meant this PR was only safe if its child landed with it.

710492cb2 moves that normalization into this layer: repairResponsesJsonItemIds for whole-object rewriting, applied to the synthesized-SSE and WS-reframe paths after the raw recording. New tests prove repaired ids on both bounded-JSON paths and that a provider without repair keeps the body byte-identical. #1027 was rebased on top and now carries only its own repairInvalidIds work.

@lidge-jun
lidge-jun changed the base branch from codex/stack-03-sparse-snapshot-repair to dev August 5, 2026 00:46
@lidge-jun
lidge-jun merged commit c1e9a20 into dev Aug 5, 2026
23 of 25 checks passed
@lidge-jun
lidge-jun deleted the codex/stack-04-deepseek-bounded-json branch August 5, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant