Skip to content

fix(pi): recover fork targets from previous sessions - #28538

Open
voltcrash wants to merge 1 commit into
pingdotgg:mainfrom
voltcrash:voltcrash/pi-cross-session-fork
Open

voltcrash wants to merge 1 commit into
pingdotgg:mainfrom
voltcrash:voltcrash/pi-cross-session-fork

Conversation

@voltcrash

Copy link
Copy Markdown
Contributor

Pi forks fail when the selected turn's native entry lives in an earlier session and later background wakes carry uncaptured turn references. The adapter searches only the current session tree and reports that no captured entry was found.

Recover a unique previous native session containing the selected turn, using Pi's parent-session lineage to distinguish fork copies. Fork that session through Pi's native path and trim later wakes while preserving the selected turn's history. Missing or ambiguous matches retain the existing safe failure.

Fixes #28377.

Scope and approval

This is one adapter-boundary bug fix. The issue has not yet received maintainer triage, and this PR does not claim upstream approval or the small-fix exception. The author requested submission of the completed candidate for maintainer consideration despite that outstanding contribution-policy requirement.

Verification

  • Added focused cross-session regressions first; the original adapter failed with the reported uncaptured-entry protocol error.
  • vp run check:changed passed formatting, lint, both knip passes, 9 affected-package typechecks, and 99 tests in 2 files.
  • Exercised the actual adapter against native Pi 1.4.0 subprocesses with isolated temporary session files and no credentials or paid model turns. Baseline reproduced the protocol error. Four fixed consecutive-fork checks preserved the selected turn and its intervening messages, excluded later wakes, and left the source unchanged. Cases covered prior sessions both with and without later wakes, with two successive forks per case.
Before: Pi turn 2 has no captured session-tree entry and none was found in the session tree
After:  fork=1, previous has later wakes=false — PASS
        fork=2, previous has later wakes=false — PASS
        fork=1, previous has later wakes=true  — PASS
        fork=2, previous has later wakes=true  — PASS
Retained ids: u1,a1,steer1,a1b; source unchanged

Limits: recovery covers completed, strongly referenced targets in V3 native session files beside the current session, with a unique matching lineage. Older native formats and ambiguous histories fail closed. Session discovery reads sibling files sequentially on this exceptional path. No UI, other-provider, rollback, or broad history-reconstruction changes.

Reviewed with review-loop: 2 rounds with Claude Opus 5.5 on xhigh. Reviewer verdict: approved. The lineage-selection blocker and an unnecessary-parse nit were fixed; optional performance, older-format compatibility, and rare safe-failure lineage improvements were deferred.

Created with GPT-6.1 Sol on xhigh in the Codex harness through T3 Code.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 1, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 99e07c5

Macroscope's review found this PR approvable — Pi forks can recover selected turns from a uniquely matching previous session, with lineage and history-boundary checks. Recovery remains limited to explicit forks and requires a separate destination session, preserving source history.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7195b69 and 99e07c5.

Files selected for processing: 2
  • packages/provider-pi/src/server/adapter.test.ts
  • packages/provider-pi/src/server/adapter.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

The Pi adapter now searches sibling session files when an uncaptured fork target is absent from the current session. It selects a unique matching source, recovers the fork boundary, and rejects invalid or reused source files. Tests cover successful and rejected prior-session fork cases.

Changes: Prior-session fork recovery

Layer / File(s) Summary
Find and recover prior-session targets
packages/provider-pi/src/server/adapter.ts
The adapter reads sibling session files when an uncaptured strong target is absent from the current session. It selects a source only when one matching root remains and recovers a boundary from the session tree.
Fork from the recovered source
packages/provider-pi/src/server/adapter.ts
The fork process receives the selected source file. The adapter uses the recovered boundary when needed and rejects a missing result or one that matches either source file.
Validate prior-session fork cases
packages/provider-pi/src/server/adapter.test.ts
Parameterized tests cover exact targets, later wakes, copied histories, duplicate matching sessions, and unrelated timestamps.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant PiAdapter
  participant SessionFiles
  participant PiForkProcess
  PiAdapter->>SessionFiles: Search sibling files for the target
  SessionFiles-->>PiAdapter: Return unique matching source and entries
  PiAdapter->>PiAdapter: Recover fork boundary
  PiAdapter->>PiForkProcess: Start fork with source and boundary
  PiForkProcess-->>PiAdapter: Return fork session file
  PiAdapter->>PiAdapter: Validate returned session file
Loading

