Skip to content

Rewind Pi chats with Pi's own fork - #37944

Open
Anneo22 wants to merge 2 commits into
stablyai:mainfrom
Anneo22:feat/pi-chat-rewind
Open

Anneo22 wants to merge 2 commits into
stablyai:mainfrom
Anneo22:feat/pi-chat-rewind

Conversation

@Anneo22

@Anneo22 Anneo22 commented Nov 3, 2026

Copy link
Copy Markdown

ELI5

Pi chats get “Rewind to here”. Pick a sent message and it returns to the composer; that message and everything after it disappear. Pi's own conversation moves back too. Files on disk stay as they are.

What Changed

Pi currently disables rewind. This enables the existing action and uses Pi's RPC fork at the first removed prompt. Before forking, it checks that Pi's active branch ends with the prompts Orca is removing; a mismatch refuses the rewind.

The fork uses Orca's saved-fork and session-replacement path, and resumes on relaunch. Pi's path-shaped fork IDs get a digest for the provider-handle link. The stop-checkpoint helper moves into its own file to keep the adapter under the line limit.

Why

Pi's RPC has fork, but not navigate_tree. Letting Pi do the fork keeps its context in step with the transcript and preserves the abandoned conversation in the original session file.

Related: #28873 and OMP PR #36258, which leaves Pi rewind disabled.

Linked Issue

Fixes #37942

Visual Proof

Before: three prompts. After rewinding to TWO: only ONE remains, and TWO is back in the composer.

rewind.mp4

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

On macOS, commit 4fb657a875, Node 24.22.1, Pi 1.5.0: the six new/updated regression suites pass (77 tests), pnpm tc and pnpm run build:electron-vite pass. The changed-code quality gate reports zero new findings across all 19 files.

In an isolated dev build, sent ONE, TWO and THREE, then rewound to TWO. The recording shows the result. After restarting, only ONE remained; asked for earlier prompts, Pi listed only ONE.

Full pnpm build stopped at missing mobile/ dependencies. Full lint/test/build are left to CI. Linux, Windows, SSH and WSL were not run locally.

Risk

Level: Medium

The shared fork-rewind path now serves Pi as well as Claude. Pi refuses mismatched branches instead of guessing where to cut. A plain revert removes the action; forks already created remain valid Pi session files. File rollback is not included.

AI Disclosure

AI-assisted implementation with Claude Opus 5.5. OpenAI GPT via Pi helped with verification and PR preparation. The commit has an Assisted-by: trailer.

Review

Agent review: the new behavior is Pi-only; Claude keeps its existing fork path, and Codex/OMP are untouched. Paths come from Pi's RPC rather than local file access, so there is no added local-only assumption for SSH. Work happens only on rewind, with no new UI components or external inputs. Cross-platform and remote behavior still need CI or maintainer testing.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Conversation rewind only, matching the existing Claude/Codex behavior.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Pi native chats declared rewind: false, so "Rewind to here" was never
offered on a Pi chat. Rewind now asks the running Pi to fork (its RPC
`fork` command) at the first removed prompt, after checking that Pi's
active branch ends with exactly the prompts the chat removes; otherwise
it refuses and leaves the conversation alone. The fork rides the
existing fork-rewind path (saved fork, epoch replacement, forked handle
link), and Pi launch resumes a saved fork the way Claude launch does.

- The Pi adapter reports that its rewind cuts at the prompt, so the
  desktop offers the action on sent Pi messages, which carry Orca's own
  key rather than a provider item id.
- A fork named by a file path (Pi) gets a digest link id, because
  `rewind-<path>` is not a valid handle link id.
- The Pi adapter's stop-checkpoint wait moves to its own module so the
  adapter stays within the file-size limit.

Assisted-by: Claude (claude-opus-5-5)
Copilot AI balanced review requested due to automatic review settings November 3, 2026 22:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The changes add prompt-based rewind support for Pi. The UI can admit submitted prompts when the provider declares prompt-cut support. Structured rewind cuts provide ordered prompt text, and the Pi RPC implementation validates that text against the active branch before forking. The session launch and completion paths select and record the materialized fork. The changes also update Claude target validation and structured rewind handling.

