Skip to content

fix(telegram): initialize isolated polling bot - #81975

Merged
steipete merged 4 commits into
openclaw:mainfrom
neeravmakwana:fix/telegram-isolated-ingress-init
May 15, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
neeravmakwana:fix/telegram-isolated-ingress-init

Conversation

@neeravmakwana

@neeravmakwana neeravmakwana commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Initialize the grammY bot before isolated polling ingress drains spooled updates through handleUpdate.
  • Keep the existing recoverable setup retry path for init failures so transient Telegram/network errors restart the polling cycle instead of wedging the drain.
  • Add a focused Telegram polling-session regression that asserts init completes before the spooled update handler runs.

Root Cause

Isolated polling ingress bypasses @grammyjs/runner and dispatches spooled updates directly through bot.handleUpdate(update). grammY requires bot.init() or constructor botInfo before handleUpdate; most polling bots are created without botInfo, so isolated ingress could repeatedly fail with Bot not initialized! and leave spool files in place.

Linked Issue

Fixes #81973.

Why This Is Safe

bot.init() is grammY's normal initialization path and is idempotent when bot info is already available. The change runs only in the isolated-ingress path, before the worker and drain timer start, and reuses the existing recoverable setup retry behavior.

Security / Runtime Controls

Security posture and runtime policy are unchanged. This does not change Telegram token handling, webhook cleanup policy, ingress spool file ownership, message filtering, command authorization, or prompt text; it only initializes the existing bot instance before dispatching updates.

Real Behavior Proof

Behavior addressed: isolated polling ingress no longer calls handleUpdate on an uninitialized grammY bot.
Real environment tested: local PR checkout/package OpenClaw 2026.5.14 (cbba677) with a real Telegram bot token from local env, public Telegram config, and default isolated polling ingress.
Exact steps or command run after this patch: verified Bot API getMe; ran focused Telegram tests; attempted the official direct Telegram QA env lane; then started the PR gateway with TELEGRAM_BOT_TOKEN and sent a real Telegram /status DM to the bot.
Evidence after fix: redacted runtime log and terminal output from a real Telegram gateway run after this patch:

$ openclaw --version
OpenClaw 2026.5.14 (cbba677)
$ openclaw gateway start
[telegram][diag] isolated polling ingress started spool=<redacted>
[telegram] sendMessage ok chat=<redacted> message=<redacted>
$ rg "Bot not initialized" /tmp/openclaw/openclaw-<redacted>.log
(no matches)

Observed result after fix: Telegram isolated polling initialized the grammY bot, processed the inbound update, and sent a Telegram reply successfully.
What was not tested: the official bot-to-bot openclaw qa telegram lane did not run from this local env because it requires OPENCLAW_QA_TELEGRAM_GROUP_ID plus distinct driver/SUT bot tokens; the provided env had only the SUT-style telegram_bot_token.

Out Of Scope

  • Changing isolated ingress worker polling behavior or spool persistence format.
  • Changing Telegram webhook cleanup, token resolution, or delivery policy.
  • Adding live Telegram E2E coverage.

AI-assisted: yes.

Made with Cursor

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XS triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 15, 2026
@clawsweeper

clawsweeper Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR calls bot.init() before Telegram isolated polling starts its worker and drains spooled updates, updates the regression test, aligns Telegram type imports, adjusts the test tsconfig root, and adds a changelog entry.

Reproducibility: yes. Source inspection shows current main can call handleUpdate in isolated ingress without grammY initialization, and grammY 1.42.0 throws until init() or constructor botInfo supplies bot info.

Real behavior proof
Override: A maintainer applied proof: override for this PR.

Next step before merge
No ClawSweeper repair lane is needed; this is an active focused PR with proof override and no actionable review finding.

Security
Cleared: The diff initializes an existing Telegram bot instance and updates tests/types/changelog; it does not change secrets handling, workflows, dependencies, package resolution, or install/build scripts.

Review details

Best possible solution:

Land the narrow Telegram initialization fix after normal PR checks and maintainer review, then close #81973 through the merged PR.

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

Yes. Source inspection shows current main can call handleUpdate in isolated ingress without grammY initialization, and grammY 1.42.0 throws until init() or constructor botInfo supplies bot info.

Is this the best way to solve the issue?

Yes. Calling grammY's idempotent bot.init() before isolated worker startup and spool drain is the narrow owner-local fix, and preserving the existing recoverable setup retry path is maintainable.

What I checked:

  • Current main bypasses runner initialization: runUntilAbort selects #runIsolatedIngressCycle(bot) when isolated ingress is enabled, so this path does not use @grammyjs/runner's automatic init path. (extensions/telegram/src/polling-session.ts:161, 916fc3d09ae1)
  • Current main drains via handleUpdate without init: The isolated spool drain calls params.bot.handleUpdate(...); #runIsolatedIngressCycle currently starts the worker and drain without first initializing the grammY bot. (extensions/telegram/src/polling-session.ts:269, 916fc3d09ae1)
  • Bot construction can leave grammY uninitialized: createTelegramBotCore only passes botInfo when opts.botInfo exists, so normal polling bot construction can produce a bot that needs init() before direct handleUpdate. (extensions/telegram/src/bot-core.ts:137, 916fc3d09ae1)
  • Dependency contract matches the fix: grammY 1.42.0 throws Bot not initialized! from handleUpdate when bot info is missing; @grammyjs/runner 2.0.3 calls bot.init() before its normal first update fetch.
  • PR patch targets the implicated path: The PR head calls await bot.init() before worker creation and routes init failures through the existing recoverable setup retry helper. (extensions/telegram/src/polling-session.ts:318, d8001f64552c)
  • Regression coverage checks init ordering: The PR's focused isolated-spool test adds a mocked init and asserts it is called before handleUpdate. (extensions/telegram/src/polling-session.test.ts:390, d8001f64552c)

Likely related people:

  • joshavant: Commit fd244fd added the Telegram polling ingress/spool path and regression coverage around the implicated isolated polling cycle. (role: introduced isolated ingress behavior; confidence: high; commits: fd244fd76de3; files: extensions/telegram/src/polling-session.ts, extensions/telegram/src/polling-session.test.ts, extensions/telegram/src/telegram-ingress-worker.runtime.ts)
  • steipete: Current-main blame for the central polling-session path points to 0844e77, and recent Telegram bot-core/polling history includes 42f6d90 on adjacent API timeout setup. (role: recent area contributor; confidence: medium; commits: 0844e771a8df, 42f6d909170e; files: extensions/telegram/src/polling-session.ts, extensions/telegram/src/bot-core.ts)
  • VACInc: Commit 3f13237 updated isolated spool lane draining and adjacent tests in the same path. (role: recent adjacent drain contributor; confidence: medium; commits: 3f132370f4a3; files: extensions/telegram/src/polling-session.ts, extensions/telegram/src/polling-session.test.ts)
  • obviyus: Commit 52c9860 simplified spooled lane tracking, and obviyus committed the adjacent VACInc drain fix. (role: recent adjacent owner/merger; confidence: medium; commits: 52c9860bdecf, 3f132370f4a3; files: extensions/telegram/src/polling-session.ts, extensions/telegram/src/polling-session.test.ts)

Remaining risk / open question:

  • I did not run tests in this read-only sweep; the focused regression result comes from the maintainer comment and PR discussion, while CI remains the normal merge gate.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 916fc3d09ae1.

@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label May 15, 2026
@neeravmakwana

Copy link
Copy Markdown
Contributor Author

Updated the PR body with redacted real Slack bot-to-bot QA proof from this branch:

  • OPENCLAW_ENABLE_PRIVATE_QA_CLI=1 OPENCLAW_QA_REDACT_PUBLIC_METADATA=1 node scripts/run-node.mjs qa slack --credential-source env --provider-mode mock-openai --scenario slack-canary --output-dir .artifacts/qa-e2e/slack-pr81975-pass
  • Result: Slack canary echo passed, reply matched in 6201ms, 1 passed / 0 failed scenarios.
  • Also verified the package install reports OpenClaw 2026.5.14 (cbba677).

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 15, 2026
@clawsweeper

clawsweeper Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed proof: supplied External PR includes structured after-fix real behavior proof. labels May 15, 2026
@neeravmakwana

Copy link
Copy Markdown
Contributor Author

Added Telegram-specific proof to the PR body.

Redacted local proof from this PR checkout:

  • Installed package reports OpenClaw 2026.5.14 (cbba677).
  • Focused Telegram tests passed: polling-session.test.ts and telegram-live.runtime.test.ts (58 tests total).
  • Bot API getMe succeeded with the local telegram_bot_token (token not printed).
  • Official openclaw qa telegram --credential-source env could not start from this .env alone because it requires OPENCLAW_QA_TELEGRAM_GROUP_ID and distinct driver/SUT bot tokens.
  • Real Telegram gateway proof succeeded: the PR checkout started Telegram provider @<redacted>, logged isolated polling ingress startup, then after a real /status DM it logged sendMessage ok chat=<redacted> message=<redacted> with no Bot not initialized! error.

@clawsweeper re-review

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 15, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 15, 2026
@steipete steipete added the proof: override Maintainer override for the external PR real behavior proof gate. label May 15, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 15, 2026
@steipete
steipete force-pushed the fix/telegram-isolated-ingress-init branch from cbba677 to 13a4d0e Compare May 15, 2026 06:29
@steipete

Copy link
Copy Markdown
Contributor

Verification for maintainer merge:

Behavior addressed: Telegram isolated polling now initializes the grammY bot before the isolated ingress worker drains spooled updates, so handleUpdate() no longer runs before bot.init().

Local proof on PR head d8001f64552c67570d41fdb6de747f2545c93f5b:

node scripts/run-vitest.mjs extensions/telegram/src/polling-session.test.ts
pnpm tsgo:prod
pnpm check:test-types
node node_modules/@typescript/native-preview/bin/tsgo.js -p extensions/telegram/tsconfig.json --noEmit --incremental --tsBuildInfoFile extensions/telegram/dist/.boundary-tsc-fix-81975.tsbuildinfo
git diff --check

Observed result after fix: focused Telegram polling regression passes; prod types, test types, Telegram package-boundary compile, and whitespace check pass locally.

CI proof on PR head d8001f64552c67570d41fdb6de747f2545c93f5b:

CI run: https://github.com/openclaw/openclaw/actions/runs/25904354858
CodeQL Critical Quality run: https://github.com/openclaw/openclaw/actions/runs/25904354878
Real behavior proof run: https://github.com/openclaw/openclaw/actions/runs/25904353898

Known proof gaps: no new live Telegram token run by me; PR body and issue comments include redacted real deployment proof showing isolated polling starts, Telegram replies send, and no Bot not initialized matches after the patch.

@steipete
steipete merged commit 1109abc into openclaw:main May 15, 2026
109 of 111 checks passed
@neeravmakwana
neeravmakwana deleted the fix/telegram-isolated-ingress-init branch May 15, 2026 12:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram mantis: telegram-visible-proof Mantis should capture Telegram visible proof. proof: override Maintainer override for the external PR real behavior proof gate. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Isolated polling ingress never calls bot.init() — Telegram channel halts with "Bot not initialized"

2 participants