mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2744] [Issue]: Provider upstream SSE parsing gaps — strict data: prefix, discarded buffer/no decoder flush, swallowed failures, lost event name, hardcoded finishReason #1383
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1383
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2744
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The Anthropic and Google streaming parsers require a literal
data:(with trailing space) and slice a fixed 6 chars, unlike the OpenAI provider's tolerantextractSseData(startsWith('data:')+slice(5).trimStart()). Against a non-canonical/compatible/proxy endpoint that emitsdata:{...}, Anthropic drops every event and returns an empty assistant message; Google hard-fails with "no candidates". Google also discards the residualbufferat stream end and none of the three parsers flush theTextDecoder. The OpenAI Responses parser swallowsresponse.failed(no throw, unlikechat()/Anthropic), so a mid-stream failure can be saved as a truncated-but-complete message, and it resetscurrentEventinside the read loop so a splitevent:/data:frame loses its type. Finally, the basechatComplete()collector hardcodesfinishReason: 'stop', so streaming Anthropic/Googlemax_tokenstruncation is reported as a clean completion.Sub-bug 1: Anthropic strict 'data: ' prefix -> empty generation (MEDIUM, truncation)
if (!trimmed.startsWith('data: ')) continue; const data = trimmed.slice(6);drops everydata:{...}(no-space) frame; nocontent_block_deltais parsed, no tokens yielded, nomessage_stop— the generation appears to hang then returns empty.baseUrlis user-configurable, so a proxy/compatible endpoint reaches this.data:without the space; replies come back empty.anthropic.provider.ts:552-554; contrastopenai.provider.ts:146-149.Sub-bug 2: Google strict 'data: ' prefix (LOW, truncation)
google.provider.ts:729-730samestartsWith('data: ')+slice(6); spaceless frames yield no parts and the post-loop guard throws "Gemini stream returned no candidates/content". Canonical?alt=sseis fine; risk is proxy reframing (the file comments document proxy reshaping).google.provider.ts:729-730, throw at786-792.Sub-bug 3: Google discards trailing buffer / no flush (LOW, truncation)
donethe loop breaks and the retainedbuffer = lines.pop()is never re-parsed; there is nodecoder.decode()flush. Gemini SSE has no[DONE]/message_stopsentinel (termination depends on socket close), so the un-flushed final frame is the one carrying finishReason+usageMetadata+last text. Only bites if the final frame lacks its trailing newline (spec-violating), so latent.google.provider.ts:716-804; decoder created704, onlydecode(...,{stream:true})at720.Sub-bug 4: No final decoder flush in any parser (LOW, truncation)
decode(value,{stream:true})and never a no-arg flush. Cannot drop a content codepoint of a well-formed stream (last bytes are ASCII terminators), but a code smell.anthropic.provider.ts:547,openai.provider.ts:1002/1250/1720/1921,google.provider.ts:720.Sub-bug 5: Responses swallows response.failed (LOW, wrong-output)
case 'response.failed'only logs + breaks in bothchatResponsesandchatCompleteResponses; neither throws (unlikechat()1027-1031 / Anthropic 571-573). A mid-stream failure after some tokens leaves a non-empty partial that is saved as a normal message with no error/retry. (Zero-token case is caught by the empty-response guard at6617.)openai.provider.ts:1789-1795(chatResponses),2047-2053(chatCompleteResponses).Sub-bug 6: Responses event name lost across chunk boundary (LOW, wrong-output)
let currentEvent = ''is declared inside thewhile(true)loop, so anevent:line in read N is wiped before its split-offdata:line is parsed in read N+1; typing then falls back toparsed.type. Real OpenAI always includestype, so only an atypical proxy that stripstypetriggers a dropped delta.openai.provider.ts:1724(chatResponses),1925(chatCompleteResponses).Sub-bug 7: hardcoded finishReason:'stop' (LOW, wrong-output)
chatComplete()returnsfinishReason: 'stop'unconditionally; thechat()generator carries no finish reason out. For non-tool Anthropic/Google calls (which fall back tosuper.chatComplete), a realmax_tokenstruncation is reported as clean — Professor Mari's workspace agent never marks the turn length-truncated and offers no continue affordance.base-provider.ts:613-627(hardcoded 626); fallbackanthropic.provider.ts:270-272,google.provider.ts:413-415; consumerworkspace-agent.service.ts:1022-1025.Suggested Fix
startsWith('data: ')+slice(6)withstartsWith('data:')+slice(5).trimStart(), mirroringextractSseData.buffer += decoder.decode();and parse any residual completedata:line; add the no-arg flush to all parsers.response.failedin both Responses parsers (mirrorchat()/Anthropic); optionally throw at stream end if nothing yielded and noresponse.completed.let currentEvent = ''above thewhileloop in both Responses parsers.message_delta.delta.stop_reason, Googlecandidate.finishReason) sochatCompletereports actual truncation instead of hardcoding'stop'.Root-cause throughline
Each provider hand-rolls its own SSE parser instead of sharing the tolerant OpenAI
extractSseData/finish-reason logic, so the same fixed-offsetdata:assumption, missing trailing-buffer/decoder flush, and dropped finish-reason/failure semantics are re-implemented inconsistently across Anthropic, Google, and the Responses path.Verification checklist (leave all UNCHECKED)
pnpm checkAffected files
packages/server/src/services/llm/providers/anthropic.provider.tspackages/server/src/services/llm/providers/google.provider.tspackages/server/src/services/llm/providers/openai.provider.tspackages/server/src/services/llm/base-provider.tsAudit provenance
Found by a multi-agent static audit of the streaming/SSE subsystem (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged
stagingtree. Severity: MEDIUM.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on PR #2747. Anthropic and Gemini SSE parsers now accept data: without a space and flush decoder/residual buffers at EOF; OpenAI Responses parsers preserve event names across chunks and throw on response.failed; streamed usage can carry normalized finishReason so Anthropic/Gemini max-token truncation reports length instead of stop. Deferred full pnpm validation until the end of the issue sweep, per maintainer request.