Repository navigation
Description
Summary
PR #60604 introduces per-message grammY sequentialize keys to unblock steer-mode message injection on Telegram. However, the inbound debouncer's keyChains promise chain re-serializes messages within the same debounce key, making the per-message grammY key optimization ineffective.
Root Cause
When queue mode is steer and a run is active:
-
Msg 1 arrives → grammY per-message key → handler starts →
debouncer.enqueue()→ buffer created → flushes after debounce window →processMessage()→ starts agent run (long-running). ThekeyChainsmap holds the promise for this entire handler. -
Msg 2 arrives while msg 1's agent run is still active → grammY per-message key allows parallel handler → handler starts →
await debouncer.enqueue()→ detectskeyChains.has(key)is true (msg 1's task still running) → enqueues behind msg 1's entire agent run → msg 2's handler blocks.
The handler awaits debouncer.enqueue(), so even though grammY allows parallel execution, the debouncer's keyChains ordering guarantee re-serializes them. Msg 2 never reaches runReplyAgent → steer path is never hit.
Reference: src/auto-reply/inbound-debounce.ts — the enqueueKeyTask / keyChains mechanism ensures same-key ordering but blocks steer messages behind the active run.
Secondary Issue
Even without the keyChains blocking, the debouncer's 15s debounce window would delay steer messages. When msg 1's buffer has already flushed and the run is active, msg 2 enters a fresh buffer and waits the full debounce window before flushing.
Suggested Fix
When queue mode is steer / steer-backlog / steer+backlog and an embedded Pi run is active for the session, bypass the inbound debouncer entirely and route the message directly to processMessage → runReplyAgent → queueEmbeddedPiMessage.
This could be implemented as a run-active check in the channel's shouldDebounce callback or as a fast-path in the debouncer itself when the queue mode and run state indicate steer is appropriate.
Impact
Without this fix, steer mode on Telegram (and any other channel using the inbound debouncer) cannot inject messages mid-run, regardless of the grammY sequentialize key changes in #60604. The per-message grammY key is necessary but not sufficient.
Related
- fix(telegram): use per-message sequential key to unblock steer-mode message injection #60604 — Telegram per-message sequentialize keys
- fix: use isActive instead of isStreaming for steer mode message injection #52351 —
isActivevsisStreamingfor steer guard - Steer mode does not inject messages mid-turn for main sessions #48003 — Original steer mode bug report
- [Feature]: Agent turn blocks chat when polling long-running tasks — need turn interruption #9457 — Agent turn blocks chat when polling long-running tasks
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
jetd1 commentedon Apr 12, 2026
Resolved by PR #65222 — when queue mode is steer/interrupt and an embedded run is active, the Telegram handler now bypasses the inbound debouncer entirely (lines 1097-1164 of bot-handlers.runtime.ts). Both issues are addressed:
processMessage()without entering the debouncer.The bypass uses
chatSessionCacheto resolve session key + queue mode at the grammY handler level (before debouncer enqueue), andisRunActiveForSessionKeyto check if a run is active.