Severity of issue fixed: Medium

Merge Risk: Moderate · up to d73b0

Large Pi chats may be unable to rewind even their latest prompt. Use a bounded history read before merging unless that limitation is explicitly accepted.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: enabling Pi chat rewind through Pi's native fork mechanism.
Description check Passed The description follows the required template and explains the user-visible behavior, implementation, rationale, linked issue, visual proof, testing, risks, AI use, compatibility considerations, and c…
Linked Issues check Passed Issue [#37942] requires rewind for sent Pi messages, removal of the selected prompt and later prompts, restoration of the selected prompt to the composer, movement of Pi's conversation, unchanged file…
Out of Scope Changes check Passed The changes stay within [#37942]. Pi RPC fork handling, prompt-cut computation, renderer admission, launch resumption, rewind completion, and regression tests directly implement or support Pi conversa…
Full details: Description check

Explanation

The description follows the required template and explains the user-visible behavior, implementation, rationale, linked issue, visual proof, testing, risks, AI use, compatibility considerations, and checklist status. It also explains that full build and cross-platform testing remain for CI or maintainers.

Full details: Linked Issues check

Explanation

Issue [#37942] requires rewind for sent Pi messages, removal of the selected prompt and later prompts, restoration of the selected prompt to the composer, movement of Pi's conversation, unchanged files on disk, and automated coverage. The PR enables Pi rewind support and prompt admission. structuredRewindCut creates a prompt-based Pi target and retains only earlier rows. forkPiRpcSessionForRewind verifies the active branch, calls Pi RPC fork before the first removed prompt, and preserves the source session. The Pi fork, cut, launch-resume, completion, and renderer tests cover the implementation. No unmet coding requirement is shown.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#37942]. Pi RPC fork handling, prompt-cut computation, renderer admission, launch resumption, rewind completion, and regression tests directly implement or support Pi conversation rewind. Shared rewind changes preserve the existing provider paths and support the Pi fork-through-agent behavior. The Claude validation change and checkpoint extraction are supporting changes. No unrelated product behavior is shown.

Full details: Docstring Coverage

Explanation

Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 19 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Comment thread src/main/pi/rpc-rewind-fork.ts Resolved
Two paths could leave a running agent on a fork Orca never recorded,
while the chat still points at the source conversation:

- Pi's `fork` fails with anything but a Pi error reply (an unreadable
  reply, a timeout), so Pi may have forked anyway. Close the Pi child,
  as a fork whose state read fails already does; the fork's own error
  is still what the rewind reports if closing fails too.
- The fork is made but saving the rewind record fails. Stop the agent
  before rethrowing, so its next start resumes the recorded chat.

Assisted-by: Claude (claude-opus-5-5)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Avoid a full-history RPC read for Pi rewind. · rpc-rewind-fork.ts:58

src/main/pi/rpc-rewind-fork.ts:58
Major · Stability & Availability · Heavy lift

Avoid a full-history RPC read for Pi rewind.

When the get_entries response exceeds the RPC peer’s 8 MiB line limit, readPiEntries(connection, null) rejects. The catch in forkPiRpcSessionForRewind then returns provider-refused, so a large Pi chat cannot rewind even to its latest prompt. Read only the history needed to prove the active-branch cut, or use a bounded history source. (raw.githubusercontent.com)

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80fdba91-e0c6-43fe-8045-49ae81c079f6
Commits

Reviewing files that changed from the base of the PR and between 4fb657a and d73b06d.

Files selected for processing: 4
  • src/main/native-chat/agent-session-wire/structured-agent-session-fork-rewind.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-rewind.ts
  • src/main/pi/rpc-rewind-fork.test.ts
  • src/main/pi/rpc-rewind-fork.ts

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

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Rewind Pi chats in the Chat UI

2 participants