Skip to content

fix(telegram): message_sent plugin hooks lose the session key - #197670

Closed
rodricksz4h5 wants to merge 1 commit into
openclaw:mainfrom
rodricksz4h5:fix/telegram-message-sent-session-key
Closed

rodricksz4h5 wants to merge 1 commit into
openclaw:mainfrom
rodricksz4h5:fix/telegram-message-sent-session-key

Conversation

@rodricksz4h5

@rodricksz4h5 rodricksz4h5 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #197669
Related: #197186

What Problem This Solves

Fixes: plugin message_sent hooks get no sessionKey for Telegram sends, so plugins that match a send to its session (alongside agent_end, llm_output or message_sending) cannot correlate Telegram replies.

User Impact

User impact: plugins observing message_sent now receive the session key for Telegram replies, finalized previews and native plugin command sends, the same as on the core outbound path and Slack. Sends without a session are unchanged.

Why This Change Was Made

emitTelegramMessageSentHooks already receives the session key from every caller and uses it for the internal message:sent hook, but left it out of the canonical context that feeds the plugin hook. It now passes sessionKeyForInternalHooks through: the canonical runtime session key, with no policy-key fallback, as established for shared outbound hooks in #73706. It's the same key core and Slack pass to message_sent, and the one #197519 forwards to message_sending, so both hooks correlate on one value.

Evidence

  • Real Gateway proof (isolated mock-Gateway harness, two runs each). I ran the source Gateway the same way the Telegram e2e runner's --source-gateway mode does: node --import ./scripts/tsx.mjs src/entry.ts gateway, plugins.load.paths → extensions/telegram, OPENCLAW_BUNDLED_PLUGINS_DIR set, isolated state, fake bot token. The only stand-in was Telegram's Bot API, a local HTTP server reached through channels.telegram.apiRoot. A real plugin loaded from disk registers /plug and a message_sent hook that records what it receives. A DM /plug update arrives through the real polling ingress, is dispatched as a native command, and is answered with sendMessage:

    Run Telegram send Plugin message_sent ctx.sessionKey / event.sessionKey
    main (fix line removed), runs 1 and 2 sendMessage chat 4242 "Choose a deployment", success absent / absent
    this PR, runs 1 and 2 sendMessage chat 4242 "Choose a deployment", success agent:main:main / agent:main:main

    The same /plug command was registered through setMyCommands in every run. Removing the one fix line is the only difference between the rows.

    Redacted after-fix trace (this PR)
    [telegram] [default] starting provider (@proof_sut_bot)
    [telegram] [diag] isolated polling ingress started account=default
    bot-api  setMyCommands  commands include "plug"
    bot-api  getUpdates  -> update_id=1 message chat=4242 text="/plug" entities=[bot_command]
    [telegram] [diag] isolated polling worker batch received queued=1
    [telegram] [diag] isolated polling batch spooled updateId=1
    bot-api  sendMessage  chat_id=4242 text="Choose a deployment"
    plugin   message_sent ctx={channelId:"telegram", conversationId:"4242", sessionKey:"agent:main:main"} event={sessionKey:"agent:main:main", success:true, content:"Choose a deployment"}
    

    On main, the same trace ends with no sessionKey in either ctx or event. Chat and user ids are synthetic; the token and local ports are omitted.

    Live gap: the repo's Telegram Test Server userbot proof uses Convex-leased team credentials, which I don't have access to as an outside contributor. Happy for a maintainer to run it if needed.

  • Regression: the existing native-command delivery test ("settles a progress edit once") now also asserts the plugin hook context's session key. On main it fails (expected [ undefined ] to deeply equal [ 'agent:main:main' ]); with this change the file passes 19/19. Net 0 test lines.

  • Related Telegram suites pass (96 tests across 7 files): delivery (paragraphs, media resolution), finalized-preview lifecycle, dispatch transcript, native-command concurrency and send recovery.

  • check:changed ratchets pass (line-cap, max-lines, assertion-safety, test-timeout-race, test-mock-exports), plus format and oxlint. Locally on Windows the oxlint wrapper falls back to non-type-aware linting, so type-aware lint is left to CI.

  • Typecheck: the Telegram package and the changed test file (under the extension-test config) report 0 errors.

  • Local review: autoreview isn't set up here. Reviewed manually instead: traced all four emitTelegramMessageSentHooks callers, confirmed the internal message:sent hook is unchanged, and checked the field against PluginHookMessageContext.sessionKey.

