Skip to content

improve(telegram): reduce reply preparation overhead [AI] - #128308

Merged
steipete merged 1 commit into
mainfrom
codex/perf-telegram-outbound-current
Aug 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-telegram-outbound-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Telegram text and media delivery repeated the same reply/thread parameter projection for every chunk, adding avoidable local preparation work to ordinary outbound sends.

Why This Change Was Made

Reuse the canonical reply/thread parameters already prepared by the outbound plan. For implicit single-use replies, lazily prepare the no-reply variant at most once and reuse it for later chunks or media. Provider payloads, chunk ordering, retry behavior, and reply semantics remain unchanged.

User Impact

Chunked Telegram sends spend less CPU time in local outbound preparation. There is no provider-visible behavior change.

Evidence

  • Deterministic owner-path probe: reply-parameter builder calls fall from 65 to 1 for a 64-chunk delivery.
  • Representative in-process benchmark (64 chunks, 20,000 deliveries, 9 samples): median 119.280 ms → 58.858 ms, a 50.655% reduction (2.027× faster for this preparation segment).
  • Current-head semantic differential is byte-identical to the audited baseline; both outputs have SHA-256 c92a044beba4fc2ffff633e06be69581569354efc9ace1f0693a080f591c81a5.
  • Focused owner/sibling tests: 4 files, 288 tests passed.
  • Full source-equivalent Telegram suite from the isolated audit: all 212 shards passed.
  • node scripts/check-changed.mjs -- extensions/telegram/src/send-message.ts: passed all classified format, type, lint, dead-export, doctor, boundary, database, media, and import-cycle checks.
  • Fresh Codex gpt-5.6-sol/high autoreview: no P0/P1 findings; correctness confidence 0.90.
  • No live Telegram message was sent: this is a behavior-neutral provider-boundary preparation change, covered by byte-level provider-call comparison and the owner/full suites.

AI-assisted implementation and review were used. No agent transcript is published.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS maintainer Maintainer-authored PR labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 17:47

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for exact head 1f76b69ce5828fec22cc24ecccd706c31074f76b:

  • Root cause: ordinary Telegram text/media delivery discarded prepareTelegramOutbound.threadParams and rebuilt the same reply/thread projection for each chunk.
  • Owner-local repair: carry the prepared reply-bearing params forward and lazily materialize one no-reply variant only for implicit single-use multipart delivery. Production delta: +16/-13; test delta: +0/-0. No public/config/protocol/security/storage/retry surface changed.
  • Provider-call semantic differential: byte-identical, SHA-256 c92a044beba4fc2ffff633e06be69581569354efc9ace1f0693a080f591c81a5.
  • Structural/performance proof: 65 → 1 reply-parameter builder calls for 64 chunks; representative median 119.280 ms → 58.858 ms (50.655% lower for this local preparation segment).
  • node scripts/run-vitest.mjs extensions/telegram/src/send.test.ts extensions/telegram/src/reply-parameters.test.ts extensions/telegram/src/outbound-adapter.test.ts extensions/telegram/src/channel.message-adapter.test.ts --reporter=verbose — 288/288 passed.
  • node scripts/check-changed.mjs -- extensions/telegram/src/send-message.ts — all classified gates passed.
  • Source-equivalent full Telegram suite — 212/212 shards passed.
  • Fresh Codex gpt-5.6-sol/high autoreview — no P0/P1 findings, correctness confidence 0.90.
  • Native review artifacts validated with READY FOR /prepare-pr, issue status valid, and no findings.
  • Exact-head CI run 32655952654 — green, including openclaw/ci-gate.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128308 — passed in hosted_exact_or_recent_parent mode using the exact-head hosted gates; no separate Testbox lease was needed or provisioned.

No live Telegram message was sent: the changed contract is local provider-boundary preparation, final provider calls are byte-identical, and a network send would not exercise a distinct behavior. The full ClawSweeper review is still replacing its in-progress placeholder; no Rank-up moves: have been published yet, and the final comment will be read and dispositioned before merge.

@steipete
steipete merged commit 000aea1 into main Aug 23, 2026
194 checks passed
@steipete
steipete deleted the codex/perf-telegram-outbound-current branch August 23, 2026 18:05

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 1:54 PM ET / 17:54 UTC.

ClawSweeper review

What this changes

This PR reuses prepared Telegram reply and thread parameters across chunked text and media sends to reduce repeated local preparation work.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. The planner already owns reply/thread projection, and the patch reuses that result without a concrete semantic regression found; scoped Telegram policy still calls for after-fix reply-context proof before landing. Likely related people: steipete and Jesse Merhi.

Priority: P3
Reviewed head: 1f76b69ce5828fec22cc24ecccd706c31074f76b

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 6 items Changed owner boundary: The PR passes reply and quote inputs into the existing outbound planner and reuses its prepared thread parameters; a lazily built reply-less variant preserves the single-use reply path.
Planner contract: The existing planner resolves the target/thread once and builds reply parameters from the same message ID, quote text, and quote-source inputs now supplied by this caller.
Delivery-path preservation: Text delivery copies parameters into each request before dispatch, while quote fallback derives a replacement legacy-reply object rather than mutating the cached prepared parameters.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

