# fix\(providers\): correct Pi retry, teardown and turn-boundary handling · stienswout/t3code

[View on GitCafe](https://git.cafe/stienswout/t3code/commit/244f2291d18c3e12f4bb9b14b68c1d7b9b238819)

Repository: [stienswout/t3code](https://git.cafe/stienswout/t3code)

Visibility: public

Requested revision: 244f2291d18c3e12f4bb9b14b68c1d7b9b238819

Requested commit: 244f2291d18c3e12f4bb9b14b68c1d7b9b238819

Commit: 244f2291d18c3e12f4bb9b14b68c1d7b9b238819

Tree: 6fa88d01ffa41ce3649ab34321abeae1a349a5dd

Author: Wout Stiens

Committer: Wout Stiens

## Message

```
fix(providers): correct Pi retry, teardown and turn-boundary handling

Six review findings from the protocol-gap round:

- A recovered auto-retry no longer terminalizes as failed. Pi emits the
  erroring `message_end` before retrying, and `auto_retry_end` success left
  that failure in place, so `agent_settled` failed the whole turn.
- A failed `prompt` send finalizes the turn again. The fire-and-forget
  change moved the send off `request`, dropping the cleanup, so a send
  failure left `activeTurn` set and wedged every later turn.
- `startTurn` now holds the session permit, so a new turn cannot start while
  the previous `finalizeTurn` is still awaiting `get_entries`. That race let
  the old finalizer capture the new turn's entry and publish idle after the
  new turn had already published active.
- `switch_session` clears the model and thinking baselines too, so
  "Pi default"/"inherit" cannot replay the previous session's defaults.
- Termination re-checks liveness before SIGTERM and before escalating to
  SIGKILL. Signalling a pid that already exited can hit an unrelated process
  once the OS recycles the pid or pgid.
- Windows tears down the whole tree with `taskkill /T`, matching
  `AcpSessionRuntime`. `process.kill` reached only pi itself and left
  extension subprocesses holding inherited stdio handles.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

```

## Parents

- [8dbf009fa5e8273f6a0fd6fc1bd8295bb2a1baef](https://git.cafe/stienswout/t3code/commit/8dbf009fa5e8273f6a0fd6fc1bd8295bb2a1baef?format=markdown)

[Source at this commit](https://git.cafe/stienswout/t3code/tree/244f2291d18c3e12f4bb9b14b68c1d7b9b238819?format=markdown)
