Skip to content

fix(gateway): preserve paragraph boundaries in streamed replies - #140833

Merged
obviyus merged 3 commits into
openclaw:mainfrom
leapdragon:fix/live-item-paragraph-boundary
Sep 10, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
leapdragon:fix/live-item-paragraph-boundary

Conversation

@leapdragon

@leapdragon leapdragon commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When a tool-calling turn produces distinct assistant messages, public Gateway chat events and OpenAI-compatible HTTP streams join their text without a paragraph boundary. A second message starting with a list or table becomes part of the preceding paragraph in the combined text.

Why This Change Was Made

The shared text merger now keeps inserted separator bytes separate from each item's text. Snapshots and deltas use the same boundary calculation, including an initially empty item. This fixes the reviewed split-newline case without retracting output already sent over HTTP. Display truncation also retires separator state so a later correction cannot recreate discarded padding.

User Impact

Distinct assistant items keep their paragraph boundaries in public chat text, the embedded terminal backend, Chat Completions, and OpenResponses. Existing blank lines do not gain extra padding. Same-item updates, provisional replacement, legacy unkeyed streams, media handling, and terminal fallback retain their contracts.

The tested current WebChat already displayed separate paragraph, tool, and list blocks. That layout and transcript order remain correct. Its public combined text was still affected, including the final event.

Evidence

  • Baseline: 18f452584417a122747415fefc3089e296dc22cf. Runtime/public proof: adb13ba9a810357878b3829d50808c954b3f887e. Current head 053b12bae1a4d1be0fcbacc16e1de18a34c498f3 adds only two test-file corrections; all production and fixture inputs are unchanged.
  • A real isolated Gateway and bundled WebChat used a controlled Responses provider and an actual read tool. The same normal prompt produced distinct assistant items on both builds.
  • Baseline public chat and both HTTP streams returned First paragraph.- Second item\n- Third item. Candidate live and final text is First paragraph.\n\n- Second item\n- Third item.
  • All 12 candidate HTTP runs passed: list, table, trailing newlines, leading newlines, both edges, and split leading-newline provider deltas, through both endpoints. Each stream completed normally with consistent terminal text.
  • The real producer normalizes edge whitespace. Separate official-SDK endpoint regressions cover raw delta-only events: all four new cases failed on the contributor patch and passed after repair.
  • A display-limit correction also has a verified failing control and passing regression coverage. The original 713 focused Gateway, abort, and terminal tests passed. CI then identified omitted worker expectations and a shutdown fixture; both were corrected, and all 82 tests in those affected files passed. Formatting, syntax/boundary lint, source-size and assertion checks passed.
  • An optional fresh-session browser probe hit an auxiliary title-request limitation in the controlled provider and was stopped. It is excluded from the successful proof claims; its failure is retained with the full evidence.

Complete private traffic, provider requests, inspected screenshots, command logs, and review history are retained. No claim is made that the baseline browser layout was broken or that its final event repaired the missing boundary.

…nt items

The live chat buffer concatenated a retained item prefix directly onto the next item's text. Each assistant message of a tool-calling turn is its own keyed item and its text is trimmed, so the buffer glued the last line of one message onto the first line of the next. Lists and tables that started a middle message were rendered as paragraph continuation lines in the WebChat. Insert the missing newlines at the item boundary, without adding any when a paragraph break is already present.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

Claude-Session: https://claude.ai/code/session_01VsJbS7YcJnDVxErEuaM8xP
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 10:24 PM ET / September 10, 2026, 02:24 UTC (Revision 3).

ClawSweeper review

What this changes

Preserves paragraph separation between distinct assistant messages in Gateway chat, HTTP streams, and the embedded terminal interface, including updates and display truncation.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main. The earlier split-newline finding is resolved, recorded runtime proof covers the unchanged production code, and no blocking defect remains.

Priority: P2
Reviewed head: 053b12bae1a4d1be0fcbacc16e1de18a34c498f3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant runtime observations, useful boundary regressions, and no remaining blocking finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded before/after output exercises the shared merger through a real isolated Gateway, public chat events, and both HTTP endpoints using a controlled provider and actual tool call. Candidate output retains paragraph boundaries and completes consistently; the current head changes only tests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded before/after output exercises the shared merger through a real isolated Gateway, public chat events, and both HTTP endpoints using a controlled provider and actual tool call. Candidate output retains paragraph boundaries and completes consistently; the current head changes only tests.
Evidence reviewed 9 items Current main still needs the repair: The keyed-message path still concatenates the retained prefix directly with the next item's text, without inserting a paragraph boundary.
Latest release has the same behavior: Inspection at the supplied v2026.9.3 release commit also found direct prefix-plus-item concatenation.
Shared boundary repair: Inserted padding is tracked separately from provider text, so split leading-newline deltas and their matching snapshots agree. Display capping separately retires padding and prefix state.
Findings None None.
Security None None.

How this fits together

The Gateway combines assistant message snapshots and incremental text into replies for chat clients, HTTP consumers, and the terminal interface. Shared separator handling keeps those outputs consistent while live displays retain their existing size limit.

