Skip to content

fix(pi): stop waiting for pi 30s after an abort it can't settle - #154

Draft
jonnyparris wants to merge 5 commits into
mainfrom
fix/post-abort-wait-grace
Draft

jonnyparris wants to merge 5 commits into
mainfrom
fix/post-abort-wait-grace

Conversation

@jonnyparris

Copy link
Copy Markdown
Owner

Why

Follow-up from #148 review round 3. After a user abort or a turn stall, PiEngine.run awaited submission.wait(this.ctx) with no signal and no bound, with the event stream still attached. #148 assumed pi's abort cascade means this can't hang. It can: a model request or tool that ignores the abort signal keeps pi's run alive, and run() never returned (red check below).

What

  • src/pi/engine.ts: after an abort, waitAfterAbort gives pi PI_ABORT_GRACE_MS (30s) to settle. Then it stops waiting, the finally detaches the stream, it logs pi: run did not settle after abort, and run() returns unanswered with reason abort_timeout. The grace wait has its own abort signal, so no orphaned wait is left behind.
  • PiTurnInput.abortGraceMs overrides the grace (tests). CodingAgent.piAbortGraceMsOverride is the test hook.
  • Docs: docs/session-watchdog.md covers the grace and the known gap. It also moves two Limitations bullets back under their heading (fix(prompts): fail a turn that stops making progress, not only inside a model request #148 put the guard section in the middle of the list).

Known gap (not fixed here)

While the orphan is stuck, pi queues the session's next submission behind it. After the orphan ends, pi sometimes runs the queued prompt and sometimes leaves it queued with no task. Then only the turn stall guard (15 min) ends it. Both outcomes showed up in the e2e. The same happens on the engine from main, so this PR didn't cause it. close() + reopen and harness.resume() did not free the queued submission. The e2e pins the part that is deterministic.

Tests

  • test/pi-engine.test.ts: a tool that ignores the abort. run() returns abort_timeout within the grace and logs the warning. Red check: with the old unbounded wait, this test times out.
  • test/pi-default-e2e.test.ts, in a real CodingAgent DO: a model request that ignores the abort (stuck model prompt in pi-models-mock). The prompt ends aborted, and run() returns abort_timeout ~300ms after the abort. A prompt sent meanwhile stays running and its model request isn't made. After release it either completes or fails with Turn stalled.
  • npx vitest run: 116 files, 1379 tests pass. tsc --noEmit and biome lint are clean.

Adversarial review: 4 rounds (claude-haiku-5-5, plus gemini-3.5-flash on round 3; Gemini and its DeepSeek fallback timed out on rounds 1, 2 and 4 under Mac load). Round 4 ran because round 3 found two medium test issues. 10 findings fixed. Rejected: "an orphan can commit a late reply into the transcript". That is pre-existing, and runPiChat already returns early on an aborted signal. The round-4 lows were fixed without another review.

beep-boop-🤖

After a user abort or a turn stall, PiEngine.run waited on submission.wait
with no bound and kept the event stream attached. A model request or tool
that ignores the abort signal keeps pi's run alive, so run() never returned.
Now it waits PI_ABORT_GRACE_MS (30s), then detaches, logs, and returns
unanswered (abort_timeout).

Known gap, documented: pi still queues the session's next prompt behind the
orphan until it ends. Tests show close + reopen doesn't free it either.

Also moves two watchdog Limitations bullets back under their heading.
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Preview deployed: https://dodo-preview.jonnyparris.club

Serves ca629c6 from this PR. Access-gated (same policies as prod). Load it in a Browser Run session with the Dodo service token to verify UI changes.

The preview is shared: the next PR push replaces this build, and this PR gets a new comment when that happens. Add the preview-lock label to hold it during a live check, and remove the label when you are done.

Replaced 2777f58 from #153.

@github-actions

Copy link
Copy Markdown

Preview replaced: https://dodo-preview.jonnyparris.club now serves 8e11710 from #155, not this PR's ca629c6.

A live check on this PR that started before now is no longer testing this branch. Re-run this PR's deploy-preview job to take the preview back, or add the preview-lock label to deploy it and hold it.

This branch was successfully deployed

1 active deployment
dodo-preview — ca629c6d Deployed Oct 23, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant