The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(delegation): a one-shot-started session joins children on interactive turns
Teknium9d558a14a132
diff --git a/tests/tools/test_finite_delegation_outcomes.py b/tests/tools/test_finite_delegation_outcomes.pyindex 3fb3c68d2b9..ba026d2b127 100644--- a/tests/tools/test_finite_delegation_outcomes.py+++ b/tests/tools/test_finite_delegation_outcomes.py@@ -262,3 +262,20 @@ def test_owner_finite_scope_overrides_history_without_leaking(harness, monkeypatassert dict(os.environ) == beforeassert finite_turn_required() is Noneassert _resolve_async_wake_sid("history", True) is None+++def test_oneshot_started_session_joins_children_on_an_interactive_turn(harness, monkeypatch):+ """A ``chat -q`` session resumed interactively keeps its pinned one-shot ``delegate_task`` schema ("joined in+ this call", no list/steer/stop), so an interactive (finite=False) turn must still join, never detach."""+ from agent.oneshot_footprint import agent_is_oneshot+ from gateway.session_finite import finite_turn_scope+ from gateway.session_policy import build_policy, policy_scope++ parent, _children, dispatch = harness+ monkeypatch.delenv("HERMES_SINGLE_QUERY_SESSION")+ with policy_scope(build_policy({"source": "oneshot", "cwd": str(os.getcwd()), "model": "m"}, {})):+ assert agent_is_oneshot(parent) # the pin the tool build froze for this session+ sc.set_session_vars(async_delivery=True)+ with finite_turn_scope(False):+ result = dispatch("completed", "error")+ _joined(result, ["completed", "error"])diff --git a/tools/delegate_tool_dispatch.py b/tools/delegate_tool_dispatch.pyindex 39662bfaeab..30a4d5412b9 100644--- a/tools/delegate_tool_dispatch.py+++ b/tools/delegate_tool_dispatch.py@@ -246,18 +246,22 @@ def _run_sync_with_note(batch: _Batch, reason: str) -> str:result["note"] = _SYNC_FALLBACK_NOTES[reason]return json.dumps(result, ensure_ascii=False)-def _resolve_async_wake_sid(origin_wake_sid: str, origin_session_history_delivery: bool = False) -> Optional[str]:+def _resolve_async_wake_sid(+ origin_wake_sid: str, origin_session_history_delivery: bool = False, oneshot_session: bool = False,+) -> Optional[str]:"""Detached result target: empty for push, a resumable API id, or None for inline.API completion only persists a row; this does not authorize a model wake. The- continuation must read that row, not an authoritative caller-owned snapshot."""+ continuation must read that row, not an authoritative caller-owned snapshot.+ *oneshot_session*: the parent's tools[] froze the one-shot ``delegate_task`` ("joined in this call", no+ list/steer/stop) for the whole session, so a later interactive turn (``chat -q`` then ``--resume``) joins too."""from gateway.session_context import get_session_env# Finite consumers need the result in this tool round. Owner admission scope# wins over legacy standalone launch markers, without changing terminal delivery.from gateway.session_finite import finite_turn_requiredfinite = finite_turn_required()- if finite is True or (finite is None and get_session_env("HERMES_SINGLE_QUERY_SESSION") == "1"):+ if oneshot_session or finite is True or (finite is None and get_session_env("HERMES_SINGLE_QUERY_SESSION") == "1"):return Nonetry:@@ -431,7 +435,10 @@ def _dispatch_background(batch: _Batch) -> str:running synchronously (with an explanatory ``note``) when the session cannot receive detached completions or theasync pool is at capacity."""from tools.delegate_tool import _get_max_async_children- wake_sid = _resolve_async_wake_sid(batch.origin_wake_sid, batch.origin_session_history_delivery)+ wake_sid = _resolve_async_wake_sid(+ batch.origin_wake_sid, batch.origin_session_history_delivery,+ oneshot_session=getattr(batch.parent_agent, "_oneshot_session", None) is True, # agent_is_oneshot's pin+ )if wake_sid is None:logger.info("delegate_task: async delivery unsupported on this session runtime; running the batch synchronously instead.")return _run_sync_with_note(batch, "no_async")