Repository navigation
Description
Summary
In a headless execution, if the model spawns background subagents (the Task/Agent tools, or a background workflow) and then ends its turn intending to wait for the completion notification, the CLI exits normally with stop_reason=end_turn. Trinity's teardown then kills every one of those subagents (pgid SIGTERM/SIGKILL followed by kill_cgroup_orphans), and the execution is recorded as status=success with the model's "I'll wait for the notification" placeholder as its stored response.
No error is raised, nothing is logged as a failure, cost is billed, and the actual work is lost. The operator has no signal at all: the run looks like a normal successful execution in the UI.
This is the sibling branch of #1870. There, a late <task-notification> does arrive after end_turn, the CLI reports error_during_execution, and a completed turn is wrongly discarded. Here nothing arrives, so a turn that completed no work is wrongly recorded as a success.
Component
Agent Runtime (agent base image headless executor)
Priority
P2 — a workaround exists (instruct the agent to work inline only), but it is undiscoverable without reading the schedule_executions row by hand, and each occurrence is billed.
Observed
A single MCP-triggered async execution:
| Field | Value |
|---|---|
status |
success |
| wall clock | 909 s |
cost |
~$0.65 |
execution_log |
392 KB |
response |
221 characters |
The entire stored response was the announcement, not a result:
The workflow is running — 6 parallel agents reading all corpus files
simultaneously. I'll wait for the notification and then write [...]
The six subagents were killed at teardown. Subsequent runs of the same task, with the prompt explicitly forbidding background subagents, completed normally — which confirms the work itself was viable and only the turn structure caused the loss.
Location
- Result classification:
docker/base-image/agent_server/services/headless_executor.py(theerror_during_execution/ empty-result / clean-exit branches, ~L1090-1180) - Teardown:
docker/base-image/agent_server/utils/subprocess_pgroup.py,docker/base-image/agent_server/utils/orphan_sweep.py
Root Cause
The result classifier has branches for non-zero exit, error_during_execution (#1870 recovery), a lost result line (#520/#640/#678), and an empty response on clean exit (#160). None of them inspect whether the final assistant turn left background subagent invocations without matching completions.
A clean end_turn is therefore trusted unconditionally, which makes a turn that merely announced future work indistinguishable from a turn that did the work.
Note that the teardown itself is correct and should not change: cgroup-membership killing is the #817 guarantee, and background work legitimately cannot outlive the process. The defect is that the platform reports success for a turn whose work it just killed.
Reproduction Steps
- Trigger any agent execution (schedule, chat, or MCP) with a prompt whose natural shape makes the agent fan out to background subagents, for example "run this multi-file ingestion to completion".
- The agent spawns the subagents and ends its turn to wait for the notification.
- The execution completes as
successwell before the subagent work could have finished. - Inspect the row:
status=success,costpopulated,execution_loglarge, andresponsecontaining only the announcement.
Suggested Fix
Either or both:
1. Detect it in the result path. Before accepting a clean end_turn, scan the session transcript for background-subagent invocations with no corresponding completion. On a mismatch, either fail the execution with an explicit error, or store the response with a prepended warning so it is visible in the UI and in /error-analysis.
2. Prevent it at the source. State the constraint in the base-image agent instructions — background work cannot outlive the turn, so everything must run inline — and consider adding the background/subagent tools to the default disallowed_tools for headless executions, since they cannot function correctly there by construction.
Environment
- Trinity: post-v0.8.5 dev
- Runtime: Claude Code headless (
-p), agent base image
Related
- bug: completed turn discarded on error_during_execution — jsonl_recovery never consulted, response lost despite end_turn in the JSONL #1870 — completed turn discarded on
error_during_execution(the opposite branch of this same race) - bug: #1673's errors[0] picks Claude Code's internal [ede_diagnostic] header — real error text dropped, resume-not-found self-healing defeated #1849 —
[ede_diagnostic]marker masks the real error text - bug: error_during_execution runs store zero telemetry (no execution_log/session_id/cost) and the JSONL is reaped in 1-7h — failure class is undiagnosable #1853 —
error_during_executionruns store zero telemetry - bug: Runaway subprocess after task failure makes agent-server unresponsive, triggering persistent CB cascade #817 — cgroup orphan sweep (the teardown mechanism; working as designed)
- Upstream:
anthropics/claude-code#82235
Activity
webmixgamer commentedon Aug 14, 2026
/claim
github-actions commentedon Aug 14, 2026
Claimed by @webmixgamer. Label
status-in-progressadded.Next steps:
feature/2127-<short-slug>Fixes #2127fix(agent-runtime): make AGENT_IDLE_FINALIZE_S actually settable (#2127)
fix(agent-runtime): stop killing a fan-out turn mid-wait and calling …
fix(executions): killed background task leaves a queryable trace, not…
fix(watchdog): claim a finished sync turn's retained terminal instead…