TypeScript
feat(mcp): unlink every PR in given states with one call (#27925)
maria78aa0d5ca511
diff --git a/apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts b/apps/server/src/mcp/toolkits/pullRequests/handlers.test.tsindex 88691423c0e..29ccb921267 100644--- a/apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts+++ b/apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts@@ -517,6 +517,39 @@ describe("pull request toolkit handlers", () => {}),);+ it.effect("unlinks every visible pull request in the given states in one call", () =>+ Effect.gen(function* () {+ const withState = (number: number, state: "open" | "closed" | "merged") => {+ const link = makeLink(number, { headBranch: `branch-${number}` });+ return { ...link, snapshot: { ...link.snapshot!, state } };+ };+ const harness = yield* makeHarness({+ thread: makeThread([+ withState(1, "merged"),+ withState(2, "open"),+ withState(3, "closed"),+ makeLink(4),+ { ...withState(5, "merged"), source: "stack-dismissed" },+ ]),+ });+ const result = yield* harness.call("unlink_pull_requests", {+ states: ["closed", "merged"],+ });+ expect(result).toEqual({+ unlinked: [+ { host: "github.com", repository: "t3tools/t3code", state: "merged", numbers: [1] },+ { host: "github.com", repository: "t3tools/t3code", state: "closed", numbers: [3] },+ ],+ unlinkedCount: 2,+ remaining: 2,+ });+ expect(yield* Ref.get(harness.commands)).toMatchObject([+ { type: "thread.pull-request.unlink", number: 1 },+ { type: "thread.pull-request.unlink", number: 3 },+ ]);+ }),+ );+it("reports an older Forgejo link's HTTP port when listing thread links", () => {const result = listThreadPullRequests(makeThread([diff --git a/apps/server/src/mcp/toolkits/pullRequests/handlers.ts b/apps/server/src/mcp/toolkits/pullRequests/handlers.tsindex a4cd07b89fb..0c06ed3ebaf 100644--- a/apps/server/src/mcp/toolkits/pullRequests/handlers.ts+++ b/apps/server/src/mcp/toolkits/pullRequests/handlers.ts@@ -426,6 +426,42 @@ const make = Effect.gen(function* () {};}),),+ unlink_pull_requests: writesThread((input) =>+ Effect.gen(function* () {+ const thread = yield* requireThread(PullRequestUnlinkFailedError, input.threadId);+ const visible = visibleThreadPullRequests(threadPullRequestsOf(thread));+ const matching = visible.flatMap((link) => {+ const state = link.snapshot?.state;+ return state !== undefined && input.states.includes(state)+ ? [{ ...normalizeThreadPullRequestKey(link), state }]+ : [];+ });+ yield* Effect.forEach(matching, ({ host, repository, number }) =>+ Effect.gen(function* () {+ yield* engine.dispatch({+ type: "thread.pull-request.unlink",+ commandId: yield* commandId("mcp-pr-unlink", thread.id),+ threadId: thread.id,+ host,+ repository,+ number,+ });+ }).pipe(Effect.catchCause(dispatchFailure(PullRequestUnlinkFailedError))),+ );+ // Numbers grouped by repository and state keep a large batch's result small.+ const groups = Map.groupBy(matching, (pr) => `${pr.host}/${pr.repository}/${pr.state}`);+ return {+ unlinked: [...groups.values()].map((prs) => ({+ host: prs[0]!.host,+ repository: prs[0]!.repository,+ state: prs[0]!.state,+ numbers: prs.map((pr) => pr.number),+ })),+ unlinkedCount: matching.length,+ remaining: visible.length - matching.length,+ };+ }),+ ),list_thread_pull_requests: McpToolAccess.reads((input) =>requireThread(PullRequestListFailedError, input.threadId).pipe(Effect.map(listThreadPullRequests),diff --git a/apps/server/src/mcp/toolkits/pullRequests/tools.ts b/apps/server/src/mcp/toolkits/pullRequests/tools.tsindex 866580fc5e0..d0cdf31066d 100644--- a/apps/server/src/mcp/toolkits/pullRequests/tools.ts+++ b/apps/server/src/mcp/toolkits/pullRequests/tools.ts@@ -231,6 +231,20 @@ export const UnlinkPullRequestResult = Schema.Struct({});export type UnlinkPullRequestResult = typeof UnlinkPullRequestResult.Type;+export const UnlinkPullRequestsResult = Schema.Struct({+ unlinked: Schema.Array(+ Schema.Struct({+ host: Schema.String,+ repository: Schema.String,+ state: PullRequestState,+ numbers: Schema.Array(Schema.Int),+ }),+ ),+ unlinkedCount: Schema.Int,+ remaining: Schema.Int,+});+export type UnlinkPullRequestsResult = typeof UnlinkPullRequestsResult.Type;+export const WatchPullRequestResult = Schema.Struct({...PullRequestIdentity,watching: Schema.Boolean,@@ -297,6 +311,24 @@ const UnlinkPullRequestTool = Tool.make("unlink_pull_request", {.annotate(Tool.Idempotent, true).annotate(Tool.OpenWorld, false);+const UnlinkPullRequestsTool = Tool.make("unlink_pull_requests", {+ description:+ "Unlink every PR on a thread whose last known state (as `list_thread_pull_requests` shows) is in `states`, in one call. Use it instead of one `unlink_pull_request` per PR. PRs with no known state stay linked.",+ parameters: Schema.Struct({+ environmentId: OrchestratorMcpEnvironmentTarget,+ threadId: Schema.optional(ThreadId.annotate({ description: "Thread. Default: this thread." })),+ states: Schema.Array(PullRequestState).check(Schema.isMinLength(1)),+ }),+ success: UnlinkPullRequestsResult,+ failure: PullRequestToolError,+ dependencies,+})+ .annotate(Tool.Title, "Unlink pull requests by state")+ .annotate(Tool.Readonly, false)+ .annotate(Tool.Destructive, true)+ .annotate(Tool.Idempotent, true)+ .annotate(Tool.OpenWorld, false);+const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {description:"List PRs linked to a thread, with last known state and stack order (bottom to top). Call only when you need that list. Never as an end-of-work check.",@@ -411,6 +443,7 @@ const ReadPullRequestGuideTool = Tool.make("read_pull_request_guide", {export const PullRequestsToolkit = Toolkit.make(LinkPullRequestTool,UnlinkPullRequestTool,+ UnlinkPullRequestsTool,ListThreadPullRequestsTool,WatchPullRequestTool,UnwatchPullRequestTool,diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.jsonindex 07830f90d05..c4ddc084c02 100644--- a/apps/server/src/provider/agentContextBudget.json+++ b/apps/server/src/provider/agentContextBudget.json@@ -1,5 +1,5 @@{"claudeSystemAppendBytes": 5129,"codexAdditionalContextBytes": 6859,- "mcpToolListJsonBytes": 46109+ "mcpToolListJsonBytes": 46596}diff --git a/evals/mcp-tool-use/cases/pull-requests.ndjson b/evals/mcp-tool-use/cases/pull-requests.ndjsonindex 378dc9e4576..2f96d44cc72 100644--- a/evals/mcp-tool-use/cases/pull-requests.ndjson+++ b/evals/mcp-tool-use/cases/pull-requests.ndjson@@ -27,3 +27,7 @@{"id": "control-nightly-time-question", "area": "pull-requests", "kind": "control", "pattern": "question about a CI schedule is not a schedule ask", "experience": "'When does the next nightly go out?' is answered from the workflow file, with no scheduler tools.", "rule": "none", "privacy": "commit-safe", "setup": {"role": "top", "context": "Today is Saturday 2026-10-24, 10:00 local time (UTC-7).", "shellMocks": [{"match": "^date\\b", "output": "Sat Oct 24 10:00:00 PDT 2026"}, {"match": "gh run list", "output": "completed\tsuccess\tnightly\tmain\tschedule\t991\t21m\t2026-10-24T09:00:00Z"}], "world": {"files": {".github/workflows/nightly.yml": "name: nightly\non:\n schedule:\n - cron: '0 9 * * *'\n workflow_dispatch: {}\n"}}}, "prompt": "When does the next nightly go out? Want to start testing this asap", "expect": {"notCalls": ["schedule_task", "list_scheduled_tasks", "run_scheduled_task_now"]}, "notes": ""}{"id": "control-fix-with-background-pr", "area": "pull-requests", "kind": "control", "pattern": "ordinary code fix that names a PR", "experience": "A plain code fix that mentions the PR which added the bug needs no PR tools.", "rule": "Do not link unrelated PRs mentioned only as background.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/session.ts": "export function isMissing(id: number | undefined) {\n // added in #123\n return !id;\n}\n"}}}, "prompt": "The isMissing guard that #123 added in src/session.ts treats an id of 0 as missing. Fix it. Don't open a PR, I'll review the diff here.", "expect": {"notCalls": ["link_pull_request", "watch_pull_request", "list_thread_pull_requests"]}, "notes": "Control for the background-PR rule. Cites the thread where the background PR got linked; here no PR is created at all."}{"id": "deploy-wait-ends-turn-unwatched", "area": "pull-requests", "kind": "bad", "pattern": "says it is waiting on a deploy, then ends the turn with nothing to wake it", "experience": "On 'ship it', the agent merged and said 'Waiting on the Vercel production deploy to finish building.', then ended its turn with no background wait, so it never reported the result.", "rule": "Never wait with sleep, loops, gh --watch, Monitor, or ScheduleWakeup.", "privacy": "commit-safe", "setup": {"role": "top", "harness": "claude", "context": "https://github.com/acme/app/pull/123 is linked to this thread and is not watched.", "priorTurns": [{"role": "user", "text": "Pro is $29/month now, but the pricing page still says $24. Fix it."}, {"role": "assistant", "text": "Fixed in [#123](https://github.com/acme/app/pull/123): the Pro plan now costs 2900 cents ($29/month). All checks pass, including the Vercel preview build. Ship it?", "toolCalls": [{"tool": "Edit", "input": {"file_path": "/home/user/.t3/worktrees/t3code/t3-f8cdd940/apps/web/src/pricing/plans.ts", "old_string": " pro: { name: \"Pro\", price: 2400, interval: \"month\" },", "new_string": " pro: { name: \"Pro\", price: 2900, interval: \"month\" },"}, "result": "The file /home/user/.t3/worktrees/t3code/t3-f8cdd940/apps/web/src/pricing/plans.ts has been updated successfully."}, {"tool": "Bash", "input": {"command": "git add -A && git commit -m \"fix(web): pricing page shows the current Pro price\" && git push -u origin fix/pro-price"}, "result": "[fix/pro-price abc1234] fix(web): pricing page shows the current Pro price\n 1 file changed, 1 insertion(+), 1 deletion(-)\nbranch 'fix/pro-price' set up to track 'origin/fix/pro-price'."}, {"tool": "Bash", "input": {"command": "gh pr create --fill"}, "result": "https://github.com/acme/app/pull/123"}, {"tool": "link_pull_request", "input": {"url": "https://github.com/acme/app/pull/123"}, "result": {"host": "github.com", "repository": "acme/app", "number": 123, "url": "https://github.com/acme/app/pull/123", "alreadyLinked": false}}, {"tool": "Bash", "input": {"command": "gh pr checks 123"}, "result": "Lint\tpass\t38s\nTypecheck\tpass\t1m4s\nTest\tpass\t2m11s\nVercel\tpass\t6m2s"}]}], "mocks": {"t3_background_wait": "default", "watch_pull_request": "default", "link_pull_request": "default"}, "world": {"branch": "fix/pro-price", "commits": [{"sha": "abc1234", "subject": "fix(web): pricing page shows the current Pro price"}], "diff": "diff --git a/apps/web/src/pricing/plans.ts b/apps/web/src/pricing/plans.ts\n--- a/apps/web/src/pricing/plans.ts\n+++ b/apps/web/src/pricing/plans.ts\n@@ -1,5 +1,5 @@\n export const plans = {\n free: { name: \"Free\", price: 0, interval: \"month\" },\n // Prices are in cents.\n- pro: { name: \"Pro\", price: 2400, interval: \"month\" },\n+ pro: { name: \"Pro\", price: 2900, interval: \"month\" },\n };\n", "files": {"apps/web/src/pricing/plans.ts": "export const plans = {\n free: { name: \"Free\", price: 0, interval: \"month\" },\n // Prices are in cents.\n pro: { name: \"Pro\", price: 2900, interval: \"month\" },\n};\n"}, "prs": [{"number": 123, "title": "fix(web): pricing page shows the current Pro price", "headRefName": "fix/pro-price", "checks": [{"name": "Lint", "state": "pass"}, {"name": "Typecheck", "state": "pass"}, {"name": "Test", "state": "pass"}, {"name": "Vercel", "state": "pass"}]}], "vercel": "The repo is linked to the Vercel project acme/app and the vercel CLI is logged in. Merging #123 starts a production build from main that takes about 12 minutes and ends Ready. Until then `vercel ls` and `vercel inspect` show it as Building. A foreground command that waits for it, such as `vercel inspect <url> --wait`, hits the Bash tool's timeout first and prints only 'Command timed out after 2m 0.0s' (10m 0.0s with the longest timeout). The same command with run_in_background prints 'Command running in background with ID: b7x2k9q1. Output is being written to: /tmp/claude/tasks/b7x2k9q1.output'."}, "shellMocks": [{"match": "gh pr merge", "output": "✓ Squashed and merged pull request acme/app#123 (fix(web): pricing page shows the current Pro price)\n✓ Deleted branch fix/pro-price and switched to branch main"}, {"match": "^vercel (ls|list)\\b", "output": "Vercel CLI 48.2.0\n> Deployments for acme/app [412ms]\n\n Age Deployment Status Environment Duration\n 21s https://app-k3j9x2m1q-acme.vercel.app ● Building Production --\n 2h https://app-p8d7f6e5w-acme.vercel.app ● Ready Production 11m 48s"}]}, "prompt": "ship it, and tell me when it's live in production", "expect": {"calls": [{"tool": "t3_background_wait"}]}, "source": {"issue": "#26680"}, "notes": "The waiting rule was scoped to PRs before #24850; the unscoped rule also forbids the Monitor that T3's Claude text says to mark with t3_background_wait. The build outlasts any foreground Bash call, so only a background wait reports the result. Claude only: t3_background_wait is a Claude tool.", "maxSteps": 16}+{"id": "unlink-closed-and-merged-prs", "area": "pull-requests", "kind": "bad", "pattern": "unlinks finished PRs one call at a time", "experience": "Asked to unlink every closed or merged PR, the agent listed 826 links and unlinked 230 of them one call each.", "rule": "unlink_pull_request takes one PR per call", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "unlink every pr here that is either closed or merged already", "expect": {"calls": [{"tool": "unlink_pull_requests"}], "linkedNumbers": [102, 104, 107, 109, 110, 112, 114, 117, 119, 120, 122, 124, 127, 129, 130, 132, 134, 137, 139, 140, 142, 144, 147, 149, 150, 152, 154, 157, 159, 160], "maxCalls": {"unlink_pull_requests": 1, "unlink_pull_request": 0}}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}+{"id": "unlink-prs-not-open", "area": "pull-requests", "kind": "bad", "pattern": "unlinks finished PRs one call at a time", "experience": "Asked to drop links that are no longer open, the agent unlinked each finished PR with its own call.", "rule": "unlink_pull_request takes one PR per call", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "clean up this thread's pr list: unlink anything that isn't open anymore", "expect": {"calls": [{"tool": "unlink_pull_requests"}], "linkedNumbers": [102, 104, 107, 109, 110, 112, 114, 117, 119, 120, 122, 124, 127, 129, 130, 132, 134, 137, 139, 140, 142, 144, 147, 149, 150, 152, 154, 157, 159, 160], "maxCalls": {"unlink_pull_requests": 1, "unlink_pull_request": 0}}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}+{"id": "unlink-merged-prs-only", "area": "pull-requests", "kind": "guard", "pattern": "batch unlink keeps what the user wants", "experience": "A batch unlink must keep PRs in states the user did not name.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "unlink the merged prs from this thread. keep the closed ones, i still want to look at those", "expect": {"linkedNumbers": [102, 104, 105, 107, 109, 110, 112, 114, 115, 117, 119, 120, 122, 124, 125, 127, 129, 130, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 149, 150, 152, 154, 155, 157, 159, 160]}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}+{"id": "unlink-one-pr", "area": "pull-requests", "kind": "control", "pattern": "single unlink stays single", "experience": "Unlinking one named PR is ordinary work and should not touch the others.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "unlink https://github.com/acme/app/pull/142 from this thread, i linked it by mistake", "expect": {"calls": [{"tool": "unlink_pull_request"}], "notCalls": ["unlink_pull_requests"], "linkedNumbers": [101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160]}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}diff --git a/evals/mcp-tool-use/run.test.ts b/evals/mcp-tool-use/run.test.tsindex d825c3b8fce..69de4f0c6c4 100644--- a/evals/mcp-tool-use/run.test.ts+++ b/evals/mcp-tool-use/run.test.ts@@ -116,6 +116,7 @@ it("passes a good run and names every rule a bad run breaks", () => {textMust: ["t3-thread://v2/"],textMustNot: ["Paste .*token"],linked: ["~/pull/124"],+ linkedNumbers: [124],};const good: SampleRun = {calls: [@@ -158,6 +159,7 @@ it("passes a good run and names every rule a bad run breaks", () => {"textMust /t3-thread://v2//","textMustNot /Paste .*token/","linked ~/pull/124",+ "linkedNumbers",]);});diff --git a/evals/mcp-tool-use/run.ts b/evals/mcp-tool-use/run.tsindex 7cad56ae980..b58dee92081 100644--- a/evals/mcp-tool-use/run.ts+++ b/evals/mcp-tool-use/run.ts@@ -35,7 +35,12 @@ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";import { taskPrompt } from "../../apps/server/src/mcp/delegatedTaskModes.ts";import * as McpInvocationContext from "../../apps/server/src/mcp/McpInvocationContext.ts";import { advertisedJsonSchema } from "../../apps/server/src/mcp/advertisedJsonSchema.ts";-import { EnvironmentId, ORCHESTRATOR_MCP_RUNNING_TASK_NEXT, ThreadId } from "@t3tools/contracts";+import {+ EnvironmentId,+ ORCHESTRATOR_MCP_RUNNING_TASK_NEXT,+ PullRequestState,+ ThreadId,+} from "@t3tools/contracts";import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences";import { formatThreadLink } from "@t3tools/shared/threadLinks";import { buildCodexAdditionalContext } from "../../apps/server/src/provider/CodexDeveloperInstructions.ts";@@ -166,6 +171,8 @@ const McpToolUseExpect = Schema.Struct({textMustNot: Schema.optional(Schema.Array(Schema.String)),/** Each entry matches a PR URL linked at the end, as `args` values match. */linked: Schema.optional(Schema.Array(Schema.String)),+ /** The PR numbers linked at the end, exactly. */+ linkedNumbers: Schema.optional(Schema.Array(Schema.Number)),/** Device manager checks: child briefs, simulator UI over the shell, failures, recordings. */device: Schema.optional(DeviceExpect),});@@ -210,6 +217,12 @@ const McpToolUseWorld = Schema.StructWithRest(deviceInvalidCapture: Schema.optional(Schema.Boolean),/** Devices another thread's agent-device session holds, by device id: that thread's id. */deviceOwners: Schema.optional(Schema.Record(Schema.String, Schema.String)),+ /** PRs already linked to the thread, with the state T3 last saw. */+ linkedPullRequests: Schema.optional(+ Schema.Array(+ Schema.Struct({ number: Schema.Number, state: PullRequestState, title: Schema.String }),+ ),+ ),}),Rest,);@@ -731,11 +744,16 @@ export const makeSample = (testCase: McpToolUseCase, base: Base): Sample => {const prior = testCase.setup.priorTurns ?? [];const priorCalls = prior.flatMap((turn) => turn.toolCalls ?? []);const repo = testCase.setup.world?.repo ?? "acme/app";- const urls = priorCalls.flatMap((call) =>- ["link_pull_request", "watch_pull_request"].includes(call.tool) && isRecord(call.input)- ? [pullRequest(repo, call.input).url]- : [],- );+ const urls = [+ ...(testCase.setup.world?.linkedPullRequests ?? []).map(+ ({ number }) => pullRequest(repo, { number }).url,+ ),+ ...priorCalls.flatMap((call) =>+ ["link_pull_request", "watch_pull_request"].includes(call.tool) && isRecord(call.input)+ ? [pullRequest(repo, call.input).url]+ : [],+ ),+ ];const taskNumbers = [...valueText(prior).matchAll(/task-(\d+)/g)].map((match) =>Number(match[1]),);@@ -952,6 +970,15 @@ const pullRequest = (repo: string, input: Readonly<Record<string, unknown>>) =>};};+/** A linked PR as `list_thread_pull_requests` shows it. Links made in the sample are open. */+const linkedEntry = (sample: Sample, url: string) => {+ const pr = pullRequest(sample.repo, { url });+ const seeded = sample.testCase.setup.world?.linkedPullRequests?.find(+ ({ number }) => number === pr.number && pr.repository === sample.repo,+ );+ return { ...pr, state: seeded?.state ?? "open", title: seeded?.title ?? null };+};+/** A believable T3 result for a tool the case does not mock. */const t3Default = (sample: Sample, name: string, input: Readonly<Record<string, unknown>>) => {const pr = () => pullRequest(sample.repo, input);@@ -1006,6 +1033,24 @@ const t3Default = (sample: Sample, name: string, input: Readonly<Record<string,}case "unlink_pull_request":return { ...pr(), wasLinked: sample.linked.delete(pr().url) };+ case "unlink_pull_requests": {+ const states = Array.isArray(input.states) ? input.states : [];+ const unlinked = [...sample.linked]+ .map((url) => linkedEntry(sample, url))+ .filter((entry) => states.includes(entry.state));+ for (const { url } of unlinked) sample.linked.delete(url);+ const groups = Map.groupBy(unlinked, (entry) => `${entry.repository}/${entry.state}`);+ return {+ unlinked: [...groups.values()].map((entries) => ({+ host: "github.com",+ repository: entries[0]!.repository,+ state: entries[0]!.state,+ numbers: entries.map((entry) => entry.number),+ })),+ unlinkedCount: unlinked.length,+ remaining: sample.linked.size,+ };+ }case "watch_pull_request":sample.linked.add(pr().url);return { ...pr(), watching: true, wasWatching: false };@@ -1014,10 +1059,9 @@ const t3Default = (sample: Sample, name: string, input: Readonly<Record<string,case "list_thread_pull_requests":return {pullRequests: [...sample.linked].map((url) => ({- ...pullRequest(sample.repo, { url }),+ ...linkedEntry(sample, url),source: "agent",watching: false,- state: "open",})),chains: [],};@@ -1403,6 +1447,11 @@ export const gradeSample = (expect: McpToolUseCase["expect"], run: SampleRun) =>for (const p of expect.textMustNot ?? []) add(`textMustNot /${p}/`, !test(p, run.text));const isLinked = (url: string) => (run.linked ?? []).some((at) => matches(url, at));for (const url of expect.linked ?? []) add(`linked ${url}`, isLinked(url));+ if (expect.linkedNumbers !== undefined) {+ const numbers = (run.linked ?? []).map((url) => Number(/(\d+)\/?$/.exec(url)?.[1]));+ const exact = valueText(numbers.toSorted((a, b) => a - b));+ add("linkedNumbers", exact === valueText(expect.linkedNumbers.toSorted((a, b) => a - b)));+ }checks.push(...gradeDevice(expect.device, run));return checks;};diff --git a/packages/client-runtime/src/t3ToolSummary.test.ts b/packages/client-runtime/src/t3ToolSummary.test.tsindex 0a1b3c4d793..a96d2256d00 100644--- a/packages/client-runtime/src/t3ToolSummary.test.ts+++ b/packages/client-runtime/src/t3ToolSummary.test.ts@@ -35,6 +35,15 @@ describe("summarizeT3ToolCalls", () => {).toBe("Sent 2 messages to 1 thread");});+ it("counts the pull requests a batch unlink removed", () => {+ const batch = completed({ states: ["merged"] }, { unlinkedCount: 2 });+ expect(summarizeT3ToolCalls("unlink-pr", [batch, completed({ number: 3 })]).label).toBe(+ "Unlinked 3 pull requests",+ );+ const uncounted = completed({ states: ["merged"] }, { isError: false });+ expect(summarizeT3ToolCalls("unlink-pr", [uncounted]).label).toBe("Unlinked pull requests");+ });+it("excludes failed and unfinished sends even if the provider reports completed", () => {const calls: T3ToolSummaryCall[] = [completed({ threadId: "success" }, { messageId: "ok", threadId: "success" }),diff --git a/packages/client-runtime/src/t3ToolSummary.ts b/packages/client-runtime/src/t3ToolSummary.tsindex 1e9629d5803..854a8583e95 100644--- a/packages/client-runtime/src/t3ToolSummary.ts+++ b/packages/client-runtime/src/t3ToolSummary.ts@@ -391,9 +391,19 @@ export function summarizeT3ToolCalls(case "link-pr":label = phrase("Linked", "link", quantity(selected.length, "pull request"));break;- case "unlink-pr":- label = phrase("Unlinked", "unlink", quantity(selected.length, "pull request"));+ case "unlink-pr": {+ let count = 0;+ let countKnown = true;+ for (const call of selected) {+ if (typeof call.output?.unlinkedCount === "number") count += call.output.unlinkedCount;+ // A batch result too large to compact loses its count, so the label drops the number.+ else if (Array.isArray(call.input?.states)) countKnown = false;+ else count += 1;+ }+ const object = countKnown ? quantity(count, "pull request") : "pull requests";+ label = phrase("Unlinked", "unlink", object);break;+ }case "watch-pr":label = phrase("Watching", "watch", quantity(selected.length, "pull request"));break;diff --git a/packages/shared/src/t3McpToolPresentation.ts b/packages/shared/src/t3McpToolPresentation.tsindex 5848861f47a..fd3f1621bb0 100644--- a/packages/shared/src/t3McpToolPresentation.ts+++ b/packages/shared/src/t3McpToolPresentation.ts@@ -99,6 +99,11 @@ const T3_MCP_TOOLS: Readonly<Record<string, T3McpToolDefinition>> = {"unlink-pr","pull-request",),+ unlink_pull_requests: tool(+ ["Unlink", "Unlinking", "Unlinked", "pull requests by state"],+ "unlink-pr",+ "pull-request",+ ),list_thread_pull_requests: tool(["Check", "Checking", "Checked", "linked pull requests"],"list-prs",diff --git a/packages/shared/src/toolOutput.test.ts b/packages/shared/src/toolOutput.test.tsindex 405905bf2fa..e54c9408cde 100644--- a/packages/shared/src/toolOutput.test.ts+++ b/packages/shared/src/toolOutput.test.ts@@ -29,11 +29,14 @@ describe("compactDynamicToolOutput", () => {scheduledTaskId: "scheduled-1",status: "failed",summary: "A child failed; the tool itself succeeded.",+ unlinked: [{ repository: "acme/app", state: "merged", numbers: [1] }],+ unlinkedCount: 1,};expect(compactDynamicToolOutput(output)).toEqual({thread: { threadId: "thread-1" },taskId: "task-1",scheduledTaskId: "scheduled-1",+ unlinkedCount: 1,});expect(output.thread.messages).toEqual(["Private message"]);});diff --git a/packages/shared/src/toolOutput.ts b/packages/shared/src/toolOutput.tsindex 2a80641d13b..8b07deee54d 100644--- a/packages/shared/src/toolOutput.ts+++ b/packages/shared/src/toolOutput.ts@@ -43,6 +43,7 @@ interface CompactToolOutput {[MCP_APP_OUTPUT_KEY]?: McpAppReference;thread?: { threadId: string };threads?: Array<{ threadId?: string; status?: "rolled_back" }>;+ unlinkedCount?: number;}function readResult(value: unknown, budget: ResultReadBudget, depth = 0): ResultEnvelope {@@ -123,6 +124,8 @@ export function compactDynamicToolOutput(value: unknown): CompactToolOutput | unif (id !== undefined) output[key] = id;}if (data.status === "rolled_back") output.status = "rolled_back";+ if (typeof data.unlinkedCount === "number" && Number.isSafeInteger(data.unlinkedCount))+ output.unlinkedCount = data.unlinkedCount;const htmlRender = readHtmlRenderReference(data.htmlRender);if (htmlRender !== undefined) output.htmlRender = htmlRender;const mcpApp = readMcpAppReference(data[MCP_APP_OUTPUT_KEY]);