Skip to content

improve(telegram): avoid rescanning expired rich-text spans - #151965

Merged
vincentkoc merged 1 commit into
mainfrom
perf/telegram-rich-span-expiry-m4-20260918
Sep 18, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/telegram-rich-span-expiry-m4-20260918

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Telegram rich-text rendering repeatedly scans expired formatting spans when one long formatting span contains many short spans.

User Impact

Messages with many nested formatting spans require less compositor work while preserving their Markdown and HTML output, crossing-span ordering, and delivery-page contents.

Why This Change Was Made

The existing rich-text compositor now admits spans in start order and removes expired spans as it advances. A continuing outer span can no longer keep expired inner spans in every later scan. Existing atom handling and formatting precedence remain unchanged.

Evidence

  • Both Markdown and HTML regressions fail on the original code at 530,434 span-end reads. The candidate stays within the 16,416-read budget with complete rich-message and delivery-page output assertions intact.
  • All 208 selected rich-text, HTML, progress-preview, and regression cases pass with zero skips.
  • Focused production and test typechecks, typed lint, canonical formatting, and the line-cap check pass. Independent scoped review found no actionable defects.
  • These are local behavioral and work-count results. Matched direct-VM stack measurements remain outstanding; no deployment speedup is claimed.

Punchcard-Session: ember-river-harbor-t4

Punchcard-Session: ember-river-harbor-t4
@vincentkoc vincentkoc self-assigned this Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 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.

@vincentkoc
vincentkoc marked this pull request as ready for review September 18, 2026 16:48
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: S maintainer Maintainer-authored PR labels Sep 18, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 18, 2026, 12:55 PM ET / 16:55 UTC.

ClawSweeper review

What this changes

The PR removes expired formatting spans from Telegram’s rich-text rendering sweep and adds Markdown and HTML regression coverage that checks output and processing work.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful, focused optimization: current main still rescans expired inner spans. No actionable correctness or security defect was found.

Priority: P2
Reviewed head: c894b80d2f8449d8efd73436f517440355ec23f2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, sound optimization with targeted work-count and output regression coverage and clearly bounded performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored internal optimization is exempt from the external-contributor proof gate. Its tests exercise the changed compositor through rich-message and delivery-page planning; no live Telegram or deployment-speed result is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored internal optimization is exempt from the external-contributor proof gate. Its tests exercise the changed compositor through rich-message and delivery-page planning; no live Telegram or deployment-speed result is claimed.
Evidence reviewed 7 items Introduced change: The verified merge-base-to-head diff changes only span admission/expiry and its regression test. Filtering preserves sorted order, and the existing atom-containment, annotation precedence, and container-reopening logic remain intact.
Current main still needs the optimization: Current main advances firstSpanIndex only past expired leading spans. A continuing outer span therefore retains expired inner spans in subsequent scans.
Latest release comparison: The supplied latest release, v2026.9.4, filters the complete spans array at every rendered boundary; it does not contain this optimization. The release blob was inspected through GitHub after local historical-object retrieval failed.
Findings None None.
Security None None.

How this fits together

Telegram’s rich-message planner converts outgoing Markdown and embedded HTML into formatted message blocks. The compositor combines formatting ranges before those blocks are split into delivery pages.

flowchart LR
  A[Outgoing Markdown and HTML] --> B[Parse text and formatting ranges]
  B --> C[Admit started spans]
  C --> D[Remove expired spans]
  D --> E[Compose formatted blocks]
  E --> F[Plan Telegram delivery pages]
Loading

Before merge

  • Resolve merge risk (P1) - Reduced span-end reads do not establish wall-clock, allocation, or deployed latency improvement; the PR explicitly leaves those measurements outstanding.
Agent review details

Security

None.

PR surface

Source -7, Tests +90. Total +83 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 13 -7
Tests 1 90 0 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 96 13 +83

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep span expiry inside the existing compositor while preserving formatting output and avoiding claims of deployment speedup without matched measurements.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep span expiry inside the existing compositor while preserving formatting output and avoiding claims of deployment speedup without matched measurements.

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

Yes, from source: a long outer formatting span prevents current main’s leading-span cursor from skipping expired inner spans. The supplied regression exercises that shape; no tests were executed in this read-only review.

Is this the best way to solve the issue?

Yes. Incremental admission and expiry address the redundant work within its existing owner while preserving ordering and containment semantics.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded performance improvement for heavily formatted messages on the optional Telegram rich-message path.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored internal optimization is exempt from the external-contributor proof gate. Its tests exercise the changed compositor through rich-message and delivery-page planning; no live Telegram or deployment-speed result is claimed.

