Repository navigation
fix(telegram): code blocks lose blank lines when replies are split - #153576
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 2:06 PM ET / 18:06 UTC (Revision 26). ClawSweeper reviewWhat this changesPreserves blank lines and formatting in split Telegram code replies by protecting complete code regions and letting Telegram’s renderer own message splitting. Merge readiness✅ Ready for maintainer review This repair remains necessary after the merged prerequisites. The focused implementation and recorded real Telegram recipient proof support it, and no blocking correctness or security finding remains. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s reply pipeline passes Markdown and delivery settings to the Telegram plugin. The plugin groups paragraphs, renders bounded messages, and sends them to the recipient. flowchart TD
A[Reply Markdown] --> B[Telegram delivery adapter]
C[Account limits and delivery overrides] --> B
B --> D[Code-aware paragraph grouping]
D --> E[Rendered message splitting]
E --> F[Telegram recipient]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -1, Tests -78. Total -79 across 9 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep code intact through paragraph grouping and use the existing Telegram renderer as the single owner of bounded message splitting. Do we have a high-confidence way to reproduce the issue? Yes: current main’s fenced-only paragraph guard splits the supplied oversized indented-code fixture at its internal blank line. This review establishes the path from source; it did not execute a reproduction. Is this the best way to solve the issue? Yes: the patch reuses canonical code-region detection and the existing rendered-size splitter, removing redundant raw-Markdown splitting while carrying existing delivery settings to their owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 14393070236e. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (25 earlier review cycles; latest 8 shown)
|
6120677 to
240468a
Compare
240468a to
385e809
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
385e809 to
58d9b27
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
58d9b27 to
effe83a
Compare
5d82356 to
190f393
Compare
190f393 to
8ae3661
Compare
687da72 to
ab7ff1b
Compare
|
Hi @obviyus — thanks for opening #154857 and #154875. I've read both and want to make sure #153576 aligns with how you'd like this split to land, rather than overlapping or competing with your two PRs. As I read them, the three touch different layers:
The file sets don't overlap, so they look complementary rather than redundant. But your split suggests you'd prefer each layer fixed on its own, and #153576 is currently blocked on Telegram Test Server recipient proof that this machine can't produce (no Test Server credentials; ClawSweeper's reviewer request was also rejected before execution). A couple of options, and I'm happy to follow whichever you prefer: A. Keep #153576 scoped to just the B. Close #153576 in favor of your two PRs, if you intend the chunker-layer protection to be handled differently or not at all. C. Something else — e.g. rebase #153576 on top of #154857 + #154875 once they land, if the chunker fix is still wanted as a third piece. Which direction would you like? I don't want to keep pushing a large PR that cuts across the layers you've deliberately separated. |
chunkByParagraph used parseFenceSpans (only fenced code) to guard paragraph breaks, so blank lines inside 4-space indented code blocks split the block mid-content and stripped indentation. Switch to findCodeRegions which covers fenced, indented, and inline code. Long paragraphs now route through chunkMarkdownText so fence-aware splitting and reopening apply to indented code too, instead of the code-unaware chunkText fast path.
1483dfc to
f04d5e3
Compare
|
Hi @obviyus — following up on my earlier question. I've gone ahead and narrowed this PR to align with the per-layer split you started with #154857 and #154875. What I changed in this push (head
So #153576 now covers only the I'm not trying to push this ahead of your two PRs — happy to rebase on top of them once they land, close it if you'd rather fold the chunker fix in differently, or leave it sitting here until you decide. Whatever's least work for you. Just wanted to help with the chunking path since it was the original gap. Thanks for untangling the layers — the split makes the whole thing much easier to reason about. |
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. Co-authored-by: Ayaan Zaidi <[email protected]>
#154857) Related: #153576 ## What Problem This Solves Fixes indented code losing its leading spaces when the embedded agent prepares its final reply payload. ## User Impact CLI JSON consumers and downstream renderers receive the authored code indentation instead of a first line that looks like ordinary prose. Ordinary prose padding is still trimmed, and existing empty or hidden-only reply suppression is unchanged. No configuration or storage migration is required. ## Why This Change Was Made Final payload preparation used generic optional-string normalization after the assistant text had already been preserved. It now uses the existing code-aware trim owner at that boundary. No parser, new API, or channel-specific policy is added. This is the independent producer fix only. It does not change paragraph chunking or Telegram page rendering and does not claim to complete the separate channel-splitting repair. ## Evidence - Independently reproduced through the supported `openclaw agent --local --json` command on pinned main `10c229159ceb9ae4fe42b40495d718256d68a3fc`, using an isolated configured provider and the existing loopback HTTP fixture. The provider supplied 266 bytes of indented code, and the canonical persisted assistant still contained all 266 bytes, but the public CLI payload contained only 262 bytes: the first four spaces were lost. - With only this two-file change applied, the same public CLI path returned the exact 266-byte code fixture. A padded ordinary-prose control returned the same trimmed 15-byte answer on both baseline and candidate. Each model completed one real HTTP request to the loopback fixture; no direct calls or stubs replaced the payload builder or runner. - The retained focused negative control fails code preservation on the original owner while its prose control passes. The isolated candidate's payload and payload-error suites passed **105 tests** in **34.78 seconds** total runner time. The shards took 24.69 and 7.31 seconds, primarily transformation/import work; the added code regression took 3 ms. - The runtime build passed, including 95 bundled plugin builds and 53 built control-plane checks. Scoped type-aware lint, formatting, and both source-size ratchets passed. All owned providers and observed CLI children settled, and both proof ports closed. Proof used local Node 24.21.0, fresh synthetic state and credentials, and loopback transport. It does not claim a Gateway/channel delivery, a live paid provider, or the combined Telegram fix. Both sides retain SQLite automatic-maintenance stale-input warnings; the command outcomes and canonical transcript assertions completed successfully. No external operation was admitted. Co-authored-by: Ayaan Zaidi <[email protected]>
|
landpr-approve-unrelated-red |
|
Landed in 2e6c53b. Telegram paragraph-mode delivery now preserves indented code and its internal blank lines through the existing renderer. Verified with real Telegram Test Server recipient captures, the registered Gateway Thanks @SunnyShu0925 for the original repair and for narrowing the PR to keep the fixes complementary. |
|
@obviyus Thanks~ |
…#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]>
openclaw#154857) Related: openclaw#153576 ## What Problem This Solves Fixes indented code losing its leading spaces when the embedded agent prepares its final reply payload. ## User Impact CLI JSON consumers and downstream renderers receive the authored code indentation instead of a first line that looks like ordinary prose. Ordinary prose padding is still trimmed, and existing empty or hidden-only reply suppression is unchanged. No configuration or storage migration is required. ## Why This Change Was Made Final payload preparation used generic optional-string normalization after the assistant text had already been preserved. It now uses the existing code-aware trim owner at that boundary. No parser, new API, or channel-specific policy is added. This is the independent producer fix only. It does not change paragraph chunking or Telegram page rendering and does not claim to complete the separate channel-splitting repair. ## Evidence - Independently reproduced through the supported `openclaw agent --local --json` command on pinned main `c84ec3940151ebdf3050161cfdad976f9a7a7e82`, using an isolated configured provider and the existing loopback HTTP fixture. The provider supplied 266 bytes of indented code, and the canonical persisted assistant still contained all 266 bytes, but the public CLI payload contained only 262 bytes: the first four spaces were lost. - With only this two-file change applied, the same public CLI path returned the exact 266-byte code fixture. A padded ordinary-prose control returned the same trimmed 15-byte answer on both baseline and candidate. Each model completed one real HTTP request to the loopback fixture; no direct calls or stubs replaced the payload builder or runner. - The retained focused negative control fails code preservation on the original owner while its prose control passes. The isolated candidate's payload and payload-error suites passed **105 tests** in **34.78 seconds** total runner time. The shards took 24.69 and 7.31 seconds, primarily transformation/import work; the added code regression took 3 ms. - The runtime build passed, including 95 bundled plugin builds and 53 built control-plane checks. Scoped type-aware lint, formatting, and both source-size ratchets passed. All owned providers and observed CLI children settled, and both proof ports closed. Proof used local Node 24.21.0, fresh synthetic state and credentials, and loopback transport. It does not claim a Gateway/channel delivery, a live paid provider, or the combined Telegram fix. Both sides retain SQLite automatic-maintenance stale-input warnings; the command outcomes and canonical transcript assertions completed successfully. No external operation was admitted. Co-authored-by: Ayaan Zaidi <[email protected]>
…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]>
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
sendRPC 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.