Skip to content

bug: turn ending with background subagents still in flight records the execution as SUCCESS and silently discards the work #2127

Closed

Description

@obasilakis

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 (the error_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

  1. 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".
  2. The agent spawns the subagents and ends its turn to wait for the notification.
  3. The execution completes as success well before the subagent work could have finished.
  4. Inspect the row: status=success, cost populated, execution_log large, and response containing 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

Activity

  1. added
    priority-p2
    type-bug
    theme-reliability
    status-ready
    on Aug 12, 2026
  2. removed
    status-ready
    on Aug 14, 2026
  3. webmixgamer commented on Aug 14, 2026

    @webmixgamer
    Contributor

    /claim

  4. added
    status-in-progress
    on Aug 14, 2026
  5. github-actions commented on Aug 14, 2026

    @github-actions

    Claimed by @webmixgamer. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/2127-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #2127
  6. added
    status-in-dev
    and removed
    status-in-progress
    on Aug 15, 2026
  7. removed
    status-in-dev
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p2theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions