The best way to control Claude Code, Codex and more from any computer or phone
fix(client-runtime): a failed issue refresh keeps older comments already loaded (#39000)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 19, 2026 at 08:51 UTC
1d5ebe3f8e6ec7cec898269f14a1e054c084f280
4 files changed
+246
-14
apps/web/src/components/issue/IssueDetailPanel.tsx
+6
-2
@@ -11,7 +11,7 @@ import {
11
noIssuePicks,
12
} from "@t3tools/client-runtime/issue-selection";
13
import { isSelected, toggleSelection } from "@t3tools/client-runtime/pull-request-selection";
14
-import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
14
+import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
15
import type {
16
EnvironmentId,
17
IssueAssigneeCandidate,
@@ -577,7 +577,11 @@ export function IssueDetailPanel({
577
variant="ghost"
578
aria-label={gt("Refresh issue")}
579
disabled={detailQuery.isPending}
580
- onClick={() => void pager.refresh(registry, detailQuery.refresh)}
580
+ onClick={() =>
581
+ void pager.refresh(registry, () =>
582
+ executeAtomQuery(registry, detailAtom, { refresh: true, reportFailure: false }),
583
+ )
584
+ }
585
>
586
<RefreshIcon size="sm" refreshing={detailQuery.isPending} />
587
</Button>
packages/client-runtime/src/state/issues.test.ts
+71
-3
@@ -8,10 +8,13 @@ import {
8
ProjectId,
9
type IssueComment,
10
type IssueCommentsPage,
11
+ type IssueDetail,
12
type IssueListEntry,
13
type IssueListResult,
14
} from "@t3tools/contracts";
15
+import * as Cause from "effect/Cause";
16
import * as Effect from "effect/Effect";
17
+import * as Option from "effect/Option";
18
import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
19
import { describe, expect, it } from "vite-plus/test";
20
@@ -84,7 +87,34 @@ const comment = (id: string): IssueComment => ({
87
});
88
89
describe("createIssueCommentPager", () => {
87
- it("drops older pages on refresh, including one still loading, and pauses paging until it ends", async () => {
90
+ it("keeps older pages through a failed refresh", async () => {
91
+ const loaded = AsyncResult.success({ comments: [comment("newest")], commentsCursor: "first" });
92
+ const detail =
93
+ Atom.make<AsyncResult.AsyncResult<Pick<IssueDetail, "comments" | "commentsCursor">, string>>(
94
+ loaded,
95
+ );
96
+ const pager = createIssueCommentPager(detail);
97
+ const registry = AtomRegistry.make();
98
+ const unmount = registry.mount(pager.view);
99
+ try {
100
+ await pager.loadOlder(registry, async () =>
101
+ AsyncResult.success({ comments: [comment("older")], nextCursor: null }),
102
+ );
103
+ await pager.refresh(registry, async () => {
104
+ registry.set(detail, AsyncResult.waiting(loaded));
105
+ registry.set(
106
+ detail,
107
+ AsyncResult.failure(Cause.fail("rate limited"), { previousSuccess: Option.some(loaded) }),
108
+ );
109
+ });
110
+ expect(registry.get(pager.view).comments.map(({ id }) => id)).toEqual(["older", "newest"]);
111
+ } finally {
112
+ unmount();
113
+ registry.dispose();
114
+ }
115
+ });
116
+
117
+ it("drops older pages once a refresh lands, including one still loading, and pauses paging until it ends", async () => {
118
// The refreshed detail hands back the same cursor, so only the refresh itself can tell pages apart.
119
const detail = Atom.make(
120
AsyncResult.success({ comments: [comment("newest")], commentsCursor: "first-page" }),
@@ -109,15 +139,21 @@ describe("createIssueCommentPager", () => {
139
const pending = Promise.withResolvers<typeof page>();
140
const inFlight = pager.loadOlder(registry, () => pending.promise);
141
const refreshed = Promise.withResolvers<void>();
112
- const refresh = pager.refresh(registry, () => refreshed.promise);
142
+ const refresh = pager.refresh(registry, async () => {
143
+ await refreshed.promise;
144
+ registry.set(
145
+ detail,
146
+ AsyncResult.success({ comments: [comment("newest")], commentsCursor: "first-page" }),
147
+ );
148
+ });
149
pending.resolve(page);
150
await inFlight;
115
- expect(ids()).toEqual(["newest"]);
151
152
await pager.loadOlder(registry, read);
153
expect(registry.get(pager.view).canLoadOlder).toBe(false);
154
refreshed.resolve();
155
await refresh;
156
+ expect(ids()).toEqual(["newest"]);
157
await pager.loadOlder(registry, read);
158
expect(cursors).toEqual(["first-page", "first-page"]);
159
expect(ids()).toEqual(["older", "newest"]);
@@ -126,6 +162,38 @@ describe("createIssueCommentPager", () => {
162
registry.dispose();
163
}
164
});
165
+
166
+ it("discards loaded and late older pages after refreshing unchanged detail", async () => {
167
+ const value = { comments: [comment("newest")], commentsCursor: "first" };
168
+ const detail = Atom.make(AsyncResult.success(value));
169
+ const pager = createIssueCommentPager(detail);
170
+ const registry = AtomRegistry.make();
171
+ const unmount = registry.mount(pager.view);
172
+ const pending = Promise.withResolvers<AsyncResult.Success<IssueCommentsPage>>();
173
+ try {
174
+ await pager.loadOlder(registry, async () =>
175
+ AsyncResult.success({ comments: [comment("older")], nextCursor: "second" }),
176
+ );
177
+ const inFlight = pager.loadOlder(registry, () => pending.promise);
178
+ await pager.refresh(registry, async () => {
179
+ registry.set(detail, AsyncResult.waiting(registry.get(detail)));
180
+ registry.set(detail, AsyncResult.success(value));
181
+ });
182
+ const afterRefresh = registry.get(pager.view);
183
+
184
+ pending.resolve(AsyncResult.success({ comments: [comment("oldest")], nextCursor: null }));
185
+ await inFlight;
186
+
187
+ expect(afterRefresh.comments.map(({ id }) => id)).toEqual(["newest"]);
188
+ const settled = registry.get(pager.view);
189
+ expect(settled.comments.map(({ id }) => id)).toEqual(["newest"]);
190
+ expect(settled.nextCursor).toBe("first");
191
+ expect(settled.canLoadOlder).toBe(true);
192
+ } finally {
193
+ unmount();
194
+ registry.dispose();
195
+ }
196
+ });
197
});
198
199
describe("createMergedIssueCandidatesAtoms", () => {
packages/client-runtime/src/state/issues.ts
+14
-9
@@ -105,20 +105,25 @@ export function createIssueCommentPager<E>(
105
106
return {
107
view,
108
- async refresh(registry: AtomRegistry.AtomRegistry, read: () => void | Promise<void>) {
108
+ /** `read` settles once the detail has been read again, whether or not that read failed. */
109
+ async refresh(registry: AtomRegistry.AtomRegistry, read: () => Promise<unknown>) {
110
const current = registry.get(state);
111
if (current.refreshing) return;
111
- // The refreshed detail can return the same cursor, so invalidate outstanding pages explicitly.
112
- registry.set(state, {
113
- ...current,
114
- older: null,
115
- refreshing: true,
116
- refreshes: current.refreshes + 1,
117
- });
112
+ registry.set(state, { ...current, refreshing: true });
113
+ let succeeded = false;
114
try {
115
await read();
116
+ const result = registry.get(detailAtom);
117
+ succeeded = result._tag === "Success" && !result.waiting;
118
} finally {
121
- registry.set(state, { ...registry.get(state), refreshing: false });
119
+ const latest = registry.get(state);
120
+ // A successful read invalidates older pages even when the query reuses unchanged detail.
121
+ registry.set(
122
+ state,
123
+ succeeded
124
+ ? { ...latest, older: null, refreshing: false, refreshes: latest.refreshes + 1 }
125
+ : { ...latest, refreshing: false },
126
+ );
127
}
128
},
129
async loadOlder(
scripts/scenarios/issues-failed-refresh-keeps-loaded-comments.e2e.ts
new
+155
@@ -0,0 +1,155 @@
1
+/// <reference lib="dom" />
2
+import type { IssueComment, IssueDetail, IssueRef } from "@t3tools/contracts";
3
+import { expect } from "e2e";
4
+
5
+import { test, WEB } from "./t3.ts";
6
+
7
+test(
8
+ "A failed issue refresh keeps the older comments already loaded",
9
+ WEB,
10
+ async ({ t3, app, browser, screen }) => {
11
+ await t3.project("demo");
12
+ await browser.addInitScript(() => {
13
+ let rateLimited = false;
14
+ Object.assign(window, {
15
+ armIssueRefreshFailure: () => {
16
+ rateLimited = true;
17
+ },
18
+ });
19
+ const refresh = new Promise<void>((resolve) => {
20
+ Object.assign(window, { releaseIssueRefresh: () => resolve() });
21
+ });
22
+ const comment = (id: string, body: string, day: string): IssueComment => ({
23
+ id,
24
+ body,
25
+ author: null,
26
+ createdAt: `2026-10-${day}T00:00:00.000Z`,
27
+ url: null,
28
+ });
29
+ const send = WebSocket.prototype.send;
30
+ WebSocket.prototype.send = function (data) {
31
+ const request: {
32
+ _tag: string;
33
+ id: string;
34
+ tag: string;
35
+ payload: IssueRef & { cursor?: string };
36
+ } | null = typeof data === "string" ? JSON.parse(data) : null;
37
+ if (request?._tag !== "Request") return send.call(this, data);
38
+ const reply = (exit: unknown) =>
39
+ this.dispatchEvent(
40
+ new MessageEvent("message", {
41
+ data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }),
42
+ }),
43
+ );
44
+ if (request.tag === "issues.comments" && request.payload.cursor === "older-page") {
45
+ queueMicrotask(() =>
46
+ reply({
47
+ _tag: "Success",
48
+ value: {
49
+ comments: [comment("older", "Older comment already read", "01")],
50
+ nextCursor: null,
51
+ },
52
+ }),
53
+ );
54
+ return;
55
+ }
56
+ if (request.tag !== "issues.detail") return send.call(this, data);
57
+ if (rateLimited) {
58
+ void refresh.then(() =>
59
+ reply({
60
+ _tag: "Failure",
61
+ cause: [
62
+ {
63
+ _tag: "Fail",
64
+ error: {
65
+ _tag: "IssueOperationError",
66
+ operation: "detail",
67
+ detail: "GitHub API rate limit exceeded.",
68
+ reason: "rate-limited",
69
+ },
70
+ },
71
+ ],
72
+ }),
73
+ );
74
+ return;
75
+ }
76
+ const { projectId, tracker, scope, key } = request.payload;
77
+ const detail: IssueDetail = {
78
+ projectId,
79
+ tracker,
80
+ scope,
81
+ key,
82
+ host: "github.com",
83
+ displayKey: "#42",
84
+ projectTitle: "demo",
85
+ title: "Issue before the rate limit",
86
+ body: "The details from the last successful read.",
87
+ url: "https://github.com/example/demo/issues/42",
88
+ author: null,
89
+ state: { category: "open", name: "Open" },
90
+ createdAt: "2026-10-01T00:00:00.000Z",
91
+ updatedAt: "2026-10-01T00:00:00.000Z",
92
+ closedAt: null,
93
+ assignees: [],
94
+ labels: [],
95
+ commentCount: 101,
96
+ writable: false,
97
+ capabilities: {
98
+ create: false,
99
+ edit: false,
100
+ comment: false,
101
+ labels: false,
102
+ assignees: false,
103
+ reactions: false,
104
+ templates: false,
105
+ linkedPullRequests: false,
106
+ events: false,
107
+ search: true,
108
+ },
109
+ viewerPermissions: {
110
+ setState: false,
111
+ comment: false,
112
+ edit: false,
113
+ labels: false,
114
+ assignees: false,
115
+ },
116
+ states: [],
117
+ viewer: null,
118
+ comments: [comment("newest", "Newest comment", "02")],
119
+ commentsCursor: "older-page",
120
+ events: [],
121
+ linkedPullRequests: [],
122
+ };
123
+ queueMicrotask(() => reply({ _tag: "Success", value: detail }));
124
+ };
125
+ });
126
+
127
+ await t3.open("/issues?selectedProjectId=demo&tracker=github&scope=example/demo&key=42");
128
+ const loadOlder = screen.getByRole("button", "Load older comments", { exact: true });
129
+ const loadedComment = screen.getByText("Older comment already read", { exact: true });
130
+ await loadOlder.waitFor({ timeout: 60_000 });
131
+ await loadOlder.tap();
132
+ await loadedComment.waitFor();
133
+ await browser.evaluate(() => {
134
+ (window as unknown as { armIssueRefreshFailure: () => void }).armIssueRefreshFailure();
135
+ return null;
136
+ });
137
+ await screen.getByRole("button", "Refresh issue", { exact: true }).tap();
138
+ const refreshing = browser.locator('button[aria-label="Refresh issue"]:disabled');
139
+ await refreshing.waitFor();
140
+ await browser.evaluate(() => {
141
+ (window as unknown as { releaseIssueRefresh: () => void }).releaseIssueRefresh();
142
+ return null;
143
+ });
144
+ await refreshing.waitFor({ state: "hidden" });
145
+ await screen.getByText("GitHub API rate limit exceeded.", { exact: false }).waitFor();
146
+ await screen.getByText("Newest comment", { exact: true }).waitFor();
147
+ const activity = 'section[aria-label^="Activity"]';
148
+ await browser.evaluate((selector) => {
149
+ document.querySelector(selector)?.scrollIntoView({ block: "start" });
150
+ return null;
151
+ }, activity);
152
+ await app.screenshot("activity-after-failed-refresh");
153
+ await expect(browser.locator(activity)).toContainText("Older comment already read");
154
+ },
155
+);