Skip to content

fix(gateway): return delegated results before background tasks finish - #140691

Closed
nateEc wants to merge 2 commits into
NousResearch:mainfrom
nateEc:codex/fix-bg-delegation-results
Closed

nateEc wants to merge 2 commits into
NousResearch:mainfrom
nateEc:codex/fix-bg-delegation-results

Conversation

@nateEc

@nateEc nateEc commented Oct 17, 2026 •

Copy link
Copy Markdown

What does this PR do?

A gateway /bg agent currently returns a detached delegation handle and finishes before its child completes. The synthetic background session has no late-completion route, so the child result is lost.

Bind the existing stateless-delivery capability inside the background executor context. The delegation tool uses its existing synchronous fallback and the background task delivers the actual child result. The interactive caller keeps its asynchronous delivery capability.

Related Issue

Fixes #140569

Type of Change

  • Bug fix

Changes Made

  • Extract background-task execution and delivery into a focused mixin in a separate, behavior-preserving commit, avoiding growth of the oversized turn module.
  • Mark the finite background executor as unable to receive late completions.
  • Exercise the real delegation dispatcher and final send with controlled model/transport boundaries.

How to Test

Based on main edab579989a1, tested on macOS with Python 3.11:

  • New regression failed on the base: a detached batch was dispatched with no completion consumer.
  • scripts/run_tests.sh tests/gateway/test_background_command.py tests/gateway/test_multiplex_background_task_scope.py tests/gateway/test_async_delivery_capability.py -q -j 2: 10 passed.
  • python scripts/check: all 12 checks passed.

No live Telegram/model request was made; full repository suite not run. No configuration, tool-schema or documentation contract changed.

Checklist

  • Read contributing guide and searched existing PRs.
  • Conventional Commits with non-empty bodies.
  • Focused behavioral regression proven red on base, green on fix.
  • Only changes related to the fix and required module extraction.

Main compatibility check — 2026-10-23

Validated a temporary local merge of unchanged head ae82f3002b56 with main fab9b01c915a on macOS/Python 3.11: 10 passed, 0 failed.

Command: HERMES_PYTHON=/Users/nathanshan/anaconda3/bin/python HERMES_TEST_FILE_RETRIES=0 scripts/run_tests.sh tests/gateway/test_background_command.py tests/gateway/test_multiplex_background_task_scope.py tests/gateway/test_async_delivery_capability.py -q -j 2.

No merge conflict or required code change was found. Ready for review; upstream Actions still await maintainer approval and have not started jobs. No branch-history rewrite or full-suite claim.

- 将后台任务运行和结果投递移动到独立 mixin,保持原有入口和行为。

- 避免继续扩展超长的 run_turn 模块;原有后台任务与作用域测试 3 项通过。
- 将 /bg 执行上下文标记为不支持异步投递,复用委派工具的同步回退路径。

- 通过真实委派分发验证结果进入最终回复,且普通聊天的异步能力保持不变。

- 回归测试先复现失败;后台任务、配置作用域及异步投递相关 10 项测试通过。
@alt-glitch alt-glitch added comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists tool/delegate Subagent delegation type/bug Something isn't working labels Oct 17, 2026
@nateEc
nateEc marked this pull request as ready for review October 19, 2026 02:24
@teknium1

teknium1 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks @nateEc. This landed on main in #147745 (b8e0f9e). Your gateway /bg join is in it, with authorship kept. #147745 also applies the same join to the classic CLI /bg and the TUI/Desktop shared-owner /bg path. Closing as superseded.

@teknium1 teknium1 closed this Nov 2, 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 P2 Medium — degraded but workaround exists tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway /bg: async delegate_task result is silently lost (v0.22.2)

3 participants