Skip to content

fix(gateway): preserve depth-capped interrupt follow-ups - #61027

Open
embwl0x wants to merge 1 commit into
NousResearch:mainfrom
embwl0x:agent/telegram-voice-interrupt-queue
Open

fix(gateway): preserve depth-capped interrupt follow-ups#61027
embwl0x wants to merge 1 commit into
NousResearch:mainfrom
embwl0x:agent/telegram-voice-interrupt-queue

Conversation

@embwl0x

@embwl0x embwl0x commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #61008.

When an interrupt-drain chain reaches _MAX_INTERRUPT_DEPTH, the gateway currently tries to park a remaining string interrupt_message via adapter.queue_message(...). Normal gateway adapters use _pending_messages and do not implement that legacy method, so a transcribed voice follow-up can be dropped exactly when the recursion guard fires.

This patch adds a shared GatewayRunner._requeue_interrupt_depth_pending() helper that:

  • requeues a full pending MessageEvent through the existing FIFO pending-event path,
  • converts a plain interrupt transcript string into a real MessageEvent when no full event remains,
  • preserves FIFO ordering when another pending slot is already occupied,
  • keeps the legacy queue_message() fallback only for non-standard adapters without _pending_messages.

Validation

  • uv run --extra dev pytest tests/gateway/test_queue_consumption.py -q — 16 passed
  • uv run --extra dev pytest tests/gateway/test_stt_config.py tests/gateway/test_telegram_audio_vs_voice.py -q — 12 passed
  • uv run --extra dev pytest tests/gateway/test_busy_session_ack.py -q — 26 passed
  • uv run --extra dev pytest tests/gateway/test_run_progress_interrupt.py tests/gateway/test_pending_drain_no_recursion.py tests/gateway/test_internal_event_never_interrupts_busy_session.py -q — 10 passed
  • uv run --extra dev pytest tests/gateway/test_queue_command.py tests/gateway/test_busy_session_auth_bypass.py tests/gateway/test_subagent_protection_30170.py -q — 26 passed
  • uv run --extra dev pytest tests/gateway -q -k "queue or interrupt or voice" — 442 passed, 7 skipped, 8515 deselected
  • uv run --extra dev ruff check gateway/run.py tests/gateway/test_queue_consumption.py — passed
  • python -m py_compile gateway/run.py tests/gateway/test_queue_consumption.py — passed
  • git diff --check origin/main..HEAD — passed
  • gitleaks git --log-opts='origin/main..HEAD' --redact . — no leaks found

Duplicate / overlap check

Those do not preserve a depth-capped gateway interrupt transcript as a pending turn.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 8, 2026
@embwl0x
embwl0x force-pushed the agent/telegram-voice-interrupt-queue branch from 697de30 to ca59a5e Compare July 10, 2026 09:26
@embwl0x
embwl0x marked this pull request as ready for review July 10, 2026 09:26
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for isolating the plain-text fallback separately from the retained voice-event path.

  • Current main still assigns an interrupt_message when no pending_event remains (gateway/run.py:19571-19580), then calls adapter.queue_message(...) at the depth cap (gateway/run.py:19681-19692). A repository-wide search finds no adapter implementation of that legacy method.
  • The proposed helper routes the fallback into the existing FIFO event mechanism (gateway/run.py:4371-4385), and BasePlatformAdapter drains that pending event into a fresh task (gateway/platforms/base.py:5164-5201). This preserves the current non-recursive drain invariant.
  • The issue's original voice-event report is already covered by the retained-event drain path, as noted in the issue discussion; this PR addresses the distinct interrupt_message-only fallback still present on current main.

Automated hermes-sweeper review.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 10, 2026
@embwl0x
embwl0x force-pushed the agent/telegram-voice-interrupt-queue branch 4 times, most recently from e1f420a to 5803948 Compare July 30, 2026 04:32
@embwl0x
embwl0x force-pushed the agent/telegram-voice-interrupt-queue branch from 5803948 to e793876 Compare July 30, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Voice messages arriving mid-stream cause interrupt recursion deadlock — transcribed message lost, session hangs

3 participants