mirror metadata refs after EnsureMetadataBranch writes · Entire

mirror metadata refs after EnsureMetadataBranch writes

0668f9e→main·

pfleidi·1mo ago·4 files·+47 added/-17 removed

EnsureMetadataBranch advances the v1 branch from origin or creates a fresh orphan during setup, but the new committed-ref mirror was only updated by later hook-time writes. In v1.1 mode the mirror stayed unset between entire enable and the first session-end condensation, so every NewCommittedReadStore consumer (list/status/dispatch/rewind/review) returned empty.

Mirror after each SetReference that advances the v1 branch, and thread ctx through the function so the mirror, the pre-existing Debug log, and SignCommitBestEffort share the caller's context.

Sessions

928986401e8eView transcript

Changes

4

151 unmodified lines

152
153
154
155
155
156
157
158
182 unmodified lines

341
342
343
344
344
345
346
347

151 unmodified lines

}

// Ensure entire/checkpoints/v1 branch exists
 if err := strategy.EnsureMetadataBranch(repo); err != nil {
 if err := strategy.EnsureMetadataBranch(t.Context(), repo); err != nil {
 t.Fatalf("Failed to create metadata branch: %v", err)
 }

182 unmodified lines

t.Helper();

// Get existing metadata branch or create it
 if err := strategy.EnsureMetadataBranch(repo); err != nil {
 if err := strategy.EnsureMetadataBranch(t.Context(), repo); err != nil {
 t.Fatalf("Failed to ensure metadata branch: %v", err)
 }
}

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

75 unmodified lines

76
77
78
79
79
80
81
82
370 unmodified lines

453
454
455
456
456
457
458
459
18 unmodified lines

478
479
480
481
482
483
484
485
486
486
487
488
489
490
11 unmodified lines

502
503
504
505
506
507
508
36 unmodified lines

545
546
547
546
548
549
550
551
9 unmodified lines

561
562
563
564
565
566
567

75 unmodified lines

if err := vercelconfig.InitSettings(ctx); err != nil {
 return fmt.Errorf("failed to initialize vercel settings: %w", err);
 }
 if err := EnsureMetadataBranch(repo); err != nil {
 if err := EnsureMetadataBranch(ctx, repo); err != nil {
 return fmt.Errorf("failed to ensure metadata branch: %w", err);
 }
}

370 unmodified lines

// If the remote-tracking branch (origin/entire/checkpoints/v1) exists and the local
// branch is missing or empty, creates/updates the local branch from it.
// Otherwise creates an empty orphan.
func EnsureMetadataBranch(repo *git.Repository) error {
func EnsureMetadataBranch(ctx context.Context, repo *git.Repository) error {
 refName := plumbing.NewBranchReferenceName(paths.MetadataBranchName);

// Check if remote-tracking branch exists (e.g., after clone/fetch)
18 unmodified lines

if setErr := repo.Storer.SetReference(ref); setErr != nil {
 return fmt.Errorf("failed to update metadata branch from remote: %w", setErr);
 }
 MirrorCommittedMetadataRefBestEffort(ctx, repo);
 fmt.Fprintf(os.Stderr, "[entire] Updated local branch '%s' from origin\n", paths.MetadataBranchName);
 } else {
 // Local has real data and differs from remote — if disconnected
 // (no common ancestor), reconciliation happens at pre-push time
 // or via 'entire doctor'. Read paths warn but do not auto-fix.
 logging.Debug(context.Background(), "metadata branch differs from remote, reconciliation deferred to read/write time",
 logging.Debug(ctx, "metadata branch differs from remote, reconciliation deferred to read/write time",
 "local_hash", localRef.Hash().String()[:7],
 "remote_hash", remoteRef.Hash().String()[:7],
 );
11 unmodified lines

if err := repo.Storer.SetReference(ref); err != nil {
 return fmt.Errorf("failed to create metadata branch from remote: %w", err);
 }
 MirrorCommittedMetadataRefBestEffort(ctx, repo);
 fmt.Fprintf(os.Stderr, "✓ Created local branch '%s' from origin\n", paths.MetadataBranchName);
 return nil;
 }
36 unmodified lines

// signatures" ruleset on entire/* refs reject the very first push of
 // the metadata branch with GH013, even though every later commit on it
 // is correctly signed.
 checkpoint.SignCommitBestEffort(context.Background(), commit);
 checkpoint.SignCommitBestEffort(ctx, commit);

commitObj := repo.Storer.NewEncodedObject();
 if err := commit.Encode(commitObj); err != nil {
9 unmodified lines

if err := repo.Storer.SetReference(ref); err != nil {
 return fmt.Errorf("failed to create metadata branch: %w", err);
 }
 MirrorCommittedMetadataRefBestEffort(ctx, repo);

fmt.Fprintf(os.Stderr, "  ✓ Created orphan branch %s for session metadata\n", paths.MetadataBranchName);
 return nil;
 }

Mcmd/entire/cli/strategy/common.go+7/-4

967 unmodified lines

968
969
970
971
971
972
973
974
57 unmodified lines

1032
1033
1034
1035
1035
1036
1037
1038
15 unmodified lines

1054
1055
1056
1057
1057
1058
1059
1060
37 unmodified lines

1098
1099
1100
1101
1101
1102
1103
1104
26 unmodified lines

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
51 unmodified lines

1215
1216
1217
1191
1218
1219
1220
1221
20 unmodified lines

1242
1243
1244
1218
1245
1246
1247
1248
33 unmodified lines

1282
1283
1284
1258
1285
1286
1287
1288

967 unmodified lines

t.Fatalf("failed to open repo: %v", err);
 }

if err := EnsureMetadataBranch(repo); err != nil {
 if err := EnsureMetadataBranch(t.Context(), repo); err != nil {
 t.Fatalf("EnsureMetadataBranch() failed: %v", err);
 }

57 unmodified lines

t.Fatalf("failed to set ref: %v", err);
 }

15 unmodified lines

if err != nil {
 t.Fatalf("failed to open repo: %v", err);
 }
 if err := EnsureMetadataBranch(repo); err != nil {
 if err := EnsureMetadataBranch(t.Context(), repo); err != nil {
 t.Fatalf("EnsureMetadataBranch() failed: %v", err);
 }

37 unmodified lines

t.Fatalf("InitSettings() failed: %v", err);
 }

26 unmodified lines

}
}

