fix: sub-agents skip task message due to overly broad resume guard

The previous guard `if not self.state.messages` broke sub-agents because
they can have pre-loaded context messages in their state before agent_loop
is called. This caused them to start without a task and produce no output.

Fix: only skip the initial task message when parent_id is None AND messages
is already populated (= root agent resume). Sub-agents always get their
task message regardless of whether their state has prior context.

- Fresh root agent:        parent_id=None, messages=[]   → adds task ✓
- Fresh sub-agent:         parent_id=set,  messages=[]   → adds task ✓
- Sub-agent with context:  parent_id=set,  messages=[..] → adds task ✓
- Resumed root agent:      parent_id=None, messages=[..] → skips  ✓

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
root 2026-03-19 08:40:26 +01:00
parent fd5366f612
commit 91fb78179c

View file

@ -382,11 +382,14 @@ class BaseAgent(metaclass=AgentMeta):
if not self.state.task:
self.state.task = task
# Added for Resume Feature: skip adding the initial task message when
# resuming because the full message history is already in state.messages.
# On a fresh start state.messages is always empty here — original behavior
# is 100% unchanged.
if not self.state.messages:
# Added for Resume Feature: only skip the task message when this is the
# ROOT agent being resumed (parent_id is None AND messages already has
# history from the checkpoint).
# Sub-agents can have pre-loaded context messages and still need their task
# message added — the old `if not self.state.messages` guard broke them.
# Original behavior is 100% unchanged for all non-resume paths.
_is_root_resume = (self.state.parent_id is None and bool(self.state.messages))
if not _is_root_resume:
self.state.add_message("user", task)
async def _process_iteration(self, tracer: Optional["Tracer"]) -> bool | None: