Skip to content

fix: preserve code blank lines when formatted replies split - #154875

Merged
obviyus merged 1 commit into
mainfrom
omp-codeboundary153576
Sep 21, 2026
Merged

obviyus merged 1 commit into
mainfrom
omp-codeboundary153576

Conversation

@obviyus

@obviyus obviyus commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Related: #153576

What Problem This Solves

Fixes internal blank lines disappearing when formatted code exceeds a message limit and the receiving service trims whitespace at message edges.

User Impact

Long code replies retain their internal blank lines across message boundaries. Ordinary prose splitting, size limits, Unicode boundaries, and existing progress behavior for impossible budgets remain unchanged.

Why This Change Was Made

The existing rendered-size splitter now uses its parsed code spans to avoid placing internal code whitespace at message edges when a content-bearing cut fits. It preserves the source rather than dropping or deferring whitespace, with no new parser, configuration, or public API.

This is an independent renderer prerequisite for #153576; it does not change final-reply payload preparation or Telegram paragraph grouping.

Evidence

  • Real Telegram Test Server recipient proof from a checkout containing only this two-file renderer patch: a fenced reply containing 700 & characters, an internal blank line, and 700 B characters. Its 1,410-character Markdown source stays below the existing 4,000-character raw limit, while HTML escaping requires rendered-size splitting. The recipient received two native code entities of 1,176 and 226 UTF-16 units; their combined text exactly preserved all 1,402 intended code units, including the internal blank line. No payload-preparation or Telegram-adapter prerequisite was present.
  • Both new soft-boundary and hard-Unicode regressions failed before the renderer repair. The focused renderer suite passed all 33 tests, including existing impossible-budget and grapheme cases; its latest Vitest duration was 0.249 seconds.
  • Retained earlier native evidence, with final-payload and paragraph-handling fixes present but this renderer repair absent, still lost the blank line between code messages. The standalone capture above uses a different fixture; it is not a matched independent before/after pair.
  • Existing Telegram, Google Chat, Signal, Slack, SMS, and WhatsApp consumer tests passed: 11 files across eight shards in 57.87 seconds. These are local consumer checks, not live verification of the other services.
  • Type-aware lint passed. The independent checkout's QA runtime build passed, including all 95 bundled plugins and the bootstrap/control-plane checks.

The native observation excludes Telegram's omission of the code block's terminal framing newline; the authored internal blank line was preserved. The maintained runner completed successfully and removed its credential scratch state.

@clawsweeper

clawsweeper Bot commented Sep 21, 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 size: S maintainer Maintainer-authored PR labels Sep 21, 2026
@obviyus
obviyus marked this pull request as ready for review September 21, 2026 13:27
@clawsweeper

clawsweeper Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 9:37 AM ET / 13:37 UTC.

ClawSweeper review

What this changes

The shared Markdown splitter keeps internal code whitespace away from message edges where receiving services may trim it, with regression coverage for ordinary and Unicode boundaries.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main retains the problematic splitting behavior, and the supplied recipient observation isolates the repair. No blocking correctness or security finding was identified.

Priority: P2
Reviewed head: da2aa0133c66adfe9a8aedfef090b4886e0e7492

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful regression coverage and specific recipient-observed evidence; no blocking defect was found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied standalone Telegram Test Server observation exercises HTML-expansion splitting through the changed shared renderer and reports recipient code entities preserving the internal blank line and all 1,402 intended units; it does not claim live coverage of other services.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied standalone Telegram Test Server observation exercises HTML-expansion splitting through the changed shared renderer and reports recipient code entities preserving the internal blank line and all 1,402 intended units; it does not claim live coverage of other services.
Evidence reviewed 8 items Pinned introduced change: The merge-base-to-head diff changes only the shared renderer splitter and its regression tests; unrelated endpoint drift is not attributed to this PR.
Still necessary on fetched main: The current splitter selects whitespace boundaries without consulting code spans. Its rendered-size retry can therefore place an internal code separator at a transport-trimmed message edge.
Latest release inspection: The v2026.9.5 source also uses the whitespace-preferred splitter without the proposed code-span protection; no shipped implementation of this repair was established.
Findings None None.
Security None None.

How this fits together

OpenClaw parses replies into text and formatting spans, then splits them against each channel’s rendered message limit. Channel adapters deliver those formatted chunks to recipients.

