fix(gateway): respawn session processing after goal continuation enqueue#28691
Open
Ade5954 wants to merge 3 commits into
Open
fix(gateway): respawn session processing after goal continuation enqueue#28691Ade5954 wants to merge 3 commits into
Ade5954 wants to merge 3 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fix
/goalauto-continue loop never firing on gateway platforms (Telegram, Discord).The continuation event was enqueued into
adapter._pending_messagesafter_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_usedstayed 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
Changes Made
gateway/run.py: _post_turn_goal_continuation()— changed return type fromNonetobool. ReturnsTruewhen a continuation event was enqueued,Falseotherwise.gateway/run.py: _handle_message()— after thefinallyblock releases_running_agentsstate, checks the_goal_continuation_enqueuedflag. IfTrue, pops the actual pending event fromadapter._pending_messagesand feeds it toadapter._start_session_processing(), following the same pattern as_drain_pending_after_session_commandinbase.py.How to Test
python -m pytest tests/gateway/test_goal_verdict_send.py tests/gateway/test_goal_status_notice.py -q/goal <multi-step task>. Observe that continuation turns fire automatically after each response instead of requiring a user message.Checklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AVerification Log
Environment: Windows 11, Python 3.14.3