Skip to content

refactor(telegram): consolidate command and transport handling - #167196

Merged
steipete merged 5 commits into
mainfrom
deslop/d05-p2-20261007
Oct 8, 2026
Merged

steipete merged 5 commits into
mainfrom
deslop/d05-p2-20261007

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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/src plus 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.

  • The package-boundary correction replaces direct Promise.withResolvers with the existing SDK createDeferred helper. 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.
  • The callback correction restores the arrow-function property for 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.
  • Managed review of the full repaired candidate and each subsequent correction completed with no actionable P0–P2 findings.
  • Broad proof at preceding head 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.
  • Supplemental exact-source proof: 1,032 scheduler interleavings / 37,491 requests per implementation; 176,196 mention-policy variants with 1,458 independent expectations and a detected negative control; 20 fast-command model-context cases; 94 binding-mutation cases. Unbind preserves per-iteration membership checks after awaited commits; lifecycle updates retain their prefiltered snapshot.

The first hosted run failed check-additional-extension-package-boundary on the lane-owned ES2024 promise API use; its aggregate openclaw/ci-gate failed and fail-fast canceled 35 jobs. The SDK-helper correction passed that hosted package-boundary job at b02b7096. That run then failed check-lint-extensions-1 on 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 on de996803. 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 exec output, 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 exec output 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.ts run reported these cases in order:

  1. requires host-owned current-message authority for reactions, edits and deletes — 120-second timeout.
  2. binds a topicless reaction to trusted topic 77 without borrowing another chat — 120-second timeout.
  3. binds a topicless reaction to trusted topic 1 without borrowing another chat — 120-second timeout.
  4. rejects conflicting host authority, including threadless and missing-origin invocations — two unexpected late setMessageReaction requests before the expected deleteMessage.

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.

@clawsweeper

clawsweeper Bot commented Oct 8, 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.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XL labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 11:32
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 8, 2026, 8:35 AM ET / 12:35 UTC (Revision 3).

ClawSweeper review

What this changes

This PR consolidates Telegram command, callback, delivery, cache, and transport handling while retaining existing behavior.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful consolidation with substantial recorded synthetic validation and no actionable finding, limited by the pending scoped live proof.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes
Reason: The change continues the area's established owner-led consolidation direction and reduces repeated maintenance within existing responsibilities.

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
Reviewed head: de996803ca6d8fbf913f41a698fc5d8e0e5c9502

Before merge

  • Complete next step (P2) - Complete and publish the already planned live Telegram Test Server verification for this candidate.
  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.

Findings

None.

Tests

  • Missing end-to-end proof: The planned live Telegram Test Server verification of the consolidated command, callback, and delivery paths remains pending. Reported synthetic, localhost, and test runs are supplemental; this read-only review executed no target code.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

Testing

Proof path: in-process harness. Added test files: 1.

Security

None.

Evidence

What I checked:

  • Pinned introduced patch: Inspected merge-base-to-head hunks across command, callback, authorization, transport, rendering, storage, and test-support paths, including files omitted from the supplied metadata. Endpoint drift was excluded from attribution. (de996803ca6d)
  • Latest correction: GitHub's exact-head commit patch changes only persistUpdateId from method syntax to an arrow-function property. The current owner preserves monotonic acceptance, retry, and shutdown behavior; monitor passes this callback detached from its owner. (extensions/telegram/src/update-offset-persistence.ts:85, de996803ca6d)
  • Detached callback consumer: The polling session receives offsetPersistence.persistUpdateId directly, confirming that the latest correction preserves the existing detached-callback contract. (extensions/telegram/src/monitor.ts:182, de996803ca6d)
  • Scoped live-proof requirement: The fully read Telegram guide requires real Telegram proof for touched transport, streaming, callback, authorization, and reply-context paths, plus crash-window or restart-replay coverage for reliability paths. (extensions/telegram/AGENTS.md:136, de996803ca6d)
  • Proof and re-review continuity: The complete REST-fetched body still explicitly marks live Telegram Test Server proof pending. It reports broad synthetic validation and focused checks after the two corrections, but no completed live result. REST comments and reviews provide no newer result. Captured context source identity: a8156f304cca80099e3fa76126f22d59cac18ccc163fd5d6853fc401e178985d. (de996803ca6d)
  • Accepted-delivery custody: The prepared sender retains one acceptance ledger, records physical message IDs before fallible observers, and derives partial-delivery IDs and visibility from that ledger. The revised text callers consume its first-message return value. (extensions/telegram/src/send-prepared.ts:94, de996803ca6d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

PR surface statistics unavailable: the file list is incomplete.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/telegram/doctor-contract-api.ts, unknown-truncated-pull-files. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is internal maintenance with no intended user-visible behavior change.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach the completed live Telegram Test Server result for the reviewed candidate.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-08T11:39:15.447Z sha a3d253b :: blocked before merge. :: none
  • reviewed 2026-10-08T12:09:18.156Z sha b02b709 :: blocked before merge. :: none

@steipete
steipete merged commit f353b88 into main Oct 8, 2026
264 of 331 checks passed
@steipete
steipete deleted the deslop/d05-p2-20261007 branch October 8, 2026 13:13
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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