Skip to content

fix(telegram): cap rich block depth measurement - #160437

Merged
obviyus merged 5 commits into
openclaw:mainfrom
Ayushdevo:fix/telegram-rich-block-depth-160431
Oct 2, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
Ayushdevo:fix/telegram-rich-block-depth-160431

Conversation

@Ayushdevo

@Ayushdevo Ayushdevo commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Real Telegram path: an isolated built Gateway received a Test Server user turn and a deterministic assistant reply containing 5,000 nested details. Current main (a9665e46cc28db91063e21a06fdc0fd814231773) failed outbound delivery with Maximum call stack size exceeded; no assistant payload arrived, only a generic failure notice. On the final candidate, one messageRichMessage arrived. TDLib getFullRichMessage confirmed is_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.
  • Real OpenAI control: ran on ef0583a20f3d88ab66f1916ce8eabdc62cfedf6b, before the lint and media-source follow-ups. A normal Markdown response arrived as messageRichMessage with 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.
  • Compatibility: a three-level details/list fixture produced byte-identical serialized blocks, plain text, and degradation reasons on base and final candidate (SHA-256 2c38123dc82ee10b19b6585b8375aec2b95cae62e703b3789f60491267fe0c94). Existing list and HTML-island cases pass unchanged.
  • Regression: raw Markdown and supplied-block cases failed before with 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).
  • Checks: scoped Oxfmt and Oxlint passed on all six changed files. OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build passed 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
baseline: telegram final reply failed: OutboundDeliveryError: Maximum call stack size exceeded
candidate: rich-degrade=nesting-limit
candidate TDLib: messageRichMessage, is_full=true
candidate content: summaries=5000, leaf-marker=present
candidate media: a.jpg=present, a.mp4=present, a.mp3=present
candidate: RICH_MESSAGE_DEPTH_INVALID=absent, stack-overflow=absent
wire-depth probe: 3/8/12/14/15 accepted; 16 rejected

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.

@clawsweeper

clawsweeper Bot commented Sep 28, 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 channel: telegram Channel integration: telegram size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 10:44 PM ET / October 2, 2026, 02:44 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: 31d49ef08bfd5115ab611b22c754f78441957750

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with strong final-head Telegram evidence, meaningful regressions, and no remaining actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The captured final-head logs exercise the changed Telegram rendering and delivery owners through an isolated built Gateway and Test Server user turn. TDLib confirms full rich delivery with all deep summaries, leaf text, and three media URLs after the baseline stack overflow; ordinary-content compatibility is supplemental. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The captured final-head logs exercise the changed Telegram rendering and delivery owners through an isolated built Gateway and Test Server user turn. TDLib confirms full rich delivery with all deep summaries, leaf text, and three media URLs after the baseline stack overflow; ordinary-content compatibility is supplemental. No stored-data contract changes.
Evidence reviewed 11 items Pinned introduced changes: Reviewed the verified merge-base-to-head delta and affected production owners. Parsing and emission are bounded before recursive consumers; splitting and serialization normalize supplied blocks. Endpoint drift and the stale test merge were not treated as PR changes.
Current main still needs the repair: The pinned fetched main retains recursive rich-text measurement, block measurement, and plain projection. Its Markdown renderer retains only the list-specific post-render nesting guard. Read pinned source through GitHub’s contents API.
Latest release does not contain this repair: The supplied latest-release identity, v2026.9.7, also retains the recursive measurement and plain-text projection. This PR is not established as already shipped.
Findings None None.
Security None None.

How this fits together

Telegram’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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +204, Tests +59. Total +263 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 288 84 +204
Tests 1 59 0 +59
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 347 84 +263

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #160431
Summary: The linked open issue supplies the concrete nested-details failure this PR repairs; earlier merged pagination work addresses a distinct transport budget.

Members:

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

Technical review

