The best way to control Claude Code, Codex and more from any computer or phone
perf(linear): overlap issue details and viewer reads (#39801)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Adamulek123 committed
Nov 20, 2026 at 18:26 UTC
667d8a120aa72e8c37795c9e391596acb141170b
2 files changed
+48
-9
packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts
+32
-1
@@ -1,4 +1,5 @@
1
import { describe, expect, it } from "@effect/vitest";
2
+import * as Deferred from "effect/Deferred";
3
import * as Effect from "effect/Effect";
4
import * as Layer from "effect/Layer";
5
import * as Option from "effect/Option";
@@ -74,6 +75,7 @@ const bareDetail = (identifier: string) =>
75
function fakeLinear(
76
answers: Record<string, (variables: Record<string, unknown>) => unknown>,
77
stored: string | null = "lin_api_stored",
78
+ beforeAnswer?: (operation: string) => Effect.Effect<void>,
79
) {
80
const requests: Array<{
81
readonly authorization: string | undefined;
@@ -83,7 +85,7 @@ function fakeLinear(
85
const http = Layer.succeed(
86
HttpClient.HttpClient,
87
HttpClient.make((request) =>
86
- Effect.sync(() => {
88
+ Effect.gen(function* () {
89
const body = request.body;
90
const text =
91
body._tag === "Uint8Array" ? new TextDecoder().decode(body.body) : String(body._tag);
@@ -94,6 +96,7 @@ function fakeLinear(
96
operation,
97
query: parsed.query,
98
});
99
+ if (beforeAnswer !== undefined) yield* beforeAnswer(operation);
100
const answer = answers[operation];
101
const answered = answer?.(parsed.variables);
102
const response =
@@ -132,6 +135,34 @@ function fakeLinear(
135
const target = { cwd: "/w/web", host: "linear.app", scope: "ENG" };
136
137
describe("LinearIssueTracker", () => {
138
+ it.effect("cancels the in-flight viewer read when the issue is missing", () =>
139
+ Effect.gen(function* () {
140
+ const viewerStarted = yield* Deferred.make<void>();
141
+ const viewerCanceled = yield* Deferred.make<void>();
142
+ const { tracker } = fakeLinear(
143
+ {
144
+ T3Issue: () =>
145
+ new Response(JSON.stringify({ errors: [{ message: "Issue not found" }] }), {
146
+ headers: { "content-type": "application/json" },
147
+ }),
148
+ },
149
+ "lin_api_stored",
150
+ (operation) =>
151
+ operation === "T3Viewer"
152
+ ? Deferred.succeed(viewerStarted, undefined).pipe(
153
+ Effect.andThen(Effect.never),
154
+ Effect.onInterrupt(() => Deferred.succeed(viewerCanceled, undefined)),
155
+ )
156
+ : Deferred.await(viewerStarted),
157
+ );
158
+
159
+ const api = yield* tracker;
160
+ const error = yield* Effect.flip(api.getIssue({ ...target, key: "ENG-1" }));
161
+ expect(error.reason).toBe("not-found");
162
+ expect(yield* Deferred.isDone(viewerCanceled)).toBe(true);
163
+ }),
164
+ );
165
+
166
it.effect("parses Linear issue links with their workspace and team", () =>
167
Effect.gen(function* () {
168
const api = yield* fakeLinear({}).tracker;
packages/issue-tracker-linear/src/server/LinearIssueTracker.ts
+16
-8
@@ -485,15 +485,23 @@ export const make: Effect.Effect<StandaloneIssueTrackerApi, never, LinearApi.Lin
485
getIssue: Effect.fn("LinearIssueTracker.getIssue")(function* (input) {
486
const identifier = yield* requireIdentifier("getIssue", input.key);
487
// One read of the viewer: the id matches reactions, the handle is what the client sees.
488
- const [issue, me] = yield* Effect.all([
489
- linear.getIssue(identifier, COMMENTS_PAGE),
490
- linear.viewer().pipe(
491
- Effect.map((data) => data.viewer),
492
- Effect.orElseSucceed(() => null),
493
- ),
494
- ]);
488
+ // A missing issue interrupts it rather than waiting for it.
489
+ const [issue, me] = yield* Effect.all(
490
+ [
491
+ linear.getIssue(identifier, COMMENTS_PAGE).pipe(
492
+ Effect.filterOrElse(
493
+ (issue) => issue !== null,
494
+ () => notFound("getIssue"),
495
+ ),
496
+ ),
497
+ linear.viewer().pipe(
498
+ Effect.map((data) => data.viewer),
499
+ Effect.orElseSucceed(() => null),
500
+ ),
501
+ ],
502
+ { concurrency: 2 },
503
+ );
504
const viewer = me?.id ?? null;
496
- if (issue === null) return yield* notFound("getIssue");
505
return {
506
...toSummary(issue, issue.comments.nodes.length),
507
body: issue.description ?? "",