Repository navigation
refactor(telegram): consolidate command and transport handling - #167196
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: blocked before merge. Reviewed October 8, 2026, 8:35 AM ET / 12:35 UTC (Revision 3). ClawSweeper reviewWhat this changesThis PR consolidates Telegram command, callback, delivery, cache, and transport handling while retaining existing behavior. Review scores
ProductKind: Refactor · Worth it: Yes Merge readiness⛔ Blocked before merge - 2 items remain Useful owner-led consolidation with no concrete introduced defect found. This PR needs real behavior proof before merge under the Telegram-scoped policy; the previously requested live verification remains pending. Priority: P3 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe Telegram plugin receives chat updates, applies conversation and sender policy, and submits admitted messages to OpenClaw agents. It converts commands, callbacks, and agent replies into Telegram requests while maintaining delivery records and conversation context. flowchart LR
A[Telegram updates] --> B[Telegram plugin]
B --> C[Sender and conversation policy]
C --> D[Commands and agent turns]
D --> E[Delivery preparation]
E --> F[Telegram requests]
B --> G[Stored context and routing]
G --> D
Technical reviewBest possible solution: Keep consolidation within the existing Telegram owners, preserving transport policy, accepted-delivery custody, and stored-state contracts. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a behavior-preserving refactor rather than a reported existing-behavior defect. Is this the best way to solve the issue? Yes: the inspected changes share work within existing Telegram responsibilities and cut over callers without introducing a competing public API or configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b3196dfda335. Provenance checked
TestingProof path: in-process harness. Added test files: 1. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfacePR surface statistics unavailable: the file list is incomplete. Stored data modelPersistent data-model change detected: LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment History |
…law#167196) Consolidate Telegram command and callback context, delivery variants, polling and throttle bookkeeping, and cache traversal within the existing transport owners. Preserve user-visible text, configuration, protocol fields, persisted records, authorization, recovery, and public SDK contracts. Remove 1,159 net production lines. Keep existing test assertions; three support lookups follow the consolidated registration seam. Validation: full Telegram directory (167 files, 2,327 tests), changed-file checks, focused correction tests, strict package compilation, zero runtime/static cycles, unchanged SDK API, exact-head hosted CI, and the canonical Telegram Test Server lifecycle. The live recording includes same-message progress edits, successful tool execution, a separate persistent final reply, native reply linkage, and progress deletion. PR evidence retains earlier local failures and their limitations.
What Problem This Solves
Telegram repeats command, callback, delivery, and transport bookkeeping across closely related variants.
User Impact
No user-visible change. Features, message text, configuration, public SDK contracts, protocol fields, persisted records, authorization, and recovery behavior stay the same. No migration or operator action is required. The Doctor entry change only shares the existing lazy import across backup collection, legacy-state detection, and migration delegation; migration IDs, labels, input/output records, migration implementation, and config/default/schema definitions are unchanged.
Why This Change Was Made
Share the common work across explicit variants and derive redundant bookkeeping from the queues, promises, and records that own it. This includes command/model context, approval rendering, delivery fallback, callback preparation, cache traversal, polling acknowledgements, and throttle lane selection. Telegram continues to use plugin SDK seams and remains transport-only.
The candidate removes 1,159 net production lines: 1,154 in
extensions/telegram/srcplus five in the adjacent Doctor entry. All 273 original source files and 20 adjacent production modules were reviewed, with more than two hours of active implementation. Three test/support lookups adapt to the removed individual-handler registration seam; all test assertions remain unchanged. Assertion baseline changes are shrink-only.Evidence
Current candidate:
de996803ca6d8fbf913f41a698fc5d8e0e5c9502.Promise.withResolverswith the existing SDKcreateDeferredhelper. The strict Telegram package-boundary compile now passes with the unchanged ES2023 configuration; 51 polling/liveness tests, all 3 lint-suppression checks, and the deprecated-API guard passed. Runtime and static cycle checks report zero cycles.persistUpdateId, which callers detach from the persistence owner. Whole-directory Telegram type-aware lint and the strict package compile passed; 47 offset/polling cases and all 3 suppression checks passed in 149.19 seconds. Both cycle checks remain at zero. No tests changed.a3d253bb: complete changed-file check (production/test types, all lint batches, Knip and repository guards), full Telegram directory 167 files / 2,327 tests, complete build, both cycle checks, and SDK API comparison all passed. SDK comparison reported no Plugin SDK API changes. Audit/delivery/recovery correction coverage passed 93 tests. Only the SDK deferred import/call and offset callback function shape changed afterward; their package, polling, lint, cycle and suppression checks were refreshed as described above.The first hosted run failed
check-additional-extension-package-boundaryon the lane-owned ES2024 promise API use; its aggregateopenclaw/ci-gatefailed and fail-fast canceled 35 jobs. The SDK-helper correction passed that hosted package-boundary job atb02b7096. That run then failedcheck-lint-extensions-1on three lane-owned unbound-method diagnostics in unchanged callback consumers; its aggregate gate failed and 7 jobs were canceled. The arrow-function correction passed hosted CI onde996803. Duplicate startup workflows initially left canceled jobs; every affected workflow was rerun. The exhaustive exact-head check-run census after CI cancellation recovery records 129 successes, 103 scoped skips, one neutral result, and no failures or cancellations. No main-red or admin exception is used.Earlier proof retained at
1486e5ad, before the final two lint corrections: explicit E2Es 3 files / 40 tests, localhost HTTP 1 test, and four root integration files 59 tests all passed. Focused dependency selection also passed 57 Vitest shards before the lint corrections/base integrations; affected paths and the full Telegram directory were rechecked afterward. The modified E2E file passed all 13 cases with--maxWorkers=1: 377.89 seconds wall time (375.27 seconds reported by Vitest), including normal full build preparation on Linux. Committed test cases and assertions are unchanged.Exact-head macOS build passed in 5m25s; build metadata and both clean-input stamps matched the candidate. One canonical Telegram Test Server recording showed typing, same-message progress edits, commentary, successful
execoutput, and native replies to the trigger. Its fixed 30-second window ended before final delivery: final response headers arrived 289 ms after shutdown began, text delivery succeeded afterward, and progress deletion failed during teardown. Native final visibility and deletion remain unproved by that recording. Credentials, processes, and listeners were cleaned up. The Linux run below completes the missing lifecycle observation; the Mac cutoff is retained as a limitation of that attempt.Live Telegram Test Server proof passed on the exact reviewed source tree after a clean Linux AWS build (318 seconds). The canonical built Gateway scenario used unchanged 45-second startup and 30-second observation limits. Native Telegram events showed typing at 0.77 seconds; progress at 6.22 seconds with same-message commentary/tool edits at 7.27 and 9.36 seconds; a separate final at 14.70 seconds; and permanent progress deletion at 15.68 seconds. Progress and final both replied to the confirmed trigger, and final remained through the end of recording. The exact
execoutput was observed, with two main completions, one auxiliary recap, and three embeddings. Credential release, process/listener cleanup, private command-environment cleanup, and cloud lease release were verified. One preparation log-append timeout and one live upstream-fetch warning were retained; neither is counted as missing message proof or hidden by a retry. No timing limits changed.Local macOS attempts hit the unchanged 600-second full-tree Knip limit and 300-second SDK declaration-preparation limit. The complete Linux changed check passed with its normal limits. An earlier local action-runtime attempt had three 120-second timeouts and a following assertion polluted by late requests; the original-order file later passed all 36 cases on Linux, and the final full-directory suite passed. The original stall remains unexplained. No timeout, retry, skip, assertion, or lint suppression was weakened.
Investigated local test failures
The original
action-runtime.test.tsrun reported these cases in order:requires host-owned current-message authority for reactions, edits and deletes— 120-second timeout.binds a topicless reaction to trusted topic 77 without borrowing another chat— 120-second timeout.binds a topicless reaction to trusted topic 1 without borrowing another chat— 120-second timeout.rejects conflicting host authority, including threadless and missing-origin invocations— two unexpected latesetMessageReactionrequests before the expecteddeleteMessage.Source inspection locates the first awaited cache/state access before the throttler. The fixture clears a shared request array between cases but does not cancel timed-out test bodies, allowing later requests to contaminate a subsequent assertion. That explains a possible spillover path, not the original stall. The source differential validates scheduler ordering separately and does not model HTTP, grammY, or host contention. No test timeout, retry, skip, or assertion was changed.
On the rebased candidate, the complete file later passed all 36 cases in original order on Linux: 60.08 seconds in Vitest, 63 seconds for the wrapper. This did not reproduce the failure and is not claimed as a fix for the original stall.