flowchart TD
  A[Assistant message events] --> B[Shared text merger]
  B --> C[Track message boundaries]
  C --> D[Uncapped HTTP streams]
  C --> E[Live display size limit]
  E --> F[Gateway chat clients]
  E --> G[Embedded terminal]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +36, Tests +174. Total +210 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 3 50 14 +36
Tests 9 216 42 +174
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 266 56 +210

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +36 lines; tests net +174 lines Production growth tracks separator ownership and truncation; most growth protects the shared behavior across consumers.

Technical review

Best possible solution:

Keep paragraph-boundary ownership in the shared merger while preserving provider text, append-only HTTP guarantees, and the existing live-display cap.

Do we have a high-confidence way to reproduce the issue?

Yes: current main directly joins two distinct keyed assistant messages, making a paragraph followed by a list run together. Source establishes the path; this review did not execute it.

Is this the best way to solve the issue?

Yes: repairing the existing shared merger avoids separate client fixes, and the revised separator bookkeeping addresses the earlier split-newline failure without weakening HTTP completion guarantees.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8cc90fe5d745.

Labels

Label justifications:

  • P2: Repairs malformed paragraph boundaries in streamed replies with a bounded formatting impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded before/after output exercises the shared merger through a real isolated Gateway, public chat events, and both HTTP endpoints using a controlled provider and actual tool call. Candidate output retains paragraph boundaries and completes consistently; the current head changes only tests.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded before/after output exercises the shared merger through a real isolated Gateway, public chat events, and both HTTP endpoints using a controlled provider and actual tool call. Candidate output retains paragraph boundaries and completes consistently; the current head changes only tests.

Evidence

What I checked:

  • Current main still needs the repair: The keyed-message path still concatenates the retained prefix directly with the next item's text, without inserting a paragraph boundary. (src/gateway/agent-event-assistant-text.ts:100, 8cc90fe5d745)
  • Latest release has the same behavior: Inspection at the supplied v2026.9.3 release commit also found direct prefix-plus-item concatenation. (src/gateway/agent-event-assistant-text.ts:100, 1391f7cd2d40)
  • Shared boundary repair: Inserted padding is tracked separately from provider text, so split leading-newline deltas and their matching snapshots agree. Display capping separately retires padding and prefix state. (src/gateway/agent-event-assistant-text.ts:109, 053b12bae1a4)
  • Production proof remains applicable: The delta from the runtime-proof revision contains only server-close and worker live-chat test corrections; production code is unchanged. (053b12bae1a4)
  • Recorded real Gateway and HTTP results: The captured PR body reports an isolated Gateway with a controlled Responses provider and an actual read tool. Public live/final chat text changed from glued paragraph/list output to separated output; 12 candidate runs across both HTTP endpoints completed consistently. Raw private traffic was not available for independent inspection. Downloaded images belong to the earlier related PR and were not counted as proof of this fix. (adb13ba9a810)
  • Regression coverage preserves transport contracts: Both HTTP suites cover split leading newlines, initially empty items, repeated snapshots, and uncapped text, with successful completion assertions. Merger and worker coverage exercise shorter corrections and retired display prefixes. Tests were inspected, not executed during this read-only review. (src/gateway/openai-http.test.ts:2539, 053b12bae1a4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-07T05:11:43.973Z sha 80a5b6f :: needs real behavior proof before merge. :: [P2] Keep split leading-newline updates consistent with later snapshots
  • reviewed 2026-09-10T02:09:47.826Z sha adb13ba :: needs maintainer review before merge. :: none

@obviyus obviyus self-assigned this Sep 10, 2026
@obviyus obviyus changed the title fix(gateway): keep a paragraph boundary between distinct live assistant items fix(gateway): preserve paragraph boundaries in streamed replies Sep 10, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 10, 2026
@obviyus
obviyus merged commit 0a20262 into openclaw:main Sep 10, 2026
213 checks passed
@obviyus

obviyus commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks @leapdragon! Merged in 0a20262.

  • Bug: Combined streamed text joined distinct assistant messages without a paragraph boundary.
  • Fix: The shared merger tracks inserted padding separately, so updates and display truncation preserve the boundary without retracting emitted text.
  • Proof: A real Gateway, WebChat, and read tool exercised the public path. All 12 HTTP scenarios completed consistently, and browser layout and transcript order stayed correct.
  • Validation: 795 focused tests passed. Final review found no actionable issue, and all required CI checks passed. The final correction changed only tests, preserving the production code used for the live proof.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 10, 2026
…claw#140833)

Preserve paragraph boundaries between distinct assistant items in public Gateway chat, Chat Completions, OpenResponses, and the embedded terminal backend. Reconstruct item text without inserted padding so later snapshots cannot retract streamed newlines, and retire padding consistently at the display limit.

Validation: real isolated Gateway and WebChat with an actual read tool; baseline and candidate public text; 12 append-only HTTP scenarios; 795 focused tests; verified failing controls for both corrected regressions; clean exact-head review. Browser layout and transcript order remain correct.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants