# fix\(pi\): fork and revert past turns whose session entry was never captured · PR \#20521 · pingdotgg/t3code

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

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

Visibility: public

State: merged

Source repository: Unavailable fork

Source branch: fix/pi-fork-uncaptured-boundary

Target branch: main

Head commit: 3093a81a3c4bc05fd62dac6bb89f577663f69f67

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

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

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

## Description

---

Pi turns interrupted before T3 captures their session entry keep a weak turn reference. Forking or reverting past one then fails even though Pi persisted the prompt.

Recover the discarded turn's user entry from the active session branch, bounded by the retained turn's completion and the discarded turn's completion. Reuse the existing branch walker and reject missing ancestry, timestamps, or an unresolved boundary. At thread start, use the earlier of provider thread creation and turn start so adopted wakes are included while inherited parent history stays intact.

Thanks @henrychu04 for the reproduction and original fix in [#20521](https://github.com/pingdotgg/t3code/pull/20521). Maintainer takeover preserves the author's commit and adds the current-main merge, a smaller branch walk, and inherited-history coverage. Adversarial review caught a wrong-cut case where a later steer could hide a wake predating T3's turn; the revised root test reproduces it and the creation-time bound fixes it.

Verification on Linux / Node 24:

- PR regression tests: 2 → 3 in `packages/provider-pi/src/server/adapter.test.ts`; the file now has 96 tests. All three recovery cases fail without the PR fix; the revised root case fails with the pre-review implementation (selects the later steer). The interrupted implementation failed all three; the rebuilt implementation passes them.
- All 152 Pi package tests pass; all 8 Pi orchestration replay scenarios pass.
- Scoped Pi typecheck, changed-file lint, formatting, and whitespace checks pass, with existing warnings only.
- Real Pi 1.3.0, isolated state and a local mock OpenAI-compatible endpoint: complete prompt 1, kill Pi during prompt 2's model request, then recover through T3's Pi adapter. Fork and rollback retain prompt 1 and discard prompt 2. Root rollback also recovers a wake predating T3's first turn while retaining inherited prompt 1 (failed before the review fix, passes after it). No model credentials or live user state were used.

The change has no visual UI, so behavior tests and the native session files are the proof. macOS, Windows, iOS, Android, and Electron desktop were not verified. Authenticated model-provider behavior was not exercised; the live check used a local mock model.

[Native before/after behavior proof](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/bdaaa7b8f87bc8c5/proof.txt).

Tests: Codex GPT-6 Astra (high). Implementation and integrated verification: Codex GPT-6.1 Sol (high). Adversarial review: Claude Opus 5.5 and Codex GPT-6 Sol, through T3 Code.

