Skip to content

[Bug]: Agents fetch Linear issues twice when given a link #38424

Closed

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Connect Linear in Settings.
  2. Bind a project to the Linear team that owns the issue.
  3. Open an agent thread in that project.
  4. Ask the agent to read the issue using its full Linear link.

Expected behavior

One successful fetch is enough for the agent to get the issue details.

Actual behavior

T3 Code fetches the full issue to check the workspace, then fetches it again before replying. If Linear rate-limits that second fetch, the agent gets an error instead of the issue.

Impact

Minor bug or occasional failure. Every agent read by Linear link makes the extra request, so repeated reads use up the rate limit faster.

Version or commit

main at f92c5e8f98. The cause is at apps/server/src/issue/IssueService.ts:676.

Environment

Linux x64, the repository's own tests.

Logs or stack traces

Linear's rate limit was reached.
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/apps/server/src/mcp/toolkits/issues/handlers.test.ts b/apps/server/src/mcp/toolkits/issues/handlers.test.ts
index 58b9cb23b6..07f4b4e019 100644
--- a/apps/server/src/mcp/toolkits/issues/handlers.test.ts
+++ b/apps/server/src/mcp/toolkits/issues/handlers.test.ts
@@ -10,6 +10,10 @@ import {
   SourceControlProviderKind,
 } from "@t3tools/contracts";
 import { describe, expect, it } from "@effect/vitest";
+import {
+  IssueTrackerError,
+  type StandaloneIssueTrackerApi,
+} from "@t3tools/source-control-core/server/IssueTracker";
 import * as Effect from "effect/Effect";
 import * as Layer from "effect/Layer";
 import * as Option from "effect/Option";
@@ -18,10 +22,13 @@ import * as Stream from "effect/Stream";
 import type { Tool } from "effect/ai";
 
 import * as IssueService from "../../../issue/IssueService.ts";
+import * as IssueTrackerRegistry from "../../../issue/IssueTrackerRegistry.ts";
 import * as Orchestrator from "../../../orchestration-v2/Orchestrator.ts";
 import * as ThreadIssueService from "../../../orchestration-v2/ThreadIssueService.ts";
 import { v2PullRequestThread } from "../../../orchestration-v2/testkit/pullRequestFixtures.ts";
+import * as IssueTrackerBindings from "../../../persistence/IssueTrackerBindings.ts";
 import * as ProjectService from "../../../project/ProjectService.ts";
+import * as RepositoryIdentityResolver from "../../../project/RepositoryIdentityResolver.ts";
 import * as McpInvocationContext from "../../McpInvocationContext.ts";
 import * as McpToolAccess from "../../McpToolAccess.ts";
 import * as McpToolAccessTestkit from "../../McpToolAccess.testkit.ts";
@@ -133,37 +140,41 @@ const detail: IssueDetail = {
   linkedPullRequests: [],
 };
 