pnpm openclaw --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128308-TXU675/target$ pnpm openclaw --help
$ node scripts/run-node.mjs --help
pnpm openclaw --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 97.17 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 13.4s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4161ms (slowest: built plugin control-plane loads 3439ms)

OpenClaw 2026.8.1 (1f76b69) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console 
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

Telegram outbound delivery prepares a target, topic, and reply context before sending text chunks or media through the Telegram API. This change sits between outbound planning and the text/media delivery paths.

flowchart LR
A[Outbound send request] --> B[Telegram outbound planner]
B --> C[Prepared reply and topic parameters]
C --> D[Text chunk delivery]
C --> E[Media delivery]
D --> F[Telegram API]
E --> F
Loading

Before merge

  • Resolve merge risk (P1) - Reply and quote preparation is delivery-sensitive; the PR provides source and CI claims but no posted after-fix Telegram trace or mock-gateway harness verdict for the changed reply-context path.
  • Complete next step (P2) - No code repair is indicated; the remaining merge gate is scoped reply-context proof.
Agent review details

Security

None.

PR surface

Source +3. Total +3 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 16 13 +3
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 16 13 +3

Review metrics

Metric Value Why it matters
Production versus test LOC production +16, -13 (net +3); tests 0 The small production increase carries planner-owned prepared state and a lazy no-reply cache; no test coverage changed in this PR.

Merge-risk options

Maintainer options:

  1. Capture reply-context proof (recommended)
    Add a redacted after-fix Telegram trace or mock-gateway verdict covering chunked text or media with a reply and topic before merge.
  2. Accept source-only evidence
    Merge on the inspected semantic equivalence and existing CI while explicitly accepting the absence of transport-boundary proof.

Technical review

Best possible solution:

Keep reply/thread projection canonical in the outbound planner and add a redacted after-fix bot-to-bot trace or mock-gateway verdict that demonstrates unchanged reply and topic payloads.

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

Not applicable: this is a performance optimization, not a report of broken existing behavior; source comparison shows the former per-call projection and the planner-owned equivalent.

Is this the best way to solve the issue?

Yes. The planner already owns target and thread resolution, so reusing its prepared result is cleaner than adding separate caches in text and media delivery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against bca206d794bd.

Labels

Label changes:

  • add P3: This is a narrowly scoped performance optimization with no demonstrated user-facing regression.
  • add merge-risk: 🚨 message-delivery: The changed cache feeds reply and topic parameters used by Telegram text and media sends, so transport-boundary proof remains relevant.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.

Label justifications:

  • P3: This is a narrowly scoped performance optimization with no demonstrated user-facing regression.
  • merge-risk: 🚨 message-delivery: The changed cache feeds reply and topic parameters used by Telegram text and media sends, so transport-boundary proof remains relevant.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.

Evidence

What I checked:

  • Changed owner boundary: The PR passes reply and quote inputs into the existing outbound planner and reuses its prepared thread parameters; a lazily built reply-less variant preserves the single-use reply path. (extensions/telegram/src/send-message.ts:73, 1f76b69ce582)
  • Planner contract: The existing planner resolves the target/thread once and builds reply parameters from the same message ID, quote text, and quote-source inputs now supplied by this caller. (extensions/telegram/src/send-outbound.ts:116, 1f76b69ce582)
  • Delivery-path preservation: Text delivery copies parameters into each request before dispatch, while quote fallback derives a replacement legacy-reply object rather than mutating the cached prepared parameters. (extensions/telegram/src/send-message-text.ts:119, 1f76b69ce582)
  • Existing semantic coverage: Unchanged tests cover implicit single-use reply handling across media follow-up text, chunked topic replies, explicit replies, and native-quote fallback. (extensions/telegram/src/send.test.ts:2715, 1f76b69ce582)
  • Current-main provenance: Current-main blame attributes the replaced caller-side preparation shape to the retained commit by Jesse Merhi; the PR changes that fragment rather than adding a parallel path. (extensions/telegram/src/send-message.ts:73, 13f0e02de62d)
  • Head validation context: The supplied PR context reports green changed-surface checks and CI, but no attached live Telegram trace or mock-gateway verdict JSON. (1f76b69ce582)

Likely related people:

  • steipete: Retained history includes the Telegram outbound-topic preparation and direct-message topic-routing refactors that define the planner seam reused here. (role: recent outbound-preparation contributor; confidence: high; commits: 92bacda20699, d7133e7df6f5; files: extensions/telegram/src/send-outbound.ts, extensions/telegram/src/send-message.ts)
  • Jesse Merhi: Current-main blame ties the former caller-side preparation shape to this retained commit; the PR replaces that local projection with the planner-owned result. (role: current-main caller-fragment author; confidence: medium; commits: 13f0e02de62d; files: extensions/telegram/src/send-message.ts)

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.

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 size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants