fix: bootstrap metadata branch from checkpoint_remote during enable#1382
Draft
alishakawaguchi wants to merge 3 commits into
Draft
fix: bootstrap metadata branch from checkpoint_remote during enable#1382alishakawaguchi wants to merge 3 commits into
alishakawaguchi wants to merge 3 commits into
Conversation
When a checkpoint_remote is configured and the repo is freshly cloned on a second device, neither the local entire/checkpoints/v1 branch nor origin's remote-tracking ref exists — the real branch lives on the checkpoint remote. EnsureSetup previously went straight to EnsureMetadataBranch, which minted an unrelated empty orphan, hiding existing checkpoints from `entire checkpoint list` and rejecting later fetches as non-fast-forward. EnsureSetup now fetches the metadata branch from the configured checkpoint_remote first (best-effort, only when no local branch exists), mirroring what `entire resume` already does. The fetch failing — e.g. the remote branch doesn't exist before the first push from any device — falls back to orphan creation as before. Fixes #1374 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a multi-device enable/setup bug where a fresh clone with a configured checkpoint_remote would create an unrelated orphan entire/checkpoints/v1 locally instead of bootstrapping it from the checkpoint remote, which could hide existing checkpoints and later cause non-fast-forward fetch rejections.
Changes:
- Run a best-effort metadata-branch bootstrap from
checkpoint_remoteduringEnsureSetupbefore opening the main repo handle. - Extend
fetchMetadataBranchIfMissingto return(fetched bool, err error)so callers can report when a local branch was created from a remote fetch. - Add/strengthen unit + integration regression coverage, including an HTTPS multi-remote enable test reproducing #1374.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/entire/cli/strategy/common.go | Calls checkpoint-remote bootstrap during setup and clarifies EnsureMetadataBranch’s local-ref-only behavior. |
| cmd/entire/cli/strategy/checkpoint_remote.go | Adds bootstrapMetadataFromCheckpointRemote and changes fetchMetadataBranchIfMissing to return a fetched boolean. |
| cmd/entire/cli/strategy/checkpoint_remote_test.go | Updates tests to assert the new fetched return value in missing/no-op scenarios. |
| cmd/entire/cli/integration_test/http_remote_test.go | Adds HTTPS regression test ensuring enable bootstraps metadata from checkpoint_remote instead of minting an orphan. |
A first `entire enable` whose checkpoint-remote fetch fails (no token, network down, remote branch not pushed yet) falls back to minting an empty local orphan. fetchMetadataBranchIfMissing skipped the fetch whenever the local branch existed, so that orphan permanently closed the bootstrap window — a later enable with working auth (or after a teammate's first checkpoint push) never recovered. The skip-on-exists gate now exempts empty branches: a local metadata branch with no checkpoint data no longer blocks the bootstrap fetch. SafelyAdvanceLocalRef discards the no-op orphan commit during the promote, so the local branch lands exactly on the remote tip. Also log a warning when the bootstrap fetch fails instead of silently swallowing it (auth/network problems were invisible in .entire/logs), and fix the stale comment claiming promote errors are returned. Follow-up to aa5169f (issue #1374). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Conflict in strategy/common.go: main renamed EnsureMetadataBranch to EnsurePrimaryRef and rewrote it around refs.Primary. Kept main's implementation plus this branch's doc note pointing at bootstrapMetadataFromCheckpointRemote. Updated the recovery regression test to call EnsurePrimaryRef. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #1374
Problem
When
entire enableruns on a second device in a repo with a configuredcheckpoint_remoteand an existingentire/checkpoints/v1branch on that remote, it created a fresh empty orphan branch locally instead of fetching the existing one. Consequences:entire checkpoint listreturned 0 results (local ref exists but points at an empty tree, so the origin fallback never triggers)git fetch <checkpoint-remote> entire/checkpoints/v1:entire/checkpoints/v1was rejected as non-fast-forward (the orphan shares no ancestry with the real branch)Root cause:
EnsureMetadataBranchonly consults the local ref andorigin/entire/checkpoints/v1before minting an empty orphan — it never consults the configuredcheckpoint_remote, even thoughentire resumealready fetches from it first.Fix
EnsureSetupnow calls a newbootstrapMetadataFromCheckpointRemotebefore opening the repo handle:remote.Configured→remote.FetchURL→fetchMetadataBranchIfMissing. Notes on placement and behavior:EnsureSetup, notEnsureMetadataBranch— covers both enable paths and the lifecycle hook path (lifecycle.go), keepsEnsureMetadataBrancha pure repo-handle function (existing unit tests call it with CWD = real repo, which itself has acheckpoint_remoteconfigured — an in-function fetch would mutate the real repo during tests), and the repo handle opened afterward sees the freshly fetched packfilesfetchMetadataBranchIfMissingnow returns(fetched bool, err error)so enable can print✓ Created local branch 'entire/checkpoints/v1' from checkpoint remoteTesting
TestHTTPS_EnableBootstrapsMetadataFromCheckpointRemote(watched fail before the fix): device A pushes checkpoints to a separate HTTPS checkpoint remote; device B clones origin and runsentire enablevia the real binary; asserts the local metadata branch tip equals the checkpoint remote tip and contains device A's checkpoint metadatafetchMetadataBranchIfMissingtests with the newfetchedreturn assertionsmise run test:integration: 395/395 pass; E2E canary: all pass;mise run fmt && mise run lint: cleancmd/entire/cliunit tests (TestRunAuthStatus_RendersSessionsTable,TestExplainCmd_*) fail identically on the clean tree — environment-sensitive, not from this change🤖 Generated with Claude Code
Note
Medium Risk
Changes shared setup/enable metadata initialization for multi-repo checkpoint routing; failures still fall back to orphan creation, but wrong fetch behavior could hide checkpoints or cause sync conflicts.
Overview
Fixes #1374: on a fresh clone with a separate
checkpoint_remote,entire enableno longer creates an unrelated emptyentire/checkpoints/v1orphan when checkpoints only exist on that remote (not on origin).EnsureSetupnow runsbootstrapMetadataFromCheckpointRemotebefore opening the go-git repo handle: if a checkpoint remote is configured, it resolves the fetch URL and callsfetchMetadataBranchIfMissingsoEnsureMetadataBranchsees real history instead of minting an empty branch. Bootstrap is best-effort (warnings + orphan fallback when the remote branch does not exist yet). When a fetch actually creates the local branch, enable prints✓ Created local branch 'entire/checkpoints/v1' from checkpoint remote.fetchMetadataBranchIfMissingreturns(fetched bool, err error); callers (including push settings resolution) ignore the bool except for that message.Tests: new HTTPS integration
TestHTTPS_EnableBootstrapsMetadataFromCheckpointRemote(device A pushes to checkpoint remote; device B clones origin and runs enable; local tip and checkpoint metadata must match the remote). Unit tests assert the newfetchedreturn value.Reviewed by Cursor Bugbot for commit aa5169f. Configure here.