The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 08:30 UTC
fix(server): skip global reflog scans for local turn commits (#37926)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Vallone committed
Nov 16, 2026 at 22:37 UTC
09458669eac03ae4e6a8c1ec191f416276795df1
2 files changed
+125
-13
apps/server/src/vcs/GitVcsDriver.test.ts
+77
@@ -1385,6 +1385,83 @@ it.effect.each([1_700_000_000, 1_700_000_000.9999])(
1385
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1386
);
1387
1388
+it.effect.each(["local", "mixed", "exit"] as const)(
1389
+ "checkpoint authorship uses local evidence or full fallback ($0)",
1390
+ (mode) =>
1391
+ Effect.gen(function* () {
1392
+ const fs = yield* FileSystem.FileSystem;
1393
+ const path = yield* Path.Path;
1394
+ const driver = yield* GitVcsDriver.makeVcsDriverShape();
1395
+ const liveProcess = yield* VcsProcess.VcsProcess;
1396
+ const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-authorship-" });
1397
+ const { git } = yield* makeCheckpointFixture(driver, cwd);
1398
+ yield* git(["commit", "-am", "baseline"]);
1399
+ const fromCheckpointRef = CheckpointRef.make("refs/t3/checkpoints/authorship/from");
1400
+ const toCheckpointRef = CheckpointRef.make("refs/t3/checkpoints/authorship/to");
1401
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef: fromCheckpointRef });
1402
+ if (mode === "mixed") {
1403
+ yield* fs.writeFileString(path.join(cwd, "imported.txt"), "upstream\n");
1404
+ yield* git(["add", "."]);
1405
+ const tree = (yield* git(["write-tree"])).stdout.trim();
1406
+ const imported = (yield* git([
1407
+ "commit-tree",
1408
+ tree,
1409
+ "-p",
1410
+ "HEAD",
1411
+ "-m",
1412
+ "upstream",
1413
+ ])).stdout.trim();
1414
+ yield* git([
1415
+ "update-ref",
1416
+ "--create-reflog",
1417
+ "-m",
1418
+ "fetch origin: fast-forward",
1419
+ "refs/remotes/origin/main",
1420
+ imported,
1421
+ ]);
1422
+ yield* git(["reset", "--hard", imported]);
1423
+ }
1424
+ yield* fs.writeFileString(path.join(cwd, "local.txt"), "local\n");
1425
+ yield* git(["add", "."]);
1426
+ yield* git(["commit", "-m", "local"]);
1427
+ yield* driver.checkpoints.captureCheckpoint({
1428
+ cwd,
1429
+ checkpointRef: toCheckpointRef,
1430
+ previousCheckpointRef: fromCheckpointRef,
1431
+ });
1432
+
1433
+ const reflogScopes: string[] = [];
1434
+ const queryDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(
1435
+ Effect.provideService(VcsProcess.VcsProcess, {
1436
+ run: (input) => {
1437
+ if (!input.args.includes("--walk-reflogs")) return liveProcess.run(input);
1438
+ const scope = input.args.includes("--all") ? "--all" : "HEAD";
1439
+ reflogScopes.push(scope);
1440
+ if (scope === "--all" || mode !== "exit") return liveProcess.run(input);
1441
+ return Effect.fail(
1442
+ new VcsProcessExitError({
1443
+ operation: input.operation,
1444
+ command: input.command,
1445
+ cwd: input.cwd,
1446
+ exitCode: 1,
1447
+ detail: "HEAD reflog unavailable.",
1448
+ }),
1449
+ );
1450
+ },
1451
+ }),
1452
+ );
1453
+ assert.deepEqual(
1454
+ yield* queryDriver.checkpoints.listAuthoredPaths({
1455
+ cwd,
1456
+ fromCheckpointRef,
1457
+ toCheckpointRef,
1458
+ }),
1459
+ new Set(["local.txt"]),
1460
+ );
1461
+ assert.deepEqual(reflogScopes, mode === "local" ? ["HEAD"] : ["HEAD", "--all"]);
1462
+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),
1463
+);
1464
+
1465
it.effect("a branch switch landing after the snapshot belongs to the next checkpoint", () =>
1466
Effect.gen(function* () {
1467
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/vcs/GitVcsDriver.ts
+48
-13
@@ -487,6 +487,20 @@ const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
487
// one, so an unknown subject keeps its commit attributed.
488
const REF_MOVE_REFLOG_SUBJECT =
489
/^(?:$|(?:checkout|reset|branch|clone|fetch)\b|[^:]*\((?:start|finish|abort|reset)\): |(?:merge|pull|rebase|cherry-pick)\b[^()]*: fast-forward$)/i;
490
+
491
+function parseCheckpointReflogEntry(line: string) {
492
+ const [commit = "", selector = "", ...subject] = line.split(" ");
493
+ return {
494
+ commit,
495
+ fetched: selector.startsWith("refs/remotes/"),
496
+ subject: subject.join(" "),
497
+ };
498
+}
499
+
500
+function isLocalReflogCreation(entry: ReturnType<typeof parseCheckpointReflogEntry>) {
501
+ return !entry.fetched && !REF_MOVE_REFLOG_SUBJECT.test(entry.subject);
502
+}
503
+
504
const WORKSPACE_GIT_HARDENED_CONFIG_ARGS = [
505
"-c",
506
"core.fsmonitor=false",
@@ -2117,13 +2131,14 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
2131
return null;
2132
}
2133
2120
- const listLines = (args: ReadonlyArray<string>, stdin?: string) =>
2134
+ const listLines = (args: ReadonlyArray<string>, stdin?: string, timeoutMs?: number) =>
2135
execute({
2136
operation,
2137
cwd: input.cwd,
2138
// log.showSignature prints verification text into the output.
2139
args: ["-c", "log.showSignature=false", ...args],
2140
...(stdin === undefined ? {} : { stdin }),
2141
+ ...(timeoutMs === undefined ? {} : { timeoutMs }),
2142
maxOutputBytes: VcsDriver.CHECKPOINT_DIFF_MAX_OUTPUT_BYTES,
2143
outputMode: "error",
2144
}).pipe(Effect.map((result) => result.stdout.split("\n").filter((line) => line !== "")));
@@ -2158,14 +2173,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
2173
"--all",
2174
`--since=@${capturedAt}`,
2175
"--format=%H %gD %gs",
2161
- ])).map((line) => {
2162
- const [commit = "", selector = "", ...subject] = line.split(" ");
2163
- return {
2164
- commit,
2165
- fetched: selector.startsWith("refs/remotes/"),
2166
- subject: subject.join(" "),
2167
- };
2168
- });
2176
+ ])).map(parseCheckpointReflogEntry);
2177
// A push records commits this repository already had.
2178
const fetchedTips = new Set(
2179
entries
@@ -2175,9 +2183,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
2183
if (fetchedTips.size === 0) return fetchedTips;
2184
// Fetching another branch can deliver a commit that was made here and pushed.
2185
const createdHere = new Set(
2178
- entries
2179
- .filter((entry) => !entry.fetched && !REF_MOVE_REFLOG_SUBJECT.test(entry.subject))
2180
- .map((entry) => entry.commit),
2186
+ entries.filter(isLocalReflogCreation).map((entry) => entry.commit),
2187
);
2188
const fetched = yield* listLines(
2189
["rev-list", `--since=@${capturedAt}`, "--stdin"],
@@ -2196,9 +2202,38 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
2202
],
2203
{ concurrency: "unbounded" },
2204
);
2205
+ // Local creation evidence already overrides fetched history in the full scan.
2206
+ const unprovenCommits = new Set(recentCommits);
2207
+ if (recentCommits.length > 0 && recentCommits.length <= HEAD_MOVES_SCAN_LIMIT) {
2208
+ yield* listLines(
2209
+ [
2210
+ "log",
2211
+ "--walk-reflogs",
2212
+ `--max-count=${HEAD_MOVES_SCAN_LIMIT}`,
2213
+ "HEAD",
2214
+ `--since=@${capturedAt}`,
2215
+ "--format=%H %gD %gs",
2216
+ ],
2217
+ undefined,
2218
+ 1_000,
2219
+ ).pipe(
2220
+ Effect.map((lines) => {
2221
+ for (const line of lines) {
2222
+ const entry = parseCheckpointReflogEntry(line);
2223
+ if (isLocalReflogCreation(entry)) unprovenCommits.delete(entry.commit);
2224
+ }
2225
+ }),
2226
+ Effect.catch((error) =>
2227
+ Effect.logDebug("local authorship probe failed; using full reflogs", {
2228
+ operation,
2229
+ errorTag: error._tag,
2230
+ }),
2231
+ ),
2232
+ );
2233
+ }
2234
// Without readable reflogs every recent commit stays attributed, as before.
2235
const importedCommits =
2201
- recentCommits.length === 0
2236
+ unprovenCommits.size === 0
2237
? new Set<string>()
2238
: yield* listImportedCommits.pipe(Effect.orElseSucceed(() => new Set<string>()));
2239
const ownCommits = recentCommits.filter((commit) => !importedCommits.has(commit));