Skip to content

refactor(telegram): split bot handler runtime - #106324

Merged
steipete merged 5 commits into
mainfrom
codex/refactor-telegram-bot-handlers-runtime
Jul 13, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/refactor-telegram-bot-handlers-runtime

Conversation

@steipete

@steipete steipete commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #106268

What Problem This Solves

The Telegram bot handler runtime concentrated unrelated authorization, callback, inbound message, migration, reaction, and message-event responsibilities in one 4,200-line module. That made ownership and focused maintenance difficult.

Why This Change Was Made

Split the runtime into a 20-line public composer plus 19 responsibility-owned runtime modules. Registration order, factory scope, behavior, configuration, and APIs remain unchanged. Every extracted module stays below 500 lines; the largest is 424 lines.

User Impact

No user-visible behavior change. Maintainers get smaller modules with clearer responsibility boundaries.

Evidence

  • Exact head: 5def24fc7b05b349f8d08d5543891debc006642f.
  • Blacksmith Testbox through Crabbox: tbx_01kxe3zrth9srfg7kvp9pk4xen; Actions run.
  • pnpm check:changed: passed formatting, production/test TypeScript, lint, import-cycle, and repository guards.
  • pnpm test:extension telegram: 143 files and 2,727 tests passed.
  • Exact-head hosted CI run 29265917500: passed.
  • Fresh autoreview cohorts and both follow-up reviews: no accepted/actionable findings remain.

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XL maintainer Maintainer-authored PR labels Jul 13, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at exact head b55ea436eb20486b5ad70abafa60104d3f343593.

Proof:

  • Testbox tbx_01kxdhx6ybfqx079esq1vk72hg, Actions run 29244467773: pnpm check:changed -- <eight Telegram runtime files> passed; pnpm test:extension telegram passed 143 files / 2,727 tests.
  • Focused bot-handlers.runtime.test.ts + bot.test.ts: 121 tests passed before and after extraction.
  • Hosted CI identified two extraction-local unused exports. Commit b55ea436 removes them; Testbox tbx_01kxdjqf89jb6jcyq8v0x0zvvg then passed scoped check:changed with format, production/test TS, lint, import-cycle, and repository guards.
  • Fresh autoreview cohorts and the follow-up fix review: no accepted/actionable findings.

