From 216e4ef2b721eb565f394725ca339513a8614735 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:52:20 +0100 Subject: [PATCH 1/3] test(web): retrying a failed Issues list keeps another environment's read Co-authored-by: Claude Opus 5.5 --- .../client-runtime/src/state/issues.test.ts | 33 ++++ ...ues-retry-keeps-pending-environment.e2e.ts | 153 ++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 scripts/scenarios/issues-retry-keeps-pending-environment.e2e.ts diff --git a/packages/client-runtime/src/state/issues.test.ts b/packages/client-runtime/src/state/issues.test.ts index 7c52da1c5004b..587280be65912 100644 --- a/packages/client-runtime/src/state/issues.test.ts +++ b/packages/client-runtime/src/state/issues.test.ts @@ -218,6 +218,39 @@ describe("createMergedIssueListAtoms", () => { } }); + it("retries only failed environments, leaving one still loading to finish", () => { + const registry = AtomRegistry.make(); + const targets = ["slow", "flaky"].map((environmentId) => ({ + environmentId: EnvironmentId.make(environmentId), + input: { state: "open" as const }, + })); + const requests: string[] = []; + const lists = Atom.family((environmentId: string) => + Atom.make( + Effect.suspend(() => { + requests.push(environmentId); + return environmentId === "flaky" ? Effect.fail("Tracker unavailable") : Effect.never; + }), + ), + ); + const listings = createMergedIssueListAtoms( + (target) => lists(target.environmentId), + () => "Tracker unavailable", + ); + const view = listings.atom(targets); + const unmount = registry.mount(view); + try { + expect(registry.get(view)).toMatchObject({ error: "Tracker unavailable", isPending: true }); + + listings.retry(registry, targets); + + expect(requests).toEqual(["slow", "flaky", "flaky"]); + } finally { + unmount(); + registry.dispose(); + } + }); + it("releases historical search targets when the list closes", async () => { NodeV8.setFlagsFromString("--expose-gc"); const gc = NodeVM.runInNewContext("gc") as () => void; diff --git a/scripts/scenarios/issues-retry-keeps-pending-environment.e2e.ts b/scripts/scenarios/issues-retry-keeps-pending-environment.e2e.ts new file mode 100644 index 0000000000000..8cf489e4ca6c2 --- /dev/null +++ b/scripts/scenarios/issues-retry-keeps-pending-environment.e2e.ts @@ -0,0 +1,153 @@ +/// +import type { IssueListResult } from "@t3tools/contracts"; +import { expect } from "e2e"; + +import { SECOND_HOME, startSecondServer } from "./second-server.ts"; +import { makeState, test, WEB } from "./t3.ts"; + +test( + "Retrying a failed environment keeps the Issues refresh already in progress", + WEB, + async ({ t3, app, screen, browser }) => { + await t3.project("demo"); + const server = startSecondServer(app.baseUrl ?? ""); + try { + const { host, token } = await server.ready; + await makeState(SECOND_HOME).state.project("remote-demo"); + await browser.addInitScript((remoteHost) => { + const { promise: slowRead, resolve: release } = Promise.withResolvers(); + let refreshing = false; + let primaryRefreshStarted = false; + let remoteRefreshStarted = false; + Object.assign(window, { + armIssuesRefresh: () => { + refreshing = true; + }, + releaseSlowIssuesRead: release, + }); + const date = "2026-10-01T00:00:00.000Z"; + const tracker = "github" as IssueListResult["trackers"][number]["tracker"]; + const list = (title: string, remote: boolean): IssueListResult => { + const key = remote ? "2" : "1"; + return { + entries: [ + { + tracker, + host: "github.com", + scope: "example/demo", + key, + displayKey: "#" + key, + title, + projectId: (remote + ? "remote-demo" + : "demo") as IssueListResult["entries"][number]["projectId"], + projectTitle: remote ? "remote-demo" : "demo", + url: "https://github.com/example/demo/issues/" + key, + author: null, + state: { category: "open", name: "Open" }, + createdAt: date, + updatedAt: date, + closedAt: null, + assignees: [], + labels: [], + commentCount: 0, + }, + ], + errors: [], + nextCursors: {}, + viewers: {}, + trackers: [ + { + tracker, + host: "github.com", + projectCount: 1, + capabilities: null, + configured: true, + detail: null, + }, + ], + }; + }; + const send = WebSocket.prototype.send; + WebSocket.prototype.send = function (data) { + const request: { _tag: string; id: string; tag: string } | null = + typeof data === "string" ? JSON.parse(data) : null; + if (request?._tag !== "Request" || request.tag !== "issues.list") + return send.call(this, data); + const remote = new URL(this.url).host === remoteHost; + const reply = (exit: unknown) => + this.dispatchEvent( + new MessageEvent("message", { + data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }), + }), + ); + const success = (title: string) => reply({ _tag: "Success", value: list(title, remote) }); + + if (!refreshing) { + queueMicrotask(() => + success(remote ? "Issue from the linked environment" : "Before refresh"), + ); + } else if (remote && !remoteRefreshStarted) { + remoteRefreshStarted = true; + queueMicrotask(() => + reply({ + _tag: "Failure", + cause: [ + { + _tag: "Fail", + error: { + _tag: "IssueOperationError", + operation: "list", + detail: "The linked environment could not list issues.", + }, + }, + ], + }), + ); + } else if (remote) { + queueMicrotask(() => success("Issues recovered on the linked environment")); + } else if (!primaryRefreshStarted) { + primaryRefreshStarted = true; + // Only the original slow read is allowed to finish. Restarting it strands its result. + void slowRead.then(() => success("Updated issue from the slow environment")); + } + }; + }, new URL(host).host); + + await t3.open("/settings/connections"); + await screen.getByRole("button", "Add environment").tap(); + const dialog = screen.getByRole("dialog"); + await dialog.getByPlaceholder("backend.example.com").fill(host); + await dialog.getByPlaceholder("PAIRCODE").fill(token); + await dialog.getByRole("button", "Add environment").tap(); + await screen.getByRole("button", "More actions for Scenario").waitFor({ timeout: 60_000 }); + await app.open("/issues"); + + await screen.getByText("Before refresh", { exact: true }).waitFor({ timeout: 60_000 }); + await screen.getByText("Issue from the linked environment", { exact: true }).waitFor(); + await browser.evaluate(() => { + (window as unknown as { armIssuesRefresh: () => void }).armIssuesRefresh(); + return null; + }); + await screen.getByRole("button", "Refresh issues", { exact: true }).tap(); + await screen.getByText(/Showing the issues that loaded/).waitFor(); + await screen.getByRole("button", "Retry", { exact: true }).tap(); + await screen + .getByText("Issues recovered on the linked environment", { exact: true }) + .waitFor(); + await browser.evaluate(() => { + (window as unknown as { releaseSlowIssuesRead: () => void }).releaseSlowIssuesRead(); + return null; + }); + try { + await expect( + screen.getByText("Updated issue from the slow environment", { exact: true }), + ).toBeVisible(); + } finally { + await app.screenshot("partial-issues-after-retry"); + } + } finally { + await server.stop(); + } + }, +); From 40905c43c01cbd1270cb479d3837dd488695d0b8 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:53:57 +0100 Subject: [PATCH 2/3] fix(web): retrying a failed Issues list no longer restarts another environment's read Retry reloaded every environment's listing, cancelling one still in flight so its answer never arrived. The merged listing now retries only environments that failed and are not already reloading, as the filter candidates already do. Co-authored-by: Claude Opus 5.5 --- apps/web/src/components/issue/IssuesPage.tsx | 4 ++-- apps/web/src/state/issues.ts | 8 ++++++-- packages/client-runtime/src/state/issues.ts | 10 +++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/issue/IssuesPage.tsx b/apps/web/src/components/issue/IssuesPage.tsx index bd8627a2e6689..ed4102d899ef9 100644 --- a/apps/web/src/components/issue/IssuesPage.tsx +++ b/apps/web/src/components/issue/IssuesPage.tsx @@ -468,7 +468,7 @@ export function IssuesPage() { ) : noneAnswered && list.error ? ( ) : groups.length === 0 ? ( @@ -494,7 +494,7 @@ export function IssuesPage() { {list.error} Showing the issues that loaded. - diff --git a/apps/web/src/state/issues.ts b/apps/web/src/state/issues.ts index 1d384d7f9e9a1..fff8e8af4c1fe 100644 --- a/apps/web/src/state/issues.ts +++ b/apps/web/src/state/issues.ts @@ -25,9 +25,13 @@ const mergedIssueLists = createMergedIssueListAtoms( /** The same listing read across every connected environment, as the pull-request page does. */ export function useIssueList( targets: ReadonlyArray, -): MergedIssueList & { readonly refresh: () => void } { +): MergedIssueList & { readonly refresh: () => void; readonly retry: () => void } { const view = useAtomValue(mergedIssueLists.atom(targets)); - return { ...view, refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets) }; + return { + ...view, + refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets), + retry: () => mergedIssueLists.retry(appAtomRegistry, targets), + }; } /** After a write made beside the list, such as a state change in the detail panel. */ diff --git a/packages/client-runtime/src/state/issues.ts b/packages/client-runtime/src/state/issues.ts index 237610fe281d4..eb075b9ed5bd6 100644 --- a/packages/client-runtime/src/state/issues.ts +++ b/packages/client-runtime/src/state/issues.ts @@ -272,7 +272,8 @@ const NO_ISSUE_LISTS: MergedIssueList = { answers: [], error: null, isPending: f /** * One listing read across every environment at once: React cannot subscribe to a list of atoms * whose length changes, so the fan-out lives in one derived atom keyed by the targets. An - * environment that fails contributes nothing rather than blanking the list. + * environment that fails contributes nothing rather than blanking the list. Retry reloads only + * the environments that failed, so a read still in flight elsewhere is not restarted. */ export function createMergedIssueListAtoms( list: (target: IssueListTarget) => Atom.Atom>, @@ -311,6 +312,13 @@ export function createMergedIssueListAtoms( return atom; }, refresh, + retry: (registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray) => { + for (const target of targets) { + const atom = list(target); + const result = registry.get(atom); + if (result._tag === "Failure" && !result.waiting) registry.refresh(atom); + } + }, /** Refreshes each listing of `environmentId` that something still reads. */ refreshEnvironment: (registry: AtomRegistry.AtomRegistry, environmentId: EnvironmentId) => { for (const node of registry.getNodes().values()) { From 51ecafdb70b3a2668ffa485c8490de6f14cf48d3 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:14:34 +0100 Subject: [PATCH 3/3] refactor(issues): share the retry rule for settled failures Co-authored-by: GPT 6.2 Sol --- packages/client-runtime/src/state/issues.ts | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/client-runtime/src/state/issues.ts b/packages/client-runtime/src/state/issues.ts index eb075b9ed5bd6..0d43de70a096b 100644 --- a/packages/client-runtime/src/state/issues.ts +++ b/packages/client-runtime/src/state/issues.ts @@ -269,6 +269,18 @@ export interface MergedIssueList { const NO_ISSUE_LISTS: MergedIssueList = { answers: [], error: null, isPending: false }; +function refreshFailed( + registry: AtomRegistry.AtomRegistry, + targets: ReadonlyArray, + query: (target: Target) => Atom.Atom>, +) { + for (const target of targets) { + const atom = query(target); + const result = registry.get(atom); + if (result._tag === "Failure" && !result.waiting) registry.refresh(atom); + } +} + /** * One listing read across every environment at once: React cannot subscribe to a list of atoms * whose length changes, so the fan-out lives in one derived atom keyed by the targets. An @@ -312,13 +324,8 @@ export function createMergedIssueListAtoms( return atom; }, refresh, - retry: (registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray) => { - for (const target of targets) { - const atom = list(target); - const result = registry.get(atom); - if (result._tag === "Failure" && !result.waiting) registry.refresh(atom); - } - }, + retry: (registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray) => + refreshFailed(registry, targets, list), /** Refreshes each listing of `environmentId` that something still reads. */ refreshEnvironment: (registry: AtomRegistry.AtomRegistry, environmentId: EnvironmentId) => { for (const node of registry.getNodes().values()) { @@ -397,12 +404,7 @@ export function createMergedIssueCandidatesAtoms( return { atom: (targets: ReadonlyArray) => targets.length === 0 ? empty : family(JSON.stringify(targets)), - retry: (registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray) => { - for (const target of targets) { - const atom = candidates(target); - const result = registry.get(atom); - if (result._tag === "Failure" && !result.waiting) registry.refresh(atom); - } - }, + retry: (registry: AtomRegistry.AtomRegistry, targets: ReadonlyArray) => + refreshFailed(registry, targets, candidates), }; }