From b8b5affac42a8fd55d89214996c28afdb3c54ab1 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 04:52:25 +0100 Subject: [PATCH 1/5] fix(server): agents read a Linear issue once when given its link (#38425) Co-authored-by: Grok 4.7 --- apps/server/src/issue/IssueService.ts | 86 +++++++----- .../src/mcp/toolkits/issues/handlers.test.ts | 126 ++++++++++++++---- .../src/mcp/toolkits/issues/handlers.ts | 10 +- 3 files changed, 162 insertions(+), 60 deletions(-) diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 8f18b80a985a3..8bd3366da4d11 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -38,6 +38,7 @@ import { isStandaloneIssueTracker, type IssueTrackerApi, type StandaloneIssueTrackerApi, + type TrackerIssueDetail, } from "@t3tools/source-control-core/server/IssueTracker"; import { parseUrl } from "@t3tools/shared/url"; @@ -164,13 +165,18 @@ export class IssueService extends Context.Service< ) => Effect.Effect; /** * Resolve through a matching project, preferring `preferredProjectId`; other scopes are read-only. - * Standalone links must match the workspace in the issue's canonical URL from the connected tracker. + * Standalone links must match the workspace in the issue's canonical URL from the connected + * tracker; that read comes back as `issue`, so callers need not read it again. */ readonly resolveUrl: ( url: string, preferredProjectId?: ProjectId, ) => Effect.Effect< - IssueRef & { readonly host: string; readonly writable: boolean }, + IssueRef & { + readonly host: string; + readonly writable: boolean; + readonly issue?: IssueDetail; + }, IssueError >; } @@ -449,6 +455,20 @@ const make = Effect.gen(function* () { }; }); + const toDetail = ( + project: SupportedProject & { readonly writable: boolean }, + issue: TrackerIssueDetail, + ): IssueDetail => ({ + ...issue, + tracker: project.tracker, + host: project.host, + scope: project.scope, + projectId: project.project.id, + projectTitle: project.project.title, + writable: project.writable, + capabilities: project.api.capabilities, + }); + const detail: IssueService["Service"]["detail"] = (input) => requireProject(input).pipe( Effect.flatMap((project) => @@ -461,16 +481,7 @@ const make = Effect.gen(function* () { }) .pipe( Effect.mapError(toIssueError("detail")), - Effect.map((issue): IssueDetail => ({ - ...issue, - tracker: project.tracker, - host: project.host, - scope: project.scope, - projectId: project.project.id, - projectTitle: project.project.title, - writable: project.writable, - capabilities: project.api.capabilities, - })), + Effect.map((issue) => toDetail(project, issue)), ), ), ); @@ -692,34 +703,39 @@ const make = Effect.gen(function* () { if (lender === undefined) { return yield* new IssueUnavailableError({ reason: "tracker-unsupported" }); } - if (standalone !== null) { - // Team keys repeat across workspaces; only the credential's canonical issue URL identifies one. - const issue = yield* lender.api - .getIssue({ - cwd: lender.project.workspaceRoot, - host: lender.host, - scope: link.scope, - key: link.key, - }) - .pipe(Effect.mapError(toIssueError("resolveUrl"))); - const canonicalUrl = parseUrl(issue.url); - const canonical = canonicalUrl === null ? null : standalone.api.parseIssueUrl(canonicalUrl); - if (canonical === null || canonical.workspace !== standalone.link.workspace) { - return yield* new IssueOperationError({ - operation: "resolveUrl", - reason: "not-found", - detail: "This issue URL does not belong to the connected workspace.", - }); - } - } - return { + const served = { + ...lender, + scope: own === undefined ? link.scope : lender.scope, + writable: own !== undefined, + }; + const resolved = { projectId: lender.project.id, tracker: lender.tracker, host: lender.host, - scope: own === undefined ? link.scope : lender.scope, + scope: served.scope, key: link.key, - writable: own !== undefined, + writable: served.writable, }; + if (standalone === null) return resolved; + // Team keys repeat across workspaces; only the credential's canonical issue URL identifies one. + const issue = yield* lender.api + .getIssue({ + cwd: lender.project.workspaceRoot, + host: lender.host, + scope: link.scope, + key: link.key, + }) + .pipe(Effect.mapError(toIssueError("resolveUrl"))); + const canonicalUrl = parseUrl(issue.url); + const canonical = canonicalUrl === null ? null : standalone.api.parseIssueUrl(canonicalUrl); + if (canonical === null || canonical.workspace !== standalone.link.workspace) { + return yield* new IssueOperationError({ + operation: "resolveUrl", + reason: "not-found", + detail: "This issue URL does not belong to the connected workspace.", + }); + } + return { ...resolved, issue: toDetail(served, issue) }; }, ); diff --git a/apps/server/src/mcp/toolkits/issues/handlers.test.ts b/apps/server/src/mcp/toolkits/issues/handlers.test.ts index 58b9cb23b6e37..07f4b4e019204 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 = [], + issueLayer?: Layer.Layer, ) { const links = yield* Ref.make>([]); 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(); diff --git a/apps/server/src/mcp/toolkits/issues/handlers.ts b/apps/server/src/mcp/toolkits/issues/handlers.ts index 32c27f01e7848..1b4235ec7565b 100644 --- a/apps/server/src/mcp/toolkits/issues/handlers.ts +++ b/apps/server/src/mcp/toolkits/issues/handlers.ts @@ -1,5 +1,6 @@ import { threadIssueKeysEqual, + type IssueDetail, type IssueRef, type OrchestrationV2ThreadShell, type ProjectId, @@ -31,6 +32,8 @@ interface ResolvedTarget extends IssueRef { readonly host: string; readonly url: string | null; readonly writable: boolean; + /** Present when resolving the URL already read the issue. */ + readonly issue?: IssueDetail; } /** What the tools report from a thread shell; exported so the shape is testable without a layer. */ @@ -139,6 +142,9 @@ const make = Effect.gen(function* () { key: target.key, }); + const readIssue = (target: ResolvedTarget) => + target.issue === undefined ? issues.detail(refOf(target)) : Effect.succeed(target.issue); + /** A link needs the issue's URL, which a key-only reference does not carry; one read fills it. */ const linkFailure = (cause: Cause.Cause) => Cause.hasInterruptsOnly(cause) @@ -189,7 +195,7 @@ const make = Effect.gen(function* () { read_issue: McpToolAccess.reads((input) => Effect.gen(function* () { const target = yield* resolveTarget(input); - const detail = yield* issues.detail(refOf(target)); + const detail = yield* readIssue(target); return { ...identityOf(target), url: target.url ?? detail.url, @@ -265,7 +271,7 @@ const make = Effect.gen(function* () { projectId: input.projectId ?? thread.projectId, }); // Reading the issue proves it exists and names it for the thread's row. - const detail = yield* issues.detail(refOf(target)); + const detail = yield* readIssue(target); const url = target.url ?? detail.url; const { alreadyLinked } = yield* threadIssues .link({ From 2216ffe00688aa7e446a6d3b517bce6b804d6886 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:09:52 +0100 Subject: [PATCH 2/5] fix(server): All issues pages skip the signed-in account read (#38431) Co-authored-by: Grok 4.7 Co-authored-by: Julius Marminge --- apps/server/src/issue/IssueService.test.ts | 10 ++++- apps/server/src/issue/IssueService.ts | 18 ++++++--- packages/contracts/src/issue.ts | 2 +- .../src/server/LinearIssueTracker.test.ts | 1 - .../src/server/LinearIssueTracker.ts | 7 +--- .../src/server/IssueTracker.ts | 37 +++++++++++-------- .../src/server/ForgejoIssueTracker.test.ts | 1 - .../src/server/ForgejoIssueTracker.ts | 19 +++++----- .../src/server/GitHubIssueTracker.test.ts | 1 - .../src/server/GitHubIssueTracker.ts | 29 ++++++++------- .../src/server/GitLabIssueTracker.ts | 10 ++--- 11 files changed, 75 insertions(+), 60 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 57f795e6c5491..2e260451de2d7 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -421,7 +421,7 @@ describe("IssueService", () => { expect(result.errors).toEqual([ { projectId: "api", projectTitle: "api", message: "The issue tracker request failed." }, ]); - expect(result.viewers).toEqual({ "github.com": "julius" }); + expect(result.viewers).toEqual({}); expect(result.trackers).toEqual([ expect.objectContaining({ host: "github.com", projectCount: 4, configured: true }), expect.objectContaining({ @@ -434,7 +434,13 @@ describe("IssueService", () => { ]); // Narrowing to one host still names every tracker, so the client can switch between them. - const narrowed = yield* service.list({ state: "open", host: "github.com" }); + // Narrowing by involvement reads the account it compares against. + const narrowed = yield* service.list({ + state: "open", + host: "github.com", + involvement: "assigned", + }); + expect(narrowed.viewers).toEqual({ "github.com": "julius" }); expect(narrowed.entries.every((entry) => entry.host === "github.com")).toBe(true); expect(narrowed.trackers.map((tracker) => tracker.host)).toEqual([ "github.com", diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 8bd3366da4d11..bf3d301f73708 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -36,6 +36,7 @@ import * as SourceControlRateLimit from "@t3tools/source-control-core/server/Sou import { IssueTrackerError, isStandaloneIssueTracker, + type IssueInvolvementFilter, type IssueTrackerApi, type StandaloneIssueTrackerApi, type TrackerIssueDetail, @@ -339,8 +340,10 @@ const make = Effect.gen(function* () { const errors: IssueListProjectError[] = []; const nextCursors: Record = {}; + const involvement = input.involvement ?? "all"; + // Only a narrowed listing compares against the signed-in account; `all` never reads it. const viewerRequests = new Map>(); - for (const project of scopes.values()) { + for (const project of involvement === "all" ? [] : scopes.values()) { if (viewerRequests.has(project.host)) continue; const request = yield* Effect.cached( project.api @@ -385,15 +388,20 @@ const make = Effect.gen(function* () { // A continuation names the scopes it wants; one not named has nothing to add. if (continuing !== undefined && continuing[key] === undefined) return; const cursor = continuing?.[key]; - const page = yield* viewerRequests.get(project.host)!.pipe( - Effect.flatMap((viewer) => + const filter: Effect.Effect = + involvement === "all" + ? Effect.succeed({ involvement }) + : viewerRequests + .get(project.host)! + .pipe(Effect.map((viewer) => ({ involvement, viewer }))); + const page = yield* filter.pipe( + Effect.flatMap((filter) => project.api.listIssues({ + ...filter, cwd: project.project.workspaceRoot, host: project.host, scope: project.scope, state: input.state, - involvement: input.involvement ?? "all", - viewer, limit, query: input.query, labels: input.labels, diff --git a/packages/contracts/src/issue.ts b/packages/contracts/src/issue.ts index acd0eed54a421..574399859d4f9 100644 --- a/packages/contracts/src/issue.ts +++ b/packages/contracts/src/issue.ts @@ -300,7 +300,7 @@ export const IssueListProjectError = Schema.Struct({ export type IssueListProjectError = typeof IssueListProjectError.Type; export const IssueListResult = Schema.Struct({ - /** The signed-in account per host, which is what involvement compares against. */ + /** The signed-in account per host that involvement compared against. Empty for `all`. */ viewers: Schema.Record(TrimmedNonEmptyString, TrimmedNonEmptyString), trackers: Schema.Array(IssueTrackerSummary), /** By update, newest first, across every scope this answer covers. */ diff --git a/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts b/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts index ccaaa62d14888..eb8a16dedbf1d 100644 --- a/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts +++ b/packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts @@ -238,7 +238,6 @@ describe("LinearIssueTracker", () => { ...target, state: "open", involvement: "all", - viewer: "julius", sort: "updated", limit: 50, }), diff --git a/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts b/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts index 9721a47471fdc..885b016b23ebf 100644 --- a/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts +++ b/packages/issue-tracker-linear/src/server/LinearIssueTracker.ts @@ -11,7 +11,6 @@ import { type IssueComment, type IssueEvent, type IssueExternalTemplate, - type IssueInvolvement, type IssueLinkedPullRequest, type IssueReaction, type IssueReactionContent, @@ -22,6 +21,7 @@ import { } from "@t3tools/contracts"; import { IssueTrackerError, + type IssueInvolvementFilter, type StandaloneIssueTrackerApi, type TrackerIssueSummary, } from "@t3tools/source-control-core/server/IssueTracker"; @@ -307,10 +307,7 @@ export function toTemplate( }; } -function involvementFilter(input: { - readonly involvement: IssueInvolvement; - readonly viewer: string; -}): LinearApi.IssueFilter { +function involvementFilter(input: IssueInvolvementFilter): LinearApi.IssueFilter { switch (input.involvement) { case "assigned": return { assignee: { displayName: { eq: input.viewer } } }; diff --git a/packages/source-control-core/src/server/IssueTracker.ts b/packages/source-control-core/src/server/IssueTracker.ts index 34b0c2e257d66..32e0c6572fe62 100644 --- a/packages/source-control-core/src/server/IssueTracker.ts +++ b/packages/source-control-core/src/server/IssueTracker.ts @@ -94,6 +94,14 @@ export interface TrackerIssueDetail extends TrackerIssueSummary { readonly linkedPullRequests: ReadonlyArray; } +/** + * Whose issues a listing keeps. Only a narrowed listing names the signed-in account it compares + * against, so an `all` listing never has to read it. + */ +export type IssueInvolvementFilter = + | { readonly involvement: "all" } + | { readonly involvement: Exclude; readonly viewer: string }; + export interface IssueTrackerApi { readonly kind: IssueTrackerKind; readonly capabilities: IssueCapabilities; @@ -105,21 +113,20 @@ export interface IssueTrackerApi { }) => Effect.Effect; readonly listIssues: ( - input: IssueScopeTarget & { - readonly state: IssueListState; - readonly involvement: IssueInvolvement; - readonly viewer: string; - readonly limit: number; - /** Free text as the tracker understands it; ignored by a tracker without `search`. */ - readonly query?: string | undefined; - /** Label names an issue must carry, every one of them. */ - readonly labels?: ReadonlyArray | undefined; - /** The `login` of an assignee, as this tracker's own issues name them. */ - readonly assignee?: string | undefined; - readonly sort: IssueListSort; - /** A cursor this tracker handed back from an earlier page. Absent asks for the first. */ - readonly cursor?: string | undefined; - }, + input: IssueScopeTarget & + IssueInvolvementFilter & { + readonly state: IssueListState; + readonly limit: number; + /** Free text as the tracker understands it; ignored by a tracker without `search`. */ + readonly query?: string | undefined; + /** Label names an issue must carry, every one of them. */ + readonly labels?: ReadonlyArray | undefined; + /** The `login` of an assignee, as this tracker's own issues name them. */ + readonly assignee?: string | undefined; + readonly sort: IssueListSort; + /** A cursor this tracker handed back from an earlier page. Absent asks for the first. */ + readonly cursor?: string | undefined; + }, ) => Effect.Effect; /** The issue with its first page of conversation, in one read where the tracker allows. */ diff --git a/packages/source-control-forgejo/src/server/ForgejoIssueTracker.test.ts b/packages/source-control-forgejo/src/server/ForgejoIssueTracker.test.ts index 663817ac1b589..258850d0939e6 100644 --- a/packages/source-control-forgejo/src/server/ForgejoIssueTracker.test.ts +++ b/packages/source-control-forgejo/src/server/ForgejoIssueTracker.test.ts @@ -331,7 +331,6 @@ describe("ForgejoIssueTracker", () => { scope: "acme/web", state: "open", involvement: "all", - viewer: "julius", labels: ["bug", "p1"], assignee: "theo", sort: "created", diff --git a/packages/source-control-forgejo/src/server/ForgejoIssueTracker.ts b/packages/source-control-forgejo/src/server/ForgejoIssueTracker.ts index 1ea3f34074845..4413b15feb268 100644 --- a/packages/source-control-forgejo/src/server/ForgejoIssueTracker.ts +++ b/packages/source-control-forgejo/src/server/ForgejoIssueTracker.ts @@ -9,6 +9,7 @@ import * as Schema from "effect/Schema"; import { IssueTrackerKind, type IssueCapabilities, + type IssueInvolvement, type IssueLinkedPullRequest, type IssueViewerPermissions, } from "@t3tools/contracts"; @@ -61,6 +62,12 @@ const PAGE_SIZE = 50; /** How many pages of a listing with no cursor of its own are read before giving up on the rest. */ const MAX_PAGES = 10; +const INVOLVEMENT_PARAM: Record, string> = { + assigned: "assigned_by", + authored: "created_by", + mentioned: "mentioned_by", +}; + const repoPath = (scope: string) => `repos/${scope.split("/").map(encodeURIComponent).join("/")}`; const issuePath = (scope: string, number: number) => `${repoPath(scope)}/issues/${number}`; @@ -400,15 +407,9 @@ export const make: Effect.Effect if (labels.length > 0) params.set("labels", labels.join(",")); const text = input.query?.trim() ?? ""; if (text.length > 0) params.set("q", text); - const involvement = - input.involvement === "assigned" - ? "assigned_by" - : input.involvement === "authored" - ? "created_by" - : input.involvement === "mentioned" - ? "mentioned_by" - : null; - if (involvement !== null) params.set(involvement, input.viewer); + if (input.involvement !== "all") { + params.set(INVOLVEMENT_PARAM[input.involvement], input.viewer); + } if (input.assignee !== undefined) params.set("assigned_by", input.assignee); // `assigned_by` names one person, so "assigned to me" is kept here beside a named assignee. const alsoAssignedTo = diff --git a/packages/source-control-github/src/server/GitHubIssueTracker.test.ts b/packages/source-control-github/src/server/GitHubIssueTracker.test.ts index 643ce2551fef6..1760511cabcd4 100644 --- a/packages/source-control-github/src/server/GitHubIssueTracker.test.ts +++ b/packages/source-control-github/src/server/GitHubIssueTracker.test.ts @@ -397,7 +397,6 @@ describe("GitHubIssueTracker", () => { scope: "acme/web", state: "open", involvement: "all", - viewer: "julius", labels: ['needs "repro"'], assignee: "theo", sort: "created", diff --git a/packages/source-control-github/src/server/GitHubIssueTracker.ts b/packages/source-control-github/src/server/GitHubIssueTracker.ts index 3db6322c74859..eed4578ff389c 100644 --- a/packages/source-control-github/src/server/GitHubIssueTracker.ts +++ b/packages/source-control-github/src/server/GitHubIssueTracker.ts @@ -9,6 +9,7 @@ import { } from "@t3tools/contracts"; import { IssueTrackerError, + type IssueInvolvementFilter, type IssueTrackerApi, } from "@t3tools/source-control-core/server/IssueTracker"; @@ -58,29 +59,29 @@ function searchTerms(query: string): ReadonlyArray { .map(quotedTerm); } -const INVOLVEMENT_QUALIFIER: Record = { - all: null, +const INVOLVEMENT_QUALIFIER: Record, string> = { assigned: "assignee", authored: "author", mentioned: "mentions", }; -function searchQuery(input: { - readonly scope: string; - readonly state: "all" | "open" | "closed"; - readonly involvement: IssueInvolvement; - readonly viewer: string; - readonly query?: string | undefined; - readonly labels?: ReadonlyArray | undefined; - readonly assignee?: string | undefined; - readonly sort: IssueListSort; -}): string { - const qualifier = INVOLVEMENT_QUALIFIER[input.involvement]; +function searchQuery( + input: IssueInvolvementFilter & { + readonly scope: string; + readonly state: "all" | "open" | "closed"; + readonly query?: string | undefined; + readonly labels?: ReadonlyArray | undefined; + readonly assignee?: string | undefined; + readonly sort: IssueListSort; + }, +): string { return [ "is:issue", `repo:${input.scope.trim()}`, ...(input.state === "all" ? [] : [`is:${input.state}`]), - ...(qualifier === null ? [] : [`${qualifier}:${input.viewer}`]), + ...(input.involvement === "all" + ? [] + : [`${INVOLVEMENT_QUALIFIER[input.involvement]}:${input.viewer}`]), ...(input.labels ?? []).map((label) => `label:${quotedTerm(label)}`), ...(input.assignee === undefined ? [] : [`assignee:${quotedTerm(input.assignee)}`]), `sort:${input.sort}-desc`, diff --git a/packages/source-control-gitlab/src/server/GitLabIssueTracker.ts b/packages/source-control-gitlab/src/server/GitLabIssueTracker.ts index 8206b572ece5d..5716648bdcec0 100644 --- a/packages/source-control-gitlab/src/server/GitLabIssueTracker.ts +++ b/packages/source-control-gitlab/src/server/GitLabIssueTracker.ts @@ -10,11 +10,11 @@ import { IssueTrackerKind, type IssueCapabilities, type IssueEvent, - type IssueInvolvement, type IssueViewerPermissions, } from "@t3tools/contracts"; import { IssueTrackerError, + type IssueInvolvementFilter, type IssueTrackerApi, } from "@t3tools/source-control-core/server/IssueTracker"; @@ -137,11 +137,9 @@ function query(params: ReadonlyArray): string { return params.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&"); } -function involvementParams(input: { - readonly involvement: IssueInvolvement; - readonly viewer: string; - readonly assignee?: string | undefined; -}): ReadonlyArray { +function involvementParams( + input: IssueInvolvementFilter & { readonly assignee?: string | undefined }, +): ReadonlyArray { switch (input.involvement) { case "authored": return [["author_username", input.viewer]]; From 5b6f7c81ce5de290a9cd586cb568f0c9fe57d26a Mon Sep 17 00:00:00 2001 From: MINIlaolao <30876219+MINIlaolao@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:49:11 +0800 Subject: [PATCH 3/5] fix(server): recover JSON-stringified delegate targets (#38436) Co-authored-by: Julius Marminge --- apps/server/src/mcp/McpHttpServer.test.ts | 28 +++++++++++++++++++++++ packages/contracts/src/orchestratorMcp.ts | 5 +++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/apps/server/src/mcp/McpHttpServer.test.ts b/apps/server/src/mcp/McpHttpServer.test.ts index 5801a210ba6cf..761991fd48769 100644 --- a/apps/server/src/mcp/McpHttpServer.test.ts +++ b/apps/server/src/mcp/McpHttpServer.test.ts @@ -680,6 +680,34 @@ it.effect("decodes null optional arguments the way it decodes omitted ones", () }).pipe(Effect.provide(layerRecordingTools(calls))); }); +it.effect("decodes a JSON-stringified delegate target as the same object", () => { + const calls: Array = []; + return Effect.gen(function* () { + const task = "Inspect"; + const target = { + providerInstanceId: "codex", + model: "gpt-6.2-sol", + options: { reasoningEffort: "medium" }, + }; + yield* callTool("delegate_task", { task, target }); + yield* callTool("delegate_task", { task, target: JSON.stringify(target) }); + + for (const invalidTarget of ["{model:", '{"model":42}']) { + const error = yield* Effect.flip(callTool("delegate_task", { task, target: invalidTarget })); + expect(error).toBeInstanceOf(McpSchema.InvalidParams); + } + expect(calls).toHaveLength(2); + expect(calls[0]).toEqual({ + task, + target: { + ...target, + options: [{ id: "reasoningEffort", value: "medium" }], + }, + }); + expect(calls[1]).toEqual(calls[0]); + }).pipe(Effect.provide(layerRecordingTools(calls))); +}); + it.effect("rejects arguments a tool does not declare instead of dropping them", () => { const calls: Array = []; return Effect.gen(function* () { diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index ed6a62bf1eb7f..d7c607744d4a7 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -170,7 +170,10 @@ export type OrchestratorMcpTerminalDelegatedTaskStatus = export const OrchestratorMcpDelegateTaskInput = Schema.Struct({ task: OrchestratorMcpPrompt, - target: Schema.optional(OrchestratorMcpTarget), + // Some providers send the whole target object as JSON text. + target: Schema.optional( + Schema.Union([OrchestratorMcpTarget, Schema.fromJsonString(OrchestratorMcpTarget)]), + ), title: Schema.optional(OrchestratorMcpTitle), role: Schema.optional(OrchestratorMcpTaskRole), isolation: Schema.optional( From baab17bb03aecdb7db11917d64665e7e296514a7 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:59:56 +0100 Subject: [PATCH 4/5] fix(mobile): retrying an issue filter only reloads repositories that failed (#38423) Co-authored-by: Grok 4.7 Co-authored-by: Julius Marminge --- apps/mobile/src/state/issues.ts | 5 +- apps/web/src/state/issues.ts | 2 +- .../client-runtime/src/state/issues.test.ts | 66 ++++++++++++++++++- packages/client-runtime/src/state/issues.ts | 18 ++++- 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/apps/mobile/src/state/issues.ts b/apps/mobile/src/state/issues.ts index 6534218781e99..9f47acf847520 100644 --- a/apps/mobile/src/state/issues.ts +++ b/apps/mobile/src/state/issues.ts @@ -37,9 +37,10 @@ const mergedIssueCandidates = createMergedIssueCandidatesAtoms( /** The labels and people of every scope a list filter covers; no targets reads nothing. */ export function useIssueFilterCandidates(targets: ReadonlyArray) { - return useAtomValue(mergedIssueCandidates(targets)); + return useAtomValue(mergedIssueCandidates.atom(targets)); } +/** Asks again only the scopes that failed; the ones that answered keep their answer. */ export function refreshIssueFilterCandidates(targets: ReadonlyArray) { - for (const target of targets) appAtomRegistry.refresh(issueEnvironment.candidates(target)); + mergedIssueCandidates.retry(appAtomRegistry, targets); } diff --git a/apps/web/src/state/issues.ts b/apps/web/src/state/issues.ts index 8b9ae58df7d09..1d384d7f9e9a1 100644 --- a/apps/web/src/state/issues.ts +++ b/apps/web/src/state/issues.ts @@ -42,5 +42,5 @@ const mergedIssueCandidates = createMergedIssueCandidatesAtoms( /** The labels and people of every scope a list filter covers; no targets reads nothing. */ export function useIssueFilterCandidates(targets: ReadonlyArray) { - return useAtomValue(mergedIssueCandidates(targets)); + return useAtomValue(mergedIssueCandidates.atom(targets)); } diff --git a/packages/client-runtime/src/state/issues.test.ts b/packages/client-runtime/src/state/issues.test.ts index cc4bcb8eb1490..ab16b67be68f1 100644 --- a/packages/client-runtime/src/state/issues.test.ts +++ b/packages/client-runtime/src/state/issues.test.ts @@ -1,7 +1,20 @@ -import type { IssueComment, IssueListEntry, IssueTrackerKind, ProjectId } from "@t3tools/contracts"; +import { + EnvironmentId, + IssueTrackerKind, + ProjectId, + type IssueComment, + type IssueListEntry, +} from "@t3tools/contracts"; +import * as Effect from "effect/Effect"; +import { Atom, AtomRegistry } from "effect/reactivity"; import { describe, expect, it } from "vite-plus/test"; -import { issueEntryKey, mergeIssueListPage, prependIssueComments } from "./issues.ts"; +import { + createMergedIssueCandidatesAtoms, + issueEntryKey, + mergeIssueListPage, + prependIssueComments, +} from "./issues.ts"; function entry(overrides: Partial & { key: string }): IssueListEntry { return { @@ -69,3 +82,52 @@ describe("prependIssueComments", () => { expect(prependIssueComments(current, older).map((c) => c.id)).toEqual(["c1", "c2", "c3", "c4"]); }); }); + +describe("createMergedIssueCandidatesAtoms", () => { + it("retries only failed scopes that are not already reloading", () => { + const registry = AtomRegistry.make(); + const target = (scope: string) => ({ + environmentId: EnvironmentId.make("issues"), + input: { + projectId: ProjectId.make(scope), + tracker: IssueTrackerKind.make("github"), + host: "github.com", + scope, + }, + }); + const targets = [target("acme/healthy"), target("acme/flaky")]; + const requests: string[] = []; + const candidates = Atom.family((scope: string) => + Atom.make( + Effect.suspend(() => { + requests.push(scope); + if (scope === "acme/healthy") { + return Effect.succeed({ labels: [], assignees: [], truncated: false }); + } + return requests.length === 2 ? Effect.fail("Repository unavailable") : Effect.never; + }), + ), + ); + const merged = createMergedIssueCandidatesAtoms( + (t) => candidates(t.input.scope), + () => "Repository unavailable", + ); + const view = merged.atom(targets); + const unmount = registry.mount(view); + try { + expect(registry.get(view)).toMatchObject({ + error: "Repository unavailable", + isPending: false, + }); + + merged.retry(registry, targets); + expect(registry.get(view).isPending).toBe(true); + merged.retry(registry, targets); + + expect(requests).toEqual(["acme/healthy", "acme/flaky", "acme/flaky"]); + } finally { + unmount(); + registry.dispose(); + } + }); +}); diff --git a/packages/client-runtime/src/state/issues.ts b/packages/client-runtime/src/state/issues.ts index 919baeb9b370b..31d23bc3ebe82 100644 --- a/packages/client-runtime/src/state/issues.ts +++ b/packages/client-runtime/src/state/issues.ts @@ -260,7 +260,10 @@ const NO_ISSUE_CANDIDATES: MergedIssueCandidates = { truncated: false, }; -/** Fans out like the merged listing: a scope that fails leaves the others' answers in place. */ +/** + * Fans out like the merged listing: a scope that fails leaves the others' answers in place. + * Retry skips scopes that already answered or still have a request in flight. + */ export function createMergedIssueCandidatesAtoms( candidates: ( target: IssueCandidatesTarget, @@ -296,6 +299,15 @@ export function createMergedIssueCandidatesAtoms( }; }).pipe(Atom.withLabel(`issues:candidates:${key}`)), ); - return (targets: ReadonlyArray) => - targets.length === 0 ? empty : family(JSON.stringify(targets)); + 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); + } + }, + }; } From c48825322df347d266ab7465332ad490b3bf2aaf Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 21:12:39 -0800 Subject: [PATCH 5/5] fix(web): pairing links never use the desktop app's t3code:// address (#38442) --- .../settings/AuthorizedClientsSettings.tsx | 7 +++---- .../settings/ConnectionsSettings.logic.test.ts | 13 +++++++++++++ .../settings/ConnectionsSettings.logic.ts | 12 ++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/settings/AuthorizedClientsSettings.tsx b/apps/web/src/components/settings/AuthorizedClientsSettings.tsx index 651648c92c42c..ccadf09814de8 100644 --- a/apps/web/src/components/settings/AuthorizedClientsSettings.tsx +++ b/apps/web/src/components/settings/AuthorizedClientsSettings.tsx @@ -53,7 +53,6 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; import { Button } from "../ui/button"; import { Textarea } from "../ui/textarea"; import { - isLoopbackHostname, type ServerClientSessionRecord, type ServerPairingLinkRecord, } from "~/environments/primary"; @@ -208,9 +207,9 @@ const PairingLinkListRow = memo(function PairingLinkListRow({ endpointPairingUrl ?? (credential && endpointUrl != null && endpointUrl !== "" ? (hostedPairingUrl ?? resolveDesktopPairingUrl(endpointUrl, credential)) - : !servedByEnvironment || isLoopbackHostname(window.location.hostname) - ? null - : currentOriginPairingUrl); + : servedByEnvironment + ? currentOriginPairingUrl + : null); const [failedCopyValue, setFailedCopyValue] = useState(null); const revealValue = failedCopyValue ?? shareablePairingUrl ?? credential ?? ""; const isRevealValueUrl = revealValue !== credential; diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts index a664dc99a8f42..e35fa52220c51 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts @@ -5,6 +5,7 @@ import { isServerNetworkAccessible, parseManualDesktopSshTarget, resolveAccessEnvironmentId, + resolveCurrentOriginPairingUrl, resolveTailscaleServeBaseUrl, selectQrEndpointOption, togglePairingScopeSelection, @@ -53,6 +54,18 @@ describe("parseManualDesktopSshTarget", () => { }); }); +describe("resolveCurrentOriginPairingUrl", () => { + it.each([ + ["t3code://app/settings/connections", null], + ["http://127.0.0.1:3774/settings", null], + ["http://localhost:5173/", null], + ["https://host.example.ts.net/settings", "https://host.example.ts.net/pair#token=abc"], + ["http://192.168.1.20:3773/", "http://192.168.1.20:3773/pair#token=abc"], + ])("from %s", (href, expected) => { + expect(resolveCurrentOriginPairingUrl("abc", href)).toBe(expected); + }); +}); + describe("resolveTailscaleServeBaseUrl", () => { it.each([ ["https://host.tail.ts.net:441/", 443, "https://host.tail.ts.net"], diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.ts index 91698629e9d69..4ec7d9dec9af1 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.ts @@ -7,6 +7,7 @@ import { getPairingTokenFromUrl, setPairingTokenOnUrl } from "@t3tools/shared/re import { readHostedPairingRequest } from "../../hostedPairing"; import { m, type MessageResolver } from "../../i18n/messages"; import { + isLoopbackHostname, type ServerClientSessionRecord, type ServerPairingLinkRecord, } from "~/environments/primary"; @@ -448,8 +449,15 @@ export function resolveAdvertisedEndpointPairingUrl( return resolveDesktopPairingUrl(endpoint.httpBaseUrl, credential); } -export function resolveCurrentOriginPairingUrl(credential: string): string { - const url = new URL("/pair", window.location.href); +export function resolveCurrentOriginPairingUrl( + credential: string, + currentHref: string = window.location.href, +): string | null { + const url = new URL("/pair", currentHref); + // The packaged desktop window loads from t3code://app, which no other device can open. + if ((url.protocol !== "http:" && url.protocol !== "https:") || isLoopbackHostname(url.hostname)) { + return null; + } return setPairingTokenOnUrl(url, credential).toString(); }