# fix\(pi\): fork completed turns while the next turn is running · PR \#23052 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/23052)

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

Visibility: public

State: merged

Source repository: pingdotgg/t3code

Source branch: fix/issue-23050

Target branch: main

Head commit: 1372a7af05a99986ff154c41ec3d6c83b21f51c3

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/23052)

[Commits](https://git.cafe/pingdotgg/t3code/pull/23052/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/23052/diffs?format=markdown)

## Description

---

## Problem

Forking a completed Pi turn while the next turn is still running fails with “Pi turn 2 has no captured session-tree entry and none was found in the session tree.” The running turn has a synthetic weak reference and no completion timestamp, although Pi has already persisted its prompt.

## Change

Allow the existing session-tree recovery window to remain open at its upper end for a running boundary turn. Keep the retained turn’s lower bound, ancestry validation, and earliest-user-entry selection, so the fork cuts before the running turn’s prompt rather than a later steer. Completed boundary turns keep their finite upper bound.

Add one adapter regression for the running weak-reference boundary. This is a server-only Pi adapter change; no client, wire contract, or other provider changes.

## Scope and approval

Fixes #23050

Triaged bug via the automated issue flow. Focused repair of the existing fork behavior, following [#20521](https://git.cafe/pingdotgg/t3code/pulls/20521); no authentication, credential, permission, approval, mode, sandbox, or MCP changes.

## Verification

- Test-first: the running-boundary regression fails on main with the exact reported protocol error; the existing three native-fork tests pass. Independent proof audit reruns red and green.
- `./node_modules/.bin/vp test run packages/provider-pi/src/server/adapter.test.ts`: 84/84 pass on the final head, including the existing completed-uncaptured-boundary cases.
- Scoped Pi typecheck, changed-file lint, formatting, whitespace checks, and `knip --workspace packages/provider-pi --no-config-hints` pass. Lint reports one existing unused `layer` warning outside this change.
- Temporary fake-Pi runtime driver: before fails with the exact protocol error; after returns `/fake/forked.jsonl` and sends native fork at `u2`, excluding turn 2 and its later steer. Evidence is from the adapter’s fake Pi protocol harness, not native session persistence.
- Codex GPT-6.1 Sol and Claude Opus 5.5 independent reviews: MERGE, no confirmed bugs. Removed their nonblocking fixture-only ancestry assertion.
- UI evidence matrix is empty. No visual changes; no screenshots or recordings required.

[23050-runtime-proof.txt](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/be53774a16dfccf0/23050-runtime-proof.txt)
[23050-proof-matrix.txt](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/f806ac5eab7bc328/23050-proof-matrix.txt)

Pi 1.3.0 installed without model credentials. Attempted the isolated worktree web flow, but repeated dev watcher restarts on source/test-cache changes and reconnect failures prevented completing the live two-turn sequence. Live Pi, authenticated model behavior, Windows, Electron desktop, and mobile remain unverified. No live T3 state was written. Main was fetched and merged locally; it was already up to date.

Implementation and regression test: Claude Opus 5.5. Triage, integrated verification, proof audit, and review: Codex GPT-6.1 Sol and Claude Opus 5.5 through T3 Code (Codex and Claude Agent harnesses).


<!-- gc2-pull-create:5df8596b38e7d7c0d92e018a3d53c0d57eedf12e78e72a10b4f75cc017aab621 -->

