ci: keep every run's session records so a review can always continue

A cache entry cannot be overwritten, so the fixed key restored the same old
snapshot on every later run and no progress made after it survived. Save each
run under its own key and restore the newest one, and cache the OCR session
records only: the checkout is rebuilt from scratch every run, which is what
keeps files the new head deleted out of the review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NwflowerandClaude Opus 5.5 committed 2026-12-04 01:56:38 -07:00
1 parent d28b97c4ea
commit 90c69525d3
3 files changed
+24 -35

No files matched your search

+8 -20
View File
@@ -616,7 +616,7 @@ export function resumeSessionDir(settings = process.env) {
const stateDirectory = settings.PR_REVIEW_STATE_DIR;
const home = settings.PR_REVIEW_SESSION_HOME?.trim();
return join(home || (settings.LOCALAPPDATA ? join(settings.LOCALAPPDATA, "reims-go", "pr-review") : "pr-review"),
"sessions", stateKey(stateDirectory, settings));
stateKey(stateDirectory, settings));
}
function stateKey(stateDirectory, settings) {
@@ -773,14 +773,8 @@ async function prepareGitWorkspace({ repo, home, repository, number, pull, token
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository)) throw new Error("Invalid GitHub repository name");
const env = isolatedEnvironment(home);
const fetchEnv = gitEnvironment(home, token);
const source = "https://github.com/" + repository + ".git";
git(repo, ["init", "--quiet", "--template="], env);
// The checkout survives between runs, so the remote is usually already there.
if (git(repo, ["remote"], env).stdout.split(/\r?\n/).some((name) => name.trim() === "origin")) {
git(repo, ["remote", "set-url", "origin", source], env);
} else {
git(repo, ["remote", "add", "origin", source], env);
}
git(repo, ["remote", "add", "origin", "https://github.com/" + repository + ".git"], env);
let headRef = headSha;
const fetchRange = (depth) => git(repo, ["fetch", "--no-tags", "--no-recurse-submodules", depth, "origin", baseSha, headRef], fetchEnv);
try {
@@ -807,9 +801,6 @@ async function prepareGitWorkspace({ repo, home, repository, number, pull, token
if (!mergeBase) throw new Error("Git could not determine the PR merge base");
git(repo, ["config", "core.symlinks", "false"], env);
git(repo, ["checkout", "--force", "--detach", headSha], env);
// A checkout reused between runs keeps files the new head deleted; OCR scans
// the worktree, so only tracked files of this head may remain.
git(repo, ["clean", "-ffdx"], env);
// Keep PR-owned OCR settings out of the filesystem configuration search.
await rm(join(repo, ".opencodereview"), { recursive: true, force: true });
return {
@@ -904,17 +895,14 @@ export async function run() {
const stateDirectory = required("PR_REVIEW_STATE_DIR");
await mkdir(stateDirectory, { recursive: true });
await writeFile(join(stateDirectory, "state.json"), JSON.stringify({ repository, pr: number }) + "\n");
// Whatever this run replaces goes first: an aborted run leaves a checkout
// whose worktree may not match the new commits.
if (process.env.PR_REVIEW_FRESH_STATE === "true") {
await rm(join(resumeSessionDir(), "repo"), { recursive: true, force: true });
await rm(join(resumeSessionDir(), "home"), { recursive: true, force: true });
}
// The checkout and the OCR home survive between runs so a review that stopped
// short continues instead of paying for the same files again. The OCR config
// records how to read the token (printenv), never the token itself.
// The OCR home survives between runs, so a review that stopped short continues
// from its session records instead of paying for the same files again. It
// records how to read the token (printenv), never the token itself. The
// checkout is rebuilt every run: a worktree reused across heads keeps files
// the new head deleted, and only the session records are worth keeping.
const repo = join(resumeSessionDir(), "repo");
const home = join(resumeSessionDir(), "home");
await rm(repo, { recursive: true, force: true });
await mkdir(repo, { recursive: true });
await mkdir(home, { recursive: true });
const workspace = await prepareGitWorkspace({ repo, home, repository, number, pull, token });
+2 -2
View File
@@ -513,11 +513,11 @@ test("each pull request gets its own review state", async (t) => {
const directory = await tempDirectory(t, "ocr-state-");
await writeFile(join(directory, "state.json"), JSON.stringify({ repository: "Nwflower/Reims-Go", pr: 163 }));
const dir = resumeSessionDir({ PR_REVIEW_STATE_DIR: directory, PR_REVIEW_SESSION_HOME: join(directory, "home") });
assert.equal(dir, join(directory, "home", "sessions", "Nwflower-Reims-Go-163"));
assert.equal(dir, join(directory, "home", "Nwflower-Reims-Go-163"));
const other = await tempDirectory(t, "ocr-state-");
await writeFile(join(other, "state.json"), "not json");
assert.equal(resumeSessionDir({ PR_REVIEW_STATE_DIR: other, PR_REVIEW_SESSION_HOME: join(other, "home"), GITHUB_WORKSPACE: "/w/repo" }),
join(other, "home", "sessions", "repo"));
join(other, "home", "repo"));
});
test("an incomplete previous review is recognised and never anchors an incremental range", () => {