Skip to content

Commit 92357b4

Browse files
committed
refactor(pr): narrow state sync to saved summaries
1 parent 5b21ab3 commit 92357b4

5 files changed

Lines changed: 27 additions & 57 deletions

File tree

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,19 +5128,19 @@ it.effect("reuses an observed merged state for strict settlement reads", () =>
51285128
}),
51295129
);
51305130

5131-
it.effect("announces state, edits, and conflicts a detail read sees", () =>
5131+
it.effect("announces state a detail read sees first or newly", () =>
51325132
Effect.gen(function* () {
51335133
let detail = {
5134-
...hostedChangeRequest("body"),
51355134
state: "open" as "open" | "closed" | "merged",
5135+
updatedAt: "2026-07-02T00:00:00Z",
51365136
};
51375137
let summaryState: "open" | "merged" = "open";
51385138
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
51395139
const service = yield* makeService({
51405140
projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
51415141
providers: [
51425142
fakeProvider(SourceControlProviderKind.make("github"), {
5143-
getChangeRequest: () => Effect.succeed(detail),
5143+
getChangeRequest: () => Effect.succeed({ ...hostedChangeRequest("body"), ...detail }),
51445144
getChangeRequestSummary: () =>
51455145
Effect.succeed({
51465146
...changeRequest(1, "2026-07-04T00:00:00Z"),
@@ -5159,37 +5159,28 @@ it.effect("announces state, edits, and conflicts a detail read sees", () =>
51595159
yield* Effect.yieldNow;
51605160
});
51615161

5162-
// First sight announces; unchanged fields, even from a fresh read, do not.
5162+
// First sight announces; the same state again, even from a fresh read, does not.
51635163
yield* readDetail;
51645164
yield* readDetail;
51655165
assert.deepStrictEqual(announced, ["github.com/acme/web#1"]);
51665166

5167-
// An edit bumps the host update time; a new conflict does not, and announces anyway.
5168-
detail = { ...detail, title: "Updated title", updatedAt: "2026-07-02T12:00:00Z" };
5167+
detail = { state: "closed", updatedAt: "2026-07-03T00:00:00Z" };
51695168
yield* readDetail;
51705169
assert.strictEqual(announced.length, 2);
5171-
detail = { ...detail, mergeability: "conflicting" };
5172-
yield* readDetail;
5173-
yield* readDetail;
5174-
assert.strictEqual(announced.length, 3);
5175-
5176-
detail = { ...detail, state: "closed", updatedAt: "2026-07-03T00:00:00Z" };
5177-
yield* readDetail;
5178-
assert.strictEqual(announced.length, 4);
51795170

51805171
// A summary seeing the merge first does not hide it from the detail read after.
51815172
summaryState = "merged";
51825173
yield* service.summary(reference, { recoverTransientFailure: false });
51835174
yield* Effect.yieldNow;
5184-
assert.strictEqual(announced.length, 4);
5185-
detail = { ...detail, state: "merged", updatedAt: "2026-07-04T00:00:00Z" };
5175+
assert.strictEqual(announced.length, 2);
5176+
detail = { state: "merged", updatedAt: "2026-07-04T00:00:00Z" };
51865177
yield* readDetail;
5187-
assert.strictEqual(announced.length, 5);
5178+
assert.strictEqual(announced.length, 3);
51885179

51895180
// A detail read older than the merge cannot announce a reopen.
5190-
detail = { ...detail, state: "open", updatedAt: "2026-07-03T00:00:00Z" };
5181+
detail = { state: "open", updatedAt: "2026-07-03T00:00:00Z" };
51915182
yield* readDetail;
5192-
assert.strictEqual(announced.length, 5);
5183+
assert.strictEqual(announced.length, 3);
51935184
}),
51945185
);
51955186

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ export interface PullRequestMergeEvent extends PullRequestRef {
9999
readonly mergedAt: string;
100100
}
101101

102-
type PullRequestReading = Pick<
103-
PullRequestSummary,
104-
"state" | "updatedAt" | "observedAt" | "mergeability"
105-
>;
102+
type PullRequestReading = Pick<PullRequestSummary, "state" | "updatedAt" | "observedAt">;
106103

107104
/** Whether `next` is a newer reading of a pull request than `current`. Merged is final. */
108105
function supersedesReading(current: PullRequestReading | undefined, next: PullRequestReading) {
@@ -242,8 +239,8 @@ export class PullRequestService extends Context.Service<
242239
Scope.Scope
243240
>;
244241
/**
245-
* Pull requests a detail read saw for the first time or changed (state, host update time,
246-
* mergeability), so thread links can catch up before the next sync sweep. Best effort.
242+
* Pull requests a detail read saw for the first time or in a new state (opened, closed,
243+
* merged), so thread links can catch up before the next sync sweep. Best effort.
247244
*/
248245
readonly subscribeStateChanges: Effect.Effect<
249246
Stream.Stream<ThreadPullRequestKey>,
@@ -3139,9 +3136,9 @@ export const make = Effect.gen(function* () {
31393136
// it read under. Summary reads stay out: they would hide a change from the detail read after.
31403137
const detailStates = new Map<string, PullRequestReading>();
31413138
/**
3142-
* Announces a pull request a detail read sees first or changed, so a client showing a fresh
3143-
* merge, edit, or conflict brings the thread's link and its settlement along, rather than
3144-
* leaving them to the next sync sweep.
3139+
* Announces a pull request a detail read sees first or in a new state, so a client showing a
3140+
* fresh merge brings the thread's link and its settlement along, rather than leaving them to
3141+
* the next sync sweep.
31453142
*/
31463143
const noteDetailReading = (ref: PullRequestRef, next: PullRequestSummary) =>
31473144
Effect.suspend(() => {
@@ -3157,16 +3154,8 @@ export const make = Effect.gen(function* () {
31573154
state: next.state,
31583155
updatedAt: next.updatedAt,
31593156
observedAt: next.observedAt,
3160-
mergeability: next.mergeability,
31613157
});
3162-
// Hosts bump `updatedAt` for title, branch, draft, and diff changes; mergeability moves
3163-
// with the base branch instead.
3164-
const changed =
3165-
current === undefined ||
3166-
current.state !== next.state ||
3167-
current.updatedAt !== next.updatedAt ||
3168-
current.mergeability !== next.mergeability;
3169-
return changed && ref.host !== undefined
3158+
return current?.state !== next.state && ref.host !== undefined
31703159
? PubSub.publish(stateChanges, {
31713160
host: ref.host,
31723161
repository: ref.repository,

‎apps/web/src/components/RightPanelTabs.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,17 +790,16 @@ function PullRequestSurfaceIcon({
790790
const reference = useMemo(
791791
() => ({
792792
projectId: surface.projectId as ProjectId,
793-
...(host === null ? {} : { host }),
794793
repository: surface.repository,
795794
number: surface.number,
796795
}),
797-
[surface.projectId, host, surface.repository, surface.number],
796+
[surface.projectId, surface.repository, surface.number],
798797
);
799798
const sharedSummary = useSharedPullRequestSummary(resolvedEnvironmentId, reference, null);
800799
// The compact tab intentionally shows lifecycle and draft state only. Conflict warnings have
801800
// their own presentation on surfaces that have mergeability, while this tab stays stable as
802801
// detail data arrives.
803-
const status = newestPullRequestSummary(detail, sharedSummary) ?? linkedSnapshot ?? seed ?? null;
802+
const status = linkedSnapshot ?? newestPullRequestSummary(detail, sharedSummary) ?? seed ?? null;
804803
if (status === null) {
805804
return <PullRequestGlyph.pullRequest className="size-3 shrink-0 text-muted-foreground" />;
806805
}

‎apps/web/src/components/ThreadStatusIndicators.tsx‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,12 @@ export function useLinkedThreadPullRequest(
104104
// Stable per link: the shared summary effect keys on this object, and a sidebar row must not
105105
// touch the cache on every render.
106106
const reference = useMemo(() => {
107-
const projectId = linkedPullRequest?.projectId ?? branchPullRequest?.projectId;
108-
if (current !== null && projectId !== undefined) return { ...current, projectId };
109107
if (fallback == null) return null;
110108
const host = parseChangeRequestUrl(fallback.url)?.host;
111109
return { ...fallback, ...(host === undefined ? {} : { host }) };
112-
}, [current, linkedPullRequest?.projectId, branchPullRequest?.projectId, fallback]);
110+
}, [fallback]);
113111
const queried = useEnvironmentQuery(
114-
!enabled || current !== null || environmentId === null || reference === null
112+
!enabled || environmentId === null || reference === null
115113
? null
116114
: linkedPullRequestDetailAtom({ environmentId, input: reference }),
117115
);
@@ -123,10 +121,9 @@ export function useLinkedThreadPullRequest(
123121
);
124122

125123
return useMemo(() => {
124+
if (current !== null) return linkedPullRequestSnapshotStatus(current);
126125
return detail === null
127-
? current === null
128-
? null
129-
: linkedPullRequestSnapshotStatus(current)
126+
? null
130127
: {
131128
pr: pullRequestDetailToVcsStatus(detail),
132129
sourceControlProvider: { kind: detail.provider, name: detail.provider, baseUrl: "" },

‎apps/web/src/components/pullRequest/PullRequestLinkPreview.tsx‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "react";
1313

1414
import { formatRelativeTimeLabel } from "~/timestampFormat";
15-
import { pullRequestEnvironment, useSharedPullRequestSummary } from "~/state/pullRequests";
15+
import { pullRequestEnvironment } from "~/state/pullRequests";
1616
import { useAtomQueryRunner } from "~/state/use-atom-query-runner";
1717
import { useEnvironmentQuery } from "~/state/query";
1818

@@ -85,18 +85,12 @@ export function PullRequestLinkPreview({
8585
})
8686
: link;
8787
const detail = detailQuery.data;
88-
const summary = useSharedPullRequestSummary(
89-
target.environmentId,
90-
target.input,
91-
detail,
92-
detailQuery.dataUpdatedAt,
93-
);
9488
const showCard = detail !== null || (detailQuery.error !== null && fallback !== undefined);
9589
const showUrlTooltip = open && detailQuery.error !== null && !showCard;
9690
const state =
97-
summary === null
91+
detail === null
9892
? null
99-
: resolvePullRequestState({ state: summary.state, isDraft: summary.isDraft ?? false });
93+
: resolvePullRequestState({ state: detail.state, isDraft: detail.isDraft });
10094
const authorLabel =
10195
detail?.author === null
10296
? "ghost"
@@ -139,7 +133,7 @@ export function PullRequestLinkPreview({
139133
)}
140134
</div>
141135
<p className="mt-1 text-sm font-medium leading-snug text-foreground text-pretty">
142-
{summary?.title ?? detail.title}
136+
{detail.title}
143137
</p>
144138
<div className="mt-2 flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground">
145139
<PullRequestActorAvatar actor={detail.author} className="size-4" />

0 commit comments

Comments
 (0)