Repository navigation
improve(telegram): avoid redundant parsing of formatted replies - #148285
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 14, 2026, 10:23 AM ET / 14:23 UTC. ClawSweeper reviewWhat this changesThe Telegram formatter skips unnecessary Markdown parsing when checking formatted replies for transcript-role headers and expands coverage for encoded delimiters and code examples. Merge readiness✅ Ready for maintainer review The optimization remains useful: current main still performs the redundant parse. No actionable correctness or security defect was found, and the supplied measurements support the narrowly stated performance benefit. Priority: P2 Review scores
Verification
How this fits togetherTelegram’s formatter converts assistant replies into HTML and splits them into bounded messages. Its transcript-header check prevents assistant-generated text from appearing to introduce another speaker. flowchart TD
A[Assistant reply] --> B[Telegram HTML formatting]
B --> C[Project visible text]
C --> D{Possible header delimiter?}
D -->|No| F[Keep formatted content]
D -->|Yes| E[Parse with code exclusions]
E --> F
F --> G[Bounded Telegram messages]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +8, Tests +12. Total +20 across 2 files. View PR surface stats
Review metrics
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 the optimization inside the existing private predicate while preserving the original parser for every potentially encoded header. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction: this is an optimization, supported by source-confirmed redundant work and supplied before/after formatter measurements. Is this the best way to solve the issue? Yes. The conservative delimiter check avoids unnecessary work without replacing the parser, changing public APIs, or duplicating header recognition. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 10d67c803047. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Closes #148284
What Problem This Solves
Long formatted Telegram replies spend avoidable time reparsing visible text while finding message chunk boundaries.
User Impact
Formatting the measured long reply takes 23% less time on Node 26 and 28% less on Node 24, with identical output and chunk boundaries. Some annotation and raw-HTML cases instead add about 20–32 microseconds on average. Whole-child RSS rises slightly; this is not a universal speedup or memory-saving claim.
Why This Change Was Made
After the existing HTML projection, skip the additional Markdown parse only when its text contains no literal or potentially entity-encoded header delimiter. Retain the original parser and code-exclusion masking whenever
[,<, or&occurs. The change stays in the existing private predicate and preserves role-header protection, entity decoding, formatting, and limits.Evidence
markdownToTelegramChunksandsplitTelegramHtmlChunks, plus six unchanged Slack controls. Quiet confirmation followed coordinated settlement of other task jobs; ordinary OS/user activity remained. Screening overlapped unrelated work. These are complete local conversions/splits, not Telegram API or Gateway delivery measurements.Quiet mean milliseconds per complete conversion/split (baseline → candidate):
The long styled fixture saves 428/602 ms on Node 26/24, with all paired means and medians improving. The separate contended cohort saves 516/526 ms and has the same pair consistency. Long-workload CPU means also fall 22.85%/28.18% in quiet confirmation; small-cell CPU readings are heavily quantized and support no general CPU claim.
Counterevidence, separate screening results, and reproducibility scope
Quiet annotation means add 20.47/23.32 µs; five of six Node 26 and four of six Node 24 paired means regress. Their pooled medians change less: +3.05 µs on Node 26 and effectively unchanged on Node 24. Raw HTML code/Unicode on Node 26 adds 22.07 µs mean and 32.20 µs median, with five of six pairs slower by both measures. Node 24's aggregate reverses its screening regression but retains a +96.76% adverse paired mean (+98.97 µs). Raw HTML entity means add 31.70/25.80 µs. Node 26 plain-short retains a final pair with +65.34% mean and +68.60% median, approximately 9.3 µs extra. Dense-link and Markdown-Unicode aggregate improvements retain opposing pairs; they are not headline acceptance evidence.
Separate contended mean milliseconds per conversion/split:
The six unchanged Slack controls also vary. Quiet mean changes for plain, styled links, multichunk, dense links, fenced code, and annotations are respectively −3.78%, −3.96%, +0.035%, −0.11%, −1.89%, −1.16% on Node 26 and −3.76%, −1.64%, +0.67%, +0.21%, +11.35%, −1.89% on Node 24. Screening changes are +5.17%, +3.45%, −0.18%, −4.44%, −0.78%, +6.78% and +1.46%, −11.55%, −1.43%, −9.06%, +4.16%, −8.92%. They demonstrate residual variability; they do not provide a correction factor or excuse recurring regressions.
Quiet mean peak RSS rises 218.32 → 219.64 MiB on Node 26 and 247.12 → 248.18 MiB on Node 24. Final RSS adds 2.00/0.16 MiB. Screening peak means are 222.42 → 221.89 MiB and 246.64 → 247.60 MiB. These whole-child readings include imports, controls, and all workloads, and establish neither allocation savings nor retained-memory improvement. Quiet baseline/candidate zero-CPU batches are 141/146 of 270 on Node 26 and 131/150 of 270 on Node 24.
The benchmark retains all timing batches, references, controls, runtime identities, graph captures, and resource observations. The independent saved-data auditor verifies fixtures, outputs, callback traces, pinned source/runtime identities, and all cells. It does not independently implement the whole Markdown parser or replay discarded per-invocation outputs and warmups. Setup and reference checking stay outside timed calls.
Measured baseline:
e3b9b3810976cadf1cf0a02e342cea93d30b9b0b. Refreshed PR base:8638c54e15f8323f1c4926ade7cffa86226ed1c9, preserving exact owner/test bytes. Candidate production SHA-256:35998826328f8307542f470f03c749e69179fb1c9bbc1a8c0074030eb0f82378. Frozen benchmark manifest:30eb0325aed30058c8af82690e3aa86169fd7c4e3698f2c1efda86433186f1f2; quiet audit:00a80b61935c5cb3b7f216d32b1bafed70b071d665f372ceaa6f8069674dc5e9; contended audit:fc7f83719530e810873f69c73c51f95c855b17077a95613fa77fae1e7a361c7b. These identify retained local evidence, not downloadable artifacts. No live Telegram transport or cross-platform benchmark was run.