Skip to content

fix(dashboard-api): ensure trailing buffered chunk is newline-terminated before done marker - #5946

Open
vaibhavsrv wants to merge 1 commit into
Osmantic:public-betafrom
vaibhavsrv:fix/pixel-router-trailing-buffer-newline
Open

vaibhavsrv wants to merge 1 commit into
Osmantic:public-betafrom
vaibhavsrv:fix/pixel-router-trailing-buffer-newline

Conversation

@vaibhavsrv

Copy link
Copy Markdown
Contributor

Why this matters

In ods/extensions/services/dashboard-api/routers/pixel.py, pixel_chat_stream streams SSE events from upstream services to authenticated clients. When reading chunks from upstream, buffered accumulates raw bytes and yields complete lines split on \n. At the end of the stream, if buffered retains trailing bytes (for example, when upstream closes connection without terminating its last SSE data payload with a trailing newline), the handler yields bytes(buffered) followed immediately by b"data: [DONE]\n\n".

Yielding trailing buffer bytes without a newline causes the subsequent data: [DONE]\n\n frame to concatenate directly onto the previous chunk line (e.g. {"chunk": 1}data: [DONE]\n\n). This breaks Server-Sent Events line framing and causes client parsers to miss the completion signal.

This change verifies whether bytes(buffered) ends with \n before yielding it, appending a newline if omitted. This ensures strict SSE record separation across stream terminations. Normal already-delimited SSE chunks remain completely untouched.

Validation

  • Tested baseline reproduction against unpatched code: when upstream emitted a final chunk without a newline before disconnection, the subsequent data: [DONE] merged into the trailing chunk without line demarcation.
  • Tested post-fix behavior: trailing chunks lacking a newline have a newline appended before yielding, ensuring data: [DONE]\n\n starts on its own record line.
  • Telemetry statement: "Dashboard-api suites: 1 passed. New-test Ruff, py_compile, and diff checks pass; new regression wired into Linux CI."

Overlap check

Risk / AI disclosure

AI-assisted defect analysis, implementation, and regression verification. This strengthens streaming frame protocol conformance and does not modify persistent files, models, or runtime routing logic. Independent human review remains a gate.

Follow-up integration evidence

Composed cleanly on top of #5569, #5871, and #5875 at HEAD without conflicts. Production and test diffs passed together; adjacent pixel-agent and pixel-settings checks remain intact.
Backlog composition was local-only (production/test diffs, excluding workflow/Makefile wiring); it is not an upstream merge or independent human approval. Declared live-review gates remain open.

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.

1 participant