Best 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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured final-head logs exercise the changed Telegram rendering and delivery owners through an isolated built Gateway and Test Server user turn. TDLib confirms full rich delivery with all deep summaries, leaf text, and three media URLs after the baseline stack overflow; ordinary-content compatibility is supplemental. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured final-head logs exercise the changed Telegram rendering and delivery owners through an isolated built Gateway and Test Server user turn. TDLib confirms full rich delivery with all deep summaries, leaf text, and three media URLs after the baseline stack overflow; ordinary-content compatibility is supplemental. No stored-data contract changes.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Deep assistant Markdown can suppress Telegram replies in the existing rich-message workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured final-head logs exercise the changed Telegram rendering and delivery owners through an isolated built Gateway and Test Server user turn. TDLib confirms full rich delivery with all deep summaries, leaf text, and three media URLs after the baseline stack overflow; ordinary-content compatibility is supplemental. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured final-head logs exercise the changed Telegram rendering and delivery owners through an isolated built Gateway and Test Server user turn. TDLib confirms full rich delivery with all deep summaries, leaf text, and three media URLs after the baseline stack overflow; ordinary-content compatibility is supplemental. No stored-data contract changes.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Deep replies and preserved media URLs are user-visible Telegram behavior; the supplied final-head Test Server observations cover this requirement.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the verified merge-base-to-head delta and affected production owners. Parsing and emission are bounded before recursive consumers; splitting and serialization normalize supplied blocks. Endpoint drift and the stale test merge were not treated as PR changes. (extensions/telegram/src/rich-block-model.ts:465, 31d49ef08bfd)
  • Current main still needs the repair: The pinned fetched main retains recursive rich-text measurement, block measurement, and plain projection. Its Markdown renderer retains only the list-specific post-render nesting guard. Read pinned source through GitHub’s contents API. (extensions/telegram/src/rich-block-model.ts:300, 8273590a26de)
  • Latest release does not contain this repair: The supplied latest-release identity, v2026.9.7, also retains the recursive measurement and plain-text projection. This PR is not established as already shipped. (extensions/telegram/src/rich-block-model.ts:300, c074824a27c9)
  • Prior media-loss finding resolved: Compared the earlier reviewed head with the final head through GitHub’s compare API after local historical-object retrieval returned HTTP 403. Both early HTML cutoffs now request media-source preservation; the iterative projection retains img/video/audio src values. Delivery-page regressions cover depths 31 and 61. (extensions/telegram/src/rich-blocks-html.ts:129, 31d49ef08bfd)
  • Final-head real Telegram proof: The captured body, source revision d038bc8d6d071d3af9d0ae07ffcd4bb8aeec8db277c70b81d07827d628d386fa, identifies the exact final candidate and an isolated built Gateway receiving a Test Server user turn. The baseline failed outbound delivery with stack overflow; final-head TDLib observations report one full messageRichMessage containing all 5,000 summaries, the leaf marker, and image/video/audio URLs beyond the cutoff, without depth rejection or whole-message plain fallback. The ordinary real-provider control is explicitly earlier-head evidence. (31d49ef08bfd)
  • Regression and ordinary-content compatibility: Added cases exercise raw Markdown and supplied blocks through production delivery-page planning with independent expected text. The captured body reports pre-fix RangeErrors, media-loss negative controls, 189 owner tests plus a temporary compatibility control passing in 2.11 seconds, and byte-identical ordinary details/list output. These are supplied results; this read-only review did not execute contributor code. (extensions/telegram/src/rich-blocks.test.ts:905, 31d49ef08bfd)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • sunlit-deng: 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-28T12:14:14.966Z sha 0790af5 :: needs real behavior proof before merge. :: [P1] Enforce the nesting limit in the traversal
  • reviewed 2026-10-02T02:27:17.855Z sha ef0583a :: blocked before merge. :: [P2] Preserve media sources when flattening over-depth HTML

Copy link
Copy Markdown
Contributor Author

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.

@obviyus

obviyus commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added size: M and removed size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Oct 2, 2026
@obviyus

obviyus commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 2, 2026
@obviyus
obviyus merged commit b734148 into openclaw:main Oct 2, 2026
114 of 118 checks passed
@obviyus

obviyus commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Landed as b734148. Thanks @Ayushdevo for starting this; we built the depth cap and media-preserving fallback on top of your commit.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram P1 High-priority user-facing bug, regression, or broken workflow. 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: 🐚 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.

[Bug]: Deeply nested <details> in assistant markdown crashes the Telegram rich-block pipeline with RangeError

2 participants