Skip to content

Fix Telegram DM session binding key mismatch and stale binding cleanup#109

Open
jdm0830 wants to merge 9 commits into
pwrdrvr:mainfrom
jdm0830:patched
Open

Fix Telegram DM session binding key mismatch and stale binding cleanup#109
jdm0830 wants to merge 9 commits into
pwrdrvr:mainfrom
jdm0830:patched

Conversation

@jdm0830
Copy link
Copy Markdown

@jdm0830 jdm0830 commented Apr 22, 2026

Fixes #108
Related: openclaw/openclaw#70288

Summary

  • Telegram DM parentConversationId key mismatch: toConversationTargetFromInbound was passing event.parentConversationId through for all Telegram channels, including DMs. For DMs (no topic), this produced an inbound key with a trailing user-ID component that never matched bindings stored at bind time. Fix: set parentConversationId = undefined when channel === "telegram" and no thread/topic exists.

  • Stale OpenClaw binding cleanup: When the plugin's internal thread state is cleared without properly detaching from OpenClaw's session binding registry, subsequent inbound messages find resolvedBinding === null but OpenClaw still routes them to this plugin. Previously the plugin returned { handled: false }, silently falling through to the LLM. Fix: check OpenClaw's session binding service for an active binding, unbind it, and notify the user (⚠️ Codex session expired. Run /cas_resume to start a new thread.), then return { handled: true }.

Context

The parentConversationId regression was introduced by the PR-96 Telegram topic support merge, which added Telegram-specific handling but left the DM path passing the raw event value through.

The stale binding issue surfaces most visibly once the key mismatch is fixed — previously DM messages never claimed the binding at all, so the stale path was unreachable.

Both fixes are needed alongside the OpenClaw core fix in openclaw/openclaw#70288, which ensures that when a plugin returns { handled: true } from inbound_claim, the channel handler does not fire a silent NO_REPLY fallback before the plugin's async response arrives.

Validation

  • Telegram DM with active session: message correctly claimed, Codex responds
  • Telegram DM after session expiry/restart: stale binding detected, user notified, LLM fallback suppressed
  • Telegram topic thread: existing behavior unchanged
  • Discord: unaffected

niemandBot and others added 9 commits April 11, 2026 11:04
…g cleanup

- Set parentConversationId=undefined for Telegram DMs (no topic) so the
  inbound conversation key matches what was stored at bind time. Prior code
  passed event.parentConversationId through unconditionally, producing a key
  with a trailing user-ID component that never matched stored bindings.

- In handleInboundClaim, when resolvedBinding is null, check OpenClaw's
  session binding service for an active binding on the same conversation. If
  found, unbind it and notify the user (session expired, run /cas_resume)
  instead of silently falling through to the LLM agent.

Fixes pwrdrvr#108
Related: openclaw/openclaw#70288
@huntharo
Copy link
Copy Markdown
Contributor

Thank you for your contribution!

Unfortunately there are still changes needed to support such an ambitious plugin in OpenClaw. Some of this functionality is now being included directly in OpenClaw.

I have made a new project, https://github.com/pwrdrvr/PwrAgent, that gives you a Codex Desktop replacement app (uses Codex) but also integrates with messaging with openclaw-codex-app-server-like functionality.

Bindings can be viewed within the PwrAgent desktop thread. You can see them right on the threads you have bound and you can click on the chip for the binding to unbind it right from PwrAgent. When a thread is archived the bindings are removed automatically and the messaging platform receives a notice of this. I think you'll like it.

Please give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram DM session binding key mismatch and stale binding not cleared

3 participants