Skip to content

fix(gateway): inject newline separator at stream iteration boundaries - #2376

Closed
sprmn24 wants to merge 1 commit into
NousResearch:mainfrom
sprmn24:fix/stream-consumer-iteration-boundary
Closed

fix(gateway): inject newline separator at stream iteration boundaries#2376
sprmn24 wants to merge 1 commit into
NousResearch:mainfrom
sprmn24:fix/stream-consumer-iteration-boundary

Conversation

@sprmn24

@sprmn24 sprmn24 commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a bug where resumed streamed text after tool calls was concatenated directly onto prior content with no separator, making multi-iteration responses unreadable.

Related Issue

Closes #2177

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • gateway/stream_consumer.py: Updated on_delta() to treat None as an iteration boundary signal. When None is received and the buffer does not already end with a newline, a separator is injected into the queue.
  • tests/gateway/test_stream_consumer.py: New test file — 8 tests covering the boundary injection logic, including the exact regression case from this issue.

No changes to run_agent.py — it already emits stream_delta_callback(None) at the right point; the consumer just wasn't handling it.

How to Test

  1. Enable gateway streaming (streaming.enabled: true in config.yaml)
  2. Send a message that triggers a tool call mid-response (e.g. "search for X and summarize")
  3. Observe that resumed text after the tool call starts on a new line
  4. Run unit tests: python3 -m pytest tests/gateway/test_stream_consumer.py -v

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

8/8 tests passing: python3 -m pytest tests/gateway/test_stream_consumer.py -v

Treat stream_delta_callback(None) as an iteration boundary signal in
GatewayStreamConsumer.on_delta(). When the accumulated buffer does not
end with a newline, inject one so resumed text after tool calls starts
on a new line instead of being concatenated directly.

Closes NousResearch#2177
@sprmn24

sprmn24 commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

I created a new PR without realizing that there were already PRs created previously.
I noticed there are similar PRs (#2186, #2187) addressing this issue.
My approach handles the boundary signal in on_delta() with 8 unit tests.
Happy to collaborate or close this if another PR is preferred.

@teknium1

Copy link
Copy Markdown
Contributor

Closing — the streaming linebreak issue was fixed via PR #2473 (deferred flag approach from #2433). Thanks!

@teknium1 teknium1 closed this Mar 22, 2026
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.

[Bug]: Gateway streaming concatenates resumed text after tool calls without linebreak

2 participants