@devries-cameron20 / t3code-1 / commits / 200dad3b39
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): keep PR check counts in sync (#23548)

Julius Marminge committed Oct 22, 2026 at 16:11 UTC 200dad3b39aa9c2562b4bae54106ab8acdcc4163
10 files changed +202 -36
apps/server/src/pullRequest/PullRequestService.test.ts
+28
@@ -2748,6 +2748,34 @@ it.effect("deduplicates routed PR reports without dropping draft changes", () =>
2748 }),
2749 );
2750
2751 +it.effect("preserves check observation time on cache hits and advances it on refresh", () =>
2752 + Effect.gen(function* () {
2753 + let reads = 0;
2754 + const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
2755 + const service = yield* makeService({
2756 + projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
2757 + providers: [
2758 + fakeProvider(SourceControlProviderKind.make("github"), {
2759 + getChangeRequestChecks: () =>
2760 + Effect.sync(() => {
2761 + reads += 1;
2762 + return { state: "open" as const, checks: [] };
2763 + }),
2764 + }),
2765 + ],
2766 + });
2767 + yield* TestClock.setTime(1_000);
2768 + const first = yield* service.checks(reference);
2769 + expect(first).toMatchObject({ observedAt: 1_000 });
2770 + yield* TestClock.adjust("1 second");
2771 + expect(yield* service.checks(reference)).toEqual(first);
2772 + expect(reads).toBe(1);
2773 + yield* TestClock.adjust("15 seconds");
2774 + expect(yield* service.checks(reference)).toMatchObject({ observedAt: 17_000 });
2775 + expect(reads).toBe(2);
2776 + }),
2777 +);
2778 +
2779 it.effect("reuses an observed merged state for strict settlement reads", () =>
2780 Effect.gen(function* () {
2781 const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
apps/server/src/pullRequest/PullRequestService.ts
+5 -1
@@ -2790,7 +2790,11 @@ export const make = Effect.gen(function* () {
2790 host: project.host,
2791 number: input.number,
2792 })
2793 - .pipe(Effect.mapError(toPullRequestError("checks"))),
2793 + .pipe(
2794 + Effect.mapError(toPullRequestError("checks")),
2795 + observeRead,
2796 + Effect.map(({ value, observedAt }) => ({ ...value, observedAt })),
2797 + ),
2798 ),
2799 );
2800 },
apps/web/src/components/chat/ThreadDetailsPrRow.tsx
+2 -6
@@ -32,6 +32,7 @@ import {
32 buildFixFindingsHandoff,
33 buildResolveConflictsPrompt,
34 classifyPullRequestChecks,
35 + resolvePullRequestDetailChecks,
36 describePullRequestChecks,
37 isPullRequestConflicting,
38 resolvePullRequestMergeMethod,
@@ -135,12 +136,7 @@ export function ThreadDetailsPrRow({
136 const checksSettledEmpty = useEnvironmentQuerySelector(checksAtom, isSettledWithoutChecks);
137 const checksQuery = useEnvironmentQueryRefresh(checksAtom);
138 const checksAreNewer = useEnvironmentQueryIsNewer(checksAtom, detailAtom);
138 - const detail =
139 - detailData === null
140 - ? null
141 - : checksData !== null && checksAreNewer
142 - ? { ...detailData, ...checksData }
143 - : detailData;
139 + const detail = resolvePullRequestDetailChecks(detailData, checksData, checksAreNewer);
140 const open = reference !== null && (detail?.state ?? pr?.state) === "open";
141 const refreshKey = `${environmentId}:${project?.id}:${reference?.host}:${reference?.repository}:${number}`;
142 useLiveRefresh(
apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+54
@@ -46,6 +46,7 @@ import {
46 checkoutFailureDescription,
47 readPullRequestDetailSnapshot,
48 resolveDisplayedPullRequestDetail,
49 + resolvePullRequestDetailChecks,
50 resolvePullRequestReferenceHost,
51 resolvePullRequestPrimaryControl,
52 allowsSinglePullRequestMerge,
@@ -1245,6 +1246,59 @@ describe("cached pull request detail", () => {
1246 ...overrides,
1247 }) as PullRequestDetail;
1248
1249 + it("uses fresh checks for detail counts without replacing other PR fields", () => {
1250 + const pending = (name: string): PullRequestCheck => ({
1251 + name,
1252 + status: "pending",
1253 + url: null,
1254 + description: null,
1255 + });
1256 + const original = detail({ checks: [pending("build"), pending("test")] });
1257 + const checks = [pending("build"), { ...pending("test"), status: "success" as const }];
1258 + expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, true)).toEqual({
1259 + ...original,
1260 + state: "closed",
1261 + checks,
1262 + });
1263 + expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, false)).toBe(
1264 + original,
1265 + );
1266 + expect(resolvePullRequestDetailChecks(original, null, true)).toBe(original);
1267 + expect(resolvePullRequestDetailChecks(null, { state: "closed", checks }, true)).toBeNull();
1268 + });
1269 +
1270 + it("keeps newer checks when an older cached detail arrives later", () => {
1271 + const pending: PullRequestCheck = {
1272 + name: "build",
1273 + status: "pending",
1274 + url: null,
1275 + description: null,
1276 + };
1277 + const cached = detail({ observedAt: 1_000, checks: [pending] });
1278 + const checks = {
1279 + state: "open" as const,
1280 + checks: [{ ...pending, status: "success" as const }],
1281 + observedAt: 2_000,
1282 + };
1283 + const resolved = resolvePullRequestDetailChecks(cached, checks, false);
1284 + expect(resolved?.checks).toEqual(checks.checks);
1285 + expect(resolved?.observedAt).toBe(1_000);
1286 + expect(
1287 + resolvePullRequestDetailChecks(cached, { state: checks.state, checks: checks.checks }, true)
1288 + ?.checks,
1289 + ).toEqual(checks.checks);
1290 + const refreshed = detail({ observedAt: 3_000, checks: [pending] });
1291 + expect(resolvePullRequestDetailChecks(refreshed, checks, true)).toBe(refreshed);
1292 + });
1293 +
1294 + it("keeps merged details settled while applying newer checks", () => {
1295 + const merged = detail({ state: "merged", observedAt: 1_000 });
1296 + const checks = [{ name: "build", status: "success" as const, url: null, description: null }];
1297 + expect(
1298 + resolvePullRequestDetailChecks(merged, { state: "open", observedAt: 2_000, checks }, true),
1299 + ).toEqual({ ...merged, checks });
1300 + });
1301 +
1302 const makeStorage = () => {
1303 const held = new Map<string, string>();
1304 return {
apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+20
@@ -10,6 +10,7 @@ import {
10 type PullRequestActor,
11 type PullRequestBaseComparison,
12 type PullRequestCheck,
13 + type PullRequestChecks,
14 type PullRequestChecksState as ContractPullRequestChecksState,
15 type PullRequestComment,
16 type PullRequestCommit,
@@ -1419,3 +1420,22 @@ export function resolveDisplayedPullRequestDetail(input: {
1420 return null;
1421 }
1422 }
1423 +
1424 +export function resolvePullRequestDetailChecks(
1425 + detail: PullRequestDetail | null,
1426 + checks: PullRequestChecks | null,
1427 + checksAreNewer: boolean,
1428 +): PullRequestDetail | null {
1429 + if (detail === null || checks === null) return detail;
1430 + const newer =
1431 + detail.observedAt !== undefined && checks.observedAt !== undefined
1432 + ? checks.observedAt >= detail.observedAt
1433 + : checksAreNewer;
1434 + return newer
1435 + ? {
1436 + ...detail,
1437 + state: detail.state === "merged" ? "merged" : checks.state,
1438 + checks: checks.checks,
1439 + }
1440 + : detail;
1441 +}
apps/web/src/components/pullRequest/usePullRequestDetail.ts
+31 -4
@@ -7,6 +7,8 @@ import {
7 } from "@t3tools/contracts";
8 import { useEffect, useEffectEvent, useState } from "react";
9
10 +import { usePullRequestChecksRefresh } from "~/hooks/usePullRequestChecksRefresh";
11 +import { useServerConfigs } from "~/state/entities";
12 import { useEnvironmentQuery } from "~/state/query";
13 import { useEnvironmentScope } from "~/state/session";
14 import {
@@ -18,6 +20,7 @@ import {
20 import {
21 readPullRequestDetailSnapshot,
22 resolveDisplayedPullRequestDetail,
23 + resolvePullRequestDetailChecks,
24 writePullRequestDetailSnapshot,
25 } from "./pullRequestDetail.logic";
26 import { pullRequestChecksState } from "./pullRequestPresentation";
@@ -42,11 +45,35 @@ export function usePullRequestDetail(
45 const scopeKey = `${environmentId}:${pullRequestRefKey(reference)}`;
46 const canWriteSourceControl = useEnvironmentScope(environmentId, AuthSourceControlWriteScope);
47 const detailQuery = useEnvironmentQuery(
45 - pullRequestEnvironment.detail({ environmentId, input: reference }),
48 + pullRequestEnvironment.detail({ environmentId, input: { ...reference, allowStale: false } }),
49 );
50 const activityQuery = useEnvironmentQuery(
51 pullRequestEnvironment.activity({ environmentId, input: reference }),
52 );
53 + const serverConfigs = useServerConfigs();
54 + const supportsChecks =
55 + serverConfigs.get(environmentId)?.environment.capabilities.pullRequestChecks === true;
56 + const checksQuery = useEnvironmentQuery(
57 + supportsChecks && detailQuery.data !== null
58 + ? pullRequestEnvironment.checks({ environmentId, input: reference })
59 + : null,
60 + );
61 + const liveDetail = resolvePullRequestDetailChecks(
62 + detailQuery.data,
63 + checksQuery.data,
64 + checksQuery.dataUpdatedAt >= detailQuery.dataUpdatedAt,
65 + );
66 + usePullRequestChecksRefresh({
67 + refresh: () => {
68 + if (!checksQuery.isPending && !detailQuery.isPending) checksQuery.refresh();
69 + },
70 + enabled:
71 + liveDetail?.state === "open" &&
72 + supportsChecks &&
73 + !(checksQuery.isSuccess && checksQuery.data === null),
74 + key: `workspace-pr-checks:${environmentId}:${reference.projectId}:${reference.host}:${reference.repository}:${reference.number}`,
75 + checks: liveDetail?.checks ?? [],
76 + });
77 const [cachedDetail, setCachedDetail] = useState(() =>
78 readPullRequestDetailSnapshot(
79 typeof window === "undefined" ? undefined : window.localStorage,
@@ -79,16 +106,16 @@ export function usePullRequestDetail(
106 useEffect(() => {
107 if (detailQuery.data !== null) saveDetailSnapshot(detailQuery.data);
108 }, [detailQuery.data]);
82 - const detailSummary = pullRequestDetailSummary(detailQuery.data);
109 + const detailSummary = pullRequestDetailSummary(liveDetail);
110 const observedSummary = useSharedPullRequestSummary(
111 environmentId,
112 reference,
113 detailSummary,
87 - detailQuery.dataUpdatedAt,
114 + Math.max(detailQuery.dataUpdatedAt, checksQuery.dataUpdatedAt),
115 );
116 const activity = activityQuery.data;
117 const resolvedCoreDetail = resolveDisplayedPullRequestDetail({
91 - live: detailQuery.data,
118 + live: liveDetail,
119 cached: cachedDetail,
120 reference,
121 });
packages/client-runtime/src/state/pullRequests.test.ts
+29
@@ -1277,6 +1277,35 @@ it.effect("shares close, reopen, and merge with an untouched client's mounted PR
1277 ),
1278 );
1279
1280 +it.effect("shares checks reads across reference property order", () =>
1281 + Effect.scoped(
1282 + Effect.gen(function* () {
1283 + let reads = 0;
1284 + const client = {
1285 + [WS_METHODS.pullRequestsSubscribeRefreshes]: () => Stream.never,
1286 + [WS_METHODS.pullRequestsChecks]: () =>
1287 + Effect.sync(() => {
1288 + reads += 1;
1289 + return { state: "open", checks: [], observedAt: 1_000 };
1290 + }),
1291 + } as unknown as WsRpcProtocolClient;
1292 + const { atoms, registry } = yield* makeTestRuntime(client);
1293 + const projectId = ProjectId.make("project-1");
1294 + const row = atoms.checks({
1295 + environmentId: TARGET.environmentId,
1296 + input: { host: "github.com", repository: "acme/web", number: 1, projectId },
1297 + });
1298 + const panel = atoms.checks({
1299 + environmentId: TARGET.environmentId,
1300 + input: { projectId, host: "github.com", repository: "acme/web", number: 1 },
1301 + });
1302 + yield* AtomRegistry.getResult(registry, row);
1303 + yield* AtomRegistry.getResult(registry, panel);
1304 + expect(reads).toBe(1);
1305 + }),
1306 + ),
1307 +);
1308 +
1309 it.effect("keeps live detail reads separate from reads that allow stale data", () =>
1310 Effect.scoped(
1311 Effect.gen(function* () {
packages/client-runtime/src/state/pullRequests.ts
+31 -24
@@ -55,6 +55,26 @@ export class EnvironmentHttpConnectionNotReadyError extends Data.TaggedError(
55
56 const LINKED_PULL_REQUEST_IDLE_TTL_MS = 5_000;
57
58 +function normalizePullRequestQuery<A>(
59 + query: (target: { readonly environmentId: EnvironmentId; readonly input: PullRequestRef }) => A,
60 +) {
61 + return ({
62 + environmentId,
63 + input: { projectId, host, repository, number, allowStale, expectedAccountId },
64 + }: Parameters<typeof query>[0]) =>
65 + query({
66 + environmentId,
67 + input: {
68 + projectId,
69 + ...(host === undefined ? {} : { host }),
70 + repository,
71 + number,
72 + ...(allowStale === undefined ? {} : { allowStale }),
73 + ...(expectedAccountId === undefined ? {} : { expectedAccountId }),
74 + },
75 + });
76 +}
77 +
78 function writableQueryFamily<A, E>(
79 family: (target: {
80 readonly environmentId: EnvironmentId;
@@ -77,22 +97,7 @@ function writableQueryFamily<A, E>(
97 (refresh) => refresh(source),
98 ).pipe(Atom.setIdleTTL(5 * 60_000)),
99 );
80 - return ({
81 - environmentId,
82 - input: { projectId, host, repository, number, allowStale },
83 - }: Parameters<typeof family>[0]) =>
84 - writable(
85 - family({
86 - environmentId,
87 - input: {
88 - projectId,
89 - ...(host === undefined ? {} : { host }),
90 - repository,
91 - number,
92 - ...(allowStale === undefined ? {} : { allowStale }),
93 - },
94 - }),
95 - );
100 + return normalizePullRequestQuery((target) => writable(family(target)));
101 }
102
103 /** Restart pre-mutation reads before patching so they cannot restore stale values. */
@@ -319,14 +324,16 @@ export function createPullRequestEnvironmentAtoms<R, E>(
324 }),
325 detail,
326 preview,
322 - checks: createEnvironmentRpcQueryAtomFamily(runtime, {
323 - label: "environment-data:pull-requests:checks",
324 - persistence: persistQuery(Schema.NullOr(PullRequestChecks)),
325 - tag: WS_METHODS.pullRequestsChecks,
326 - execute: (input) => routedRequest(WS_METHODS.pullRequestsChecks, input),
327 - staleTimeMs: 45_000,
328 - refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
329 - }),
327 + checks: normalizePullRequestQuery(
328 + createEnvironmentRpcQueryAtomFamily(runtime, {
329 + label: "environment-data:pull-requests:checks",
330 + persistence: persistQuery(Schema.NullOr(PullRequestChecks)),
331 + tag: WS_METHODS.pullRequestsChecks,
332 + execute: (input) => routedRequest(WS_METHODS.pullRequestsChecks, input),
333 + staleTimeMs: 45_000,
334 + refreshTrigger: ({ environmentId }) => refreshes({ environmentId, input: {} }),
335 + }),
336 + ),
337 activity,
338 threadComments: createEnvironmentRpcCommand(runtime, {
339 label: "environment-data:pull-requests:thread-comments",
packages/contracts/src/pullRequest.ts
+1
@@ -589,6 +589,7 @@ export const PullRequestDetail = Schema.Struct({
589 export type PullRequestDetail = typeof PullRequestDetail.Type;
590
591 export const PullRequestChecks = Schema.Struct({
592 + observedAt: Schema.optional(Schema.Finite),
593 state: PullRequestState,
594 checks: Schema.Array(PullRequestCheck),
595 });
packages/source-control-core/src/server/PullRequestProvider.ts
+1 -1
@@ -342,7 +342,7 @@ export interface PullRequestProviderApi {
342
343 readonly getChangeRequestChecks?: (
344 input: ProviderRepositoryRef & { readonly number: number },
345 - ) => Effect.Effect<PullRequestChecks, PullRequestProviderError>;
345 + ) => Effect.Effect<Pick<PullRequestChecks, "state" | "checks">, PullRequestProviderError>;
346
347 readonly getChangeRequest: (
348 input: ProviderRepositoryRef & { readonly number: number },