Skip to content

improve(telegram): reduce formatting work for prose replies - #150222

Merged
steipete merged 1 commit into
mainfrom
codex/perf-telegram-file-reference-r14
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-telegram-file-reference-r14

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Telegram spends unnecessary time checking prose segments for file references while formatting replies.

User Impact

Formatted prose and link-heavy replies take less CPU to format, with identical HTML and chunk boundaries. No configuration or migration is required.

Why This Change Was Made

Both filename patterns require a literal period. Skip their two replacement scans when a text segment has none, after checking the existing protected HTML contexts. This is a one-line change with no cache. Measurements include the already-landed optimization in #150213 in both baseline and candidate.

Evidence

Measured the actual markdownToTelegramChunks caller in 12 fresh processes: three alternating baseline/candidate pairs per Node version, totaling 51,120 timed calls. All scheduled results were retained. Median paired wall-time changes:

Input Node 24.19.0 Node 26.8.2
Formatted prose without periods -22.3% -20.7%
Formatted prose with periods -5.7% -12.4%
Link-heavy reply -12.6% -14.5%
Filename-heavy reply -0.8% -2.1%
Short formatted reply without a period -1.0% -3.6%
Short formatted reply with a period -8.3% -12.9%
Code block -2.5% +3.2%

The no-period prose and link-heavy cases improved in all six pairs, including process CPU. Other inputs were mixed: individual adverse wall-time pairs included +4.3% for filenames, +3.0% for punctuated prose, and +7.1% for code. No universal improvement or network-latency claim. Short cases took only tens of milliseconds per batch and their Windows CPU counters were coarse. The final Node 26 baseline overlapped review-snapshot disk activity; it remains included.

Synthetic fixtures include short replies and long prose, links, filenames, and code, using a 4,000-character HTML cap. Imports, full-output comparisons, and five warmups per case were outside timing.

  • Complete output equality for all seven caller fixtures and 112 HTML wrapping cases in every process, including anchors, code, malformed tag nesting, entity text, Unicode, and real file references.
  • All 69 loaded repository source files per process matched the merged main source, except for the measured one-line candidate.
  • 112 existing formatter tests passed on Node 26 using the repository test wrapper.
  • Repository formatting and diff checks passed; independent P0–P2 review completed with no findings.
  • Exact-head hosted CI passed, including lint, types, build, and selected tests. The borrowed local install could not run type-aware checks because the declaration builder rejects shared dependencies; hosted CI supplies that proof.
  • ClawSweeper exact-head review completed with no findings or requested changes before merge.

@clawsweeper

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

@steipete
steipete marked this pull request as ready for review September 16, 2026 18:30
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS maintainer Maintainer-authored PR labels Sep 16, 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 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 2:55 PM ET / 18:55 UTC (Revision 2).

ClawSweeper review

What this changes

The Telegram formatter skips filename-matching scans for text segments without periods, reducing formatting work while preserving HTML and chunk boundaries.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful, bounded optimization absent from inspected main and the latest release. No actionable correctness or security defects were found; the prior review also reported no findings.

Priority: P2
Reviewed head: 82dccf595934a8c2c995ca17f3d38fe293e12d9c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported optimization with useful production-caller measurements and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records before/after execution of the actual Markdown-to-Telegram chunk formatter on two Node versions, with measured CPU/wall-time improvements and unchanged complete outputs; this adequately covers the internal optimization without requiring live chat proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR records before/after execution of the actual Markdown-to-Telegram chunk formatter on two Node versions, with measured CPU/wall-time improvements and unchanged complete outputs; this adequately covers the internal optimization without requiring live chat proof.
Evidence reviewed 8 items Introduced change and correctness: The pinned merge-base-to-head diff changes only the early-return condition. Both replacement patterns require a literal period; empty strings still return unchanged, and code, preformatted, and anchor contexts remain excluded.
Production entry point: Markdown delivery calls markdownToTelegramChunks, whose rendering path applies filename wrapping before calculating HTML-limited chunks. The benchmark therefore exercises the changed production formatter.
Existing behavioral coverage: Existing tests cover prose without filename matches, protected HTML contexts, real filenames, authored links, malformed nesting, and chunk boundaries. These tests were inspected, not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