flowchart LR
  A[Markdown reply] --> B[Parsed text and formatting]
  B --> C[Rendered size splitter]
  C --> D[Code and Unicode boundary checks]
  D --> E[Channel formatted chunks]
  E --> F[Recipient messages]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +31, Tests +23. Total +54 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 32 1 +31
Tests 1 23 0 +23
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 55 1 +54

Review metrics

None.

Technical review

Best possible solution:

Keep boundary selection in the shared renderer, preserving code content through transport trimming while retaining existing size and Unicode progress rules.

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

Yes, source inspection establishes the trigger: escaping forces a code block to split at internal whitespace that the recipient trims. The supplied regressions and Telegram observation support it; this review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes, the patch adjusts the existing shared owner using parsed code spans and the existing grapheme helper, without introducing another parser or channel-specific workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs lost internal whitespace in long formatted code replies without adding configuration or changing delivery authority.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied standalone Telegram Test Server observation exercises HTML-expansion splitting through the changed shared renderer and reports recipient code entities preserving the internal blank line and all 1,402 intended units; it does not claim live coverage of other services.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Preserved code blank lines are visible Telegram behavior, and the supplied Test Server observation covers that path.

Label justifications:

  • P2: This repairs lost internal whitespace in long formatted code replies without adding configuration or changing delivery authority.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied standalone Telegram Test Server observation exercises HTML-expansion splitting through the changed shared renderer and reports recipient code entities preserving the internal blank line and all 1,402 intended units; it does not claim live coverage of other services.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Preserved code blank lines are visible Telegram behavior, and the supplied Test Server observation covers that path.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff changes only the shared renderer splitter and its regression tests; unrelated endpoint drift is not attributed to this PR. (packages/markdown-core/src/render-aware-chunking.ts:255, da2aa0133c66)
  • Still necessary on fetched main: The current splitter selects whitespace boundaries without consulting code spans. Its rendered-size retry can therefore place an internal code separator at a transport-trimmed message edge. (packages/markdown-core/src/render-aware-chunking.ts:244, ed5937fbd981)
  • Latest release inspection: The v2026.9.5 source also uses the whitespace-preferred splitter without the proposed code-span protection; no shipped implementation of this repair was established. (packages/markdown-core/src/render-aware-chunking.ts, ec9c1a13db89)
  • Production delivery connection: Telegram’s formatter invokes this shared splitter with actual HTML rendering and measures HTML length, matching the escaping-driven split described in the supplied proof. Other callers include Signal, Slack, Google Chat, SMS, and WhatsApp. (extensions/telegram/src/format.ts:801, da2aa0133c66)
  • Recipient-observed behavior proof: The complete supplied PR body reports a standalone Telegram Test Server run containing only this renderer patch: 700 ampersands, an internal blank line, and 700 B characters produced two native code entities of 1,176 and 226 UTF-16 units, preserving all 1,402 intended units. The body explicitly distinguishes this observation from an earlier, unmatched fixture with other fixes present. Captured context identity: 8f8745c2a0d9b7ccd8c8446b36ea90250dd31b294e261e3d19a0f80dfc9fc024. This review did not execute the run. (da2aa0133c66)
  • Focused regression coverage: The added cases compare concatenated recipient-trimmed text with the intended code, enforce rendered limits, and reject split surrogate pairs. Existing coverage retains impossible-budget, grapheme, semantic-whitespace, and formatting contracts. The supplied body reports both new cases failed before the fix and all 33 renderer tests passed afterward in 0.249 seconds; tests were not executed during this read-only review. (packages/markdown-core/src/render-aware-chunking.test.ts:56, da2aa0133c66)

Likely related people:

  • etzelm: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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.

@obviyus

obviyus commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-unrelated-red
pr: 154875
head: da2aa01
run: 35605792408 attempt: 1
failed: checks-node-compact-small-7 job=106352899275 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit cc18d2d into main Sep 21, 2026
183 of 186 checks passed
@obviyus
obviyus deleted the omp-codeboundary153576 branch September 21, 2026 13:58
@obviyus

obviyus commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Merged as cc18d2d. The shared renderer now avoids avoidable code-whitespace cuts at message edges while retaining existing size and Unicode rules. The independent Telegram Test Server capture preserved all 1,402 intended code units, including the internal blank line; focused renderer and sibling consumer checks passed. Exact-head review passed, and the unrelated SQLite disk-budget CI failure is documented in the scoped approval above. This fix does not change final payload preparation or Telegram paragraph grouping in #153576.

obviyus added a commit that referenced this pull request Sep 21, 2026
…153576)

