Skip to content

Background external agent finishing after the model's turn ends never starts the next turn #944

Closed

Description

@AnthonyRonning

Summary

Per docs/external-agents.md: "Maple then tells the task that the agent finished, into the running turn or the next one."

The "next one" half doesn't work. When a background external agent (Codex) finishes after the model's turn has ended, the UI shows the notice "External agent … finished. The task will read its result next." — but no new turn ever starts. The task only reads the result once the user manually sends a prompt.

Repro

  1. In a task, ask the model to start a Codex agent with agent_start(background: true).
  2. Let the model's turn end while Codex keeps running.
  3. Wait for Codex to finish.
  4. Observe: the "task will read its result next" banner appears; nothing runs until the user sends a message.

Expected

The synthetic "External agent finished, call agent_status…" user message should trigger a new turn for that task — mirroring how a background subagent completion tells the task "into the running turn or the next one."

Root cause (from code inspection)

report_background_turn_end (crates/maple-agent/src/agent/external_agents/mod.rs ~line 1632) delivers the model-directed message via steer_into_desktop_run (crates/maple-agent/src/agent.rs ~line 9710). That function requires an active desktop run for the session:

.find(|run| run.session_id == session_id && desktop_run_is_stageable(run))
.ok_or_else(|| "No active Agent run to steer".to_string())?;

When the model's turn has already ended, no active run exists, so steering fails with "No active Agent run to steer". The fallback path only appends the message to session history via session_manager.add_message — it never starts or queues a run. The banner text ("…will read its result next") therefore promises behavior that has no code path.

The background-subagent flow handles the idle-task case (its completion reaches the next turn), so external agents are missing that half of the contract.

Suggested fix direction

In the steer-failed fallback (or explicitly when no active run is stageable for the session), enqueue the synthetic user message so that the task's agent starts a new run — e.g. route it through the same mechanism a queued user message / background subagent notice uses to wake an idle task, or start a run directly. The visible notice should only claim "the task will read its result next" once such a wake-up is actually guaranteed.

Environment

Verified at commit 4178b1c; Codex 0.154.0, ChatGPT sign-in.

Activity

  1. AnthonyRonning commented on Sep 15, 2026

    @AnthonyRonning
    ContributorAuthor

    Confirmed the framing from the reporter: the failure mode is precisely "the model was no longer in turn, so there was nothing to steer."

    The fix should be send_or_steer: steer when a run is active, and when it is not, send — submit the synthetic user message through the same path a queued user message takes to start a new run, rather than the bare session_manager.add_message fallback that only writes history.

    That semantic is already the composer's own contract (Enter queues for the next turn, Ctrl+Enter steers into the current one), so the external-agent completion can lean on the existing send/queue machinery instead of inventing a third path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions