Skip to content

fix(gateway): respawn session processing after goal continuation enqueue#28691

Open
Ade5954 wants to merge 3 commits into
NousResearch:mainfrom
Ade5954:fix/goal-continuation-respawn-28649
Open

fix(gateway): respawn session processing after goal continuation enqueue#28691
Ade5954 wants to merge 3 commits into
NousResearch:mainfrom
Ade5954:fix/goal-continuation-respawn-28649

Conversation

@Ade5954

@Ade5954 Ade5954 commented May 19, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fix /goal auto-continue loop never firing on gateway platforms (Telegram, Discord).

The continuation event was enqueued into adapter._pending_messages after _run_agent() had already returned and drained pending events. The event sat orphaned until the user sent another message, so the auto-continue loop never ran — turns_used stayed at 0 for all active goals.

Why CLI works but Gateway doesn't: The CLI (cli.py) has a continuous polling loop in _pending_input, so a synthetic enqueued message gets picked up immediately. The Gateway has no equivalent — it relies on platform adapters to trigger processing, and _enqueue_fifo() does not trigger the adapter.

Before the fix: continuation event enqueued → orphaned in _pending_messages → never consumed → /goal loop stops after first turn.

After the fix: continuation event enqueued → popped from _pending_messages → fed to _start_session_processing() → next turn fires immediately.

Related Issue

Fixes #28649

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run.py: _post_turn_goal_continuation() — changed return type from None to bool. Returns True when a continuation event was enqueued, False otherwise.
  • gateway/run.py: _handle_message() — after the finally block releases _running_agents state, checks the _goal_continuation_enqueued flag. If True, pops the actual pending event from adapter._pending_messages and feeds it to adapter._start_session_processing(), following the same pattern as _drain_pending_after_session_command in base.py.

How to Test

  1. Unit tests: python -m pytest tests/gateway/test_goal_verdict_send.py tests/gateway/test_goal_status_notice.py -q
  2. Manual (gateway): Set up a Telegram/Discord gateway. Send /goal <multi-step task>. Observe that continuation turns fire automatically after each response instead of requiring a user message.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • 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: Windows 11

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

Verification Log

Environment: Windows 11, Python 3.14.3

Root cause: _post_turn_goal_continuation() enqueues the continuation event
into adapter._pending_messages AFTER _run_agent() has already returned and
drained pending events. The continuation sits orphaned until the user sends
another message, so the /goal auto-continue loop never fires on gateway
platforms (Telegram, Discord).

Fix (Option B — same pattern as _drain_pending_after_session_command):
1. _post_turn_goal_continuation() now returns bool (True=enqueued)
2. After the finally block releases _running_agents state, pop the actual
   pending event from adapter._pending_messages and feed it to
   adapter._start_session_processing() to re-enter the processing loop
   immediately

Closes NousResearch#28649
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery labels May 19, 2026
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 P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: /goal continuation loop never fires on gateway (Telegram/Discord) — event enqueued after consumer returns

2 participants