Skip to content

fix(relay): end stream on bare [DONE] line in StreamScannerHandler - #7932

Closed
orshih6 wants to merge 1 commit into
QuantumNous:mainfrom
orshih6:contribot/issue-7929
Closed

orshih6 wants to merge 1 commit into
QuantumNous:mainfrom
orshih6:contribot/issue-7929

Conversation

@orshih6

@orshih6 orshih6 commented Oct 21, 2026 •

Copy link
Copy Markdown

StreamScannerHandler accepts lines that start with either data: or [DONE], but then always ran data = data[5:]. When a line was a bare [DONE] with no data: prefix, that cut it down to "]". The "]" was then sent to the handler as a normal data frame, and scanning went on past the end of the stream.

The fix replaces the slice with strings.TrimPrefix(data, "data:"), so the prefix is removed only when it is present. A bare [DONE] now reaches the existing [DONE] branch: it sets the end reason to done, stops the scanner, and sends no frame. Handling of data: [DONE] and of normal data lines is unchanged.

Testing: I added TestStreamScannerHandler_BareDoneStopsScanner. It feeds in data: {"id":1}\n[DONE]\ndata: {"id":2}\n and checks that only {"id":1} is forwarded and that the end reason is done. The test fails on main, where the end reason comes back as eof, and passes with this change. go test ./relay/helper/, go vet and gofmt all pass.

🤖 Generated with Claude Code

Fixes #7929


This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed streaming responses so termination markers are correctly recognized, including standalone [DONE] signals.
    • Prevented data received after a termination marker from being processed.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: faa9e68e-3c6f-4b94-ada1-dedecfcc20e8
📥 Commits

Reviewing files that changed from the base of the PR and between 206e0fa and cfe4dba.

📒 Files selected for processing: 2
  • relay/helper/stream_scanner.go
  • relay/helper/stream_scanner_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The stream scanner now removes the data: prefix only when present. A bare [DONE] marker is preserved and ends scanning. A test checks that later data is not processed and that the end reason is recorded as StreamEndReasonDone.

Changes

Stream termination

Layer / File(s) Summary
Preserve and verify bare [DONE] markers
relay/helper/stream_scanner.go, relay/helper/stream_scanner_test.go
The scanner conditionally removes the data: prefix. The new test verifies that a bare [DONE] stops scanning, later data is ignored, and StreamEndReasonDone is recorded.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: calcium-ion

Merge Risk: ⚪ Minimal · up to cfe4d

The PR addresses bare [DONE] stream termination without identified merge-blocking risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: ending StreamScannerHandler processing on a bare [DONE] line.
Linked Issues check Passed Issue [#7929] requires bare [DONE] to terminate StreamScannerHandler, forward only preceding data, and avoid the erroneous "]" frame. The change replaces the unconditional five-character slice w…
Out of Scope Changes check Passed The pull request changes only the shared stream scanner logic and adds a focused regression test for issue [#7929]. Both changes directly support bare [DONE] handling. No unrelated production behavi…
Full details: Linked Issues check

Explanation

Issue [#7929] requires bare [DONE] to terminate StreamScannerHandler, forward only preceding data, and avoid the erroneous "]" frame. The change replaces the unconditional five-character slice with strings.TrimPrefix(data, "data:"), so the existing [DONE] branch receives the bare marker. TestStreamScannerHandler_BareDoneStopsScanner verifies that only {"id":1} is forwarded and that StreamEndReasonDone is recorded. The diff also preserves handling for prefixed data and data: [DONE].

Full details: Out of Scope Changes check

Explanation

The pull request changes only the shared stream scanner logic and adds a focused regression test for issue [#7929]. Both changes directly support bare [DONE] handling. No unrelated production behavior or unrelated test coverage appears in the reviewed diff.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit watched the data stream,
Then saw [DONE] end the stream.
No later frame hopped into view,
The end reason was recorded too.
The rabbit twitched its nose: all through!

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

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.

流式转发:裸 [DONE] 行未按结束处理,被切成 "]" 作为数据帧下发

2 participants