Skip to content

fix: preserve paragraph breaks in streamed replies - #125340

Closed
Adkid-Zephyr wants to merge 10 commits into
openclaw:mainfrom
Adkid-Zephyr:codex/fix-streamed-paragraph-boundaries
Closed

Adkid-Zephyr wants to merge 10 commits into
openclaw:mainfrom
Adkid-Zephyr:codex/fix-streamed-paragraph-boundaries

Conversation

@Adkid-Zephyr

@Adkid-Zephyr Adkid-Zephyr commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #42106

AI-assisted with Codex. Validation and independent code review were performed by agents.

What Problem This Solves

Streamed source line breaks can disappear between independently delivered blocks. This affects both embedded replies and ACP replies: a forced ACP flush of First.\n followed by Second. must reconstruct First.\nSecond., and paragraph boundaries must survive every shared normalization stage.

The chunker now retains source line/paragraph boundaries across drains and checkpoints when the boundary and visible text fit the cap. Coalescing respects an existing leading source line break instead of adding another joiner; ordinary text retains the configured joiner. A private streamedSourceBoundary fact carries an established continuation through presentation, coalescing, dispatch preparation and routing. The sanitizer skips only leading-empty-line removal for that fact on block replies; first blocks, suppressed output, errors, internal-context filtering, tool replies and final replies retain their normal cleanup.

ACP establishes that fact in its existing serial pipeline callback only after an earlier source block was accepted by delivery. Both routed preparation and the real routeReply normalization consume it. Async admission order, source cursors and fence handling remain with their existing owners. A direct import from the canonical payload type also avoids the type-only barrel cycle caught by CI. No public configuration/protocol fields or channel-rendering changes are introduced.

Candidate and integration

Candidate: 5847aff32fb96bd45484fadde6bbc02195789440.

Merge commit f475a3adf14862e7c7cc34ede09c1fea4304520e incorporates frozen main 5f357b747802439b4878dea48a78bb91957b7ff5. That merge commit’s tree matches the recorded conflict-free git merge-tree result, and its frozen-lockfile install passed. The current candidate descends from that verified merge. Against that base: 20 files; production +160/-29 (net +131), tests +771/-15 (net +756).

Evidence

  • On the merged candidate, 954 tests passed across 21 distinct affected/sibling files. This includes the chunker, actual embedded presentation/dispatcher/coalescing path, ACP projection and delivery, real routing, sanitizer controls, source checkpoints, fences, BTW and channel delivery.
  • Chunker regression: the old branch source failed 5 of the 70 cases; the repair passes all 70, including single-LF, split paragraph and source-cursor contracts.
  • The six new ACP source-reconstruction cases failed with the old branch normalizers, after the independent chunker repair. They pass after the cutover. The 12-case suite exercises the real projector → coordinator → preparation → direct dispatcher or real routeReply → durable wrapper, with the outbound delivery boundary mocked. Controls cover a suppressed first source, status output and marked blocks reused as final/tool replies.
  • The 17-case embedded composition suite covers both single-LF and paragraph prefixes, metadata copies and media-caption coalescing, plus lane/filter/cache controls. Its new real chunker → presentation → coalescer → dispatcher matrix checks one forced drain producing multiple source boundaries; only the two single-LF categories fail on f475a3adf1, and all four categories pass after the one-line joiner repair. Existing ordinary-text configured-joiner cases remain green.
  • The complete check-changed --base 5f357b747802439b4878dea48a78bb91957b7ff5 --head HEAD, exact pnpm check:architecture, git diff --check, scoped lint/format and owner type checks all passed. The clean private-QA runtime build passed, with temporary observation code absent.
  • Independent reviews covered the chunker and ACP changes, including their real callers and the final proof below. A separate independent agent reviewed the complete 5f357b7478..5847aff32f source diff, including source accounting, chunk limits and fences, delivery lifecycle, metadata propagation, direct/routed normalization and filtering, and reported no actionable finding. The earlier bundled autoreview helper produced no validated report; it is not counted as a successful review.

Actual Gateway evidence

The original matched experiment is retained separately: with identical scenario and log-only instrumentation, the pre-presentation-fix a32bf3f44c production overlay produced ["First", "Second"], while 5a50d8b762 produced ["First", "\n\nSecond"]. This established the earlier embedded-path repair.