Suggested reviewers: henrychu04, juliusmarminge

Merge Risk: Minimal · up to 99e07

The prior-session fork change is mergeable after normal checks; no concrete unresolved issue was established.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title "fix(pi): recover fork targets from previous sessions" states the main change: the Pi adapter now recovers fork targets that live in earlier sessions. It follows the conventional commit form…
Description check Passed The description follows the template. It states the problem and the change, and it links issue #28377. The Scope and approval section explains that the issue has no maintainer triage yet and that the …
Linked Issues check Passed Issue [#28377] requires a fork from a strong native turn in a previous Pi session and exclusion of later adopted wake turns. findForkSource scans sibling V3 .jsonl files when the current session l…
Out of Scope Changes check Passed The changes stay within the adapter-boundary fix for [#28377]. The Path.Path dependency supports sibling session discovery. custom_message recognition supports correct history trimming. The distin…
Full details: Title check

Explanation

The title "fix(pi): recover fork targets from previous sessions" states the main change: the Pi adapter now recovers fork targets that live in earlier sessions. It follows the conventional commit format and matches the raw summary and PR objectives. It does not cover every detail, such as the lineage matching or the protocol-error fallback, which is acceptable.

Full details: Description check

Explanation

The description follows the template. It states the problem and the change, and it links issue #28377. The Scope and approval section explains that the issue has no maintainer triage yet and that the PR does not claim the small-fix exception. The Verification section lists the checks run and their observed results, including before and after output. The template's trailing agent-attribution line is present, as the author wrote it. The description does not clearly establish maintainer approval of direction and scope, which the template requires, but the author states this openly. Because the rest of the template is substantially complete, the check passes.

Full details: Linked Issues check

Explanation

Issue [#28377] requires a fork from a strong native turn in a previous Pi session and exclusion of later adopted wake turns. findForkSource scans sibling V3 .jsonl files when the current session lacks the target. It selects one root through parentSession lineage. The fork uses that source file, then piPreviousSessionForkBoundary recovers the target boundary and preserves only prior history. The added tests cover a previous session with and without later wakes, native fork copies, ambiguous matches, and timestamp mismatches. The rejection cases fail closed.

Full details: Out of Scope Changes check

Explanation

The changes stay within the adapter-boundary fix for [#28377]. The Path.Path dependency supports sibling session discovery. custom_message recognition supports correct history trimming. The distinct-session-file check protects native fork creation. The added tests validate the new recovery and safe-failure paths. No unrelated UI, provider, rollback, or broad history changes appear in the reviewed diff.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@maria-rcks

Copy link
Copy Markdown
Collaborator

Note

Written by gpt-6.1-sol on behalf of Maria

Verified in a real dev environment

partial verification only. the original previous-session recovery is not proved.

ran github/main (37d7615a91) in a separate worktree first, then exact pr head 99e07c59607476dc02134f5b993b28e1c2f8cee3, with one dev server at a time and isolated empty state. used repo Playwright and system Chrome. created the projects, threads and turns through the web app, with no fixtures or mocked provider responses.

  • real Codex gpt-6.1-sol turns completed on both revisions.
  • on the pr, two ordinary native Pi forks completed real gpt-6.1-sol turns through the local proxy. both retained ORCHID-28538 and excluded the later USER-LATER-28538 user turn. the source retained that later turn.
  • the installed Pi file-trigger extension produced a real adopted background wake with a weak turn reference. forking from the preceding completed user turn then failed on both main and the pr when the fork's first provider turn started:
pi provider protocol error: Pi turn 3 has no captured session-tree entry and none was found in the session tree.

read-only inspection confirmed the strong target still exists in the current native session. this is a neighboring custom-message-wake limitation, not the previous-session case or a demonstrated regression from this pr. no source changes made.

vp test run packages/provider-pi/src/server/adapter.test.ts passed all 98 tests through blacksmith-check.

ordinary Pi fork completes with retained marker and later turn absent

main fails to start a fork after a custom-message background wake

pr head has the same custom-message background-wake fork failure

Not verified

the changed previous-session discovery and lineage selection. the original session-rotating memory/background extension is unavailable here; the installed file-trigger extension leaves the target in the same session. manufacturing session files or editing projections would not establish the requested real user path. the original bug was therefore not reproduced, and this run cannot establish that the pr fixes it.

native desktop/mobile clients, macOS/Windows, and remote/relay modes were not exercised on this Linux web run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pi: fork from a turn fails when the fork target's session entry lives in a previous Pi session

2 participants