Known gap/baseline:

  • No live Telegram probe: this is an internal extraction with preserved handler order and no transport/API/config behavior change.
  • Full deadcode/lint currently retain unrelated failures in src/config/sessions/types.ts, src/gateway/server-lanes.ts, and src/agents/session-suspension.ts; current main reproduces both in run 29245055685. The two Telegram deadcode findings are gone.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling extensions: copilot labels Jul 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 377c734596

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +72 to +73
if (!agentId) {
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include unprefixed sessions in transcript search

When the visible list contains unprefixed/default sessions such as main, resolveAgentId(row.key) returns undefined, so this continue drops those rows from keysByAgent. The previous page-level transcript search still covered the default agent, and the gateway supports disambiguating unscoped sessionKeys with agentId; with this change, transcript search on an all-default Sessions page can silently return no results even though the visible main transcript matches. Please group unprefixed keys under the resolved default/selected agent instead of skipping them.

Useful? React with 👍 / 👎.

@@ -20,6 +20,7 @@ async function loadSessionsRoute(
const gatewaySnapshot = gateway.snapshot;
const options = routeOptions(location);
const checkpointAgentId = parseAgentSessionKey(options.expandedSessionKey)?.agentId;
const scopeAgentId = checkpointAgentId ?? context.agentSelection.state.scopeId;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep unprefixed session deep links unscoped

When a user is scoped to another agent and opens a deep link like /settings/sessions?session=main, parseAgentSessionKey() returns no checkpointAgentId, so this falls back to the current page scope and the loader sends sessions.list with search=main plus that unrelated agentId. The previous behavior only scoped prefixed deep links, and sessionListOptions() still leaves unprefixed deep links unscoped; this change can show an empty page for a valid shared/default session link. Keep deep-link lookups unscoped unless the session key itself identifies an agent.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Jul 13, 2026
@clawsweeper

clawsweeper Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 13, 2026, 8:31 AM ET / 12:31 UTC.

Summary
Extracts the Telegram bot-handler runtime into responsibility-owned modules while also changing workflows, macOS logging, Copilot bridging, gateway cron protocol, release scripts, session scoping, and Control UI behavior.

Reproducibility: yes. at source level: the unchanged head still skips session keys whose agent cannot be parsed and scopes unprefixed deep links to the current selected agent. No live runtime reproduction was supplied.

Review metrics: 2 noteworthy metrics.

  • Gateway protocol parameters: 1 optional parameter added (CronRunsParams.agentId). A public protocol surface changes inside a PR presented as behavior-preserving Telegram-only refactoring.
  • Supply-chain and workflow surface: 1 macOS dependency floor changed; 1 workflow write step added. These unrelated changes require separate dependency and automation review before merge.

Stored data model
Persistent data-model change detected: migration/backfill/repair: extensions/telegram/src/bot-handlers.migration.runtime.ts, migration/backfill/repair: scripts/lib/cross-os-release-checks/config.ts, persistent cache schema: scripts/ci-changed-scope.mjs, persistent cache schema: ui/src/pages/agents/identity-actions.ts, serialized state: scripts/lib/cross-os-release-checks/agent.ts, serialized state: scripts/lib/cross-os-release-checks/network-smokes.ts, and 16 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #106268
Summary: The linked issue is the canonical tracker for the Telegram runtime split, and this PR is its current implementation candidate, though the branch requires rebuilding before it is viable.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Rebuild the branch from current main with only the Telegram extraction and focused tests.
  • [P1] Add redacted live Telegram smoke evidence covering representative inbound, callback, reaction, and migration behavior.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Tests, checks, and CI are strong supplemental evidence, but the PR explicitly lacks a live Telegram probe; add a redacted transcript, terminal/live output, or runtime logs from representative handlers, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • [P1] The branch is not a reviewable behavior-preserving Telegram extraction: merging it could import unrelated workflow, dependency, protocol, provider, session, release, and UI behavior.
  • [P1] The session changes can silently omit unprefixed default-session transcript results and hide valid unprefixed deep links under an unrelated agent scope.
  • [P1] The workflow write step and extensive cross-OS release-script changes alter automation behavior independently of the Telegram refactor.
  • [P1] No real Telegram setup has demonstrated that representative message, callback, reaction, migration, and replay paths behave identically after extraction.
  • [P1] GitHub reports the current head as dirty and not cleanly mergeable, so current-main integration needs a refreshed branch and review.

Maintainer options:

  1. Rebuild from current main (recommended)
    Create a clean Telegram-only branch, preserve the existing public entry point and registration order, and rerun focused plus live Telegram validation.
  2. Accept the combined surface
    Land the broad branch only after owners explicitly review the unrelated compatibility, session, dependency, protocol, and automation changes with fresh-install and upgrade evidence.
  3. Pause this landing candidate
    Close or supersede this dirty branch with a fresh narrow PR if most unrelated changes would otherwise need to be discarded during review.

Next step before merge

  • [P1] A human owner should rebuild or explicitly rescope the dirty protected-label branch, resolve the two session regressions, and require real Telegram proof before considering merge.

Maintainer decision needed

  • Question: Should this branch be rebuilt as a Telegram-only refactor, or should maintainers intentionally review and accept the unrelated protocol, UI, dependency, provider, release-script, and automation changes as one combined landing?
  • Rationale: The linked issue explicitly scopes the work to behavior-preserving Telegram extraction, but the current dirty branch changes many unrelated compatibility-sensitive surfaces; automation cannot safely choose which changes are intended.
  • Likely owner: steipete — This person sponsored the linked refactor and has the strongest recent merged history on the central Telegram runtime boundary.
  • Options:
    • Rebuild Telegram-only (recommended): Rebase or recreate the branch from current main with only the handler extraction and its focused tests, then add real Telegram smoke proof.
    • Review as combined landing: Keep the broad branch only if maintainers explicitly own every unrelated behavior, dependency, protocol, automation, and upgrade impact and provide corresponding proof.
    • Close and replace: Close this branch and open a fresh narrow PR if separating the existing history is more expensive than recreating the Telegram extraction.

Security
Needs attention: The Telegram extraction itself shows no clear security regression, but unrelated dependency, workflow, provider-bridge, and release-execution changes create a concrete supply-chain review concern.

Review findings

  • [P1] Split unrelated changes out of this Telegram refactor — .github/workflows/control-ui-locale-refresh.yml:279
  • [P2] Include unprefixed sessions in transcript search — ui/src/pages/sessions/agent-scope.ts:76
  • [P2] Keep unprefixed session deep links unscoped — ui/src/pages/sessions/route.ts:23
Review details

Best possible solution:

Recreate the change from current main as a Telegram-only extraction preserving registration order and shared lifecycle state, include focused regression coverage, and attach a redacted live Telegram smoke transcript or runtime logs before merge.

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

Yes at source level: the unchanged head still skips session keys whose agent cannot be parsed and scopes unprefixed deep links to the current selected agent. No live runtime reproduction was supplied.

Is this the best way to solve the issue?

No. Extracting the Telegram runtime is reasonable, but carrying unrelated compatibility-sensitive changes in the same dirty branch is not the narrowest or safest implementation.

Full review comments:

  • [P1] Split unrelated changes out of this Telegram refactor — .github/workflows/control-ui-locale-refresh.yml:279
    This PR is described as a behavior-preserving Telegram extraction, but the same branch changes Control UI workflows, macOS dependencies and logging, Copilot SDK behavior, gateway protocol, release scripts, sessions, cron, and UI behavior. Because the head is also dirty against current main, merging it cannot be reviewed as the scoped refactor requested by the linked issue. Rebuild or cherry-pick the Telegram extraction onto current main so unrelated changes are excluded.
    Confidence: 0.99
  • [P2] Include unprefixed sessions in transcript search — ui/src/pages/sessions/agent-scope.ts:76
    When a visible/default session key is unprefixed, resolveAgentId returns no agent and the new grouping path drops that session entirely. Group unprefixed keys under the resolved selected/default agent so transcript search still covers valid default sessions.
    Confidence: 0.96
  • [P2] Keep unprefixed session deep links unscoped — ui/src/pages/sessions/route.ts:23
    Falling back from an unprefixed deep-link key to the current agent scope can send sessions.list with an unrelated agentId, producing an empty page for a valid shared/default session. Only scope a deep-link lookup when the session key itself identifies an agent.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add merge-risk: 🚨 session-state: The added session-scoping logic can omit unprefixed transcript sessions and hide valid deep-linked sessions under the wrong agent scope.

Label justifications:

  • P2: This is a useful maintainability refactor, but the current branch has limited-blast-radius regressions and broad merge risk rather than an emergency user outage.
  • merge-risk: 🚨 compatibility: The branch changes a macOS dependency, Copilot SDK behavior, gateway protocol, UI routes/default scoping, and other surfaces outside the stated refactor.
  • merge-risk: 🚨 session-state: The added session-scoping logic can omit unprefixed transcript sessions and hide valid deep-linked sessions under the wrong agent scope.
  • merge-risk: 🚨 automation: The diff changes workflow mutation behavior and substantially restructures cross-OS release automation independently of the Telegram extraction.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Tests, checks, and CI are strong supplemental evidence, but the PR explicitly lacks a live Telegram probe; add a redacted transcript, terminal/live output, or runtime logs from representative handlers, then update the PR body to trigger review or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

Security concerns:

  • [medium] Separate unrelated supply-chain and execution changes — apps/macos/Package.swift:20
    The branch changes the macOS swift-log dependency floor and workflow/release execution paths despite a Telegram-only stated purpose; these changes need independent provenance and behavior review rather than riding with the refactor.
    Confidence: 0.92

What I checked:

  • Unchanged reviewed head: The current PR head is still 377c734, exactly matching the previous ClawSweeper review, so all three previously reported findings remain applicable. (377c7345969a)
  • Scope contamination: The branch adds a generated-artifact write step to a Control UI workflow despite the stated Telegram-only refactor scope; the supplied diff also contains unrelated macOS, Copilot, protocol, release-script, session, and UI behavior changes. (.github/workflows/control-ui-locale-refresh.yml:279, 377c7345969a)
  • Unprefixed transcript sessions omitted: The new transcript-search fan-out groups sessions only when resolveAgentId returns an agent, dropping valid unprefixed/default session keys instead of associating them with the selected or default agent. (ui/src/pages/sessions/agent-scope.ts:76, 377c7345969a)
  • Unprefixed deep links mis-scoped: The sessions route falls back from an unprefixed deep-link key to the current global agent scope, allowing an unrelated selected agent to hide a valid shared/default session. (ui/src/pages/sessions/route.ts:23, 377c7345969a)
  • Only test and CI proof supplied: The PR body explicitly states that no live Telegram probe was run; focused tests, extension tests, checks, and CI are useful supplemental evidence but do not prove the extracted handlers in a real Telegram setup. (extensions/telegram/src/bot-handlers.runtime.ts:1, 377c7345969a)
  • Canonical linked issue: The linked maintainer-scoped issue requests a behavior-preserving Telegram-only extraction with no config, protocol, storage, or public API changes, which conflicts with the branch's broader diff. (extensions/telegram/src/bot-handlers.runtime.ts:1, 377c7345969a)

Likely related people:

  • steipete: Prior merged history ties this person to Telegram handler, configuration, doctor, and loop-protection work, and the linked issue describes this as a maintainer-requested refactor. (github.com) (role: recent Telegram architecture contributor and issue sponsor; confidence: high; commits: 1109abc94701, 2fe39ce94957, 5ac6b600de45; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/doctor.ts, src/config/types.telegram.ts)
  • obviyus: Recent merged work touched Telegram inbound context boundaries, edited-message handling, and reply-context behavior adjacent to the extracted message runtime. (github.com) (role: recent Telegram runtime and context contributor; confidence: high; commits: 5abb4b18c8f0, f79117e47963, 345d45914398; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-message-context.ts)
  • vincentkoc: Recent merged changes touched Telegram message ordering, handler behavior, and configuration fields near the refactored authorization and event surfaces. (github.com) (role: adjacent Telegram runtime and configuration contributor; confidence: medium; commits: 5b418c3c4fef, c5488ea5774a, 2f589aacf9b7; files: extensions/telegram/src/bot-handlers.runtime.ts, extensions/telegram/src/bot-updates.ts, src/config/types.telegram.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-13T12:16:37.058Z sha 377c734 :: needs real behavior proof before merge. :: [P1] Split unrelated changes out of this Telegram refactor | [P2] Include unprefixed sessions in transcript search | [P2] Keep unprefixed session deep links unscoped

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Jul 13, 2026
@steipete
steipete force-pushed the codex/refactor-telegram-bot-handlers-runtime branch from 377c734 to 13e2ae3 Compare July 13, 2026 15:08
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling extensions: copilot labels Jul 13, 2026
@steipete
steipete force-pushed the codex/refactor-telegram-bot-handlers-runtime branch from 13e2ae3 to d0efd89 Compare July 13, 2026 16:05
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at 5def24fc7b05b349f8d08d5543891debc006642f.

  • Shape: extensions/telegram/src/bot-handlers.runtime.ts is now a 20-line public composer; 19 responsibility-owned runtime modules, all below 500 lines (largest: 424).
  • Review: repo-native artifacts validated with READY FOR /prepare-pr, zero findings. Fresh autoreview covered authorization, callback, inbound, and message cohorts; callback-result and file-local-type follow-ups are clean.
  • Testbox: tbx_01kxe3zrth9srfg7kvp9pk4xen, run 29265426390. pnpm check:changed passed; pnpm test:extension telegram passed 143 files / 2,727 tests.
  • Hosted exact-head CI: run 29265917500 passed.
  • Gap: no live Telegram probe; this is an internal extraction with registration order, factory scope, and grammY API results preserved.

@steipete
steipete merged commit 4a84117 into main Jul 13, 2026
105 checks passed
@steipete
steipete deleted the codex/refactor-telegram-bot-handlers-runtime branch July 13, 2026 16:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 14, 2026
* refactor(telegram): split bot handler runtime

* fix(telegram): keep extracted helper types local

* refactor(telegram): bound bot handler modules

* fix(telegram): name callback action results

* fix(telegram): keep inbound input types local
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 merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(telegram): split bot handler runtime by responsibility

1 participant