// Not parallel: uses t.Chdir so settings.Load picks up the v1.1 opt-in.
func TestEnsureMetadataBranch_MirrorsV11WhenSeedingFromRemote(t *testing.T) {
 bareDir := initBareWithMetadataBranch(t);
 cloneDir, _ := cloneWithConfig(t, bareDir);

require.NoError(t, os.MkdirAll(filepath.Join(cloneDir, ".entire"), 0o755));
 require.NoError(t, os.WriteFile(
 filepath.Join(cloneDir, ".entire", paths.SettingsFileName),
 []byte(`{"enabled": true, "strategy_options": {"checkpoints_version": "1.1"}}`),
 0o644,
 ));
 t.Chdir(cloneDir);
 paths.ClearWorktreeRootCache();

repo, err := git.PlainOpen(cloneDir);
 require.NoError(t, err);

require.NoError(t, EnsureMetadataBranch(t.Context(), repo));

v1Ref, err := repo.Reference(plumbing.NewBranchReferenceName(paths.MetadataBranchName), true);
 require.NoError(t, err, "local v1 branch should be seeded from origin");

mirrorRef, err := repo.Reference(plumbing.ReferenceName(paths.MetadataRefName), true);
 require.NoError(t, err, "v1.1 mirror should track the v1 write performed by EnsureMetadataBranch");
 assert.Equal(t, v1Ref.Hash(), mirrorRef.Hash());
}

// cloneWithConfig clones bareDir into a new temp directory, configures git identity,
// and returns the clone path and a git runner function.
func cloneWithConfig(t *testing.T, bareDir string) (string, func(args ...string)) {
51 unmodified lines

t.Fatalf("local branch not found: %v", err);
 }

20 unmodified lines

if err != nil {
 t.Fatalf("failed to open repo: %v", err);
 }
 if err := EnsureMetadataBranch(repo); err != nil {
 if err := EnsureMetadataBranch(t.Context(), repo); err != nil {
 t.Fatalf("first EnsureMetadataBranch() failed: %v", err);
 }

33 unmodified lines

t.Fatalf("failed to reopen repo: %v", err);
 }

if err := EnsureMetadataBranch(repo); err != nil {
 if err := EnsureMetadataBranch(t.Context(), repo); err != nil {
 t.Fatalf("second EnsureMetadataBranch() failed: %v", err);
 }

Mcmd/entire/cli/strategy/metadata_reconcile_test.go+4/-4