Fetch missing git-refs checkpoints on demand for reads · Entire

Fetch missing git-refs checkpoints on demand for reads

5c6d612→main·

Soph·2w ago·5 files·+28 added/-8 removed

A git-refs primary previously read only checkpoint refs already present locally, so checkpoints written on another machine (or not yet fetched after clone) read as not-found. FetchCheckpointRef fetches one ref via the checkpoint remote into the local ref of the same name; it's wired into the read commands that already inject FetchBlobsByHash (resume, explain, attribution, tokens profile) via the new OpenOptions.RefFetcher. gitRefsStore.resolveRefMaybeFetch invokes it once on a local miss and retries; a failed fetch resolves to ErrCheckpointNotFound. The git-branch backend ignores it; strategy-side Opens (condensation/rewind) read just-written local refs and pass no fetcher.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

696096934b50View transcript

Changes

5

351 unmodified lines

352
353
354
355
355
356
357
358

351 unmodified lines

return nil, fmt.Errorf("not a git repository: %w", err)

}

stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash});
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
if err != nil {
    return nil, fmt.Errorf("open checkpoint store: %w", err)
}

Mcmd/entire/cli/attribution.go+1/-1

712 unmodified lines

713
714
715
716
716
717
718
719
173 unmodified lines

893
894
895
896
896
897
898
899

712 unmodified lines

}
    // Reload to get the updated summary.
    stopLoad = startSpinner(errW, fmt.Sprintf("Reloading checkpoint %s", fullCheckpointID))
    reopened, openErr := checkpoint.Open(ctx, lookup.repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash});
    reopened, openErr := checkpoint.Open(ctx, lookup.repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
    if openErr != nil {
        stopLoad(false)
        return fmt.Errorf("open checkpoint store: %w", openErr)
    }
173 unmodified lines

// `git fetch` fails against partial-clone repos with "did not send all
// necessary objects"). Falls back to a full metadata-branch fetch if
// fetch-pack also can't reach the blobs.
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash});
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
if err != nil {
    return nil, fmt.Errorf("open checkpoint store: %w", err)
}

Mcmd/entire/cli/explain.go+2/-2

533 unmodified lines

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

533 unmodified lines

return "origin"
}

// FetchCheckpointRef fetches a single per-checkpoint ref (refs/entire/checkpoints/
// <shard>/<id>) from the checkpoint remote into the local ref of the same name,
// so the git-refs store can resolve a checkpoint written on another machine.
// Best-effort: the caller treats a fetch failure as "checkpoint not found".
func FetchCheckpointRef(ctx context.Context, ref plumbing.ReferenceName) error {
    ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
    defer cancel()

fetchTarget := resolveCheckpointFetchTarget(ctx)
    refSpec := "+" + ref.String() + ":" + ref.String()
    if _, err := remote.Fetch(ctx, remote.FetchOptions{
        Remote:   fetchTarget,
        RefSpecs: []string{refSpec},
        NoTags:   true,
    }); err != nil {
        return fmt.Errorf("fetch checkpoint ref %s from %s: %w", ref, fetchTarget, err)
    }
    return nil
}

// FetchBlobsByHash fetches specific blob objects from the remote by their SHA-1 hashes.
// Uses "git fetch <target> <hash>" which goes through normal credential helpers,
// unlike fetch-pack which bypasses them. Requires the server to support

Mcmd/entire/cli/git_operations.go+20

212 unmodified lines

213
214
215
216
216
217
218
219
81 unmodified lines

301
302
303
304
304
305
306
307
127 unmodified lines

435
436
437
438
438
439
440
441
590 unmodified lines

1032
1033
1034
1035
1035
1036
1037
1038

212 unmodified lines

}
    defer repo.Close()

stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash});
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
if err != nil {
    return nil, fmt.Errorf("open checkpoint store: %w", err)
}
81 unmodified lines

checkpointID := result.checkpointIDs[0]
    var metadata *strategy.CheckpointInfo

stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash});
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
if err != nil {
    return nil, fmt.Errorf("open checkpoint store: %w", err)
}
127 unmodified lines

refs checkpoint.PersistentRefs,
    checkpointID id.CheckpointID,
) (*strategy.CheckpointInfo, error) {
    stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{Refs: &refs, BlobFetcher: FetchBlobsByHash});
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{Refs: &refs, BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
if err != nil {
    return nil, fmt.Errorf("open checkpoint store: %w", err)
}
590 unmodified lines

return strategy.RestoredSession{}, false, fmt.Errorf("failed to open repository: %w", repoErr)
    }
    defer repo.Close()
    stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash});
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
if err != nil {
    return strategy.RestoredSession{}, false, fmt.Errorf("open checkpoint store: %w", err)
}

Mcmd/entire/cli/resume.go+4/-4

112 unmodified lines

113
114
115
116
116
117
118
119

112 unmodified lines

}
    defer repo.Close()

stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash});
stores, err := checkpoint.Open(ctx, repo, checkpoint.OpenOptions{BlobFetcher: FetchBlobsByHash, RefFetcher: FetchCheckpointRef});
if err != nil {
    return fmt.Errorf("failed to open checkpoint stores: %w", err)
}

Mcmd/entire/cli/tokens_profile.go+1/-1