Related: #154857, #154875

## What Problem This Solves

Fixes indented code blocks being divided at internal blank lines or reparsed as prose when Telegram replies exceed the paragraph-mode message limit.

## User Impact

Telegram code snippets keep their internal blank lines and code formatting while ordinary prose paragraph grouping and configured message limits continue to work.

## Why This Change Was Made

Paragraph grouping now uses the existing canonical code-region parser. Oversized Markdown paragraphs reach Telegram's existing parsed, render-aware splitter intact instead of being split twice as raw Markdown. The channel sender applies the existing configured limits and per-delivery overrides.

The producer and renderer prerequisites have landed separately in #154857 and #154875. This PR contains only the remaining nine-file paragraph/Telegram delivery change; it adds no whitespace truncation or deferred-whitespace policy, parser, configuration key, dependency, or CI change.

Thanks to @SunnyShu0925 for the original chunker repair and for removing the unrelated changes. Their latest contributor commit remains in this branch's ancestry.

## Evidence

- With both prerequisites present on main `900f00302f5`, the focused paragraph regression still fails against main's chunker: one indented code block becomes two paragraph chunks. Restoring the candidate owner makes that same regression pass.
- Fresh built-Gateway proof exercised the registered `send` RPC through durable outbound delivery and the real leased Telegram Test Server, without a model generating the message. At newline mode and a 256-unit limit, the recipient received three native code entities of 232, 24, and 2 UTF-16 units. Their combined text exactly preserved both 128-character code lines and the internal blank line. The run completed and removed credential scratch state. One unrelated mocked Activity recap request was recorded and distinguished from message generation.
- Earlier real-recipient indented-code, hard-Unicode/combining/ZWJ, and ordinary-prose controls remain applicable: the production owner-file hashes, including the now-merged prerequisites, match the tested cleaned source. The two consumer regressions now live in focused sibling suites with the same assertions and existing test support. The related parser, grapheme, Telegram formatter/sender, delivery-plan, and dependency-lock inputs are unchanged. These controls were retained rather than rerun merely for integration; Telegram's omission of the renderer-added terminal newline is recorded explicitly.
- The four affected owner test files previously passed 532 tests in 41.21 seconds. Additional prerequisite/renderer consumer coverage is recorded with the two merged PRs. The integrated runtime build passed, including 95 bundled plugins and the bootstrap/control-plane checks; scoped core and Telegram type-aware lint also passed against the integrated main contracts.

- After relocating the consumer regressions out of oversized suites, both focused tests passed through the maintained Telegram test registration in 24.92 seconds (22 ms and 13 ms test bodies). Scoped formatting and type-aware lint passed, and the line-cap ratchet passed against the exact CI main parent. Production source is byte-identical to the real-recipient-tested revision; no runtime build or native send was repeated for this test-only move.

No screenshots, native-client automation, or live verification of other channels are claimed.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…#154875)

Related: openclaw#153576

## What Problem This Solves

Fixes internal blank lines disappearing when formatted code exceeds a message limit and the receiving service trims whitespace at message edges.

## User Impact

Long code replies retain their internal blank lines across message boundaries. Ordinary prose splitting, size limits, Unicode boundaries, and existing progress behavior for impossible budgets remain unchanged.

## Why This Change Was Made

The existing rendered-size splitter now uses its parsed code spans to avoid placing internal code whitespace at message edges when a content-bearing cut fits. It preserves the source rather than dropping or deferring whitespace, with no new parser, configuration, or public API.

This is an independent renderer prerequisite for openclaw#153576; it does not change final-reply payload preparation or Telegram paragraph grouping.

## Evidence

- Real Telegram Test Server recipient proof from a checkout containing only this two-file renderer patch: a fenced reply containing 700 `&` characters, an internal blank line, and 700 `B` characters. Its 1,410-character Markdown source stays below the existing 4,000-character raw limit, while HTML escaping requires rendered-size splitting. The recipient received two native code entities of 1,176 and 226 UTF-16 units; their combined text exactly preserved all 1,402 intended code units, including the internal blank line. No payload-preparation or Telegram-adapter prerequisite was present.
- Both new soft-boundary and hard-Unicode regressions failed before the renderer repair. The focused renderer suite passed all 33 tests, including existing impossible-budget and grapheme cases; its latest Vitest duration was 0.249 seconds.
- Retained earlier native evidence, with final-payload and paragraph-handling fixes present but this renderer repair absent, still lost the blank line between code messages. The standalone capture above uses a different fixture; it is not a matched independent before/after pair.
- Existing Telegram, Google Chat, Signal, Slack, SMS, and WhatsApp consumer tests passed: 11 files across eight shards in 57.87 seconds. These are local consumer checks, not live verification of the other services.
- Type-aware lint passed. The independent checkout's QA runtime build passed, including all 95 bundled plugins and the bootstrap/control-plane checks.

The native observation excludes Telegram's omission of the code block's terminal framing newline; the authored internal blank line was preserved. The maintained runner completed successfully and removed its credential scratch state.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…penclaw#153576)

Related: openclaw#154857, openclaw#154875

## What Problem This Solves

Fixes indented code blocks being divided at internal blank lines or reparsed as prose when Telegram replies exceed the paragraph-mode message limit.

## User Impact

Telegram code snippets keep their internal blank lines and code formatting while ordinary prose paragraph grouping and configured message limits continue to work.

## Why This Change Was Made

Paragraph grouping now uses the existing canonical code-region parser. Oversized Markdown paragraphs reach Telegram's existing parsed, render-aware splitter intact instead of being split twice as raw Markdown. The channel sender applies the existing configured limits and per-delivery overrides.

The producer and renderer prerequisites have landed separately in openclaw#154857 and openclaw#154875. This PR contains only the remaining nine-file paragraph/Telegram delivery change; it adds no whitespace truncation or deferred-whitespace policy, parser, configuration key, dependency, or CI change.

Thanks to @SunnyShu0925 for the original chunker repair and for removing the unrelated changes. Their latest contributor commit remains in this branch's ancestry.

## Evidence

- With both prerequisites present on main `017c9d2a8c9`, the focused paragraph regression still fails against main's chunker: one indented code block becomes two paragraph chunks. Restoring the candidate owner makes that same regression pass.
- Fresh built-Gateway proof exercised the registered `send` RPC through durable outbound delivery and the real leased Telegram Test Server, without a model generating the message. At newline mode and a 256-unit limit, the recipient received three native code entities of 232, 24, and 2 UTF-16 units. Their combined text exactly preserved both 128-character code lines and the internal blank line. The run completed and removed credential scratch state. One unrelated mocked Activity recap request was recorded and distinguished from message generation.
- Earlier real-recipient indented-code, hard-Unicode/combining/ZWJ, and ordinary-prose controls remain applicable: the production owner-file hashes, including the now-merged prerequisites, match the tested cleaned source. The two consumer regressions now live in focused sibling suites with the same assertions and existing test support. The related parser, grapheme, Telegram formatter/sender, delivery-plan, and dependency-lock inputs are unchanged. These controls were retained rather than rerun merely for integration; Telegram's omission of the renderer-added terminal newline is recorded explicitly.
- The four affected owner test files previously passed 532 tests in 41.21 seconds. Additional prerequisite/renderer consumer coverage is recorded with the two merged PRs. The integrated runtime build passed, including 95 bundled plugins and the bootstrap/control-plane checks; scoped core and Telegram type-aware lint also passed against the integrated main contracts.

- After relocating the consumer regressions out of oversized suites, both focused tests passed through the maintained Telegram test registration in 24.92 seconds (22 ms and 13 ms test bodies). Scoped formatting and type-aware lint passed, and the line-cap ratchet passed against the exact CI main parent. Production source is byte-identical to the real-recipient-tested revision; no runtime build or native send was repeated for this test-only move.

No screenshots, native-client automation, or live verification of other channels are claimed.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 9, 2026
)

Render-aware chunking cut the source at the limit, then re-split a chunk whose rendered form overflowed by its wrapper (for example a Telegram <pre><code> block) and emitted the overflow as its own tiny message: a ~6.8k code block arrived as 3952/48/2801 characters, broken mid-word. The overflow is now carried into the next source window, so the same block arrives as 3952/2849 with exact content; #154875 whitespace protection is unchanged. Found by our Telegram Test Server bug hunt.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…claw#167958)

Render-aware chunking cut the source at the limit, then re-split a chunk whose rendered form overflowed by its wrapper (for example a Telegram <pre><code> block) and emitted the overflow as its own tiny message: a ~6.8k code block arrived as 3952/48/2801 characters, broken mid-word. The overflow is now carried into the next source window, so the same block arrives as 3952/2849 with exact content; openclaw#154875 whitespace protection is unchanged. Found by our Telegram Test Server bug hunt.

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

maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant