Fix sub-agents killed after resume: strip SCAN RESUMED from inherited context

Root cause: create_agent passes the parent's full conversation history
(inherited_messages) to each new sub-agent. After resume, the parent's
history ends with a [SYSTEM - SCAN RESUMED] message that says:
  "ALL previous sub-agents have been terminated"
  "Do NOT call agent_finish unless all testing is genuinely complete"

Sub-agents reading this in their inherited context got confused:
- They thought they were the "terminated" agents and shouldn't be running
- They avoided calling agent_finish even when their task was done
- This caused them to hang, loop, or exit immediately without reporting

Fix: filter out any [SYSTEM - SCAN RESUMED] messages from the inherited
context before giving it to sub-agents. The resume instructions are only
relevant to the root agent — sub-agents should see normal parent context.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
root 2026-03-19 10:31:23 +01:00
parent 87078de4f1
commit 8e8b86e844

View file

@ -263,7 +263,17 @@ def create_agent(
inherited_messages = []
if inherit_context:
inherited_messages = agent_state.get_conversation_history()
# Strip system-level resume/interrupt markers from the inherited context so
# sub-agents don't misread the root agent's resume instructions as applying
# to themselves (which causes them to avoid agent_finish or get confused).
inherited_messages = [
msg
for msg in agent_state.get_conversation_history()
if not (
isinstance(msg.get("content"), str)
and msg["content"].startswith("[SYSTEM - SCAN RESUMED]")
)
]
_agent_instances[state.agent_id] = agent