fix: unnecessary restore prompt, wrong checkpoint on tree nav, and leaf position persistence#4
Open
LiusCraft wants to merge 1 commit into
Open
fix: unnecessary restore prompt, wrong checkpoint on tree nav, and leaf position persistence#4LiusCraft wants to merge 1 commit into
LiusCraft wants to merge 1 commit into
Conversation
Author
|
@arpagon This PR fixes three issues with Tree navigation in pi-rewind: Issue 1: Unnecessary restore prompt + wrong checkpoint restored
Root cause: checkpoint timestamps are at Issue 2: Navigation position not persisted Issue 3 (new): Full details in the PR description. Would appreciate a review. Thanks! |
LiusCraft
force-pushed
the
main
branch
4 times, most recently
from
July 12, 2026 10:06
3aee8ab to
b615687
Compare
…af position persistence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
When using pi agent's Tree navigation (double Esc → select a previous turn), two issues occurred:
Issue 1: Unnecessary restore prompt + wrong checkpoint restored
Two facets to this bug:
Root cause: Checkpoints are created at
turn_end, with timestamps after the user message in the same turn. The originalhandleTreeRestoreusedsorted.find(c => c.timestamp <= targetTs)to locate a checkpoint for the target entry. This lookup always missed the current turn's checkpoint (its timestamp is too recent) and found one from an earlier turn instead. This caused two symptoms:cp !== latestCpwas always true, so the restore prompt always appearedIssue 2: Navigation position not persisted
After navigating back via the tree and exiting pi, running
pi -cresumed at the latest conversation tail instead of the previously navigated position.Root cause (surface):
SessionManager._buildIndex()always setsleafIdto the last entry when loading from disk —navigateTreeonly changes leafId in memory, never persisted.Root cause (deeper): The original leaf file was keyed by ephemeral session UUID (
leaf-{sessionId}.json). Sincepi -cstarts a new process with a new session UUID, the saved leaf was never found on resume.Changes
commands.ts
hasFileChangesby comparing target vs latest checkpoint; only show file-restore options when real changes exist. Remove the no-opif (!target && state.resumeCheckpoint)stub.oldLeafIdin event type; compare old-leaf checkpoint vs target-leaf checkpoint to decide whether file restore is needed. Variable names consolidated.index.ts
leafFilePath/saveLeafId/loadLeafId/clearLeafId) — keyed by repo root path (stable across session restarts), saved to~/.pi/agent/pi-rewind/leaf-{repoKey}.json.session_treelistener: save leaf on tree navigation.before_agent_start(new): clear saved leaf on new turn.initSession: restore saved leaf unconditionally on session start (noreasonguard, so it works forpi -ctoo).