refactor(delegate): docstring compaction by hand (every rule/why kept)
This commit is contained in:
@@ -94,14 +94,12 @@ def _report_child_done(parent_agent, spinner_ref, entry, tag, task_labels, n_tas
|
||||
spinner_ref.update_text(f"🔀 {'[' + tag + '] ' if tag else ''}{remaining} task{'s' if remaining != 1 else ''} remaining")
|
||||
|
||||
def _run_children_parallel(batch: _Batch, results: list, *, honor_parent_interrupt: bool) -> None:
|
||||
"""Run the batch's children in parallel, appending entries to ``results``.
|
||||
|
||||
Polls futures with a short ``wait()`` timeout instead of ``as_completed()``
|
||||
so a wedged child cannot block the parent forever after an interrupt;
|
||||
on parent interrupt the still-pending children are reported as
|
||||
``interrupted`` and abandoned (they already got the interrupt signal).
|
||||
Prints one completion line per child. ``results`` ends sorted by task_index.
|
||||
"""
|
||||
"""Run the batch's children in parallel, appending entries to ``results``
|
||||
(sorted by task_index on return, one completion line printed per child).
|
||||
Polls futures with a short ``wait()`` timeout instead of ``as_completed()`` so
|
||||
a wedged child cannot block the parent forever after an interrupt; on parent
|
||||
interrupt the still-pending children are reported ``interrupted`` and
|
||||
abandoned (they already got the interrupt signal)."""
|
||||
# Daemon workers (tools.daemon_pool): the `with` block still joins normally,
|
||||
# but if the parent is interrupted while a child is wedged, the abandoned
|
||||
# worker must not block interpreter exit.
|
||||
@@ -138,13 +136,11 @@ def _run_children_parallel(batch: _Batch, results: list, *, honor_parent_interru
|
||||
results.sort(key=lambda r: r["task_index"]) # match input order
|
||||
|
||||
def _execute_and_aggregate(batch: _Batch, *, honor_parent_interrupt: bool = True) -> dict:
|
||||
"""Run all built children, join, finalize (hooks + cost rollup), return the combined dict.
|
||||
|
||||
Shared by the sync path and the background runner: even in the background
|
||||
the batch JOINS on itself here so ONE consolidated results block re-enters
|
||||
the conversation. Live transcripts are finalized but retained as the
|
||||
full-fidelity record (retention pruning happens on future dispatches).
|
||||
"""
|
||||
"""Run all built children, join, finalize (hooks + cost rollup), return the
|
||||
combined dict. Shared by the sync path and the background runner: even in the
|
||||
background the batch JOINS on itself here so ONE consolidated results block
|
||||
re-enters the conversation. Live transcripts are finalized but retained as the
|
||||
full-fidelity record (retention pruning happens on future dispatches)."""
|
||||
from tools.delegation_live_log import update_manifest_statuses
|
||||
results: list = []
|
||||
if len(batch.task_list) == 1:
|
||||
@@ -192,13 +188,12 @@ def _run_sync_with_note(batch: _Batch, reason: str) -> str:
|
||||
def _resolve_async_wake_sid(origin_wake_sid: str) -> Optional[str]:
|
||||
"""Wake target for a detached batch, or None to force synchronous execution.
|
||||
|
||||
Finite sessions (stateless HTTP requests, one-shot Kanban workers) cannot
|
||||
route a detached result back after their turn/process ends. But if a raw
|
||||
session id is bound (the API server always binds one), gateway.wake can
|
||||
still reach the session by self-POSTing /v1/chat/completions with that id,
|
||||
so only fall back to sync when there is truly no session id to wake. Uses
|
||||
the origin captured BEFORE child construction — HERMES_SESSION_ID here
|
||||
would be the subagent's internal id.
|
||||
Finite sessions (stateless HTTP requests, one-shot Kanban workers) cannot route
|
||||
a detached result back after their turn/process ends — but if a raw session id
|
||||
is bound (the API server always binds one), gateway.wake can still reach it by
|
||||
self-POSTing /v1/chat/completions, so only fall back to sync when there is truly
|
||||
no session id to wake. Uses the origin captured BEFORE child construction —
|
||||
HERMES_SESSION_ID here would be the subagent's internal id.
|
||||
"""
|
||||
try:
|
||||
from gateway.session_context import async_delivery_supported
|
||||
@@ -222,9 +217,9 @@ def _resolve_async_session_key(parent_agent: Any, origin_ui_session_id: str) ->
|
||||
can rotate it mid-turn before the TUI-side dict is re-anchored, and a stale
|
||||
approval-context key would orphan the completion. Gateway chats keep the
|
||||
platform conversation key (agent:main:...). The CLI has no bound approval
|
||||
contextvar and no HERMES_SESSION_KEY, so the key resolves empty; its drain
|
||||
is a positive-ownership filter keyed on the durable session_id, so an empty
|
||||
key would fail closed — stamp the parent's durable id.
|
||||
contextvar and no HERMES_SESSION_KEY, so the key resolves empty; its drain is a
|
||||
positive-ownership filter on the durable session_id (empty would fail closed),
|
||||
so stamp the parent's durable id.
|
||||
"""
|
||||
from tools.approval import get_current_session_key
|
||||
session_key = get_current_session_key(default="")
|
||||
@@ -298,13 +293,10 @@ def _dispatched_payload(dispatch: dict, goals: List[str], child_agents: List[Any
|
||||
|
||||
def _dispatch_background(batch: _Batch) -> str:
|
||||
"""Dispatch the WHOLE batch as one async unit and return the tool result JSON.
|
||||
|
||||
The runner joins on every child and yields ONE consolidated results block
|
||||
that re-enters the conversation as a single message when ALL children
|
||||
finish. Falls back to running it synchronously (with an explanatory
|
||||
``note``) when the session cannot receive detached completions or the async
|
||||
pool is at capacity.
|
||||
"""
|
||||
The runner joins on every child and yields ONE consolidated results block that
|
||||
re-enters the conversation as a single message when ALL children finish. Falls
|
||||
back to running synchronously (with an explanatory ``note``) when the session
|
||||
cannot receive detached completions or the async pool is at capacity."""
|
||||
from tools.delegate_tool import _get_max_async_children
|
||||
from tools.async_delegation import dispatch_async_delegation_batch
|
||||
wake_sid = _resolve_async_wake_sid(batch.origin_wake_sid)
|
||||
|
||||
Reference in New Issue
Block a user