@clawsweeper

clawsweeper Bot commented Nov 12, 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: XS labels Nov 12, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head dcd3ad5ce987f2ea1d45597760250227164eb2d7, but the PR head is now 3e9964d7c6f7d628e3a5df19f44b063aefb3e8f9. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (2 earlier review cycles)
  • reviewed 2026-11-12T09:44:34.636Z sha dcd3ad5ce987f2ea1d45597760250227164eb2d7 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-12T10:48:40.779Z sha dcd3ad5ce987f2ea1d45597760250227164eb2d7 :: needs maintainer review before merge. :: none

@rodricksz4h5

Copy link
Copy Markdown
Contributor Author

Added real-behavior proof to the PR body: a source Gateway with only Telegram's Bot API stood in. A DM /plug native command goes through the real polling ingress and is answered by sendMessage. Across two runs each, the registered plugin's message_sent hook gets no sessionKey on main and agent:main:main (in both ctx and event) with this change. The redacted trace is in the body.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 12, 2026
emitTelegramMessageSentHooks received sessionKeyForInternalHooks from every
caller and used it for the internal message:sent hook, but left it out of
the canonical context that feeds the plugin message_sent hook, so plugins
saw ctx.sessionKey undefined for every Telegram send. Pass the canonical
runtime session key through, with no policy-key fallback, as core and Slack
already do (see openclaw#73706).
@rodricksz4h5
rodricksz4h5 force-pushed the fix/telegram-message-sent-session-key branch from dcd3ad5 to 3e9964d Compare November 12, 2026 10:54
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Nov 12, 2026
@clawsweeper clawsweeper Bot removed the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Nov 12, 2026
obviyus added a commit to lester076/openclaw that referenced this pull request Nov 13, 2026
Telegram's message_sent plugin hook context dropped the session key it
already forwards to the internal message:sent hook. Pass the same canonical
runtime key so message_sending and message_sent correlate on one value.

Folds in openclaw#197670 and covers both hooks with one delivery regression; the
test-line allocation is no longer needed under the 400-line budget.

Co-authored-by: rodricksz4h5 <[email protected]>
Co-authored-by: obviyus <[email protected]>
obviyus added a commit that referenced this pull request Nov 13, 2026
…197519)

* fix(telegram): pass the runtime session key to message_sending hooks

* chore(config): allocate test-line growth for the telegram hook session-key regressions

* fix(telegram): pass the runtime session key to message_sent hooks

Telegram's message_sent plugin hook context dropped the session key it
already forwards to the internal message:sent hook. Pass the same canonical
runtime key so message_sending and message_sent correlate on one value.

Folds in #197670 and covers both hooks with one delivery regression; the
test-line allocation is no longer needed under the 400-line budget.

Co-authored-by: rodricksz4h5 <[email protected]>
Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: lester076 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: rodricksz4h5 <[email protected]>
Co-authored-by: obviyus <[email protected]>
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this fix. Your message_sent change was carried into #197519 (co-author credit on commit ac1cab1), which landed as ec46689 together with the matching message_sending half and one regression covering both hooks.

Live proof on Telegram Test Server (real user DM, built Gateway, hook-recording plugin): on main 8ebe740 both hooks reported sessionKey: null; on the landed head both hooks reported the runtime session key for every reply.

Closing as superseded by #197519.

