GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): delegated children no longer see pull request watch tool… · incognitojam/styal@a745198

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • mcp
      • McpHttpServer.test.ts
      • McpInvocationContext.ts
      • McpSessionRegistry.ts
      • toolkits/pullRequests
        • tools.ts
    • orchestration-v2
      • ProviderSessionManager.test.ts
      • ProviderSessionManager.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/mcp/McpHttpServer.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpHttpServer.test.ts
+89Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,3 +851,92 @@ it.effect("admits provider and OAuth client credentials and points only clients
851851
}),
852852
).pipe(Effect.provide(NodeHttpServer.layerTest)),
853853
);
854+
855+
it.effect("lists pull request watch tools only to threads that are not delegated children", () =>
856+
Effect.scoped(
857+
Effect.gen(function* () {
858+
const scopeFor = (
859+
token: string,
860+
subagent: boolean,
861+
): McpInvocationContext.McpThreadInvocationScope => ({
862+
environmentId,
863+
requestNamespace: token,
864+
thread: {
865+
threadId: ThreadId.make(`thread-${token}`),
866+
providerSessionId: token,
867+
providerInstanceId: ProviderInstanceId.make("codex"),
868+
subagent,
869+
},
870+
client: undefined,
871+
capabilities: new Set(["pull-requests"]),
872+
issuedAt: 1,
873+
});
874+
const scopes = new Map([
875+
["parentToken", scopeFor("parentToken", false)],
876+
["childToken", scopeFor("childToken", true)],
877+
]);
878+
const serverLayer = McpHttpServer.layerPullRequestsToolkit.pipe(
879+
Layer.provideMerge(McpHttpServer.layerMcpTransport),
880+
Layer.provide(
881+
Layer.mock(McpSessionRegistry.McpSessionRegistry)({
882+
resolve: (token) => Effect.succeed(scopes.get(token)),
883+
}),
884+
),
885+
Layer.provide(
886+
Layer.mergeAll(
887+
McpToolAccessTestkit.liveThreadsLayer,
888+
Layer.mock(ProjectService.ProjectService)({}),
889+
Layer.mock(PullRequestReviewGuideService.PullRequestReviewGuideService)({}),
890+
Layer.mock(Orchestrator.OrchestratorV2)({}),
891+
Layer.mock(ProjectionStore.ProjectionStoreV2)({}),
892+
Layer.mock(PullRequestService.PullRequestService)({}),
893+
AnalyticsService.AnalyticsService.layerTest,
894+
NodeServices.layer,
895+
),
896+
),
897+
);
898+
yield* HttpRouter.serve(serverLayer, { disableListenLog: true, disableLogger: true }).pipe(
899+
Layer.build,
900+
);
901+
const httpClient = yield* HttpClient.HttpClient;
902+
const listedTools = (token: string) =>
903+
Effect.gen(function* () {
904+
const headers = {
905+
accept: "application/json, text/event-stream",
906+
authorization: `Bearer ${token}`,
907+
};
908+
const initialize = yield* httpClient.post("/mcp", {
909+
headers,
910+
body: HttpBody.text(
911+
`{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}`,
912+
"application/json",
913+
),
914+
});
915+
const listed = yield* httpClient.post("/mcp", {
916+
headers: {
917+
...headers,
918+
"mcp-session-id": initialize.headers["mcp-session-id"]!,
919+
"mcp-protocol-version": "2025-06-18",
920+
},
921+
body: HttpBody.text(
922+
`{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}`,
923+
"application/json",
924+
),
925+
});
926+
const body = (yield* listed.json) as {
927+
readonly result: { readonly tools: ReadonlyArray<{ readonly name: string }> };
928+
};
929+
return body.result.tools.map((tool) => tool.name);
930+
});
931+
932+
const parentTools = yield* listedTools("parentToken");
933+
const childTools = yield* listedTools("childToken");
934+
expect(parentTools).toEqual(
935+
expect.arrayContaining(["link_pull_request", "watch_pull_request", "unwatch_pull_request"]),
936+
);
937+
expect(childTools).toContain("link_pull_request");
938+
expect(childTools).not.toContain("watch_pull_request");
939+
expect(childTools).not.toContain("unwatch_pull_request");
940+
}),
941+
).pipe(Effect.provide(NodeHttpServer.layerTest)),
942+
);
Collapse file

