fix(pull-requests): shared state + not settling? #9332
Mergedmaria-rcksmerged 11 commits into
main fromrefs/pull/9332/headmerged by maria-rcks View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/ThreadStatusIndicators.tsx lines 105 to 107OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -103,3 +94,14 @@10394 );10495 }1059697+export function newestThreadPullRequest(98+ current: ThreadPr,99+ observed: PullRequestSummary | null,100+): ThreadPr {101+ if (current === null || observed === null || current.number !== observed.number) return current;102+ if (current.state === "merged") return current;103+ const currentUpdatedAt =104+ current.updatedAt == null ? Number.NEGATIVE_INFINITY : Date.parse(current.updatedAt);105+ return observed.state === "merged" || Date.parse(observed.updatedAt) >= currentUpdatedAt106+ ? pullRequestDetailToVcsStatus(observed)107+ : current;apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx line 671Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -666,13 +670,4 @@666670 }667671 activityRevision.current = next;668672 }, [activityQuery.refresh, coreDetail, pullRequestKey]);669- useEffect(() => {670- if (!detail) return;671- onStateChange?.({672- projectId: detail.projectId,673- repository: detail.repository,674- number: detail.number,675- state: detail.state,676- isDraft: detail.isDraft,677- });678- }, [detail, onStateChange]);673+ useLayoutEffect(() => {apps/web/src/state/pullRequests.ts lines 37 to 42OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -25,3 +27,16 @@2527 export const linkedPullRequestDetailAtom =2628 createLinkedPullRequestSummaryAtomFamily(connectionAtomRuntime);272930+const observedPullRequestSummaryAtom = Atom.family((key: string) =>31+ Atom.make<PullRequestSummary | null>(null).pipe(32+ Atom.setIdleTTL(5 * 60_000),33+ Atom.withLabel(`web-pull-requests:observed-summary:${key}`),34+ ),35+);36+37+export function observedPullRequestKey(38+ environmentId: EnvironmentId,39+ reference: Pick<PullRequestRef, "projectId" | "number">,40+): string {41+ return JSON.stringify([environmentId, reference.projectId, reference.number]);42+}apps/server/src/pullRequest/PullRequestService.ts line 2416OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2400,3 +2409,8 @@24002409 }),24012410 ),24022411 );2412+ const runActionAndInvalidate = (input: PullRequestActionInput) =>2413+ invalidatedByMutation(runAction)(input).pipe(2414+ Effect.tap(() =>2415+ input.action === "merge"2416+ ? PubSub.publish(mergedPullRequests, {
- @@ -2400,3 +2409,15 @@24002409 }),24012410 ),24022411 );2412+ const runActionAndInvalidate = (input: PullRequestActionInput) =>2413+ invalidatedByMutation(runAction)(input).pipe(2414+ Effect.tap(() =>2415+ input.action === "merge"2416+ ? PubSub.publish(mergedPullRequests, {2417+ projectId: input.projectId,2418+ repository: input.repository,2419+ number: input.number,2420+ }).pipe(Effect.asVoid)2421+ : Effect.void,2422+ ),2423+ );@@ -830,11 +831,16 @@830831 gitStatus.data,831832 );832833 const retainTerminalOnBranchMismatch = thread.worktreePath === null;833- const pr = resolveDisplayedThreadPr({834+ const resolvedPr = resolveDisplayedThreadPr({834835 threadBranch: thread.branch,835836 gitStatus: visibleGitStatus,836837 snapshot: changeRequestSnapshot,837838 retainTerminalOnBranchMismatch,838839 linkedPullRequest: thread.linkedPullRequest,839840 linkedPullRequestStatus,840841 });842+ const pr = useObservedThreadPullRequest(843+ leaseLiveStatus ? thread.environmentId : null,844+ leaseLiveStatus ? (thread.linkedPullRequest?.projectId ?? thread.projectId) : null,845+ resolvedPr,846+ );
- apps/server/src/pullRequest/PullRequestService.ts line 533OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -517,3 +530,4 @@517530 }518531519532 export const make = Effect.gen(function* () {533+ const mergedPullRequests = yield* PubSub.unbounded<PullRequestMergeEvent>();apps/server/src/pullRequest/PullRequestService.ts line 2421OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2400,3 +2418,4 @@24002418 }),24012419 ),24022420 );2421+ const runActionAndInvalidate = (input: PullRequestActionInput) =>
- apps/server/src/orchestration/ThreadSettlementReactor.ts line 60OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -42,4 +41,20 @@41+ const sweep = Effect.fn("ThreadSettlementReactor.sweep")(function* (42+ mergedPullRequest: PullRequestService.PullRequestMergeEvent | null,43+ ) {4244 const snapshot = yield* snapshots.getShellSnapshot();4345 const now = DateTime.formatIso(yield* DateTime.now);4446 const projects = new Map(snapshot.projects.map((project) => [project.id, project]));45- const candidates = snapshot.threads.filter((thread) => isAutoSettlementCandidate(thread, now));47+ const changedProject =48+ mergedPullRequest === null ? undefined : projects.get(mergedPullRequest.projectId);49+ if (changedProject !== undefined) {50+ yield* git.invalidateStatus(changedProject.workspaceRoot);51+ }52+ const candidates = snapshot.threads.filter(53+ (thread) =>54+ isAutoSettlementCandidate(thread, now) &&55+ (mergedPullRequest === null ||56+ (thread.linkedPullRequest == null57+ ? thread.projectId === mergedPullRequest.projectId58+ : thread.linkedPullRequest.projectId === mergedPullRequest.projectId &&59+ thread.linkedPullRequest.repository === mergedPullRequest.repository &&60+ thread.linkedPullRequest.number === mergedPullRequest.number)),
- @@ -87,0 +103,21 @@103+ input.gitStatus?.refName !== input.threadBranch ||104+ detected?.state !== "open" ||105+ input.projectId === null ||106+ input.repository === null107+ ) {108+ return null;109+ }110+ if (111+ input.linkedPullRequest.projectId === input.projectId &&112+ input.linkedPullRequest.repository.toLowerCase() === input.repository.toLowerCase() &&113+ input.linkedPullRequest.number === detected.number114+ ) {115+ return null;116+ }117+ return {118+ projectId: input.projectId,119+ repository: input.repository,120+ number: detected.number,121+ url: detected.url,122+ };123+}
- apps/web/src/components/ChatView.tsx line 3749OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3679,0 +3729,21 @@3729+ const relinkKey = `${activeThreadKey}:${replacementLinkedThreadPullRequest.projectId}:${replacementLinkedThreadPullRequest.repository}#${replacementLinkedThreadPullRequest.number}`;3730+ if (threadPrRelinkKeyRef.current === relinkKey) return;3731+ threadPrRelinkKeyRef.current = relinkKey;3732+ const openSurface = selectActiveRightPanelSurface(3733+ useRightPanelStore.getState().byThreadKey,3734+ activeThreadRef,3735+ );3736+ if (3737+ openSurface?.kind === "pull-request" &&3738+ persistedLinkedThreadPullRequest !== null &&3739+ openSurface.projectId === persistedLinkedThreadPullRequest.projectId &&3740+ openSurface.repository.toLowerCase() ===3741+ persistedLinkedThreadPullRequest.repository.toLowerCase() &&3742+ openSurface.number === persistedLinkedThreadPullRequest.number3743+ ) {3744+ useRightPanelStore3745+ .getState()3746+ .openPullRequest(activeThreadRef, replacementLinkedThreadPullRequest);3747+ }3748+3749+ void updateThreadMetadata({apps/server/src/pullRequest/PullRequestService.ts line 2427Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2400,3 +2421,7 @@24002421 }),24012422 ),24022423 );2424+ const runActionAndInvalidate: PullRequestService["Service"]["runAction"] = Effect.fn(2425+ "PullRequestService.runActionAndInvalidate",2426+ )(function* (input) {2427+ const repository = yield* runAction(input);
- @@ -3679,0 +3730,21 @@3730+ if (threadPrRelinkKeyRef.current === relinkKey) return;3731+ threadPrRelinkKeyRef.current = relinkKey;3732+ const openSurface = selectActiveRightPanelSurface(3733+ useRightPanelStore.getState().byThreadKey,3734+ activeThreadRef,3735+ );3736+ if (3737+ openSurface?.kind === "pull-request" &&3738+ persistedLinkedThreadPullRequest !== null &&3739+ openSurface.projectId === persistedLinkedThreadPullRequest.projectId &&3740+ openSurface.repository.toLowerCase() ===3741+ persistedLinkedThreadPullRequest.repository.toLowerCase() &&3742+ openSurface.number === persistedLinkedThreadPullRequest.number3743+ ) {3744+ useRightPanelStore3745+ .getState()3746+ .openPullRequest(activeThreadRef, replacementLinkedThreadPullRequest);3747+ }3748+3749+ threadPrRelinkWriteRef.current = threadPrRelinkWriteRef.current.then(async () => {3750+ if (threadPrRelinkKeyRef.current !== relinkKey) return;
maria-rcks changed the title
- @@ -3679,0 +3738,21 @@3738+ openSurface.projectId === persistedLinkedThreadPullRequest.projectId &&3739+ openSurface.repository.toLowerCase() ===3740+ persistedLinkedThreadPullRequest.repository.toLowerCase() &&3741+ openSurface.number === persistedLinkedThreadPullRequest.number3742+ ) {3743+ useRightPanelStore3744+ .getState()3745+ .openPullRequest(activeThreadRef, replacementLinkedThreadPullRequest);3746+ }3747+3748+ threadPrRelinkWriteRef.current = threadPrRelinkWriteRef.current.then(async () => {3749+ if (threadPrRelinkKeysRef.current.get(activeThreadKey) !== relinkKey) return;3750+ const result = await updateThreadMetadata({3751+ environmentId: activeThreadRef.environmentId,3752+ input: {3753+ threadId: activeThreadRef.threadId,3754+ linkedPullRequest: replacementLinkedThreadPullRequest,3755+ },3756+ });3757+ if (threadPrRelinkKeysRef.current.get(activeThreadKey) !== relinkKey) return;3758+ threadPrRelinkKeysRef.current.delete(activeThreadKey);
maria-rcks merged this854541a
maria-rcks closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed