The best way to control Claude Code, Codex and more from any computer or phone
fix(server): delegated children no longer see pull request watch tools (#24808)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 25, 2026 at 02:09 UTC
e641761e2aabd7488cc9049087d2ef6e8e24ddfc
6 files changed
+169
-4
apps/server/src/mcp/McpHttpServer.test.ts
+87
@@ -817,3 +817,90 @@ it.effect("admits provider and OAuth client credentials and points only clients
817
}),
818
).pipe(Effect.provide(NodeHttpServer.layerTest)),
819
);
820
+
821
+it.effect("lists pull request watch tools only to threads that are not delegated children", () =>
822
+ Effect.scoped(
823
+ Effect.gen(function* () {
824
+ const scopeFor = (
825
+ token: string,
826
+ subagent: boolean,
827
+ ): McpInvocationContext.McpThreadInvocationScope => ({
828
+ environmentId,
829
+ requestNamespace: token,
830
+ thread: {
831
+ threadId: ThreadId.make(`thread-${token}`),
832
+ providerSessionId: token,
833
+ providerInstanceId: ProviderInstanceId.make("codex"),
834
+ subagent,
835
+ },
836
+ client: undefined,
837
+ capabilities: new Set(["pull-requests"]),
838
+ issuedAt: 1,
839
+ });
840
+ const scopes = new Map([
841
+ ["parentToken", scopeFor("parentToken", false)],
842
+ ["childToken", scopeFor("childToken", true)],
843
+ ]);
844
+ const serverLayer = McpHttpServer.layerPullRequestsToolkit.pipe(
845
+ Layer.provideMerge(McpHttpServer.layerMcpTransport),
846
+ Layer.provide(
847
+ Layer.mock(McpSessionRegistry.McpSessionRegistry)({
848
+ resolve: (token) => Effect.succeed(scopes.get(token)),
849
+ }),
850
+ ),
851
+ Layer.provide(
852
+ Layer.mergeAll(
853
+ McpToolAccessTestkit.liveThreadsLayer,
854
+ Layer.mock(ProjectService.ProjectService)({}),
855
+ Layer.mock(PullRequestReviewGuideService.PullRequestReviewGuideService)({}),
856
+ Layer.mock(Orchestrator.OrchestratorV2)({}),
857
+ Layer.mock(ProjectionStore.ProjectionStoreV2)({}),
858
+ NodeServices.layer,
859
+ ),
860
+ ),
861
+ );
862
+ yield* HttpRouter.serve(serverLayer, { disableListenLog: true, disableLogger: true }).pipe(
863
+ Layer.build,
864
+ );
865
+ const httpClient = yield* HttpClient.HttpClient;
866
+ const listedTools = (token: string) =>
867
+ Effect.gen(function* () {
868
+ const headers = {
869
+ accept: "application/json, text/event-stream",
870
+ authorization: `Bearer ${token}`,
871
+ };
872
+ const initialize = yield* httpClient.post("/mcp", {
873
+ headers,
874
+ body: HttpBody.text(
875
+ `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}`,
876
+ "application/json",
877
+ ),
878
+ });
879
+ const listed = yield* httpClient.post("/mcp", {
880
+ headers: {
881
+ ...headers,
882
+ "mcp-session-id": initialize.headers["mcp-session-id"]!,
883
+ "mcp-protocol-version": "2025-06-18",
884
+ },
885
+ body: HttpBody.text(
886
+ `{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}`,
887
+ "application/json",
888
+ ),
889
+ });
890
+ const body = (yield* listed.json) as {
891
+ readonly result: { readonly tools: ReadonlyArray<{ readonly name: string }> };
892
+ };
893
+ return body.result.tools.map((tool) => tool.name);
894
+ });
895
+
896
+ const parentTools = yield* listedTools("parentToken");
897
+ const childTools = yield* listedTools("childToken");
898
+ expect(parentTools).toEqual(
899
+ expect.arrayContaining(["link_pull_request", "watch_pull_request", "unwatch_pull_request"]),
900
+ );
901
+ expect(childTools).toContain("link_pull_request");
902
+ expect(childTools).not.toContain("watch_pull_request");
903
+ expect(childTools).not.toContain("unwatch_pull_request");
904
+ }),
905
+ ).pipe(Effect.provide(NodeHttpServer.layerTest)),
906
+);
apps/server/src/mcp/McpInvocationContext.ts
+13
@@ -10,6 +10,7 @@ import {
10
} from "@t3tools/contracts";
11
import * as Context from "effect/Context";
12
import * as Effect from "effect/Effect";
13
+import * as Fiber from "effect/Fiber";
14
15
const ALL_MCP_CAPABILITIES = [
16
"preview",
@@ -24,6 +25,8 @@ export interface McpThreadCaller {
25
readonly threadId: ThreadId;
26
readonly providerSessionId: string;
27
readonly providerInstanceId: ProviderInstanceId;
28
+ /** A delegated child task; its parent owns the work it hands back. */
29
+ readonly subagent?: boolean;
30
}
31
32
export interface McpClientCaller {
@@ -51,6 +54,16 @@ export class McpInvocationContext extends Context.Service<
54
McpInvocationScope
55
>()("t3/mcp/McpInvocationContext") {}
56
57
+/**
58
+ * `McpSchema.EnabledWhen` for tools a delegated child must not see or call.
59
+ * EnabledWhen only receives the MCP client profile, so read the T3 caller from the request fiber.
60
+ */
61
+export const hiddenFromSubagents = (): boolean => {
62
+ const fiber = Fiber.getCurrent();
63
+ const scope = fiber && Context.getOrUndefined(fiber.context, McpInvocationContext);
64
+ return scope?.thread?.subagent !== true;
65
+};
66
+
67
export type McpCapabilityError<C extends McpCapability> = C extends "preview"
68
? PreviewAutomationUnavailableError
69
: McpCapabilityUnavailableError;
apps/server/src/mcp/McpSessionRegistry.ts
+2
@@ -18,6 +18,7 @@ export interface McpCredentialRequest {
18
/** False omits the preview capability wherever the token is honored. Defaults to full access. */
19
readonly browserToolsAvailable?: boolean;
20
readonly capabilities?: ReadonlySet<McpInvocationContext.McpCapability>;
21
+ readonly subagent?: boolean;
22
}
23
24
export interface McpIssuedCredential {
@@ -105,6 +106,7 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
106
threadId: ThreadId.make(request.threadId),
107
providerSessionId,
108
providerInstanceId: ProviderInstanceId.make(request.providerInstanceId),
109
+ subagent: request.subagent === true,
110
},
111
client: undefined,
112
capabilities: new Set<McpInvocationContext.McpCapability>([
apps/server/src/mcp/toolkits/pullRequests/tools.ts
+6
-3
@@ -10,6 +10,7 @@ import {
10
ThreadId,
11
} from "@t3tools/contracts";
12
import * as Schema from "effect/Schema";
13
+import * as McpSchema from "effect/ai/McpSchema";
14
import * as Tool from "effect/ai/Tool";
15
import * as Toolkit from "effect/ai/Toolkit";
16
@@ -326,7 +327,7 @@ const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {
327
328
const WatchPullRequestTool = Tool.make("watch_pull_request", {
329
description:
329
- "Have T3 Code watch an open pull request for this thread, linking it first if needed. T3 Code checks it every two minutes and wakes you with a message when a check fails, the required checks pass, someone else comments or reviews, or the branch starts to conflict with its base. Use this to monitor or babysit a pull request instead of polling, sleeping, or running a watcher. Only comments posted after this call wake you, so handle the existing ones first, then end your turn. A wake is news, not a merge decision: check readiness yourself before merging. While T3 Code watches, the thread stays in the user's Working list, not their inbox. When you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox. Watching ends when the pull request merges or closes, when its thread settles or is archived, when T3 Code fails to read it 8 times in a row (a host rate limit only delays it), when the user stops this thread, or when you call unwatch_pull_request. Unsettle the thread before starting a new watch. A subagent cannot watch: its parent thread owns the pull request.",
330
+ "Have T3 Code watch an open pull request for this thread, linking it first if needed. T3 Code checks it every two minutes and wakes you with a message when a check fails, the required checks pass, someone else comments or reviews, or the branch starts to conflict with its base. Use this to monitor or babysit a pull request instead of polling, sleeping, or running a watcher. Only comments posted after this call wake you, so handle the existing ones first, then end your turn. A wake is news, not a merge decision: check readiness yourself before merging. While T3 Code watches, the thread stays in the user's Working list, not their inbox. When you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox. Watching ends when the pull request merges or closes, when its thread settles or is archived, when T3 Code fails to read it 8 times in a row (a host rate limit only delays it), when the user stops this thread, or when you call unwatch_pull_request. Unsettle the thread before starting a new watch.",
331
parameters: PullRequestTargetInput,
332
success: WatchPullRequestResult,
333
failure: PullRequestToolError,
@@ -336,7 +337,8 @@ const WatchPullRequestTool = Tool.make("watch_pull_request", {
337
.annotate(Tool.Readonly, false)
338
.annotate(Tool.Destructive, false)
339
.annotate(Tool.Idempotent, true)
339
- .annotate(Tool.OpenWorld, false);
340
+ .annotate(Tool.OpenWorld, false)
341
+ .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromSubagents);
342
343
const UnwatchPullRequestTool = Tool.make("unwatch_pull_request", {
344
description:
@@ -350,7 +352,8 @@ const UnwatchPullRequestTool = Tool.make("unwatch_pull_request", {
352
.annotate(Tool.Readonly, false)
353
.annotate(Tool.Destructive, false)
354
.annotate(Tool.Idempotent, true)
353
- .annotate(Tool.OpenWorld, false);
355
+ .annotate(Tool.OpenWorld, false)
356
+ .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromSubagents);
357
358
const GuideTarget = Schema.Struct({
359
url: PullRequestTargetInput.fields.url,
apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
+53
@@ -1560,6 +1560,59 @@ it.effect(
1560
}),
1561
);
1562
1563
+it.effect.each([
1564
+ { relationshipToParent: null, subagent: false },
1565
+ { relationshipToParent: "subagent", subagent: true },
1566
+] as const)(
1567
+ "ProviderSessionManagerV2 marks MCP credentials of delegated children ($relationshipToParent)",
1568
+ ({ relationshipToParent, subagent }) =>
1569
+ Effect.gen(function* () {
1570
+ const state = yield* Ref.make(emptyState);
1571
+ const mcpConfigs = yield* Ref.make<
1572
+ ReadonlyArray<McpProviderSession.McpProviderSessionConfig | undefined>
1573
+ >([]);
1574
+ const effect = Effect.gen(function* () {
1575
+ const eventSink = yield* EventSink.EventSinkV2;
1576
+ const idAllocator = yield* IdAllocator.IdAllocatorV2;
1577
+ const manager = yield* ProviderSessionManager.ProviderSessionManagerV2;
1578
+ const registry = yield* McpSessionRegistry.McpSessionRegistry;
1579
+ const now = yield* DateTime.now;
1580
+ const threadId = ThreadId.make("thread-provider-session-manager-mcp-lineage");
1581
+ const providerSessionId = yield* idAllocator.allocate.providerSession({
1582
+ providerInstanceId: modelSelection.instanceId,
1583
+ threadId,
1584
+ });
1585
+ const created = yield* makeThreadCreatedEvent({ idAllocator, threadId, now });
1586
+ const parentThreadId = ThreadId.make("thread-provider-session-manager-mcp-parent");
1587
+ yield* eventSink.write({
1588
+ events: [
1589
+ {
1590
+ ...created,
1591
+ payload: {
1592
+ ...created.payload,
1593
+ lineage:
1594
+ relationshipToParent === null
1595
+ ? created.payload.lineage
1596
+ : { parentThreadId, relationshipToParent, rootThreadId: parentThreadId },
1597
+ },
1598
+ },
1599
+ ],
1600
+ });
1601
+ yield* manager.open({ threadId, providerSessionId, modelSelection, runtimePolicy });
1602
+
1603
+ const token = (yield* Ref.get(mcpConfigs))[0]?.authorizationHeader.replace(
1604
+ /^Bearer\s+/,
1605
+ "",
1606
+ );
1607
+ assert.isDefined(token);
1608
+ assert.equal((yield* registry.resolve(token!))?.thread.subagent, subagent);
1609
+ yield* manager.close(providerSessionId);
1610
+ });
1611
+
1612
+ yield* effect.pipe(Effect.provide(layerTest({ state, idleTimeoutMs: 1_000, mcpConfigs })));
1613
+ }),
1614
+);
1615
+
1616
it.effect(
1617
"ProviderSessionManagerV2 withholds the preview capability when agent browser access is off",
1618
() =>
apps/server/src/orchestration-v2/ProviderSessionManager.ts
+8
-1
@@ -430,6 +430,10 @@ export const layerWithOptions = (
430
>(["orchestration", "worktree", "pull-requests"]);
431
if (browserToolsAvailable) capabilities.add("preview");
432
if (deviceToolsAvailable) capabilities.add("device");
433
+ const subagent = yield* projectionStore.getThread(threadId).pipe(
434
+ Effect.map((thread) => thread.lineage.relationshipToParent === "subagent"),
435
+ Effect.orElseSucceed(() => false),
436
+ );
437
const existing = yield* mcpSessions.read(threadId);
438
if (existing !== undefined) {
439
// Reserve before async validation so release cannot revoke between validation and reservation.
@@ -450,7 +454,9 @@ export const layerWithOptions = (
454
resolved.thread.threadId === threadId &&
455
resolved.thread.providerInstanceId === providerInstanceId &&
456
resolved.capabilities.has("preview") === browserToolsAvailable &&
453
- resolved.capabilities.has("device") === deviceToolsAvailable
457
+ resolved.capabilities.has("device") === deviceToolsAvailable &&
458
+ // A credential issued while the lineage read failed is replaced once it works.
459
+ (resolved.thread.subagent === true) === subagent
460
) {
461
return { mcpCredentialId: existing.providerSessionId, issued: false };
462
}
@@ -462,6 +468,7 @@ export const layerWithOptions = (
468
providerInstanceId,
469
browserToolsAvailable,
470
capabilities,
471
+ subagent,
472
});
473
yield* mcpSessions.set(credential.config);
474
reserveMcpCredential(threadId, credential.config.providerSessionId);