+const projectLayer = Layer.mock(ProjectService.ProjectService)({
+  getShell: (id) => Effect.succeed(id === PROJECT_ID ? Option.some(project) : Option.none()),
+  listShells: () => Effect.succeed([project]),
+});
+
 const makeHarness = Effect.fn("makeIssuesToolkitHarness")(function* (
   issues: ReadonlyArray<ThreadIssueLink> = [],
+  issueLayer?: Layer.Layer<IssueService.IssueService>,
 ) {
   const links = yield* Ref.make<ReadonlyArray<ThreadIssueService.LinkThreadIssueInput>>([]);
   const layerDependencies = Layer.mergeAll(
-    Layer.mock(ProjectService.ProjectService)({
-      getShell: (id) => Effect.succeed(id === PROJECT_ID ? Option.some(project) : Option.none()),
-      listShells: () => Effect.succeed([project]),
-    }),
+    projectLayer,
     Layer.mock(Orchestrator.OrchestratorV2)({
       getThreadShell: (id) => Effect.succeed(id === THREAD_ID ? makeThread(issues) : null),
     }),
-    Layer.mock(IssueService.IssueService)({
-      detail: () => Effect.succeed(detail),
-      projectScope: (projectId) =>
-        Effect.succeed({
-          projectId,
-          tracker: GITHUB,
-          host: "github.com",
-          scope: "t3tools/t3code",
-        }),
-      resolveUrl: (url) =>
-        Effect.succeed({
-          projectId: PROJECT_ID,
-          tracker: GITHUB,
-          host: "github.com",
-          scope: "t3tools/t3code",
-          key: url.split("/").at(-1)!,
-          writable: true,
-        }),
-    }),
+    issueLayer ??
+      Layer.mock(IssueService.IssueService)({
+        detail: () => Effect.succeed(detail),
+        projectScope: (projectId) =>
+          Effect.succeed({
+            projectId,
+            tracker: GITHUB,
+            host: "github.com",
+            scope: "t3tools/t3code",
+          }),
+        resolveUrl: (url) =>
+          Effect.succeed({
+            projectId: PROJECT_ID,
+            tracker: GITHUB,
+            host: "github.com",
+            scope: "t3tools/t3code",
+            key: url.split("/").at(-1)!,
+            writable: true,
+          }),
+      }),
     Layer.mock(ThreadIssueService.ThreadIssueService)({
       link: (input) =>
         Ref.update(links, (recorded) => [...recorded, input]).pipe(
@@ -198,6 +209,75 @@ const makeHarness = Effect.fn("makeIssuesToolkitHarness")(function* (
 });
 
 describe("issue toolkit handlers", () => {
+  it.effect("returns a Linear issue by URL with one issue read left before the rate limit", () =>
+    Effect.gen(function* () {
+      const tracker = IssueTrackerKind.make("linear");
+      const host = "linear.app";
+      const url = "https://linear.app/acme/issue/ENG-7/seven";
+      const readsLeft = yield* Ref.make(1);
+      const linear: StandaloneIssueTrackerApi = {
+        kind: tracker,
+        capabilities: detail.capabilities,
+        standalone: {
+          tracker,
+          displayName: "Linear",
+          host,
+          scopeNoun: "team",
+          credential: { label: "Personal API key", helpUrl: null },
+        },
+        parseIssueUrl: (link) =>
+          link.href === url ? { host, workspace: "acme", scope: "ENG", key: "ENG-7" } : null,
+        probeCredential: () => Effect.succeed({ account: "user", scopes: [] }),
+        getViewer: () => Effect.succeed("user"),
+        listIssues: () => Effect.succeed({ items: [], nextCursor: null }),
+        getComments: () => Effect.succeed({ comments: [], nextCursor: null }),
+        getIssue: ({ key }) =>
+          Ref.getAndUpdate(readsLeft, (left) => left - 1).pipe(
+            Effect.flatMap((left) =>
+              left > 0
+                ? Effect.succeed({
+                    ...detail,
+                    reactions: [],
+                    key,
+                    url,
+                    displayKey: key,
+                    body: "Repro steps",
+                  })
+                : Effect.fail(
+                    new IssueTrackerError({
+                      tracker,
+                      operation: "getIssue",
+                      reason: "rate-limited",
+                      detail: "Linear's rate limit was reached.",
+                    }),
+                  ),
+            ),
+          ),
+      };
+      const issueLayer = IssueService.layer.pipe(
+        Layer.provide(
+          Layer.mergeAll(
+            projectLayer,
+            Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({}),
+            Layer.mock(IssueTrackerBindings.IssueTrackerBindingsRepository)({
+              list: Effect.succeed(new Map([[PROJECT_ID, { tracker, scope: "ENG" }]])),
+            }),
+            Layer.succeed(
+              IssueTrackerRegistry.IssueTrackerRegistry,
+              IssueTrackerRegistry.fromTrackers([linear]),
+            ),
+          ),
+        ),
+      );
+      const harness = yield* makeHarness([], issueLayer);
+      const result = yield* harness.call("read_issue", { url }).pipe(Effect.result);
+      expect(result).toMatchObject({
+        _tag: "Success",
+        success: { url, displayKey: "ENG-7", title: "Seven", body: "Repro steps" },
+      });
+    }),
+  );
+
   it.effect("refuses a credential without the issues capability", () =>
     Effect.gen(function* () {
       const harness = yield* makeHarness();
cd apps/server && pnpm exec vp test run src/mcp/toolkits/issues/handlers.test.ts

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions