The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(delegation): report an inherited fast tier; refused tasks settle the batch manifest
Teknium5d7fea742c46
diff --git a/tests/tools/test_delegation_route_fields.py b/tests/tools/test_delegation_route_fields.pyindex 112678ea3c3..2599aa05046 100644--- a/tests/tools/test_delegation_route_fields.py+++ b/tests/tools/test_delegation_route_fields.py@@ -85,9 +85,14 @@ def test_route_tier_reaches_the_child_and_its_sibling_keeps_the_default():({**CODEX, "service_tier": "auto"}, "auto"), # bounded windows are per user turn, meaningless for a child])def test_a_tier_the_route_does_not_offer_refuses_that_task_and_its_sibling_runs(route, needle):- result, built, _ = _spawn([route, None])+ from tools.delegation_live_log import _manifest_path++ result, built, (sibling,) = _spawn([route, None])(refused,) = result["refused"]assert refused["task_index"] == 0 and needle in refused["error"] and len(built) == 1+ # Before the sibling runs (async units never carry it), the batch manifest already shows the refusal.+ manifest = json.loads(_manifest_path(sibling._delegation_id, None).read_text(encoding="utf-8"))+ assert [t["status"] for t in manifest["tasks"]] == ["error", "running"] and "completed" not in manifest@pytest.mark.parametrize("account_offers, expected", [(False, None), (True, "ultrafast"), (None, "ultrafast")])@@ -179,3 +184,13 @@ def test_every_backend_routed_result_names_its_backend_and_the_default_keeps_its"reasoning_effort": "high", "service_tier": "normal"}_, _, (plain,) = _spawn([None], cfg=LOCAL, provider=get_active_provider({}))assert "route" not in entry_of(plain)+++def test_an_inherited_fast_tier_is_reported_as_what_ran():+ """An empty backend route inherits the parent's request settings, fast tier included: the report says fast."""+ from tools.delegate_tool_child_run import _SchemaOutcome, _build_result_entry++ _, _, (child,) = _spawn([{"label": "inherit"}], parent=_parent(request_overrides={"service_tier": "priority"}))+ entry = _build_result_entry(child, {"final_response": "ok", "completed": True}, 0, 1.0,+ _SchemaOutcome(None, None, [], 0))+ assert entry["route"]["service_tier"] == "fast"diff --git a/tools/delegate_tool.py b/tools/delegate_tool.pyindex 6750519935b..3b52feb6859 100644--- a/tools/delegate_tool.py+++ b/tools/delegate_tool.py@@ -517,6 +517,17 @@ def _routes_for(task_list: list[dict[str, Any]], cfg: dict[str, Any], credentialreturn [route] * len(task_list), None+def _settle_refused_transcripts(refused: list[dict[str, Any]], live_deleg_id: Optional[str], live_writers: list,+ live_home: Any) -> None:+ from tools.delegation_live_log import update_manifest_statuses+ for entry in refused:+ _writer = live_writers[entry["task_index"]] if entry["task_index"] < len(live_writers) else None+ if _writer is not None:+ with _quiet("Live transcript finalize failed", exc_info=True):+ _writer.finalize(entry)+ update_manifest_statuses(live_deleg_id, refused, home=live_home, completed=False)++def _oneshot_spawn_budget(parent_agent: Any, requested: int) -> Optional[str]:"""Charge *requested* children against the finite one-shot session's total (delegation.oneshot_max_children);the error text tells the model to do the work inline. Interactive and gateway sessions are never charged."""@@ -634,11 +645,8 @@ def delegate_task(task_list, context, model=creds.get("model"), provider=creds.get("provider"),home=_live_home,)- for entry in refused: # done before anything runs: their transcripts end with the refusal- _writer = live_writers[entry["task_index"]] if entry["task_index"] < len(live_writers) else None- if _writer is not None:- with _quiet("Live transcript finalize failed", exc_info=True):- _writer.finalize(entry)+ if refused: # settled before anything runs: transcripts and manifest show the refusal (async units skip them)+ _settle_refused_transcripts(refused, live_deleg_id, live_writers, _live_home)_announce_batch(parent_agent, len(task_list), live_deleg_id)origin = _capture_origin()diff --git a/tools/delegate_tool_child_run.py b/tools/delegate_tool_child_run.pyindex 0bdc9d150e5..7f4c1477f65 100644--- a/tools/delegate_tool_child_run.py+++ b/tools/delegate_tool_child_run.py@@ -33,6 +33,22 @@ def _num(value: Any, default: int = 0) -> int:def _str_or_none(value: Any) -> Optional[str]:return value if isinstance(value, str) else None+def _tier_in_effect(child: Any) -> Any:+ """The child's speed tier: its own (a route's tier), else the one its request settings carry (an inherited+ ``service_tier: priority`` or ``speed: fast``, top level or in ``extra_body``)."""+ if getattr(child, "service_tier", None):+ return child.service_tier+ overrides = getattr(child, "request_overrides", None)+ overrides = overrides if isinstance(overrides, dict) else {}+ extra = overrides.get("extra_body") if isinstance(overrides.get("extra_body"), dict) else {}+ for scope in (overrides, extra):+ if scope.get("service_tier"):+ return scope["service_tier"]+ if scope.get("speed") == "fast":+ return "priority"+ return None++def _route_report(child: Any) -> Optional[dict[str, Any]]:"""What a backend-routed child actually ran on: its backend and label plus the provider, model, reasoning effort(None = the provider's default) and speed tier read off the child when its result is assembled, so a fallback@@ -47,7 +63,7 @@ def _route_report(child: Any) -> Optional[dict[str, Any]]:effort = reasoning.get("effort") if reasoning.get("enabled", True) else "none"return {**route, "provider": _str_or_none(getattr(child, "provider", None)),"model": _str_or_none(getattr(child, "model", None)), "reasoning_effort": _str_or_none(effort),- "service_tier": service_tier_word(getattr(child, "service_tier", None)),+ "service_tier": service_tier_word(_tier_in_effect(child)),**({"fallback_activated": True} if getattr(child, "_fallback_activated", False) is True else {})}def _fabricated_entry(idx: int, status: str, error: str, child: Any, duration: float = 0) -> dict[str, Any]:diff --git a/tools/delegation_live_log.py b/tools/delegation_live_log.pyindex fe1de46563d..2e510b058ee 100644--- a/tools/delegation_live_log.py+++ b/tools/delegation_live_log.py@@ -286,8 +286,9 @@ def _write_manifest(delegation_id: str, task_list: list[dict[str, Any]],def update_manifest_statuses(delegation_id: Optional[str],results: list[dict[str, Any]],- home: Optional[Path] = None) -> None:- """Best-effort per-task status update once the batch has aggregated."""+ home: Optional[Path] = None, *, completed: bool = True) -> None:+ """Best-effort per-task status update once the batch has aggregated (``completed=False``: tasks settled+ before the batch ran, e.g. ones their backend refused, while the rest still run)."""if not delegation_id:returnwith _best_effort("manifest update"):@@ -305,7 +306,8 @@ def update_manifest_statuses(delegation_id: Optional[str],# The dispatch-time model is only the delegation.model override (None when children inherit the parent's).if not manifest.get("model"):manifest["model"] = next((t["model"] for t in manifest.get("tasks", []) if t.get("model")), None)- manifest["completed"] = time.strftime(_TIME_FMT)+ if completed:+ manifest["completed"] = time.strftime(_TIME_FMT)_dump_json(mp, manifest)