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): a follow-up to a finished remote task is a new task that… · incognitojam/styal@4b8ed6c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • mcp
      • McpToolAccess.test.ts
      • McpToolAccess.ts
      • toolkits/orchestrator
        • handlers.ts
        • tools.ts
    • orchestration-v2
      • Orchestrator.ts
    • peer
      • PeerForwarding.test.ts
      • RemoteDelegation.test.ts
      • RemoteDelegation.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpToolAccess.test.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as AnalyticsService from "../telemetry/AnalyticsService.ts";
22
import * as OrchestratorHandlers from "./toolkits/orchestrator/handlers.ts";
33
import { OrchestratorToolkit } from "./toolkits/orchestrator/tools.ts";
4+
import * as RemoteDelegation from "../peer/RemoteDelegation.ts";
45
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
56
import * as PeerLinkRequests from "../peer/PeerLinkRequests.ts";
67
import * as PeerLinks from "../peer/PeerLinks.ts";
@@ -833,6 +834,7 @@ it.effect.each([
833834
Effect.gen(function* () {
834835
const dependencies = Layer.mergeAll(
835836
NodeCrypto.layer,
837+
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
836838
Layer.succeed(McpInvocationContext.McpInvocationContext, scope),
837839
Layer.mock(ThreadManagement.ThreadManagementService)({
838840
getThreadShell: (threadId) => Effect.succeed(shells.get(threadId) ?? null),
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpToolAccess.ts
+44-2Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const refuseOutsideConstruction = (token: symbol) => {
4747
let declare: <P, A, E, R>(
4848
handle: (params: P) => Effect.Effect<A, E, R>,
4949
remote: RemoteCheck<P> | undefined,
50+
forwarded?: Forwarded<P, A, E, R>,
5051
) => Declaration<(params: P) => Effect.Effect<A, E, R>>;
5152

5253
/**
@@ -59,6 +60,16 @@ type RemoteCheck<P> = (
5960
) => Effect.Effect<unknown, OrchestratorMcpFailure, Effect.Services<typeof writingCaller>>;
6061
let remoteCheckOf: <Handler>(declaration: Declaration<Handler>) => RemoteCheck<never> | undefined;
6162

63+
/** What a call answered in a linked environment does here before it returns. */
64+
type Forwarded<P, A, E, R> = (
65+
params: P,
66+
environmentId: EnvironmentId,
67+
result: A,
68+
) => Effect.Effect<A, E, R>;
69+
let forwardedOf: <Handler>(
70+
declaration: Declaration<Handler>,
71+
) => Forwarded<never, unknown, unknown, unknown> | undefined;
72+
6273
type CheckedHandlerOf<D> = D extends Declaration<infer Handler> ? Handler : never;
6374

6475
interface CheckedHandler extends Struct.Lambda {
@@ -75,19 +86,29 @@ let handlersLayer: <Tools extends Record<string, Tool.Any>, EX, RX>(
7586
export class Declaration<out Handler> {
7687
readonly #handle: Handler;
7788
readonly #remote: RemoteCheck<never> | undefined;
89+
readonly #forwarded: Forwarded<never, unknown, unknown, unknown> | undefined;
7890
private constructor(
7991
token: typeof builtHere,
8092
handle: Handler,
8193
remote: RemoteCheck<never> | undefined,
94+
forwarded: Forwarded<never, unknown, unknown, unknown> | undefined,
8295
) {
8396
refuseOutsideConstruction(token);
8497
this.#handle = handle;
8598
this.#remote = remote;
99+
this.#forwarded = forwarded;
86100
}
87101
static {
88-
declare = (handle, remote) => new Declaration(builtHere, handle, remote);
102+
declare = (handle, remote, forwarded) =>
103+
new Declaration(
104+
builtHere,
105+
handle,
106+
remote,
107+
forwarded as Forwarded<never, unknown, unknown, unknown> | undefined,
108+
);
89109
checkedHandler = Struct.lambda<CheckedHandler>((declaration) => declaration.#handle);
90110
remoteCheckOf = (declaration) => declaration.#remote;
111+
forwardedOf = (declaration) => declaration.#forwarded;
91112
}
92113
}
93114

@@ -315,6 +336,20 @@ export const either = <P, A, E, R, A2, E2, R2>(
315336
);
316337
};
317338

339+
/**
340+
* `declaration`, whose result from a linked environment then goes through
341+
* `forwarded` here, for what this environment records about the call.
342+
*/
343+
export const afterForwarding = <P, A, E, R, E2, R2>(
344+
declaration: Declaration<(params: P) => Effect.Effect<A, E, R>>,
345+
forwarded: Forwarded<P, A, E2, R2>,
346+
) =>
347+
declare(
348+
checkedHandler(declaration) as (params: P) => Effect.Effect<A, E | E2, R | R2>,
349+
remoteCheckOf(declaration) as RemoteCheck<P> | undefined,
350+
forwarded,
351+
);
352+
318353
const fullAccessRequired =
319354
"This operation needs a live Full access thread in default interaction mode, or a Full access client.";
320355

@@ -440,6 +475,9 @@ const routed = Effect.fn("McpToolAccess.routed")(function* <Tools extends Record
440475
const tool = toolkit.tools[name];
441476
if (tool === undefined || !takesLinkedEnvironment(tool)) continue;
442477
const remote = remoteCheckOf(declaration);
478+
const forwarded = forwardedOf(declaration) as
479+
| Forwarded<object, unknown, Tool.Failure<Tools[keyof Tools]>, never>
480+
| undefined;
443481
if (remote === undefined)
444482
return yield* Effect.die(
445483
`${name} takes a linked environment, but it acts as its calling thread, which is here.`,
@@ -455,7 +493,11 @@ const routed = Effect.fn("McpToolAccess.routed")(function* <Tools extends Record
455493
if (scope.linkedEnvironments === false) return yield* PeerForwarding.linkedEnvironmentsOff;
456494
yield* (remote as RemoteCheck<typeof params>)(params);
457495
if (Option.isNone(forwarding)) return yield* linksUnavailable;
458-
return yield* forwarding.value.call(scope, tool, target, { ...params, environmentId });
496+
const result = yield* forwarding.value.call(scope, tool, target, {
497+
...params,
498+
environmentId,
499+
});
500+
return forwarded === undefined ? result : yield* forwarded(params, target, result);
459501
});
460502
}
461503
return handlers as Toolkit.HandlersFrom<Tools>;
Collapse file

‎apps/server/src/mcp/toolkits/orchestrator/handlers.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/orchestrator/handlers.ts
+23-13Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect";
55
import * as PeerForwarding from "../../../peer/PeerForwarding.ts";
66
import * as PeerLinkRequests from "../../../peer/PeerLinkRequests.ts";
77
import * as PeerLinks from "../../../peer/PeerLinks.ts";
8+
import * as RemoteDelegation from "../../../peer/RemoteDelegation.ts";
89
import { readCaller } from "../../threadAccess.ts";
910
import * as McpInvocationContext from "../../McpInvocationContext.ts";
1011
import * as McpToolAccess from "../../McpToolAccess.ts";
@@ -168,22 +169,31 @@ export const handlers = {
168169
return yield* service.update(scope, input);
169170
}),
170171
),
171-
t3_thread_send: McpToolAccess.writesThreads(
172-
(input) => [input.threadId],
173-
(input) =>
172+
t3_thread_send: McpToolAccess.afterForwarding(
173+
McpToolAccess.writesThreads(
174+
(input) => [input.threadId],
175+
(input) =>
176+
Effect.gen(function* () {
177+
const scope = yield* McpInvocationContext.McpInvocationContext;
178+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
179+
return yield* service.sendToThread(scope, input);
180+
}),
181+
{
182+
// Steering or restarting a turn stays a normal send, under the normal limits.
183+
reportTarget: (input) =>
184+
input.freshContext !== true &&
185+
(input.mode === undefined || input.mode === "auto" || input.mode === "queue")
186+
? input.threadId
187+
: undefined,
188+
},
189+
),
190+
// There the thread's parent is here, so only this side can make a follow-up a task.
191+
(input, environmentId, sent) =>
174192
Effect.gen(function* () {
175193
const scope = yield* McpInvocationContext.McpInvocationContext;
176-
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
177-
return yield* service.sendToThread(scope, input);
194+
const remote = yield* RemoteDelegation.RemoteDelegation;
195+
return yield* remote.followUp(scope, environmentId, input, sent);
178196
}),
179-
{
180-
// Steering or restarting a turn stays a normal send, under the normal limits.
181-
reportTarget: (input) =>
182-
input.freshContext !== true &&
183-
(input.mode === undefined || input.mode === "auto" || input.mode === "queue")
184-
? input.threadId
185-
: undefined,
186-
},
187197
),
188198
t3_thread_wait: McpToolAccess.reads((input) =>
189199
Effect.gen(function* () {
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/orchestrator/tools.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import * as ThreadManagementService from "../../../orchestration-v2/ThreadManage
4646
import * as PeerForwarding from "../../../peer/PeerForwarding.ts";
4747
import * as PeerLinkRequests from "../../../peer/PeerLinkRequests.ts";
4848
import * as PeerLinks from "../../../peer/PeerLinks.ts";
49+
import * as RemoteDelegation from "../../../peer/RemoteDelegation.ts";
4950
import * as McpInvocationContext from "../../McpInvocationContext.ts";
5051
import * as OrchestratorMcpService from "../../OrchestratorMcpService.ts";
5152
import * as ThreadMetadataMcpService from "../../ThreadMetadataMcpService.ts";
@@ -63,6 +64,8 @@ const linkingDependencies = [
6364
PeerLinkRequests.PeerLinkRequests,
6465
PeerLinks.PeerLinks,
6566
];
67+
/** A send there may record a follow-up to a remote task. */
68+
const sendDependencies = [...dependencies, RemoteDelegation.RemoteDelegation];
6669
const threadMetadataDependencies = [
6770
McpInvocationContext.McpInvocationContext,
6871
ThreadManagementService.ThreadManagementService,
@@ -279,7 +282,7 @@ const ThreadSendTool = Tool.make("t3_thread_send", {
279282
success: OrchestratorMcpThreadSendResult,
280283
failure: OrchestratorMcpFailure,
281284
failureMode: "return",
282-
dependencies,
285+
dependencies: sendDependencies,
283286
})
284287
.annotate(Tool.Title, "Send to a T3 thread")
285288
.annotate(Tool.Destructive, true)
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts
+25-7Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9870,20 +9870,35 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
98709870
) {
98719871
const { followUpOf } = command.remoteChild;
98729872
const parentProjection = yield* projectionStore
9873-
.getThreadRecords(
9874-
command.parentThreadId,
9875-
["runs", "providerTurns", "attempts", "subagents"],
9876-
{ subagentIds: followUpOf === undefined ? [] : [followUpOf] },
9877-
)
9873+
.getThreadRecords(command.parentThreadId, ["runs", "providerTurns", "attempts", "subagents"])
98789874
.pipe(
98799875
Effect.mapError(
98809876
(cause) => new OrchestratorProjectionError({ threadId: command.parentThreadId, cause }),
98819877
),
98829878
);
9879+
// Explicit sends and later-run observers can discover the same remote run concurrently.
9880+
if (
9881+
command.remoteChild.runId !== undefined &&
9882+
parentProjection.subagents.some(
9883+
(task) =>
9884+
task.remoteChild?.environmentId === command.remoteChild.environmentId &&
9885+
task.remoteChild.threadId === command.remoteChild.threadId &&
9886+
task.remoteChild.runId === command.remoteChild.runId,
9887+
)
9888+
)
9889+
return;
9890+
const followsUp = parentProjection.subagents.some(
9891+
(task) =>
9892+
task.result !== null &&
9893+
task.remoteChild?.environmentId === command.remoteChild.environmentId &&
9894+
task.remoteChild.threadId === command.remoteChild.threadId,
9895+
);
98839896
const followed = parentProjection.subagents.find(
98849897
(task) =>
98859898
task.id === followUpOf &&
9886-
task.remoteChild?.followsAfterRunId !== undefined &&
9899+
task.result !== null &&
9900+
task.remoteChild !== undefined &&
9901+
(task.remoteChild.followsAfterRunId !== undefined || command.parentRunId !== undefined) &&
98879902
task.remoteChild.environmentId === command.remoteChild.environmentId &&
98889903
task.remoteChild.threadId === command.remoteChild.threadId,
98899904
);
@@ -9920,7 +9935,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
99209935
parentRun === undefined ||
99219936
parentRun.rootNodeId === null ||
99229937
parentNodeId == null ||
9923-
(followed === undefined && !isActiveRun(parentRun))
9938+
(followed === undefined &&
9939+
(followsUp
9940+
? parentRun.id !== followUpOwnerRun(parentProjection.runs)?.id
9941+
: !isActiveRun(parentRun)))
99249942
) {
99259943
return yield* new OrchestratorDispatchError({
99269944
commandId: command.commandId,
Collapse file

‎apps/server/src/peer/PeerForwarding.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/peer/PeerForwarding.test.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,10 @@ const makeLaptop = Effect.gen(function* () {
320320
Layer.mock(ProjectCloneTracker.ProjectCloneTracker)({}),
321321
Layer.mock(SecretRequests.SecretRequests)({}),
322322
ServerSettings.layerTest(),
323-
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
323+
// No thread here delegated to the box, so a send there is no follow-up.
324+
Layer.mock(RemoteDelegation.RemoteDelegation)({
325+
followUp: (_scope, _environmentId, _request, sent) => Effect.succeed(sent),
326+
}),
324327
Layer.mock(PeerLinkRequests.PeerLinkRequests)({}),
325328
),
326329
),

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.