Telegram’s outbound formatter converts Markdown replies into size-limited HTML messages. Filename wrapping prevents file references from becoming unwanted links before those messages reach delivery.

flowchart TD
  A[Markdown reply] --> B[Parse and render HTML]
  B --> C[Inspect text segments]
  C --> D{Protected context or no period?}
  D -->|Yes| E[Preserve segment]
  D -->|No| F[Wrap matching filenames]
  E --> G[Size-limited HTML messages]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0. Total 0 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 1 1 0

Review metrics

None.

Technical review

Best possible solution:

Retain the existing Telegram formatter and its output contracts while avoiding scans that cannot match.

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

Not applicable as a functional bug: the unnecessary scans are evident in source, and the PR reports paired production-formatter benchmarks.

Is this the best way to solve the issue?

Yes. The period check directly expresses a necessary condition of both existing patterns without adding state, changing public APIs, or altering formatting policy.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR records before/after execution of the actual Markdown-to-Telegram chunk formatter on two Node versions, with measured CPU/wall-time improvements and unchanged complete outputs; this adequately covers the internal optimization without requiring live chat proof.

Label justifications:

  • P2: This is a measured formatter CPU improvement with limited scope and no urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR records before/after execution of the actual Markdown-to-Telegram chunk formatter on two Node versions, with measured CPU/wall-time improvements and unchanged complete outputs; this adequately covers the internal optimization without requiring live chat proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR records before/after execution of the actual Markdown-to-Telegram chunk formatter on two Node versions, with measured CPU/wall-time improvements and unchanged complete outputs; this adequately covers the internal optimization without requiring live chat proof.

Evidence

What I checked:

  • Introduced change and correctness: The pinned merge-base-to-head diff changes only the early-return condition. Both replacement patterns require a literal period; empty strings still return unchanged, and code, preformatted, and anchor contexts remain excluded. (extensions/telegram/src/format.ts:485, 82dccf595934)
  • Production entry point: Markdown delivery calls markdownToTelegramChunks, whose rendering path applies filename wrapping before calculating HTML-limited chunks. The benchmark therefore exercises the changed production formatter. (extensions/telegram/src/telegram-text-delivery.ts:148, 82dccf595934)
  • Existing behavioral coverage: Existing tests cover prose without filename matches, protected HTML contexts, real filenames, authored links, malformed nesting, and chunk boundaries. These tests were inspected, not executed during this read-only review. (extensions/telegram/src/format.wrap-md.test.ts:67, 82dccf595934)
  • Recorded production formatter measurements: The complete supplied PR body reports 51,120 timed production-caller invocations across 12 processes on Node 24.19.0 and 26.8.2, with output equality for seven caller fixtures and 112 wrapping cases. Period-free formatted prose improved by median 22.3% and 20.7%; adverse pairs and measurement limitations are explicitly retained. This is reported benchmark evidence, not a reviewer rerun. (82dccf595934)
  • Current-main necessity: The fetched main revision still runs both filename replacements on unprotected, nonempty segments without checking for a period. (extensions/telegram/src/format.ts:485, 70b587ba4056)
  • Latest-release comparison: The supplied latest release, v2026.9.4, also retains the original condition. Its source was inspected through GitHub after the local tag lookup was unavailable. (extensions/telegram/src/format.ts, 3a9d69db306c)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-16T18:36:17.866Z sha 82dccf5 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 16, 2026
@steipete
steipete merged commit ead7324 into main Sep 17, 2026
184 checks passed
@steipete
steipete deleted the codex/perf-telegram-file-reference-r14 branch September 17, 2026 02:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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