Repository navigation
fix(telegram): cap rich block depth measurement - #160437
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 October 1, 2026, 10:44 PM ET / October 2, 2026, 02:44 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR bounds Telegram rich-message nesting before rendering and delivery, replaces recursive measurements and text projections, and preserves text and media URLs when deeper content is flattened. Merge readiness✅ Ready for maintainer review The repair remains necessary on current main. Both prior findings are resolved, the final-head Telegram evidence demonstrates recovery, and this review found no remaining actionable patch defect. Priority: P1 Review scores
Verification
How this fits togetherTelegram’s outbound renderer converts assistant Markdown or supplied rich blocks into message pages. These pages carry formatted content to Telegram and readable text for delivery recovery. flowchart LR
A[Assistant Markdown] --> C[Parse and render content]
B[Supplied rich blocks] --> D[Bound nesting]
C --> D
D --> E[Measure and split pages]
E --> F[Telegram rich delivery]
F --> G[Plain text recovery]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +204, Tests +59. Total +263 across 6 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep nesting enforcement with Telegram’s existing renderer and delivery planner, preserving readable deep content within the verified wire budget. Do we have a high-confidence way to reproduce the issue? Yes: deeply nested details reach unbounded recursive rendering and measurement on current main. The supplied baseline Telegram trace confirms outbound failure; this reviewer established the path from source without executing it. Is this the best way to solve the issue? Yes: bounding the existing parser and normalization owners before recursive consumers repairs both production inputs, and iterative projection preserves the content needed for recovery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8273590a26de. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles) |
|
Independent review: a depth cap only in measurement is insufficient if rich-block parsing, rendering, or plain-text fallback still recursively walks the same tree. Please enforce the bound at the parser/normalization owner or prove every downstream traversal is bounded, then cover both pre-rendered and raw rich-message paths with a synthetic deeply nested fixture. No runtime or Telegram credentials were used. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed as b734148. Thanks @Ayushdevo for starting this; we built the depth cap and media-preserving fallback on top of your commit. |
Fixes openclaw#160431. The Telegram rich-block pipeline no longer overflows the stack on deeply nested `<details>`: rich nesting is capped at the depth Telegram accepts (15 levels observed on the Test Server; 16 is rejected with RICH_MESSAGE_DEPTH_INVALID), and deeper content is flattened to plain text inside the deepest allowed block, keeping image/video/audio sources. Normal content is byte-identical. Proof: isolated Gateway on the Telegram Test Server. main lost a 5,000-level assistant reply with a maximum-call-stack error; this change delivers one rich message with every summary, the leaf marker and media URLs beyond the cutoff. A real OpenAI Telegram control turn passed. Regression tests for the overflow and the media loss fail before and pass after. Co-authored-by: Ayaan Zaidi <[email protected]>
Fixes #160431
What Problem This Solves
Fixes lost Telegram replies when assistant Markdown contains deeply nested
<details>blocks.User Impact
Deep replies retain rich formatting through 15 container levels and preserve deeper text and media source URLs inside the rich message, rather than overflowing the stack. Ordinary details, lists, and inline formatting remain unchanged. No configuration changes or migrations are required.
Why This Change Was Made
The previous list-only guard ran after recursive rendering, and the original depth constant was unused. Bound HTML parsing and emission before recursive consumers, use iterative measurement and plain-text projection, and normalize rendered and caller-supplied blocks before splitting or serialization. Telegram Test Server accepts 15 nested details containers plus a paragraph leaf, but rejects 16 with
RICH_MESSAGE_DEPTH_INVALID.The review follow-up also preserves image, video, and audio source URLs at both early HTML cutoffs. Normal text projection is unchanged. It fixes the content-loss finding rather than merely fixing lint.
Preserves @Ayushdevo's original commit and credit. Thanks to @hpyhandsome for the concrete reproduction.
No overlap with Pash/Sarah changes.
Evidence
Final candidate:
31d49ef08bfd5115ab611b22c754f78441957750.a9665e46cc28db91063e21a06fdc0fd814231773) failed outbound delivery withMaximum call stack size exceeded; no assistant payload arrived, only a generic failure notice. On the final candidate, onemessageRichMessagearrived. TDLibgetFullRichMessageconfirmedis_full=true, all 5,000 summary characters, the leaf marker, and all three image/video/audio source URLs placed beyond the depth cutoff. No depth rejection, stack overflow, or whole-message plain fallback occurred.ef0583a20f3d88ab66f1916ce8eabdc62cfedf6b, before the lint and media-source follow-ups. A normal Markdown response arrived asmessageRichMessagewith paragraph and list nodes. Two real provider requests total, both HTTP 200. This ordinary-content observation is retained; the final-head mock Telegram and compatibility proofs were rerun. The credential was file-mounted read-only and deleted afterwards.2c38123dc82ee10b19b6585b8375aec2b95cae62e703b3789f60491267fe0c94). Existing list and HTML-island cases pass unchanged.RangeError. Additional depth-31/depth-61 media cases failed before the review repair because URLs disappeared. Final focused run: 189 owner tests plus one temporary compatibility control passed in 2.11 seconds. New cases took 119 ms, 8 ms, 2 ms, and 3 ms. Owner command:node scripts/run-vitest.mjs extensions/telegram/src/rich-blocks.test.ts extensions/telegram/src/rich-blocks-html.test.ts(the compatibility fixture was included in the measured run).OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm buildpassed in secretless Docker. The previous pushed head's two lint jobs failed on this PR's formatting/lint issues; those are corrected in the follow-up. Project-wide validation belongs to CI.Sanitized final-head Telegram observations
The depth-probe messages were deleted, including the initially uncertain receipt recovered through the leased user driver. Runner-owned Gateway/credential scratch state was removed and leases released.