15 Commits

Author SHA1 Message Date
Teknium
3d5831fa59 Merge pull request #103486 from NousResearch/fix/nested-delegate-deadline-and-summary-budget
fix(delegate): nested orchestrators get their workers' results back — delegate_task exempt from the 420 s tool deadline; summary budget uses current prompt, not the session sum
2026-09-06 12:02:43 -07:00
Teknium
0913885250 fix(delegation): summary headroom uses the aggregator's own prompt size; unknown usage means the static ceiling, never zero context
Independent review found two holes in the first fix. A parent with no usage
row yet was treated as 0 tokens used, so a 190K/200K prompt received a
384K-char dynamic summary budget instead of ~4K; the budget now returns None
(static ceiling only) when nothing is known. And under MoA the folded usage
includes advisor prompts that are not in the parent's context, over-stating
the prompt size and wrongly truncating summaries; turn_usage now records the
aggregator's pre-fold prompt_tokens as _last_prompt_size_tokens and the
budget reads that first.

Tests (2 new): unknown usage -> None; MoA-folded and unfolded parents with
the same real prompt get the same budget.
2026-09-05 06:18:41 -07:00
JonthanaHanh
d78cdd7119 fix(tools): truncation footers name the path the SANDBOX sees, not the host path (#72389, #81984, #77015)
web_extract / browser_snapshot / delegate_task spill their full text under HERMES_HOME/cache,
which is mounted read-only into docker/modal (at /root/.hermes) and synced under ~/.hermes for
ssh/daytona/vercel — but the footer told the agent the HOST path, so read_file inside the
sandbox got 'File not found'. Translate through the existing
credential_files.to_agent_visible_cache_path (what tool_result_storage already does); local and
singularity are unchanged.

Salvaged from #72429 by @JonthanaHanh (the web_extract sites), widened to every footer.
2026-09-05 18:46:16 +05:30
Teknium
903b9bf187 fix(delegate): nested orchestrators get their workers' results back — no 420 s deadline on delegate_task, summary budget uses the current prompt not the session sum
Two defects in the same path, both measured on the 1,393-agent refactor run.

1. A nested orchestrator (depth > 0) runs delegate_task synchronously by
   design: it needs its workers' results inside its own turn. But the
   sequential tool runner put every tool call under the generic 420 s
   deadline, and delegate_task was not exempt, so every batch longer than
   seven minutes returned "timed out after 420.0s" while the children kept
   running as orphans. 332 such timeouts in 234 orchestrator sessions; only
   89 nested delegate_task calls in the whole run ever returned a real result.
   The orchestrators then spent 388 h of wall time polling: 1,526 reads of
   the live transcript files, 551 list actions, 242 h of explicit sleep,
   about $4k of API turns. delegate_task is now exempt from the sequential
   deadline (the batch owns its liveness: per-child heartbeats, the stale
   monitor, delegation.child_timeout_seconds).

   Live A/B, depth-1 orchestrator dispatching a 75 s leaf with the deadline
   set to 40 s (glm-5.3-flash via Nous): main -> "Error executing tool
   'delegate_task': timed out after 40.0s", leaf result lost; branch ->
   orchestrator blocked 161 s and returned the leaf's LEAF_DONE_MARKER.

2. _parent_summary_char_budget computed the parent's context headroom from
   session_prompt_tokens, which is the running SUM of prompt tokens over
   every API call in the session. After a few hundred calls it exceeds any
   window, headroom goes negative, and every child summary collapses to the
   2,000-char floor with the full text spilled to disk. All 1,393 child
   summaries in the run were truncated this way; the orchestrator planned
   from stubs. The budget now reads the last call's prompt_tokens from
   _last_turn_usage.

Tests: delegate_task is in the exempt set and the set is narrow; budget for
a long-lived parent equals the budget for a fresh parent with the same
current prompt, and exceeds the floor.
2026-09-05 00:10:26 -07:00
Teknium
2fc516138d refactor(delegate): results — error detector / argument summary tightened 2026-09-02 19:59:16 -07:00
Teknium
9cf7c74030 refactor(delegate): module headers condensed (one-line docstrings, logger comment inline) 2026-09-02 19:43:56 -07:00
Teknium
defca3639a refactor(delegate): reflow comments/docstrings to 118 cols (word-identical, AST-identical) 2026-09-02 19:25:04 -07:00
Teknium
eabec2ff50 refactor(delegate): AST-identical re-layout pass 2 2026-09-02 19:04:50 -07:00
Teknium
52fdc02dfe refactor(delegate): results module — one input-summary builder, tighter output-tail/trim helpers 2026-09-02 18:10:42 -07:00
Teknium
b18228f377 refactor(delegate): AST-identical re-layout (pack signatures/call args, join split literals) 2026-09-02 17:59:28 -07:00
Teknium
3da2ff88e3 refactor(delegate): pack re-import block; single blank line between top-level defs (AST-identical) 2026-09-02 17:03:55 -07:00
Teknium
987bc82574 refactor(delegate): compact docstrings/comments by hand (every WHY kept); collapse orchestrator toolset branches 2026-09-02 17:03:05 -07:00
Teknium
016f31375d refactor(delegate): join wrapped logical lines that fit in 120 cols (AST-identical) 2026-09-02 16:59:26 -07:00
Teknium
884c697291 refactor(delegate): split _finalize_child_results (memory/hooks/cost rollup), lift _create_isolated_worktree and _report_child_done, collapse dead worktree-attach import fallback 2026-09-02 16:54:15 -07:00
Teknium
05526b028a refactor(tools/delegate): split delegate_tool into child_run/config/dispatch/progress/registry/results; compact delegation helpers 2026-09-02 14:45:15 -07:00