fix(acp): start a fresh agent when the last turn's own tool closed the session

Merged
SA
17d ago
+48-28

What and why

  • When a step timed out and the next step started right away, the old agent could run a tool of its own as it stopped. ownTool then closed the session and dropped it from the attempt. The next step was still waiting on that session's last turn, then prompted the closed agent and failed with MODEL_PROVIDER_FAILED ("ACP connection closed").
  • runStep now gets its session from ready() in packages/acp/src/executor.ts. After the last turn stops, ready() checks that the session is still the attempt's. If not, it starts a fresh agent.
  • The executor tests waited on the scripted agent, a child process, with vi.waitFor's 1s default and one fixed 500ms sleep. One eventually helper now gives every wait 15s, and the sleep waits for the first prompt instead.
  • The fixture wrote its tool log line only after it reported the tool, and the executor stops the agent on that report. It now writes the line first. This is the line the Node 22 job of #1452 failed on.
  • The test for this case now starts the next step at once, as the runner does. Before, it waited for the log line, which hid the race in the full file. Run alone, it failed on main.

Issue

Fixes #1456

Verified

Ran it locally: yes

  • packages/acp, npx vitest run tests/executor.test.ts: the file alone, the one test alone with -t, and under load (12 runs in parallel on 8 cores).
  • The new test shape fails without the ready() change (3 of 3 runs) and passes with it.
mainthis branch
The test alone, -t "ran once its step ended"2 of 3 runs fail: ACP connection closed3 of 3 pass
The file under load24 of 24 runs fail, 2 to 5 tests each36 of 36 runs pass, 31/31 each

Reviewed with sol-loop: 2 rounds with gpt-6.1-sol on high. Sol verdict: approved

šŸ¤– Generated with Claude Code