@obviyus obviyus closed this Nov 13, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…penclaw#197519)

* fix(telegram): pass the runtime session key to message_sending hooks

* chore(config): allocate test-line growth for the telegram hook session-key regressions

* fix(telegram): pass the runtime session key to message_sent hooks

Telegram's message_sent plugin hook context dropped the session key it
already forwards to the internal message:sent hook. Pass the same canonical
runtime key so message_sending and message_sent correlate on one value.

Folds in openclaw#197670 and covers both hooks with one delivery regression; the
test-line allocation is no longer needed under the 400-line budget.

Co-authored-by: rodricksz4h5 <[email protected]>
Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: lester076 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: rodricksz4h5 <[email protected]>
Co-authored-by: obviyus <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 14, 2026
…197519)

* fix(telegram): pass the runtime session key to message_sending hooks

* chore(config): allocate test-line growth for the telegram hook session-key regressions

* fix(telegram): pass the runtime session key to message_sent hooks

Telegram's message_sent plugin hook context dropped the session key it
already forwards to the internal message:sent hook. Pass the same canonical
runtime key so message_sending and message_sent correlate on one value.

Folds in #197670 and covers both hooks with one delivery regression; the
test-line allocation is no longer needed under the 400-line budget.

Co-authored-by: rodricksz4h5 <[email protected]>
Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: lester076 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: rodricksz4h5 <[email protected]>
Co-authored-by: obviyus <[email protected]>
(cherry picked from commit ec46689)

Release adaptation: none. The runtime key, canonical hook context mapper
and loopback Bot API fixture are present on this baseline. Both sending
and sent hooks use runtime identity, never the acted-on policy key.

Companion audit: #197670 is folded into this selected squash, not a
separate dependency. No later same-path or PR-number follow-ups through
7bccde6. SDK hook exports and fixture producers are present-equivalent.

Proof: git diff --check passed. Focused Vitest/typecheck/lint unavailable:
this isolated worktree has no node_modules; no dependencies were installed.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit 1c5e22bb5e97a9a00b1fd291e98be14b02b38d02)
RomneyDa added a commit that referenced this pull request Nov 15, 2026
Port Telegram callbacks, hook session keys, private-topic approvals and
interactive widgets with complete send/edit/route security companions.
Include Feishu captioned media, iOS permission Sendable callbacks,
WebKit animation/menu retirement and pending automations props handling.
Keep Matrix malformed formatted-mention parsing linear-time.
Adapt the 11.4 equivalents to the fixed beta baseline where available.

Source PRs: #196217, #191585, #196822, #194027, #197519, #198038,
#196991, #198380, #198658, #184432. Companion scope: #191647, #192162,
#198022, #197271, #194146; #197670 is folded into #197519 equivalent.

(cherry picked from commit 928c118)
(cherry picked from commit 569ca48)
(cherry picked from commit efa744e)
(cherry picked from commit c301da9)
(cherry picked from commit 641c4d5)
(cherry picked from commit b9d3fb4)
(cherry picked from commit a213a51)
(cherry picked from commit ec46689)
(cherry picked from commit 779d22e)
(cherry picked from commit 129ccc3)
(cherry picked from commit 849c050)
(cherry picked from commit b22f35f)
(cherry picked from commit 8b414e9)
(cherry picked from commit 01ecda4)
(cherry picked from commit f978e54)
(cherry picked from commit 6e60479)
(cherry picked from commit ec7b49a)
(cherry picked from commit 1d72ad0)
(cherry picked from commit 5e2c66f)

(cherry picked from commit dfb6454)

Co-authored-by: RomneyDa <[email protected]>

(cherry picked from commit f7c581c7f8bf0e57c7d8799e928a121b24462450)

Co-authored-by: vincentkoc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram P2 Normal backlog priority with limited blast radius. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram message_sent plugin hooks receive no sessionKey

2 participants