fix(checkpoint): fetched upstream commits no longer show as agent changes #25880
ClosedBilalIrfanContact(GitHub profile, opens in a new tab)wants to merge 12 commits into
main fromrefs/pull/25880/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/vcs/GitVcsDriver.ts line 1405OutdatedResolvedby BilalIrfanContact(GitHub profile, opens in a new tab)@@ -1347,0 +1385,21 @@1385+ subject: subject.join(" "),1386+ };1387+ });1388+ // Fetching another branch can rediscover a commit made locally during this turn.1389+ const localCommits = new Set(1390+ entries1391+ .filter(1392+ (entry) =>1393+ entry.ref === "HEAD" &&1394+ entry.updatedAt >= since &&1395+ /^commit(?: \([^)]*\))?: /.test(entry.subject),1396+ )1397+ .map((entry) => entry.commit),1398+ );1399+ const previousByRef = new Map<string, string>();1400+ const fetchRanges = entries.toReversed().flatMap((entry) => {1401+ const previous = previousByRef.get(entry.ref);1402+ previousByRef.set(entry.ref, entry.commit);1403+ if (entry.ref === "HEAD") return [];1404+ if (entry.updatedAt < since || entry.subject === "update by push") return [];1405+ return [entry.commit, ...(previous === undefined ? [] : [`^${previous}`])];
- apps/server/src/checkpointing/CheckpointStore.test.ts line 542OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -512,0 +522,21 @@522+ yield* git(tmp, ["remote", "add", "upstream", upstream]);523+ yield* git(tmp, ["fetch", "upstream"]);524+ const checkpointStore = yield* CheckpointStore.CheckpointStore;525+ const threadId = ThreadId.make("checkpoint-fetched-paths");526+ const refs = {527+ cwd: tmp,528+ fromCheckpointRef: checkpointRefForThreadTurn(threadId, 0),529+ toCheckpointRef: checkpointRefForThreadTurn(threadId, 1),530+ };531+ yield* checkpointStore.captureCheckpoint({532+ cwd: tmp,533+ checkpointRef: refs.fromCheckpointRef,534+ });535+536+ // Dated after the checkpoint, like an upstream commit pushed during the turn.537+ const afterCheckpoint = "2090-01-01T00:00:00Z";538+ yield* writeTextFile(NodePath.join(upstream, "upstream.txt"), "upstream\n");539+ yield* git(upstream, ["add", "."]);540+ yield* git(upstream, ["commit", "-m", "upstream"], { committedAt: afterCheckpoint });541+ yield* git(tmp, ["fetch", "upstream"], { committedAt: afterCheckpoint });542+ yield* git(tmp, ["merge", "--ff-only", "upstream/main"], { committedAt: afterCheckpoint });apps/server/src/vcs/GitVcsDriver.ts lines 1549 to 1558OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1347,0 +1378,21 @@1378+ )).map((line) => {1379+ const [commit = "", selector = "", ...subject] = line.split(" ");1380+ const at = selector.lastIndexOf("@{");1381+ return {1382+ commit,1383+ ref: selector.slice(0, at),1384+ updatedAt: Number(selector.slice(at + 2, -1)),1385+ subject: subject.join(" "),1386+ };1387+ });1388+ // Fetching another branch can rediscover a commit made locally during this turn.1389+ const localCommits = new Set(1390+ entries1391+ .filter(1392+ (entry) =>1393+ entry.ref === "HEAD" &&1394+ entry.updatedAt >= since &&1395+ /^commit(?: \([^)]*\))?: /.test(entry.subject),1396+ )1397+ .map((entry) => entry.commit),1398+ );apps/server/src/vcs/GitVcsDriver.ts lines 1408 to 1413OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1347,0 +1393,21 @@1393+ entry.ref === "HEAD" &&1394+ entry.updatedAt >= since &&1395+ /^commit(?: \([^)]*\))?: /.test(entry.subject),1396+ )1397+ .map((entry) => entry.commit),1398+ );1399+ const previousByRef = new Map<string, string>();1400+ const fetchRanges = entries.toReversed().flatMap((entry) => {1401+ const previous = previousByRef.get(entry.ref);1402+ previousByRef.set(entry.ref, entry.commit);1403+ if (entry.ref === "HEAD") return [];1404+ if (entry.updatedAt < since || entry.subject === "update by push") return [];1405+ return [entry.commit, ...(previous === undefined ? [] : [`^${previous}`])];1406+ });1407+ if (fetchRanges.length === 0) return new Set<string>();1408+ return new Set(1409+ (yield* lines(1410+ ["rev-list", "--stdin"],1411+ `${[...fetchRanges, `^${startHead}`].join("\n")}\n`,1412+ )).filter((commit) => !localCommits.has(commit)),1413+ );
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/vcs/GitVcsDriver.ts line 452OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -447,3 +447,6 @@447447 const CHECKPOINT_RECOVERY_MAX_CANDIDATES = 64;448448 const CHECKPOINT_RECOVERY_TIMEOUT = "5 seconds";449449 const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;450+// HEAD reflog subjects of operations that create commits. Fast-forwards are imports, so excluded.451+const LOCAL_COMMIT_REFLOG_SUBJECT =452+ /^(?:(?:commit(?: \([^)]*\))?|cherry-pick|revert|(?:rebase|pull .*) \((?:pick|reword|edit|squash|fixup)\)): |(?:merge|pull) .*: Merge made by )/;
- apps/server/src/vcs/GitVcsDriver.test.ts lines 106 to 117OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -101,3 +101,14 @@101101 },102102 });103103104+it("treats only reflog entries that create local commits as local", () => {105+ const local = [106+ "commit: own",107+ "commit (amend): own",108+ "pull: Merge made by the 'ort' strategy.",109+ "pull origin main: Merge made by the 'ort' strategy.",110+ "pull (pick): own",111+ "pull --rebase origin main (pick): own",112+ "rebase (pick): own",113+ "merge upstream/main: Merge made by the 'ort' strategy.",114+ ];apps/server/src/vcs/GitVcsDriver.ts lines 451 to 452OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -447,3 +447,6 @@447447 const CHECKPOINT_RECOVERY_MAX_CANDIDATES = 64;448448 const CHECKPOINT_RECOVERY_TIMEOUT = "5 seconds";449449 const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;450+// HEAD reflog subjects of operations that create commits. Fast-forwards are imports, so excluded.451+export const LOCAL_COMMIT_REFLOG_SUBJECT =452+ /^(?:(?:commit(?: \([^)]*\))?|cherry-pick|revert|(?:rebase|pull(?: .*)?) \((?:pick|reword|edit|squash|fixup)\)): |(?:merge .*|pull(?: .*)?): Merge made by )/;
tanstack-source added labelsbug
juliusmarminge added labelstakeover:in-progress
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge removed labelstakeover:ready
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed