Skip to content

fix: enable creates local metadata branch from remote when available#511

Merged
Soph merged 7 commits intomainfrom
fix/enable-preserve-remote-checkpoints
Feb 26, 2026
Merged

fix: enable creates local metadata branch from remote when available#511
Soph merged 7 commits intomainfrom
fix/enable-preserve-remote-checkpoints

Conversation

@dvydra
Copy link
Contributor

@dvydra dvydra commented Feb 26, 2026

Problem

When entire enable runs, EnsureMetadataBranch() creates the local entire/checkpoints/v1 branch. Previously it always created an empty orphan, even when origin/entire/checkpoints/v1 exists with real checkpoint data. This empty local branch shadows the remote — getSessionsBranchTree() finds the empty local first and never falls back to the remote, breaking entire explain with "checkpoint not found".

Reproduction:

  1. git clone a repo that has entire/checkpoints/v1 on the remote
  2. entire explain --commit <hash> → works (falls back to remote ref)
  3. entire enable → creates empty orphan local branch
  4. entire explain --commit <hash> → fails (finds empty local, never checks remote)

Fix

EnsureMetadataBranch() now checks for origin/entire/checkpoints/v1 before creating an empty orphan. If the remote branch exists, the local branch is created pointing to the same commit, preserving all checkpoint data.

Test plan

  • TestEnsureMetadataBranch/creates_from_remote_on_fresh_clone — local created from remote with data intact
  • TestEnsureMetadataBranch/creates_empty_orphan_when_no_remote — unchanged behavior when no remote
  • Verified end-to-end: fresh git clone from GitHub → enableexplain works

🤖 Generated with Claude Code

When `entire enable` runs in a cloned repo that already has
origin/entire/checkpoints/v1, it was creating an empty orphan branch
that shadowed the remote data. This caused `entire explain` (and other
checkpoint lookups) to fail with "checkpoint not found" because
getSessionsBranchTree() found the empty local branch first.

Now EnsureMetadataBranch() checks for the remote-tracking branch and
creates the local branch from it, preserving existing checkpoint data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 2865d24ae758
Copilot AI review requested due to automatic review settings February 26, 2026 03:12
@dvydra dvydra requested a review from a team as a code owner February 26, 2026 03:12
@cursor
Copy link

cursor bot commented Feb 26, 2026

PR Summary

Low Risk
Small change to branch-initialization logic plus targeted tests; low risk aside from potential edge cases in repositories without an origin remote or with unusual ref states.

Overview
Fixes EnsureMetadataBranch() so it preserves existing checkpoint data: when origin/entire/checkpoints/v1 exists, it now creates the local entire/checkpoints/v1 ref pointing at the remote’s commit instead of always creating an empty orphan branch.

Adds coverage for both paths with a new TestEnsureMetadataBranch, including a helper that uses the git CLI to create a bare repo containing remote checkpoint data and verifying fresh clones create a non-empty local metadata branch; behavior remains unchanged when no remote ref exists (still creates an empty orphan).

Written by Cursor Bugbot for commit 9017787. 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

Fixes entire enable behavior in cloned repos where origin/entire/checkpoints/v1 already exists: instead of creating an empty orphan branch that shadows existing remote metadata, the CLI now seeds the local metadata branch from the remote-tracking ref when available.

Changes:

  • Update EnsureMetadataBranch() to check for origin/entire/checkpoints/v1 and create the local entire/checkpoints/v1 ref pointing at the same commit.
  • Retain the existing behavior of creating an empty orphan branch only when neither local nor remote-tracking metadata refs exist.
  • Adjust function comment to reflect the new behavior (remote-first, orphan fallback).

@dvydra dvydra marked this pull request as draft February 26, 2026 03:20
@khaong
Copy link
Contributor

khaong commented Feb 26, 2026

bugbot run

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

dvydra and others added 2 commits February 26, 2026 15:04
When enable creates an empty orphan entire/checkpoints/v1 branch, it
shadows the remote-tracking branch that getSessionsBranchTree() would
otherwise fall back to, breaking commands like explain.

Fix EnsureMetadataBranch to detect when the local branch is an empty
orphan and the remote has real checkpoint data, and update accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: d9f7d656b38d
Use git CLI for test setup instead of manual plumbing objects.
Reuse initTestRepo helper for the no-remote case.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 80e4ad299ce1
@dvydra dvydra changed the title fix: enable creates local metadata branch from remote when available fix: enable preserves remote checkpoint data on local metadata branch Feb 26, 2026
dvydra and others added 2 commits February 26, 2026 15:27
Remove scenario 2 (updating empty orphan from remote) — that will be
a separate PR. This PR now only adds the remote-tracking branch check
for repos where the local branch doesn't exist yet.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: ca672efb0556
CI runners don't have global git user.name/user.email configured,
causing the test commit to fail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 35b128464ad9
@dvydra dvydra changed the title fix: enable preserves remote checkpoint data on local metadata branch fix: enable creates local metadata branch from remote when available Feb 26, 2026
@dvydra dvydra requested a review from Copilot February 26, 2026 05:15
@dvydra
Copy link
Contributor Author

dvydra commented Feb 26, 2026

@cursor review

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

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

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

Return wrapped errors for unexpected failures when checking local and
remote metadata branch refs, instead of silently falling through.
Only fall back to orphan creation when refs are genuinely absent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 5cf83f1be508
@dvydra
Copy link
Contributor Author

dvydra commented Feb 26, 2026

bugbot run

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

Copy link
Contributor

@khaong khaong left a comment

Choose a reason for hiding this comment

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

🎉

@Soph Soph merged commit c96536d into main Feb 26, 2026
4 checks passed
@Soph Soph deleted the fix/enable-preserve-remote-checkpoints branch February 26, 2026 10:55
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.

4 participants