fix(delegation): route async delegate_task results back to originating session - #58690
Closed
asimons81 wants to merge 1 commit into
Closed
fix(delegation): route async delegate_task results back to originating session#58690asimons81 wants to merge 1 commit into
asimons81 wants to merge 1 commit into
Conversation
…g session The completion event already carries the dispatching session's session_key (captured at dispatch time in delegate_tool.py:2798), but the delivery router ignored it — results landed in whatever session was active at completion time instead of the session that dispatched the subagent. Changes: - drain_notifications() in process_registry.py: optional session_key filter. Non-matching async_delegation events are re-queued instead of consumed, so they remain available for the correct session's drain. - cli.py process_loop: passes active session_key to drain_notifications() - tui_gateway/server.py post-turn drain: passes session_key from the TUI session dict - gateway/run.py _build_process_event_source: logs warning when routing metadata is unresolvable (previously silent drop) - Regression tests verifying session-scoped drain filtering Fixes NousResearch#58684
asimons81
force-pushed
the
fix/async-delegation-session-routing
branch
from
July 5, 2026 06:43
c5a034c to
7ffa632
Compare
Contributor
|
Merged via PR #60869 — your commit was cherry-picked onto current main with your authorship preserved in git log, plus a follow-up commit extending your session_key filter with a positive-proof ownership callback (compression-chain aware, fail-closed) for the TUI drain path. Your two-session regression tests transferred cleanly and pinned the behavior. Thanks — the drain hole was the piece none of the poller-side fixes touched. |
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.
Summary
Fixes #58684.
Background
delegate_taskresults are delivered to whichever session happens to be active when the subagent finishes, not the session that dispatched it — causing cross-contamination between unrelated sessions.Root cause: The completion event already carries the dispatching session's
session_key(captured atdelegate_tool.py:2798), but the delivery router ignored it.drain_notifications()consumed all events from the shared queue without filtering by session, and the CLI/TUI post-turn drains had no session awareness.Changes
tools/process_registry.py:drain_notifications()now accepts an optionalsession_keyparameter. When provided, async-delegation events whosesession_keydoesn't match are re-queued instead of consumed.cli.py: The process_loop drain passes the active session key todrain_notifications()tui_gateway/server.py: The post-turn drain passes the TUI session'ssession_keygateway/run.py:_build_process_event_sourcelogs a warning when routing metadata is unresolvable (previously a silent drop)Behavior
Testing
test_drain_notifications_filters_async_delegation_by_session_key(new) — verifies events are correctly filtered and re-queued per sessiontest_drain_notifications_no_filter_passes_all_async_delegation(new) — backward compatibility: no filter = all events consumedtest_crashed_runner_produces_error_completion)