‎apps/server/src/mcp/McpInvocationContext.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpInvocationContext.ts
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "@t3tools/contracts";
1111
import * as Context from "effect/Context";
1212
import * as Effect from "effect/Effect";
13+
import * as Fiber from "effect/Fiber";
1314

1415
const ALL_MCP_CAPABILITIES = [
1516
"preview",
@@ -25,6 +26,8 @@ export interface McpThreadCaller {
2526
readonly threadId: ThreadId;
2627
readonly providerSessionId: string;
2728
readonly providerInstanceId: ProviderInstanceId;
29+
/** A delegated child task; its parent owns the work it hands back. */
30+
readonly subagent?: boolean;
2831
}
2932

3033
export interface McpClientCaller {
@@ -52,6 +55,16 @@ export class McpInvocationContext extends Context.Service<
5255
McpInvocationScope
5356
>()("@styal/cli/mcp/McpInvocationContext") {}
5457

58+
/**
59+
* `McpSchema.EnabledWhen` for tools a delegated child must not see or call.
60+
* EnabledWhen only receives the MCP client profile, so read the T3 caller from the request fiber.
61+
*/
62+
export const hiddenFromSubagents = (): boolean => {
63+
const fiber = Fiber.getCurrent();
64+
const scope = fiber && Context.getOrUndefined(fiber.context, McpInvocationContext);
65+
return scope?.thread?.subagent !== true;
66+
};
67+
5568
export type McpCapabilityError<C extends McpCapability> = C extends "preview"
5669
? PreviewAutomationUnavailableError
5770
: McpCapabilityUnavailableError;
Collapse file

‎apps/server/src/mcp/McpSessionRegistry.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpSessionRegistry.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface McpCredentialRequest {
1818
/** False omits the preview capability wherever the token is honored. Defaults to full access. */
1919
readonly browserToolsAvailable?: boolean;
2020
readonly capabilities?: ReadonlySet<McpInvocationContext.McpCapability>;
21+
readonly subagent?: boolean;
2122
}
2223

2324
export interface McpIssuedCredential {
@@ -105,6 +106,7 @@ const makeWithOptions = Effect.fn("McpSessionRegistry.make")(function* (
105106
threadId: ThreadId.make(request.threadId),
106107
providerSessionId,
107108
providerInstanceId: ProviderInstanceId.make(request.providerInstanceId),
109+
subagent: request.subagent === true,
108110
},
109111
client: undefined,
110112
capabilities: new Set<McpInvocationContext.McpCapability>([
Collapse file

‎apps/server/src/mcp/toolkits/pullRequests/tools.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/pullRequests/tools.ts
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ThreadId,
1111
} from "@t3tools/contracts";
1212
import * as Schema from "effect/Schema";
13+
import * as McpSchema from "effect/ai/McpSchema";
1314
import * as Tool from "effect/ai/Tool";
1415
import * as Toolkit from "effect/ai/Toolkit";
1516

@@ -421,7 +422,7 @@ const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {
421422

422423
const WatchPullRequestTool = Tool.make("watch_pull_request", {
423424
description:
424-
"Have styal watch an open pull request for this thread, linking it first if needed. styal 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 styal 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 styal 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.",
425+
"Have styal watch an open pull request for this thread, linking it first if needed. styal 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 styal 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 styal 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.",
425426
parameters: PullRequestTargetInput,
426427
success: WatchPullRequestResult,
427428
failure: PullRequestToolError,
@@ -431,7 +432,8 @@ const WatchPullRequestTool = Tool.make("watch_pull_request", {
431432
.annotate(Tool.Readonly, false)
432433
.annotate(Tool.Destructive, false)
433434
.annotate(Tool.Idempotent, true)
434-
.annotate(Tool.OpenWorld, false);
435+
.annotate(Tool.OpenWorld, false)
436+
.annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromSubagents);
435437

436438
const UnwatchPullRequestTool = Tool.make("unwatch_pull_request", {
437439
description:
@@ -445,7 +447,8 @@ const UnwatchPullRequestTool = Tool.make("unwatch_pull_request", {
445447
.annotate(Tool.Readonly, false)
446448
.annotate(Tool.Destructive, false)
447449
.annotate(Tool.Idempotent, true)
448-
.annotate(Tool.OpenWorld, false);
450+
.annotate(Tool.OpenWorld, false)
451+
.annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromSubagents);
449452

450453
const WatchWorkflowRunTool = Tool.make("watch_workflow_run", {
451454
description:
Collapse file

‎apps/server/src/orchestration-v2/ProviderSessionManager.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,59 @@ it.effect(
17761776
}),
17771777
);
17781778

1779+
it.effect.each([
1780+
{ relationshipToParent: null, subagent: false },
1781+
{ relationshipToParent: "subagent", subagent: true },
1782+
] as const)(
1783+
"ProviderSessionManagerV2 marks MCP credentials of delegated children ($relationshipToParent)",
1784+
({ relationshipToParent, subagent }) =>
1785+
Effect.gen(function* () {
1786+
const state = yield* Ref.make(emptyState);
1787+
const mcpConfigs = yield* Ref.make<
1788+
ReadonlyArray<McpProviderSession.McpProviderSessionConfig | undefined>
1789+
>([]);
1790+
const effect = Effect.gen(function* () {
1791+
const eventSink = yield* EventSink.EventSinkV2;
1792+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1793+
const manager = yield* ProviderSessionManager.ProviderSessionManagerV2;
1794+
const registry = yield* McpSessionRegistry.McpSessionRegistry;
1795+
const now = yield* DateTime.now;
1796+
const threadId = ThreadId.make("thread-provider-session-manager-mcp-lineage");
1797+
const providerSessionId = yield* idAllocator.allocate.providerSession({
1798+
providerInstanceId: modelSelection.instanceId,
1799+
threadId,
1800+
});
1801+
const created = yield* makeThreadCreatedEvent({ idAllocator, threadId, now });
1802+
const parentThreadId = ThreadId.make("thread-provider-session-manager-mcp-parent");
1803+
yield* eventSink.write({
1804+
events: [
1805+
{
1806+
...created,
1807+
payload: {
1808+
...created.payload,
1809+
lineage:
1810+
relationshipToParent === null
1811+
? created.payload.lineage
1812+
: { parentThreadId, relationshipToParent, rootThreadId: parentThreadId },
1813+
},
1814+
},
1815+
],
1816+
});
1817+
yield* manager.open({ threadId, providerSessionId, modelSelection, runtimePolicy });
1818+
1819+
const token = (yield* Ref.get(mcpConfigs))[0]?.authorizationHeader.replace(
1820+
/^Bearer\s+/,
1821+
"",
1822+
);
1823+
assert.isDefined(token);
1824+
assert.equal((yield* registry.resolve(token!))?.thread.subagent, subagent);
1825+
yield* manager.close(providerSessionId);
1826+
});
1827+
1828+
yield* effect.pipe(Effect.provide(layerTest({ state, idleTimeoutMs: 1_000, mcpConfigs })));
1829+
}),
1830+
);
1831+
17791832
it.effect(
17801833
"ProviderSessionManagerV2 withholds the preview capability when agent browser access is off",
17811834
() =>
Collapse file

‎apps/server/src/orchestration-v2/ProviderSessionManager.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderSessionManager.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ export const layerWithOptions = (
469469
if (browserToolsAvailable) capabilities.add("preview");
470470
if (deviceToolsAvailable) capabilities.add("device");
471471
if (hardwareToolsAvailable) capabilities.add("hardware");
472+
const subagent = yield* projectionStore.getThread(threadId).pipe(
473+
Effect.map((thread) => thread.lineage.relationshipToParent === "subagent"),
474+
Effect.orElseSucceed(() => false),
475+
);
472476
const existing = yield* mcpSessions.read(threadId);
473477
if (existing !== undefined) {
474478
// Reserve before async validation so release cannot revoke between validation and reservation.
@@ -490,7 +494,9 @@ export const layerWithOptions = (
490494
resolved.thread.providerInstanceId === providerInstanceId &&
491495
resolved.capabilities.has("preview") === browserToolsAvailable &&
492496
resolved.capabilities.has("device") === deviceToolsAvailable &&
493-
resolved.capabilities.has("hardware") === hardwareToolsAvailable
497+
resolved.capabilities.has("hardware") === hardwareToolsAvailable &&
498+
// A credential issued while the lineage read failed is replaced once it works.
499+
(resolved.thread.subagent === true) === subagent
494500
) {
495501
return { mcpCredentialId: existing.providerSessionId, issued: false };
496502
}
@@ -512,6 +518,7 @@ export const layerWithOptions = (
512518
providerInstanceId,
513519
browserToolsAvailable,
514520
capabilities,
521+
subagent,
515522
});
516523
yield* mcpSessions.set({
517524
...credential.config,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.