Label justifications:

  • P2: This is a bounded performance improvement for heavily formatted messages on the optional Telegram rich-message path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored internal optimization is exempt from the external-contributor proof gate. Its tests exercise the changed compositor through rich-message and delivery-page planning; no live Telegram or deployment-speed result is claimed.

Evidence

What I checked:

  • Introduced change: The verified merge-base-to-head diff changes only span admission/expiry and its regression test. Filtering preserves sorted order, and the existing atom-containment, annotation precedence, and container-reopening logic remain intact. (extensions/telegram/src/rich-blocks.ts:240, c894b80d2f84)
  • Current main still needs the optimization: Current main advances firstSpanIndex only past expired leading spans. A continuing outer span therefore retains expired inner spans in subsequent scans. (extensions/telegram/src/rich-blocks.ts:239, ce7aa003112a)
  • Latest release comparison: The supplied latest release, v2026.9.4, filters the complete spans array at every rendered boundary; it does not contain this optimization. The release blob was inspected through GitHub after local historical-object retrieval failed. (extensions/telegram/src/rich-blocks.ts, 3a9d69db306c)
  • Regression coverage and claimed validation: The new test exercises both the rich-message builder and delivery-page planner with 512 inner italic spans under a continuing Markdown or HTML wrapper, asserting complete output and a 16,416 span-end-read ceiling. The supplied PR body reports 530,434 reads before the fix and 208 passing selected cases; these results were not rerun during this read-only review. (extensions/telegram/src/rich-blocks.span-work.test.ts:10, c894b80d2f84)
  • Existing edge-case contracts: Existing tests cover crossing formatting ranges, formatting beginning or ending inside atomic HTML content, and transcript-annotation precedence. The new expiry filtering retains spans that extend beyond an atom so they can become active afterward. (extensions/telegram/src/rich-blocks.test.ts:493, c894b80d2f84)
  • Related merged optimization: improve: format long Telegram rich replies faster #151827 is merged and explicitly documents that a long enclosing span can still leave quadratic scanning. It therefore provides related context without superseding this PR. (extensions/telegram/src/rich-blocks.ts, 22d4773dd124)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer disposition for the measurement risk in #151965 (comment): accept the review's first mitigation. Span expiry stays inside the existing compositor; complete formatting and delivery output are covered by the original-defect regression and 208 passing selected cases. The demonstrated result is reduced span-end reads. Wall-clock time, allocations and deployment latency are not established or claimed.

The matched direct-VM stack comparisons remain a separate campaign deliverable. Their absence does not block this independently justified narrow fix under the campaign's approved scope. Required exact-head CI and the native prepare/merge gates still apply. No source or test change is needed for this disposition.

@vincentkoc
vincentkoc merged commit 09741b1 into main Sep 18, 2026
170 checks passed
@vincentkoc
vincentkoc deleted the perf/telegram-rich-span-expiry-m4-20260918 branch September 18, 2026 17:04
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 18, 2026
…49090-prep

* 'main' of https://github.com/openclaw/openclaw: (1719 commits)
  test: remove redundant catalog benchmark gate (#151892)
  improve(ai): speed up Unicode message preparation (#151950)
  improve(logging): reduce filesystem work when polling logs (#151961)
  fix(cron): preserve scheduled work after creator turns end (#151919)
  improve(telegram): avoid rescanning expired rich-text spans (#151965)
  refactor(testing): share plugin assertion file scanner (#151960)
  fix: publish acknowledged managed task receipts (#151590)
  fix(qa): preserve denial warnings during A2A finalization (#150556)
  fix(subagents): clear expired blocks after successful delivery (#151949)
  test: share fresh CLI output fixtures (#151954)
  refactor: reuse channel status preparation (#151906)
  fix(plugins): avoid duplicate initialization and mixed registrations (#151927)
  fix: updates fail for plugins selected from local load paths (#151851)
  fix(msteams): reactions target the current inbound message (#151382)
  fix(state): keep the meeting transcript migration result when stage cleanup fails (#151370)
  improve(gateway): reduce allocations when selecting sessions by store (#151940)
  fix: finish Crabbox wrapper cancellation cleanup (#151862)
  fix(discord): preserve text when replying to bot messages (#151821)
  perf(fleet): run registry operations in SQLite workers (#148290)
  fix: keep I/O responsive across busy agent databases (#151909)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant