Skip to content

Inbound debouncer keyChains re-serializes steer messages, making per-message grammY keys ineffective #64951

Closed

Description

@jetd1

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:

  1. Msg 1 arrives → grammY per-message key → handler starts → debouncer.enqueue() → buffer created → flushes after debounce window → processMessage() → starts agent run (long-running). The keyChains map holds the promise for this entire handler.

  2. Msg 2 arrives while msg 1's agent run is still active → grammY per-message key allows parallel handler → handler starts → await debouncer.enqueue() → detects keyChains.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

Activity

  1. jetd1 commented on Apr 12, 2026

    @jetd1
    ContributorAuthor

    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:

    1. keyChains re-serialization: Bypassed completely — message goes directly to processMessage() without entering the debouncer.
    2. 15s debounce window delay: Bypassed — message is processed immediately.

    The bypass uses chatSessionCache to resolve session key + queue mode at the grammY handler level (before debouncer enqueue), and isRunActiveForSessionKey to check if a run is active.

  2. locked as resolved and limited conversation to collaborators on Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions