The best way to control Claude Code, Codex and more from any computer or phone
fix(web): a rewritten review guide no longer shows code from the previous push (#37864)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 17, 2026 at 03:53 UTC
47c95c28124c44bcea710078021b95648f0beb15
4 files changed
+79
-7
apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx
+26
-1
@@ -6,11 +6,16 @@ import { expect, it, vi } from "vite-plus/test";
6
import { act, render } from "../../../../test/render";
7
8
const state = vi.hoisted(() => ({
9
+ heads: new Map<
10
+ string,
11
+ Map<string | null, Atom.Atom<AsyncResult.AsyncResult<PullRequestDiffResult>>>
12
+ >(),
13
pages: new Map<string | null, Atom.Atom<AsyncResult.AsyncResult<PullRequestDiffResult>>>(),
14
}));
15
vi.mock("~/state/pullRequests", () => ({
16
pullRequestEnvironment: {
13
- diff: ({ input }: { input: { cursor?: string } }) => state.pages.get(input.cursor ?? null)!,
17
+ diff: ({ input }: { input: { cursor?: string; cacheHeadSha?: string } }) =>
18
+ (state.heads.get(input.cacheHeadSha ?? "") ?? state.pages).get(input.cursor ?? null)!,
19
},
20
}));
21
@@ -35,6 +40,7 @@ function Probe({ wantedPaths }: { wantedPaths: string[] }) {
40
41
function setup() {
42
state.pages.clear();
43
+ state.heads.clear();
44
}
45
46
function page(path: string, value: string, nextCursor: string | null): PullRequestDiffResult {
@@ -143,3 +149,22 @@ it("waits for a later cached page that is still refreshing", async () => {
149
],
150
});
151
});
152
+
153
+it("reads the guide head's pages instead of the previous push's cached ones", async () => {
154
+ setup();
155
+ await using stack = new AsyncDisposableStack();
156
+ const registry = stack.adopt(AtomRegistry.make(), (value) => value.dispose());
157
+ state.pages.set(null, Atom.make(AsyncResult.success(page("wanted.ts", "OLD_HEAD", null))));
158
+ state.heads.set(
159
+ "new-head",
160
+ new Map([[null, Atom.make(AsyncResult.success(page("wanted.ts", "NEW_HEAD", null)))]]),
161
+ );
162
+ await using screen = await render(
163
+ <RegistryContext.Provider value={registry}>
164
+ <Probe wantedPaths={["wanted.ts"]} />
165
+ </RegistryContext.Provider>,
166
+ );
167
+ expect(JSON.parse(screen.container.querySelector("output")!.textContent!).files).toEqual([
168
+ ["wanted.ts", "NEW_HEAD\n"],
169
+ ]);
170
+});
apps/web/src/components/pullRequest/guide/useGuideDiffFiles.ts
+1
-1
@@ -46,7 +46,7 @@ export function useGuideDiffFiles({
46
const pageAtom = (cursor: string | null) =>
47
pullRequestEnvironment.diff({
48
environmentId,
49
- input: { ...reference, ...(cursor === null ? {} : { cursor }) },
49
+ input: { ...reference, cacheHeadSha: headSha, ...(cursor === null ? {} : { cursor }) },
50
});
51
const loading = isMissing(current) && !current.done;
52
const query = useEnvironmentQuery(loading ? pageAtom(current.cursor) : null);
packages/client-runtime/src/state/pullRequests.test.ts
+45
-4
@@ -521,6 +521,9 @@ const makeTestRuntime = Effect.fn("makeTestRuntime")(function* (
521
localOrigin = false,
522
onAnswer: Parameters<typeof createPullRequestEnvironmentAtoms>[1] = {},
523
queryStore: typeof EnvironmentQueryStore.Service = null,
524
+ diffLoader: PullRequestDiffLoader.PullRequestDiffLoader["Service"] = {
525
+ load: () => Effect.die("unused"),
526
+ },
527
) {
528
const originTarget = localOrigin
529
? new PrimaryConnectionTarget({
@@ -588,10 +591,7 @@ const makeTestRuntime = Effect.fn("makeTestRuntime")(function* (
591
const runtime = Atom.runtime(
592
Layer.mergeAll(
593
Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry),
591
- Layer.succeed(
592
- PullRequestDiffLoader.PullRequestDiffLoader,
593
- PullRequestDiffLoader.PullRequestDiffLoader.of({ load: () => Effect.die("unused") }),
594
- ),
594
+ Layer.succeed(PullRequestDiffLoader.PullRequestDiffLoader, diffLoader),
595
Layer.succeed(EnvironmentQueryStore, queryStore),
596
),
597
);
@@ -2980,3 +2980,44 @@ it.effect("paints a saved stack answer at once while the host read is out", () =
2980
}),
2981
),
2982
);
2983
+
2984
+it.effect("loads the diff again for a new guide head without sending the head", () =>
2985
+ Effect.gen(function* () {
2986
+ const inputs: unknown[] = [];
2987
+ const { atoms, registry, supervisor } = yield* makeTestRuntime(
2988
+ {} as WsRpcProtocolClient,
2989
+ undefined,
2990
+ false,
2991
+ {},
2992
+ null,
2993
+ {
2994
+ load: (_prepared, input) =>
2995
+ Effect.sync(() => {
2996
+ inputs.push(input);
2997
+ return { patch: "", truncated: false, nextCursor: null };
2998
+ }),
2999
+ },
3000
+ );
3001
+ yield* SubscriptionRef.set(
3002
+ supervisor.prepared,
3003
+ Option.some({
3004
+ environmentId: TARGET.environmentId,
3005
+ label: TARGET.label,
3006
+ httpBaseUrl: "https://example.test",
3007
+ socketUrl: "wss://example.test",
3008
+ httpAuthorization: null,
3009
+ target: TARGET,
3010
+ }),
3011
+ );
3012
+ const reference = { projectId: ProjectId.make("project-1"), repository: "acme/web", number: 1 };
3013
+ for (const cacheHeadSha of ["old-head", "new-head"]) {
3014
+ const query = atoms.diff({
3015
+ environmentId: TARGET.environmentId,
3016
+ input: { ...reference, cacheHeadSha },
3017
+ });
3018
+ registry.mount(query);
3019
+ yield* AtomRegistry.getResult(registry, query, { suspendOnWaiting: true });
3020
+ }
3021
+ expect(inputs).toEqual([reference, reference]);
3022
+ }),
3023
+);
packages/client-runtime/src/state/pullRequests.ts
+7
-1
@@ -1292,7 +1292,13 @@ export function createPullRequestEnvironmentAtoms<R, E>(
1292
label: "environment-data:pull-requests:diff",
1293
persistence: persistQuery(PullRequestDiffResult),
1294
staleTimeMs: 60_000,
1295
- execute: loadDiff,
1295
+ // A guide tied to a commit must not reuse another push's cached pages.
1296
+ execute: ({
1297
+ cacheHeadSha: _cacheHeadSha,
1298
+ ...input
1299
+ }: PullRequestDiffInput & {
1300
+ readonly cacheHeadSha?: string;
1301
+ }) => loadDiff(input),
1302
}),
1303
diffFileContents: createEnvironmentRpcCommand(runtime, {
1304
label: "environment-data:pull-requests:diff-file-contents",