Skip to content

fix: pass fetched ref to metadata reconciliation for checkpoint URL flow#836

Open
pjbgf wants to merge 2 commits intomainfrom
fix-checkpoint-token
Open

fix: pass fetched ref to metadata reconciliation for checkpoint URL flow#836
pjbgf wants to merge 2 commits intomainfrom
fix-checkpoint-token

Conversation

@pjbgf
Copy link
Copy Markdown
Member

@pjbgf pjbgf commented Apr 2, 2026

ReconcileDisconnectedMetadataBranch was hardcoded to check refs/remotes/origin/, but when pushing to a checkpoint URL (ENTIRE_CHECKPOINT_TOKEN flow), fetchAndMergeSessionsCommon fetches to refs/entire-fetch-tmp/. This meant reconciliation never found the remote ref and returned early, leaving a disconnected "Initialize sessions branch" orphan commit in the metadata branch history.

Add a remoteRefName parameter to both IsMetadataDisconnected and ReconcileDisconnectedMetadataBranch so callers pass the actual reference to compare against. The push path now passes fetchedRefName (which is already computed as either origin or temp ref), enabling reconciliation to work correctly for both flows.


Note

Medium Risk
Medium risk because it changes how git refs are selected for metadata disconnection detection/reconciliation during pushes, which can affect branch repair behavior and history if the wrong ref is passed.

Overview
Fixes metadata-branch disconnection detection/repair to work for both normal remotes and checkpoint-URL pushes.

IsMetadataDisconnected and ReconcileDisconnectedMetadataBranch now take an explicit remoteRefName, and callers (fetchAndMergeSessionsCommon and entire doctor) pass the appropriate fetched ref (including refs/entire-fetch-tmp/...). Tests are updated accordingly and add coverage for reconciling against a temp fetched ref.

Written by Cursor Bugbot for commit 2748ecc. Configure here.

ReconcileDisconnectedMetadataBranch was hardcoded to check
refs/remotes/origin/<branch>, but when pushing to a checkpoint URL
(ENTIRE_CHECKPOINT_TOKEN flow), fetchAndMergeSessionsCommon fetches to
refs/entire-fetch-tmp/<branch>. This meant reconciliation never found
the remote ref and returned early, leaving a disconnected "Initialize
sessions branch" orphan commit in the metadata branch history.

Add a remoteRefName parameter to both IsMetadataDisconnected and
ReconcileDisconnectedMetadataBranch so callers pass the actual reference
to compare against. The push path now passes fetchedRefName (which is
already computed as either origin or temp ref), enabling reconciliation
to work correctly for both flows.

Signed-off-by: Paulo Gomes <paulo@entire.io>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 4108db521b5d
@pjbgf pjbgf requested a review from a team as a code owner April 2, 2026 20:40
Copilot AI review requested due to automatic review settings April 2, 2026 20:40
Copy link
Copy Markdown
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 metadata-branch reconciliation when pushing via checkpoint URL (ENTIRE_CHECKPOINT_TOKEN flow) by comparing against the actual fetched reference (temp ref) instead of a hardcoded refs/remotes/origin/... remote-tracking ref.

Changes:

  • Adds a remoteRefName parameter to IsMetadataDisconnected and ReconcileDisconnectedMetadataBranch so callers can supply the correct ref to compare against.
  • Updates the push fetch+merge flow to pass the computed fetchedRefName (origin-tracking ref or temp ref) into reconciliation.
  • Updates doctor + unit tests, including a new test covering the temp-ref reconciliation path.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
cmd/entire/cli/strategy/push_common.go Passes the fetched ref name into metadata reconciliation during fetch+merge recovery.
cmd/entire/cli/strategy/metadata_reconcile.go Extends reconciliation/disconnection APIs to accept a caller-supplied remote ref name.
cmd/entire/cli/strategy/metadata_reconcile_test.go Updates tests for new signatures and adds coverage for temp-ref reconciliation behavior.
cmd/entire/cli/doctor.go Updates doctor’s disconnected-metadata check/fix to pass the origin metadata remote-tracking ref explicitly.

Comment on lines 169 to 176
// branches would silently combine unrelated histories.
if reconcileErr := ReconcileDisconnectedMetadataBranch(ctx, repo, os.Stderr); reconcileErr != nil {
if reconcileErr := ReconcileDisconnectedMetadataBranch(ctx, repo, fetchedRefName, os.Stderr); reconcileErr != nil {
return fmt.Errorf("metadata reconciliation failed: %w", reconcileErr)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

ReconcileDisconnectedMetadataBranch always reconciles the local metadata branch (paths.MetadataBranchName), but here the remote ref passed in is derived from the generic branchName being synced. If fetchAndMergeSessionsCommon were ever used for a non-metadata branch, this would compare the metadata branch against an unrelated remote ref and could incorrectly cherry-pick onto that history. Consider either (a) guarding this call so reconciliation only runs when branchName == paths.MetadataBranchName, or (b) computing the remoteRefName specifically for the metadata branch (independent of branchName) to keep the function safe if reused.

Copilot uses AI. Check for mistakes.
fetchAndMergeSessionsCommon is a generic branch sync function, but
ReconcileDisconnectedMetadataBranch always operates on the metadata
branch (paths.MetadataBranchName). Without a guard, reusing this
function for a non-metadata branch would compare the metadata branch
against an unrelated remote ref, risking incorrect cherry-picks.

Add a branchName == paths.MetadataBranchName check so reconciliation
only runs when syncing the metadata branch.

Signed-off-by: Paulo Gomes <paulo@entire.io>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 311cbcd1ffe0
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.

2 participants