Skip to content

fix(gateway): respect busy_input_mode queue for normal busy sessions#12235

Closed
dpaluy wants to merge 1 commit into
NousResearch:mainfrom
dpaluy:fix/busy-input-queue-mode
Closed

fix(gateway): respect busy_input_mode queue for normal busy sessions#12235
dpaluy wants to merge 1 commit into
NousResearch:mainfrom
dpaluy:fix/busy-input-queue-mode

Conversation

@dpaluy

@dpaluy dpaluy commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

When busy_input_mode is set to 'queue', the gateway now queues incoming messages during active agent runs instead of interrupting the agent. Previously, only the drain case respected the queue setting; the normal busy case always interrupted regardless of configuration.

Changes:

  • gateway/run.py: Add queue-mode branch in _handle_active_session_busy_message that stores the message via merge_pending_message_event, sends a debounced 'Queued for next turn' ack (reusing _busy_ack_ts), and returns without calling agent.interrupt()
  • tests/gateway/test_busy_session_ack.py: Add _busy_input_mode param to _make_runner helper, add TestBusySessionQueueMode with 4 tests covering queue-mode no-interrupt, queued ack text, debounce behavior, and interrupt mode regression

Fixes: #11118

What does this PR do?

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

How to Test

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

When busy_input_mode is set to 'queue', the gateway now queues incoming
messages during active agent runs instead of interrupting the agent.
Previously, only the drain case respected the queue setting; the normal
busy case always interrupted regardless of configuration.

Changes:
- gateway/run.py: Add queue-mode branch in _handle_active_session_busy_message
  that stores the message via merge_pending_message_event, sends a debounced
  'Queued for next turn' ack (reusing _busy_ack_ts), and returns without
  calling agent.interrupt()
- tests/gateway/test_busy_session_ack.py: Add _busy_input_mode param to
  _make_runner helper, add TestBusySessionQueueMode with 4 tests covering
  queue-mode no-interrupt, queued ack text, debounce behavior, and interrupt
  mode regression

Fixes: NousResearch#11118
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/discord Discord bot adapter platform/telegram Telegram bot adapter labels Apr 23, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Superseded by #14762 (merged as commit 9d147f7). We went with @whitehatjr1001's implementation from #13894 because the diff was smaller (shared ack-building code via a single is_queue_mode flag vs duplicated status-parts block). You hit the same root cause independently and your analysis informed the final validation. Thanks!

@barteqpl

Copy link
Copy Markdown

Real-world validation: delegate_task subagent survives busy session with queue mode

Tested this branch in production on a Telegram gateway — fix works exactly as intended for the subagent/delegation use case.

Setup:

  • Branch: fix/busy-input-queue-mode (339de943)
  • Config: display.busy_input_mode: queue
  • Platform: Telegram gateway (default profile)

Test:

  1. Sent URL to #queue topic → agent started web_extract + deep research via delegate_task
  2. While subagent was still running, sent a second URL
  3. Second message received: 📥 Queued for next turn (iteration 1/80). I'll get to your message when the current task finishes.
  4. First subagent was NOT interrupted — completed normally, then second message was dequeued and processed

Log confirmation:

2026-04-23 22:17:05,879 INFO gateway.run: Queued follow-up for session agent:main:telegram:: ...

No interrupt() call. No _active_children propagation. No subagent kill.

Why this matters:
Before this fix, any new message during a delegate_task run would trigger AIAgent.interrupt() on the parent, which recursively killed all children via _active_children. This made research queues, long-running analysis, and any multi-step delegation workflow effectively unusable on messaging platforms.

This PR is the cleanest fix (#12235 vs #13894 vs #8544) — minimal scope, no default changes, good test coverage.

LGTM.

@dpaluy dpaluy deleted the fix/busy-input-queue-mode branch April 26, 2026 06:44
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 platform/discord Discord bot adapter platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Distinguish queue-mode vs interrupt-mode busy-session acknowledgements in the gateway

5 participants