fix(server): capture checkpoints before refreshing PR status (#10347)

Co-authored-by: Claude Fable 5.1 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5.1 authored and GitHub committed 2026-09-06 02:56:31 -07:00
1 parent 62f568b88b
commit e0adcc8a24
2 files changed
+64 -3

No files matched your search

@@ -302,6 +302,7 @@ describe("CheckpointReactor", () => {
readonly providerName?: ProviderDriverKind;
readonly gitStatusRefreshCalls?: Array<string>;
readonly pullRequestRefreshCalls?: Array<string>;
readonly pullRequestRefresh?: Effect.Effect<void>;
}) {
const cwd = createGitRepository();
if (options?.initializeGit === false) {
@@ -357,7 +358,7 @@ describe("CheckpointReactor", () => {
refreshPullRequestStatus: (cwd: string) =>
Effect.sync(() => {
options?.pullRequestRefreshCalls?.push(cwd);
}).pipe(Effect.as(null)),
}).pipe(Effect.andThen(options?.pullRequestRefresh ?? Effect.void), Effect.as(null)),
streamStatus: () => Stream.empty,
});
@@ -879,6 +880,49 @@ describe("CheckpointReactor", () => {
expect(pullRequestRefreshCalls).toEqual([harness.cwd]);
});
effectIt.effect("captures files while the pull request lookup is still pending", () =>
Effect.gen(function* () {
const lookupStarted = yield* Deferred.make<void>();
const finishLookup = yield* Deferred.make<void>();
const harness = yield* Effect.promise(() =>
createHarness({
seedFilesystemCheckpoints: false,
threadBranch: "t3code/feature",
localStatusRefName: "t3code/feature",
pullRequestRefresh: Deferred.succeed(lookupStarted, undefined).pipe(
Effect.andThen(Deferred.await(finishLookup)),
),
}),
);
NodeFS.writeFileSync(NodePath.join(harness.cwd, "README.md"), "completed turn\n");
harness.provider.emit({
type: "turn.completed",
eventId: EventId.make("evt-turn-completed-slow-pr"),
provider: ProviderDriverKind.make("codex"),
createdAt: "2026-01-01T00:00:00.000Z",
threadId: ThreadId.make("thread-1"),
turnId: asTurnId("turn-slow-pr"),
payload: { state: "completed" },
});
yield* Deferred.await(lookupStarted);
yield* Effect.gen(function* () {
expect(yield* harness.nextReceipt).toMatchObject({
type: "checkpoint.diff.finalized",
turnId: "turn-slow-pr",
});
expect(
gitShowFileAtRef(
harness.cwd,
checkpointRefForThreadTurn(ThreadId.make("thread-1"), 1),
"README.md",
),
).toBe("completed turn\n");
}).pipe(Effect.ensuring(Deferred.succeed(finishLookup, undefined)));
yield* Effect.promise(harness.drain);
}),
);
it("re-asks for the pull request after adopting a drifted checkout", async () => {
const pullRequestRefreshCalls: string[] = [];
const harness = await createHarness({
@@ -605,6 +605,23 @@ const make = Effect.gen(function* () {
);
});
// Refreshing git status ends in a remote PR lookup under the vcs status
// write lock. Run it on its own worker so file capture for this turn (and
// checkpoints for other threads) never wait behind that network call.
const statusRefreshWorker = yield* makeDrainableWorker(
(event: Extract<ProviderRuntimeEvent, { type: "turn.completed" }>) =>
refreshLocalGitStatusFromTurnCompletion(event).pipe(
Effect.catchCause((cause) =>
Cause.hasInterruptsOnly(cause)
? Effect.failCause(cause)
: Effect.logWarning("failed to refresh git status after turn completion", {
threadId: event.threadId,
cause: Cause.pretty(cause),
}),
),
),
);
const ensurePreTurnBaselineFromDomainTurnStart = Effect.fn(
"ensurePreTurnBaselineFromDomainTurnStart",
)(function* (
@@ -853,7 +870,7 @@ const make = Effect.gen(function* () {
const isTrackedTurn = sameId(startedTurnId, turnId);
if (isTrackedTurn) startedTurns.delete(event.threadId);
if (event.type === "turn.completed") {
yield* refreshLocalGitStatusFromTurnCompletion(event);
yield* statusRefreshWorker.enqueue(event);
}
if (
turnId !== null &&
@@ -944,7 +961,7 @@ const make = Effect.gen(function* () {
return {
start,
drain: worker.drain,
drain: worker.drain.pipe(Effect.andThen(statusRefreshWorker.drain)),
} satisfies CheckpointReactorShape;
});