Skip to content

fix: restore sessions#403

Open
gtrrz-victor wants to merge 3 commits intomainfrom
gtrrz-victor/fix-restore-sessions
Open

fix: restore sessions#403
gtrrz-victor wants to merge 3 commits intomainfrom
gtrrz-victor/fix-restore-sessions

Conversation

@gtrrz-victor
Copy link
Contributor

fixes: #402

…ion independence

Instead of storing home-relative transcript paths in checkpoint metadata,
always compute paths from the current repository location at restore time
using agent.GetSessionDir(repoRoot). This makes resume portable across
machine moves and directory changes.

## Changes

1. **Remove SessionTranscriptPath writes** (manual_commit_condensation.go)
   - Stop embedding sanitized repo path in checkpoint metadata

2. **Update RestoreLogsOnly()** (manual_commit_rewind.go)
   - Always compute transcript path from current repo location
   - Remove resolveTranscriptPathFromMetadata() helper (now unused)
   - Apply same fix to classifySessionsForRestore()

3. **Add deprecation comments** (checkpoint.go)
   - Mark TranscriptPath fields as DEPRECATED
   - Keep for backward compatibility with old checkpoints
   - Document new computation approach

4. **Add E2E test** (resume_relocated_repo_test.go)
   - Verify resume works after repo relocation
   - Ensure transcript restores to NEW location, not stored old location

## Why This Works

- **Location-independent**: agent.GetSessionDir() uses current repo path
- **Cross-machine portable**: No stored paths embedded in metadata
- **Backward compatible**: Old checkpoints with transcript_path still work
- **Simpler**: Removes fallback logic, always uses computed paths

Fixes issue where resume failed when projects moved directories or
were cloned to different machines with different absolute paths.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Entire-Checkpoint: c8200a737b62
Copilot AI review requested due to automatic review settings February 18, 2026 05:30
@gtrrz-victor gtrrz-victor requested a review from a team as a code owner February 18, 2026 05:30
@cursor
Copy link

cursor bot commented Feb 18, 2026

PR Summary

Cursor Bugbot is generating a summary for commit 19129c2. Configure here.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #402 where entire resume fails to restore sessions when a repository is moved to a different location. The root cause was that session restoration was using stored absolute paths from checkpoint metadata and .git/entire-sessions/ state files, which become stale when repos are relocated.

Changes:

  • Session restoration now computes transcript paths from current repo location instead of using stored metadata paths
  • Deprecated TranscriptPath field in checkpoint metadata (kept for backward compatibility but no longer written or read)
  • Fixed Gemini agent to use SHA256 hash of project path (matching actual Gemini CLI behavior) instead of incorrect path sanitization
  • Added comprehensive E2E test verifying resume works after repo relocation

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cmd/entire/cli/strategy/manual_commit_rewind.go Changed RestoreLogsOnly and classifySessionsForRestore to compute transcript paths using agent.ResolveSessionFile directly instead of reading from metadata
cmd/entire/cli/strategy/manual_commit_condensation.go Removed writing of deprecated SessionTranscriptPath field when creating checkpoints
cmd/entire/cli/strategy/common.go Removed unused homeRelativePath helper function
cmd/entire/cli/checkpoint/checkpoint.go Marked SessionTranscriptPath and TranscriptPath fields as deprecated with documentation
cmd/entire/cli/agent/geminicli/gemini.go Fixed GetSessionDir to use SHA256 hash (GetProjectHash) matching Gemini CLI's actual behavior; updated fallback in ResolveSessionFile to generate proper Gemini-style filenames
cmd/entire/cli/agent/geminicli/gemini_test.go Updated tests to verify new GetProjectHash function and Gemini-style fallback filenames
cmd/entire/cli/e2e_test/resume_relocated_repo_test.go New E2E test verifying resume works correctly after repository relocation

@gtrrz-victor gtrrz-victor force-pushed the gtrrz-victor/fix-restore-sessions branch from 19129c2 to 80ddc0a Compare February 18, 2026 05:55
@khaong
Copy link
Contributor

khaong commented Feb 18, 2026

bugbot run

@khaong
Copy link
Contributor

khaong commented Feb 18, 2026

Code review

Found 2 issues:

  1. rewind.go still calls ResolveSessionFilePath, which reads .git/entire-sessions/ state that may contain stale absolute paths from the original repo location. The PR explicitly avoids this function in RestoreLogsOnly and classifySessionsForRestore (with a comment explaining why), but the entire rewind command path through rewind.go was not updated. This means the location-independence fix is incomplete for interactive rewind.

// resolveTranscriptPath determines the correct file path for an agent's session transcript.
// Delegates to strategy.ResolveSessionFilePath after computing the fallback session directory.
func resolveTranscriptPath(sessionID string, agent agentpkg.Agent) (string, error) {
repoRoot, err := paths.RepoRoot()
if err != nil {
return "", fmt.Errorf("failed to get repository root: %w", err)
}
agentSessionDir, err := agent.GetSessionDir(repoRoot)
if err != nil {
return "", fmt.Errorf("failed to get agent session directory: %w", err)
}
return strategy.ResolveSessionFilePath(sessionID, agent, agentSessionDir), nil
}

The PR's own comment at lines 707-711 of manual_commit_rewind.go explains the rationale for avoiding this function:

// Compute transcript path from current repo location.
// Always use the current repo location to handle repo moves and cross-machine portability.
// Use agent.ResolveSessionFile directly (not ResolveSessionFilePath) because
// ResolveSessionFilePath reads .git/entire-sessions/ state which may contain
// stale absolute paths from the original repo location.
sessionAgentDir, dirErr := sessionAgent.GetSessionDir(repoRoot)
if dirErr != nil {
fmt.Fprintf(os.Stderr, " Warning: failed to get session dir for session %d: %v\n", i, dirErr)
continue
}
sessionFile := sessionAgent.ResolveSessionFile(sessionAgentDir, sessionID)

  1. ResolveSessionFilePath comment says it's "needed for agents like Gemini that store transcripts at paths that GetSessionDir can't reconstruct, e.g. SHA-256 hashed directories" — but this PR fixes GetSessionDir to correctly reconstruct Gemini's SHA-256 path via GetProjectHash. The comment's rationale is now obsolete and misleading, and the function's state.TranscriptPath lookup is now counterproductive for the location-independence goal.

// ResolveSessionFilePath determines the correct file path for an agent's session transcript.
// Checks session state for transcript_path first (needed for agents like Gemini that store
// transcripts at paths that GetSessionDir can't reconstruct, e.g. SHA-256 hashed directories).
// Falls back to the agent's ExtractAgentSessionID + ResolveSessionFile with fallbackSessionDir.
func ResolveSessionFilePath(sessionID string, ag agent.Agent, fallbackSessionDir string) string {
state, err := LoadSessionState(sessionID)
if err == nil && state != nil && state.TranscriptPath != "" {
return state.TranscriptPath
}
return ag.ResolveSessionFile(fallbackSessionDir, sessionID)
}

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

entire resume cmd does not restore sessions if project path is different

2 participants

Comments