fix(server): refresh file search outside checkpoint processing (#12308)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-17 16:41:06 -07:00
1 parent 67993623af
commit d17f46d763
2 files changed
+123 -8

No files matched your search

@@ -295,6 +295,7 @@ describe("CheckpointReactor", () => {
readonly checkpointLookupFailure?: (
cwd: string,
) => VcsProcessTimeoutError | VcsProcessSpawnError | undefined;
readonly workspaceRefresh?: (cwd: string) => Effect.Effect<void>;
readonly hasSession?: boolean;
readonly seedFilesystemCheckpoints?: boolean;
readonly initializeGit?: boolean;
@@ -390,10 +391,10 @@ describe("CheckpointReactor", () => {
).pipe(Layer.provide(VcsDriverRegistry.layer)),
),
Layer.provideMerge(
WorkspaceEntries.layer.pipe(
Layer.provide(WorkspacePaths.layer),
Layer.provideMerge(VcsDriverRegistry.layer),
),
(options?.workspaceRefresh
? Layer.mock(WorkspaceEntries.WorkspaceEntries)({ refresh: options.workspaceRefresh })
: WorkspaceEntries.layer
).pipe(Layer.provide(WorkspacePaths.layer), Layer.provideMerge(VcsDriverRegistry.layer)),
),
Layer.provideMerge(WorkspacePaths.layer),
Layer.provideMerge(VcsProcess.layer),
@@ -664,6 +665,99 @@ describe("CheckpointReactor", () => {
}),
);
effectIt.effect(
"finalizes checkpoints in both workspaces while entry refresh is blocked and coalesces later scans",
() =>
Effect.gen(function* () {
const entered = yield* Deferred.make<void>();
const release = yield* Deferred.make<void>();
const refreshCalls: string[] = [];
let secondCwd = "";
const harness = yield* Effect.promise(() =>
createHarness({
seedFilesystemCheckpoints: false,
secondThreadSharingWorktree: true,
secondThreadWorktreePath: () => {
secondCwd = createGitRepository();
tempDirs.push(secondCwd);
return secondCwd;
},
workspaceRefresh: (cwd) =>
Effect.gen(function* () {
refreshCalls.push(cwd);
if (refreshCalls.length === 1) {
yield* Deferred.succeed(entered, undefined);
yield* Deferred.await(release);
}
}),
}),
);
for (const [index, threadId] of [
"thread-1",
"thread-2",
"thread-1",
"thread-1",
"thread-1",
].entries()) {
const turnId = asTurnId(`turn-refresh-${index}`);
const id = ThreadId.make(threadId);
harness.provider.emit({
type: "turn.started",
eventId: EventId.make(`evt-refresh-start-${index}`),
provider: ProviderDriverKind.make("codex"),
createdAt: "2026-01-01T00:00:00.000Z",
threadId: id,
turnId,
});
if (index < 2)
expect(yield* harness.nextReceipt).toMatchObject({
type: "checkpoint.baseline.captured",
threadId: id,
});
const cwd = threadId === "thread-1" ? harness.cwd : secondCwd;
NodeFS.writeFileSync(NodePath.join(cwd, "README.md"), `snapshot ${index}\n`);
harness.provider.emit({
type: "turn.completed",
eventId: EventId.make(`evt-refresh-complete-${index}`),
provider: ProviderDriverKind.make("codex"),
createdAt: "2026-01-01T00:00:01.000Z",
threadId: id,
turnId,
payload: { state: "completed" },
});
expect(yield* harness.nextReceipt).toMatchObject({
type: "checkpoint.diff.finalized",
threadId: id,
turnId,
});
expect(yield* harness.nextReceipt).toMatchObject({
type: "turn.processing.quiesced",
threadId: id,
turnId,
});
if (index === 0) yield* Deferred.await(entered);
}
expect(refreshCalls).toEqual([harness.cwd]);
expect(
gitShowFileAtRef(
harness.cwd,
checkpointRefForThreadTurn(ThreadId.make("thread-1"), 4),
"README.md",
),
).toBe("snapshot 4\n");
expect(
gitShowFileAtRef(
secondCwd,
checkpointRefForThreadTurn(ThreadId.make("thread-2"), 1),
"README.md",
),
).toBe("snapshot 1\n");
yield* Deferred.succeed(release, undefined);
yield* Effect.promise(harness.drain);
expect(refreshCalls).toEqual([harness.cwd, secondCwd, harness.cwd]);
}),
);
effectIt.effect("captures baseline and large turn summaries before completion receipts", () =>
Effect.gen(function* () {
const harness = yield* Effect.promise(() =>
@@ -93,6 +93,25 @@ const make = Effect.gen(function* () {
const path = yield* Path.Path;
const vcsStatusBroadcaster = yield* VcsStatusBroadcaster;
const pullRequests = yield* PullRequestService.PullRequestService;
const queuedEntryRefreshes = new Set<string>();
const entryRefreshWorker = yield* makeDrainableWorker((cwd: string) =>
Effect.sync(() => queuedEntryRefreshes.delete(cwd)).pipe(
Effect.andThen(workspaceEntries.refresh(cwd)),
Effect.catchCause((cause) =>
Cause.hasInterruptsOnly(cause)
? Effect.failCause(cause)
: Effect.logWarning("failed to refresh checkpoint workspace entries", {
cwd,
}),
),
),
);
const refreshWorkspaceEntries = Effect.fn("refreshWorkspaceEntries")(function* (cwd: string) {
if (queuedEntryRefreshes.has(cwd)) return;
queuedEntryRefreshes.add(cwd);
yield* entryRefreshWorker.enqueue(cwd);
});
const startedTurns = new Map<ThreadId, TurnId>();
const pending = new Set<ThreadId>();
@@ -270,7 +289,7 @@ const make = Effect.gen(function* () {
// Refresh the workspace entry index so the @-mention file picker
// reflects files created or deleted during this turn.
yield* workspaceEntries.refresh(input.cwd);
yield* refreshWorkspaceEntries(input.cwd);
// Git may have been initialized during this turn, leaving no pre-turn
// snapshot. Keep the completion checkpoint for future turns, but do not
@@ -629,7 +648,6 @@ const make = Effect.gen(function* () {
? Effect.failCause(cause)
: Effect.logWarning("failed to refresh git status after turn completion", {
threadId: event.threadId,
cause: Cause.pretty(cause),
}),
),
),
@@ -850,7 +868,7 @@ const make = Effect.gen(function* () {
// Refresh the workspace entry index so the @-mention file picker
// reflects the reverted filesystem state.
yield* workspaceEntries.refresh(checkpointCwd);
yield* refreshWorkspaceEntries(checkpointCwd);
}
const rolledBackTurns = Math.max(0, currentTurnCount - event.payload.turnCount);
@@ -1041,7 +1059,10 @@ const make = Effect.gen(function* () {
return {
start,
drain: worker.drain.pipe(Effect.andThen(statusRefreshWorker.drain)),
drain: worker.drain.pipe(
Effect.andThen(statusRefreshWorker.drain),
Effect.andThen(entryRefreshWorker.drain),
),
} satisfies CheckpointReactorShape;
});