The current candidate 5847aff32f was then rerun as a regression confirmation, using the same stable mock stream, signed local Slack ingress, real Gateway/Slack plugin and local Crabline API. Its source and dependencies differ from the old pair, and diagnostic field bindings were renamed; this is not presented as a new strictly paired experiment against that old baseline.

Temporary log-only observation immediately after shared sanitization and before the channel transform produced:

{"text":"First","applyChannelTransforms":true,"hasChannelTransform":true,"transformAlreadyApplied":false}
{"text":"\n\nSecond","applyChannelTransforms":true,"hasChannelTransform":true,"transformAlreadyApplied":false}
{"text":"First\n\nSecond","applyChannelTransforms":false,"hasChannelTransform":false,"transformAlreadyApplied":false}

All three records were retained. The frozen predicate applyChannelTransforms && hasChannelTransform && !transformAlreadyApplied selects exactly two nonempty blocks within the 20-character cap; their concatenation exactly equals the emitted SSE source First\n\nSecond. The third record is internal final normalization with no channel transform. All reply_payload_sending records were exactly two block deliveries; native API logs contained exactly two chat.postMessage calls (First, Second) and no extra final/fallback send, update or delete.

The instrumentation and scenario copy were restored before the clean runtime rebuild and final checks. This proves the observed shared source boundary in an isolated, instrumented Gateway. Slack's existing channel transformation/rendering remains unchanged; no live external-channel result is claimed.

CI

CI run 34807553901 completed successfully for 5847aff32fb96bd45484fadde6bbc02195789440. Its completed-check snapshot recorded 169 SUCCESS, 44 SKIPPED and 1 NEUTRAL, with no failed or pending checks.

ClawSweeper Revision 18 reviewed this exact head, found the prior ACP/coalescing findings addressed and no remaining actionable defect, and marked it ready for maintainer review. Maintainer review and merge remain pending.

@clawsweeper

clawsweeper Bot commented Aug 17, 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 agents Agent runtime and tooling size: M labels Aug 17, 2026
@Adkid-Zephyr
Adkid-Zephyr marked this pull request as ready for review August 17, 2026 16:16
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. 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 Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Preserves authored line and paragraph separators through streamed reply chunking, coalescing, normalization, and routing.

Example: A newline-mode reply streams First\n\nSecond across separate deliveries.

  • Before: Reconstructing delivered block text can produce FirstSecond.
  • After: Delivered blocks retain First and \n\nSecond, reconstructing the paragraph boundary.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A useful shared-owner repair with recorded Gateway proof, meaningful regression coverage, and no actionable finding; confirmed merge conflicts remain a workflow blocker.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Recorded candidate Gateway evidence exercises signed local Slack ingress, the real Gateway and Slack plugin, shared sanitation, and local transport delivery: source blocks reconstruct First\\n\\nSecond, with exactly two outbound blocks and no extra final or fallback send; ACP direct and routed composition tests provide supporting coverage.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Streamed replies can lose authored line and paragraph boundaries, collapsing Markdown structure.
Reason: Preserving authored separators repairs an established shared delivery defect without adding configuration or a public protocol.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it provides a useful, proven repair for separator loss that remains in current main, with no actionable defect found in the pinned patch.

Priority: P2
Reviewed head: 5847aff32fb96bd45484fadde6bbc02195789440

Before merge

  • Complete next step - Resolve the confirmed conflicts with current main, preserving its newer chunker source accounting and reply-delivery lifecycle, then validate the resulting integration.

Findings

None.

Agent review details

How this fits together

Embedded agent and ACP streams enter the shared block chunker and delivery pipeline; normalized payloads leave through direct dispatch or channel routing.

flowchart TD
  A[Embedded agent stream] --> C[Block chunker]
  B[ACP event projector] --> C
  C --> D[Presentation and coalescing]
  D --> E[Shared normalization]
  E --> F[Dispatcher or reply router]
  F --> G[Channel delivery]
Loading

Technical review

Best possible solution:

Land the shared separator-preservation repair while retaining current main's chunk limits, source accounting, and delivery lifecycle.

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

Current-main source shows paragraph separators being consumed before visible chunks are emitted, and separate coalescer flushes cannot restore them; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch repairs the shared source and normalization owners, preserves ordinary configured joiners, and limits the sanitizer exception to established block continuations.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2d72268bd9e9.

Provenance checked

  • Paragraph chunking and minimum-size behavior keeps the original intent (20728e1: Paragraph-aware streaming was changed to honor minChars instead of sending every paragraph immediately.)
  • Chunk source accounting and fence continuation keeps the original intent (14d272d: Preserve complete prose lines, balanced code continuations, and delivered-source coverage so final replies do not replay code.)
  • User-facing text sanitation changes intended behavior with a stated reason (6c1dde5: Consolidate incremental visibility filters and whitespace cleanup while preserving existing sanitation behavior; this PR narrowly exempts established continuation prefixes and retains internal-context filtering.)
  • ACP serial projection keeps the original intent (295c8df: Keep one projector and dispatch path; the continuation fact is established inside that existing serial callback.)
  • Reply directive normalization changes intended behavior with a stated reason (eefb2f8: Extract shared block-delivery normalization; this PR preserves leading source separators only for established continuations.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduction reviewed: The merge-base-to-head diff contains the separator-preservation repair and its regression coverage; base movement was inspected separately. (5847aff32fb9)
  • Current main still consumes visible separators: The paragraph branch emits text before the separator and advances past it; source metadata preserves accounting but does not restore the emitted visible text. (src/agents/embedded-agent-block-chunker.ts:414, 2d72268bd9e9)
  • Continuation preservation uses existing owners: Embedded presentation establishes continuation formatting after admitted source text; ACP establishes it in the existing serial delivery callback. Shared normalization consumes private WeakMap metadata only for block replies. (src/auto-reply/reply/acp-projector.ts:191, 5847aff32fb9)
  • Earlier coalescing finding addressed: The final commit avoids inserting a configured joiner before any retained leading LF, covering the previously failing single-newline continuations. (src/auto-reply/reply/block-reply-coalescer.ts:32, 5847aff32fb9)
  • Recorded Gateway behavior: The PR body and contributor confirmation record the candidate's isolated Gateway/Slack ingress run: shared normalization produced First and \n\nSecond, with two downstream block sends and no additional final or fallback send. The inspected downloaded table screenshot concerns a different Markdown-fragmentation scenario and is not counted as proof of this repair. (5847aff32fb9)
  • Live merge blocker confirmed: A subsequent live REST response reported mergeable=false and mergeable_state=dirty for the unchanged reviewed head. (5847aff32fb9)

PR surface

Source +131, Tests +756. Total +887 across 20 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 12 160 29 +131
Tests 8 771 15 +756
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 931 44 +887

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +160/-29; tests +771/-15 Production growth carries continuation facts through existing normalization owners; regression coverage exercises distinct chunker, embedded, ACP, routing, ordering, and filtering failures.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #42106
Summary: This PR is the open repair candidate for the canonical shared block-separator issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Separator loss corrupts streamed Markdown structure with a bounded impact on reply presentation.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (21 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-14T01:15:37.008Z sha 4782f0f :: needs real behavior proof before merge. :: [P2] [P2] Preserve single newlines across forced ACP flushes
  • reviewed 2026-09-14T03:22:03.923Z sha 5b84a47 :: blocked before merge. :: [P2] [P2] Preserve single newlines across forced ACP flushes
  • reviewed 2026-09-14T03:42:45.724Z sha 9366f81 :: blocked before merge. :: [P2] [P2] Preserve single newlines across forced ACP flushes | [P2] [P2] Carry paragraph continuation through ACP normalization
  • reviewed 2026-09-14T04:38:39.675Z sha f475a3a :: needs changes before merge. :: [P2] [P2] Avoid adding a joiner before retained single newlines
  • reviewed 2026-09-14T05:14:06.166Z sha 5847aff :: needs maintainer review before merge. :: none
  • reviewed 2026-09-14T05:43:47.336Z sha 5847aff :: needs maintainer review before merge. :: none
  • reviewed September 25, 2026, 4:30 PM ET / 20:30 UTC (Revision 20) sha unknown :: blocked before merge. :: none
  • reviewed 2026-10-09T14:40:04.980Z sha 5847aff :: needs changes before merge. :: none

Reviewed October 18, 2026, 12:06 AM ET / 04:06 UTC (Revision 22).

@Adkid-Zephyr

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 17, 2026
@Adkid-Zephyr

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added 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. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Aug 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 14, 2026
@clawsweeper clawsweeper Bot added 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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Sep 25, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 18, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. We're closing older pull requests that have gone stale against current main.

This PR has had no commits since September 14 and is waiting on requested changes. Thanks for the work; please open a fresh PR rebased on main if streamed paragraph breaks are still lost on a current release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Block streaming can drop paragraph separators across streamed updates

2 participants