Skip to content

agent-runner: a stopped turn leaves its run active, so the next message in the same chat fails with "session already has active run" #654

Closed

Description

@kayahk

Symptom

In a chat conversation on a durable environment: send a message, let the turn start streaming tool calls, press Stop, then type a follow-up and send it into the same chat. The follow-up is never processed — the conversation ends failed with

executor: acp session/prompt: Invalid params: session already has active run `run_<uuid>`; use _goose/unstable/session/steer

and the message the user just typed is lost. The session stays unusable for as long as the abandoned run keeps executing, which is unbounded (a run blocked on a tool, or on a tool-permission request whose client is gone, never ends on its own).

Evidence from the deployment

paca 0.19.2, goose 1.50.1, agent paca-planner, durable environment conversation:

  • agent_conversations: 7ca6cf25-f02b-4095-a357-72179ca0410a, trigger_type=chat_message, status=failed, error_message = the line above, environment_id set.
  • Its event log is one conversation with two turns: user_message at 14:39:25 (turn 1 then streamed ~4,375 agent_thought_chunk/tool_call events), user_message at 14:42:08, environment_ready at 14:42:10 — and no turn_end for turn 1, i.e. turn 1 was stopped, not finished.
  • The run id in the error is the one turn 1 started: the session_info_update at 14:39:38 carries _meta.goose.activeRunId = run_58072af2-5693-44d0-b5f4-b2420dd531ad.

Why the code cannot already handle it

services/agent-runner/internal/acp/client.go: Prompt stops waiting when its context is cancelled and returns ctx.Err() as a clean stop; its own doc comment says the run is not cancelled ("this transport has no session/cancel call"). That was true of the goose this client was originally verified against; goose 1.50.1 has it.

In goose (crates/goose/src/acp/server.rs), start_active_run rejects a second session/prompt for a session whose active_prompt_runs entry still exists — that is this error, with the "use _goose/unstable/session/steer" hint — and only on_cancel, the session/cancel notification, clears it by cancelling the run's token. Every abandon path in the runner reaches this state: a user Stop (the reported case), the timeout_minutes turn budget, and the maxToolCalls cap. So a conversation killed by its own timeout cannot be continued either, until that abandoned run ends.

apps/acp-bridge's Runner.Interrupt already cancels at the ACP level first (client.Cancel → session/cancel) and only kills the subprocess after a grace period. The executor path has no equivalent.

Measured against the live deployment

Probe of a running paca-env-… pod (goose 1.50.1), driving /acp directly:

  • session/prompt with a sleep 60 tool call in flight, then a second session/prompt → {"code":-32602,"message":"Invalid params","data":"session already has active run run_53acf805-3b1f-4120-956c-58f60ed48f29; use _goose/unstable/session/steer"} — exact reproduction.
  • session/cancel (notification, POST answered 202) → the next session/prompt on that session succeeded 3.8 s later, and the abandoned turn's own terminal frame reported stopReason: "cancelled".

So the race window for a follow-up sent right after Stop is a few seconds, not "however long the run happens to keep going" — which is why the fix below also retries once.

Proposed fix

  • Client.Prompt cancels on every exit that did not receive the turn's terminal response: a new notify (JSON-RPC without an id — the shape goose's on_cancel is registered for, the same one apps/acp-bridge's Cancel sends) plus cancelRun. A stop then ends the run instead of orphaning it; turn timeouts and the tool-call cap get the same treatment.
  • If session/prompt is rejected because the previous run is still unwinding, cancel and send that prompt once more after a short delay, so a message typed immediately after Stop is not lost.

Acceptance criteria

  • Stopping a turn ends its run: a new message in the same chat afterwards is processed instead of failing with session already has active run.
  • No session/cancel follows a turn that ended normally (a chat conversation reuses the same session across turns).
  • A prompt rejected by an active run is retried exactly once and succeeds, its events streamed/persisted once.

Unit tests (fail on the pre-fix behaviour): TestPrompt_CancelledSendsSessionCancel — reverted, it reports session/cancel sent 0 times, want exactly 1; TestPrompt_RetriesOnceAfterActiveRunRejection — reverted, it returns Prompt: Invalid params: session already has active run …; TestPrompt_SuccessSendsNoSessionCancel.

Activity

  1. pullfrog commented on Oct 28, 2026

    @pullfrog
    Contributor
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