Repository navigation
fix(telegram): /codex detach and rebind fail with 'Telegram runtime not initialized' - #175379
Conversation
…n instance Session binding adapters were registered without their owning plugin instance. When another plugin reached a channel adapter through the core service (for example `/codex detach` in a Telegram conversation), the adapter ran in the caller's instance, so the channel's runtime lookup hit an empty slot and failed with "Telegram runtime not initialized". Wrap the normalized adapter at registration, as core already does for command handlers and channel plugins. Unregistration still matches the original adapter object, and adapters registered outside any plugin instance keep their previous behavior.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesTelegram’s binding manager retains its owning runtime so Codex commands can persist rebind and detach operations across plugin instances. Example: Run /codex bind --cwd /tmp again in an already-bound Telegram conversation, then run /codex detach.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a demonstrated bug still present on main, and its current Telegram-local implementation resolves the earlier reload concern without an actionable finding. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCodex commands call the shared conversation-binding service, whose Telegram adapter updates live routing and persists binding records through Telegram’s registry-owned SQLite worker stores. flowchart LR
A[Telegram command] --> B[Codex plugin instance]
B --> C[Conversation binding service]
C --> D[Telegram binding manager]
D --> E[Captured Telegram runtime]
E --> F[SQLite worker store]
Technical reviewBest possible solution: Keep runtime selection inside Telegram’s existing binding manager while preserving shared adapter semantics and worker-held authority. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the cross-instance runtime-slot failure, corroborated by the reporter screenshot and the PR’s recorded live base reproduction; no target code was executed during this read-only review. Is this the best way to solve the issue? The current revision is the smallest complete repair: capture the manager’s runtime once and reuse it across every persistence path, without changing core adapter invocation or reload admission. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c23f752a67e6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +20, Tests +271. Total +291 across 5 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)Reviewed October 18, 2026, 1:10 AM ET / 05:10 UTC (Revision 4). |
Add a core test that drives Telegram's real thread-binding manager, with its session binding adapter registered inside a Telegram plugin instance, through requestPluginConversationBinding and detachPluginConversationBinding from other plugin instances. It covers refresh and detach by the owning plugin root, a different plugin root, a quiesced Telegram instance, a replaced session binding adapter, and a retired plugin registry, and checks the stored Telegram entry after each refusal. Rename the outside-instance guard test in session-binding-service.test.ts to say which instance the adapter runs in, rename its runtime-store key and error message to match, and record the observed owner in a local variable.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Updated the PR body after the latest ClawSweeper review; the code is unchanged and the head is still Since #175769 landed, this PR conflicts in |
Session-binding adapter calls can run in another plugin's instance, for example /codex detach or a repeated /codex bind. Telegram resolved its plugin runtime from the caller's instance slot at write time, so those commands failed with "Telegram runtime not initialized". The thread binding manager now keeps the runtime of the Telegram instance that created it and persists through it. The core adapter registry keeps its existing call semantics, so other channels' adapters are not fenced during a plugin reload.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@obviyus Thanks for picking this up and reworking the fix. |
|
Landed in 2a30b52. Thanks @Satoshi-Kusumoto for the report, the root-cause analysis and the cross-instance tests, and for sharing it with the community. Maintainer follow-up: the fix now lives in Telegram's binding owner instead of wrapping every core session-binding adapter, so plugin reloads keep their current behavior. Proven end to end on real Telegram against main. |
The registry-backed fixture registers Telegram's channel directly and omitted the runtime initialization performed by the production loader. Since #175379 captures that runtime when creating the binding manager, the contract failed with "Telegram runtime not initialized". Initialize the fixture through Telegram's narrow runtime setter and back its state API with the existing isolated plugin-state test store. Preserve all capability, bind, unbind and cleanup assertions. Production startup, reload, cross-plugin runtime ownership and Telegram transport are unchanged. Current-main baseline reproduced the reported failure, with four other channel cases passing. The repaired contract passes all five cases under pinned Bun. Owning core/plugin-SDK test types, scoped lint, formatting and independent P2 autoreview pass. No live Telegram behavior is claimed.
…ot initialized' (openclaw#175379) `/codex detach` and a repeated `/codex bind` in a Telegram conversation no longer fail with "Telegram runtime not initialized". The Telegram thread-binding manager keeps the runtime it was created with and persists through it, whichever plugin calls its adapter. Registry checks still apply, so a retired Telegram registry still refuses the write. Core session-binding semantics are unchanged. Proof: real Telegram (Test Server) driving the bundled Codex plugin through a fresh Gateway. On main 72a9fbb the repeated bind and the detach both fail and the binding stays; the candidate binds, detaches and reports no binding. Live gate passed with openai/gpt-5-mini. Thanks @Satoshi-Kusumoto. Co-authored-by: Ayaan Zaidi <[email protected]>
The registry-backed fixture registers Telegram's channel directly and omitted the runtime initialization performed by the production loader. Since openclaw#175379 captures that runtime when creating the binding manager, the contract failed with "Telegram runtime not initialized". Initialize the fixture through Telegram's narrow runtime setter and back its state API with the existing isolated plugin-state test store. Preserve all capability, bind, unbind and cleanup assertions. Production startup, reload, cross-plugin runtime ownership and Telegram transport are unchanged. Current-main baseline reproduced the reported failure, with four other channel cases passing. The repaired contract passes all five cases under pinned Bun. Owning core/plugin-SDK test types, scoped lint, formatting and independent P2 autoreview pass. No live Telegram behavior is claimed.
Backport the fix from upstream PR openclaw#175379 (2a30b52) to the 2026.9 plugin-state API. Capture the owning Telegram runtime for every persisted binding mutation, including synchronous lifecycle updates. Add a regression covering cross-plugin bind, refresh, lifecycle update and detach. Co-authored-by: BTofu <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…ot initialized' (#175379) `/codex detach` and a repeated `/codex bind` in a Telegram conversation no longer fail with "Telegram runtime not initialized". The Telegram thread-binding manager keeps the runtime it was created with and persists through it, whichever plugin calls its adapter. Registry checks still apply, so a retired Telegram registry still refuses the write. Core session-binding semantics are unchanged. Proof: real Telegram (Test Server) driving the bundled Codex plugin through a fresh Gateway. On main d3dc09e the repeated bind and the detach both fail and the binding stays; the candidate binds, detaches and reports no binding. Live gate passed with openai/gpt-5-mini. Thanks @Satoshi-Kusumoto. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 2a30b52) Co-authored-by: RomneyDa <[email protected]>
Closes #175372
Related: #173667
What Problem This Solves
Fixes:
/codex detachand re-running/codex bindfail withCodex command failed: Telegram runtime not initializedin a Telegram conversation bound to Codex, and the conversation stays bound.User Impact
User impact: in Telegram conversations bound to Codex,
/codex detachand a repeated/codex bindsucceed, so/session unbindis no longer needed as a workaround. Other channels and the core session-binding service keep their current behavior, including during plugin reloads.Why This Change Was Made
/codexhandlers run in the Codex plugin instance. When they change a Telegram binding through the core session-binding service, Telegram's adapter runs in that caller's context. Telegram's binding persistence looked up its plugin runtime at write time, and that lookup reads the slot of the plugin instance that is currently running, so it found the Codex instance's empty slot./session unbindworked because it runs in Telegram's own inbound scope.The Telegram thread-binding manager is created inside the Telegram plugin instance when the channel starts. It now keeps that runtime and persists through it, no matter which plugin calls its adapter. The runtime's registry checks still apply, so a retired Telegram registry still refuses the write.
An earlier revision of this PR wrapped every session-binding adapter in its registering plugin instance in core. That also fixed the bug, but it made every adapter call (including reads and unscoped fan-out such as session deletion) fail while a channel plugin is quiesced during a reload. This revision keeps the fix inside Telegram's binding owner, so the core call semantics do not change and no new reload-window failure is introduced.
Thanks @Satoshi-Kusumoto for the report, the root-cause analysis and the cross-instance tests, which this revision keeps in a smaller form.
Evidence
Real Telegram (Test Server, leased QA account) driving the bundled Codex plugin through a fresh Gateway. Scenario:
/codex bind --cwd /tmp, tap Allow once,/codex binding,/codex bind --cwd /tmpagain,/codex detach,/codex binding.main(d3dc09e): the repeated bind and the detach both replyCodex command failed: Telegram runtime not initialized; the final/codex bindingstill shows the binding.Bound this conversation to a new thread in /tmp. The next message will initialize it., detach repliesDetached this conversation from Codex., and the final/codex bindingrepliesNo Codex conversation binding is attached.Focused tests (
src/plugins/conversation-binding.cross-instance.test.ts,extensions/telegram/src/thread-bindings.test.ts,extensions/telegram/src/thread-bindings-reconcile.test.ts): 27 passed. Withmain's Telegram binding files swapped back in, all three cross-instance cases fail, so the tests catch the defect.Merge danger
Two-way door: no stored state, config or schema changes, and a revert restores the old lookup. Blast radius is Telegram thread-binding persistence only; Discord, Matrix, Feishu and the core adapter registry are untouched.