The best way to control Claude Code, Codex and more from any computer or phone
fix(server): remote delegate_task runs on the driver it names (#34790)
Julius Marminge committed
Nov 11, 2026 at 22:57 UTC
6ba3de70aff98460e573ffc57773e45e148026ba
2 files changed
+113
-4
apps/server/src/peer/RemoteDelegation.test.ts
+55
-2
@@ -15,6 +15,7 @@ import {
15
type Project,
16
type RepositoryIdentity,
17
RunId,
18
+ type ServerProvider,
19
ThreadId,
20
TurnItemId,
21
} from "@t3tools/contracts";
@@ -561,9 +562,15 @@ const boxToolkitLayer = (thread: BoxThread) => {
562
),
563
),
564
Layer.provide(
564
- Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
565
+ Layer.mock(ProviderRegistry.ProviderRegistry)({
566
+ getProviders: Effect.succeed([boxClaude]),
567
+ }),
568
+ ),
569
+ Layer.provide(
570
+ Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
571
+ list: () => Effect.succeed([boxClaude.instanceId]),
572
+ }),
573
),
566
- Layer.provide(Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({})),
574
Layer.provide(Layer.mock(ScheduledTaskService.ScheduledTaskService)({})),
575
Layer.provide(
576
Layer.mock(ProjectService.ProjectService)({
@@ -597,6 +604,23 @@ const mcpClient = McpSchema.McpServerClient.of({
604
getClient: Effect.die("unused"),
605
});
606
607
+/** The box's only provider: a Claude instance, under its own id. */
608
+const boxClaude: ServerProvider = {
609
+ instanceId: ProviderInstanceId.make("claude-box"),
610
+ driver: ProviderDriverKind.make("claudeAgent"),
611
+ enabled: true,
612
+ installed: true,
613
+ version: "test",
614
+ status: "ready",
615
+ auth: { status: "authenticated" },
616
+ checkedAt: "2026-09-13T00:00:00.000Z",
617
+ models: [
618
+ { slug: "claude-sonnet-4-6", name: "Claude Sonnet", isCustom: false, capabilities: null },
619
+ ],
620
+ slashCommands: [],
621
+ skills: [],
622
+};
623
+
624
const adapter = {
625
instanceId,
626
driver,
@@ -1193,6 +1217,35 @@ it.effect("a task named only by environment inherits the parent's model, within
1217
).pipe(Effect.provide(NodeHttpServer.layerTest)),
1218
);
1219
1220
+it.effect("a task naming another driver there never runs its model on the parent's instance", () =>
1221
+ Effect.scoped(
1222
+ Effect.gen(function* () {
1223
+ const thread = yield* makeBoxThread;
1224
+ const b = yield* serveBox(thread);
1225
+ const offers = yield* SubscriptionRef.make<
1226
+ ReadonlyArray<ProviderContinuationRequests.ProviderContinuationRequest>
1227
+ >([]);
1228
+ const database = yield* SqlitePersistence.layerMemory.pipe(Layer.build);
1229
+ const a = yield* makeLaptop(database, offers);
1230
+ yield* linkTo(a.links, b, "full-access");
1231
+ yield* seedParent(a);
1232
+
1233
+ const result = yield* a.call("delegate_task", {
1234
+ task: "Run the suite on the box.",
1235
+ target: {
1236
+ environmentId: box.environmentId,
1237
+ driverKind: "claudeAgent",
1238
+ model: "claude-sonnet-4-6",
1239
+ },
1240
+ });
1241
+ expect(result.isError).toBe(false);
1242
+ expect((yield* Ref.get(thread.launchedWith))?.modelSelection.instanceId).toBe(
1243
+ boxClaude.instanceId,
1244
+ );
1245
+ }),
1246
+ ).pipe(Effect.provide(NodeHttpServer.layerTest)),
1247
+);
1248
+
1249
it.effect("refuses worktree isolation for a task there before launching anything", () =>
1250
Effect.scoped(
1251
Effect.gen(function* () {
apps/server/src/peer/RemoteDelegation.ts
+58
-2
@@ -2,6 +2,8 @@ import {
2
CommandId,
3
type EnvironmentId,
4
NodeId,
5
+ OrchestratorMcpCapabilitiesInput,
6
+ OrchestratorMcpCapabilitiesResult,
7
OrchestratorMcpFailure,
8
type OrchestratorMcpDelegateTaskInput,
9
type OrchestratorMcpTaskCancelResult,
@@ -27,7 +29,7 @@ import * as Option from "effect/Option";
29
import * as Schedule from "effect/Schedule";
30
import * as Scope from "effect/Scope";
31
import * as Stream from "effect/Stream";
30
-import type * as Tool from "effect/ai/Tool";
32
+import * as Tool from "effect/ai/Tool";
33
import { withExecutedModelNote } from "@t3tools/provider-core/server/subagentProjection";
34
35
import type * as McpInvocationContext from "../mcp/McpInvocationContext.ts";
@@ -66,6 +68,14 @@ export const FollowRetrySchedule = Context.Reference<Schedule.Schedule<unknown>>
68
69
type ThreadScope = McpInvocationContext.McpThreadInvocationScope;
70
71
+/** `orchestrator_capabilities` there. Its toolkit imports this module, so it is described here. */
72
+const RemoteCapabilitiesTool = Tool.make("orchestrator_capabilities", {
73
+ parameters: OrchestratorMcpCapabilitiesInput,
74
+ success: OrchestratorMcpCapabilitiesResult,
75
+ failure: OrchestratorMcpFailure,
76
+ failureMode: "return",
77
+});
78
+
79
/**
80
* `delegate_task` to a linked environment. The task's child is an ordinary
81
* thread there, launched through the link; the parent here records the task
@@ -202,6 +212,45 @@ const make = Effect.gen(function* () {
212
});
213
});
214
215
+ /** The instance there of the driver the caller named, preferring the one this thread runs on, as a task here does. */
216
+ const resolveRemoteInstance = Effect.fn("RemoteDelegation.resolveRemoteInstance")(function* (
217
+ scope: ThreadScope,
218
+ environmentId: EnvironmentId,
219
+ requested: {
220
+ readonly driverKind: ProviderDriverKind;
221
+ readonly providerInstanceId: ProviderInstanceId | undefined;
222
+ readonly inheritedInstanceId: ProviderInstanceId;
223
+ },
224
+ ) {
225
+ const { providers } = yield* forwarding.call(scope, RemoteCapabilitiesTool, environmentId, {});
226
+ if (requested.providerInstanceId !== undefined) {
227
+ const named = providers.find(
228
+ (provider) => provider.providerInstanceId === requested.providerInstanceId,
229
+ );
230
+ if (named !== undefined && named.driverKind !== requested.driverKind) {
231
+ return yield* new OrchestratorMcpFailure({
232
+ code: "invalid_request",
233
+ message: `Provider instance ${named.providerInstanceId} there uses driver ${named.driverKind}, not ${requested.driverKind}.`,
234
+ });
235
+ }
236
+ return requested.providerInstanceId;
237
+ }
238
+ const candidates = providers.filter(
239
+ (provider) => provider.driverKind === requested.driverKind && provider.canRunChildTask,
240
+ );
241
+ const chosen =
242
+ candidates.find(
243
+ (provider) => provider.providerInstanceId === requested.inheritedInstanceId,
244
+ ) ?? candidates[0];
245
+ if (chosen === undefined) {
246
+ return yield* new OrchestratorMcpFailure({
247
+ code: "provider_unavailable",
248
+ message: `No instance of driver ${requested.driverKind} there can run a child task. orchestrator_capabilities with this environmentId lists its providers.`,
249
+ });
250
+ }
251
+ return chosen.providerInstanceId;
252
+ });
253
+
254
const delegate: RemoteDelegation["Service"]["delegate"] = Effect.fn("RemoteDelegation.delegate")(
255
function* (scope, input) {
256
const parent = yield* threads.getThreadRecords(scope.thread.threadId, ["runs"]).pipe(
@@ -240,7 +289,14 @@ const make = Effect.gen(function* () {
289
// The provider and model inherit as they do for a task here. Another
290
// provider there has no model to inherit, so the caller names one.
291
const inherited = parent.thread.modelSelection;
243
- const instanceId = target.providerInstanceId ?? inherited.instanceId;
292
+ const instanceId =
293
+ target.driverKind === undefined
294
+ ? (target.providerInstanceId ?? inherited.instanceId)
295
+ : yield* resolveRemoteInstance(scope, target.environmentId, {
296
+ driverKind: target.driverKind,
297
+ providerInstanceId: target.providerInstanceId,
298
+ inheritedInstanceId: inherited.instanceId,
299
+ });
300
const model =
301
target.model ?? (instanceId === inherited.instanceId ? inherited.model : undefined);
302
if (model === undefined) {