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 — feat(server): a task delegated to another environment can run in its … · mediavee/t3code@5a25d91

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • environment
      • ServerEnvironment.ts
    • mcp
      • OrchestratorMcpService.test.ts
      • OrchestratorMcpService.ts
    • orchestration-v2
      • Orchestrator.ts
    • peer
      • PeerForwarding.ts
      • PeerLinks.testkit.ts
      • PeerLinks.ts
      • PeerWorktreeBase.ts
      • RemoteDelegation.test.ts
      • RemoteDelegation.ts
      • http.ts
    • provider
      • agentContextBudget.json
    • server.ts
    • vcs
      • GitVcsDriver.ts
  • docs
    • orchestration-v2
      • orchestrator-mcp-server.md
    • user
      • remote-access.md
  • packages/contracts/src
    • environment.ts
    • environmentHttp.ts
    • orchestrationV2.ts
    • orchestratorMcp.ts
    • peerLink.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/environment/ServerEnvironment.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/environment/ServerEnvironment.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export const make = Effect.gen(function* () {
302302
linkThreadStream: true,
303303
linkClientPairing: true,
304304
linkParentDone: true,
305+
linkWorktreeBase: true,
305306
linkPairingForLink: true,
306307
mcpApprovalCodes: true,
307308
peerLinkPairingCodes: true,
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.test.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3755,7 +3755,7 @@ describe("OrchestratorMcpService provider resolution", () => {
37553755
const parent = yield* orchestrator.getThreadProjection(parentThreadId);
37563756
return { taskId: parent.subagents[0]!.id };
37573757
}).pipe(Effect.orDie),
3758-
runStatus: () => Effect.succeed(null),
3758+
readThere: () => Effect.succeed(null),
37593759
});
37603760
}),
37613761
).pipe(Layer.provide(layerWatchedThreads));
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.ts
+14-34Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,9 +2297,13 @@ const make = Effect.gen(function* () {
22972297
waitTimedOut: boolean,
22982298
acknowledgeTerminal: boolean,
22992299
): Effect.fn.Return<OrchestratorMcpDelegateTaskResult, OrchestratorMcpFailure> {
2300+
// A task with its result needs nothing more from there.
2301+
const there = task.result === null ? yield* remoteDelegation.readThere(scope, task) : null;
2302+
// A task with its result keeps the checkout its result was read from.
2303+
const worktree = there?.worktree ?? task.remoteChild?.worktree;
23002304
const status: OrchestratorMcpDelegateTaskResult["status"] =
23012305
task.result === null
2302-
? (yield* remoteDelegation.runStatus(scope, task)) === "starting"
2306+
? there?.status === "starting"
23032307
? "starting"
23042308
: "running"
23052309
: task.status === "completed" ||
@@ -2351,6 +2355,7 @@ const make = Effect.gen(function* () {
23512355
remoteChild: task.remoteChild,
23522356
link: formatThreadLink(task.remoteChild, task.remoteChild.title),
23532357
}),
2358+
...(worktree == null ? {} : { worktree }),
23542359
childRunId: null,
23552360
childNodeId: task.id,
23562361
status,
@@ -2428,39 +2433,8 @@ const make = Effect.gen(function* () {
24282433
effect.pipe(Effect.timeoutOption(Duration.millis(timeoutMs)), Effect.map(Option.flatten)),
24292434
);
24302435

2431-
const refExists = (cwd: string, revision: string) =>
2432-
gitDriver.resolveCommit({ cwd, revision }).pipe(
2433-
Effect.as(true),
2434-
Effect.orElseSucceed(() => false),
2435-
);
2436-
2437-
const resolveScheduledTaskBaseRef = Effect.fn(
2438-
"OrchestratorMcpService.resolveScheduledTaskBaseRef",
2439-
)(function* (cwd: string) {
2440-
const remoteName = yield* gitDriver
2441-
.resolvePrimaryRemoteName(cwd)
2442-
.pipe(Effect.orElseSucceed(() => null));
2443-
const conventional = ["main", "master"];
2444-
if (remoteName !== null) {
2445-
const remoteDefault = yield* gitDriver
2446-
.resolveDefaultBranchName(cwd, remoteName)
2447-
.pipe(Effect.orElseSucceed(() => null));
2448-
// Fetch does not update a recorded HEAD, so it can outlive the branch it names.
2449-
for (const branch of remoteDefault === null
2450-
? conventional
2451-
: [remoteDefault, ...conventional]) {
2452-
// Launch resolves a bare name through a local branch's upstream, or else assumes `origin`.
2453-
if (yield* refExists(cwd, `refs/remotes/${remoteName}/${branch}`)) {
2454-
return `${remoteName}/${branch}`;
2455-
}
2456-
}
2457-
}
2458-
// Local-only repositories, or a remote with neither a usable HEAD nor a conventional branch.
2459-
for (const branch of conventional) {
2460-
if (yield* refExists(cwd, `refs/heads/${branch}`)) return branch;
2461-
}
2462-
return "main";
2463-
});
2436+
const resolveScheduledTaskBaseRef = (cwd: string) =>
2437+
GitVcsDriver.defaultWorktreeBaseRef(gitDriver, cwd);
24642438

24652439
const scheduledTaskWorkspaceStrategy = Effect.fn(
24662440
"OrchestratorMcpService.scheduledTaskWorkspaceStrategy",
@@ -3077,6 +3051,12 @@ const make = Effect.gen(function* () {
30773051
? result
30783052
: { ...result, runtimeModeSteppedDown };
30793053
}
3054+
if (input.baseRef !== undefined) {
3055+
return yield* failure(
3056+
"invalid_request",
3057+
'baseRef is for a task in another environment (target.environmentId). Here, isolation "worktree" starts from this checkout\'s commit.',
3058+
);
3059+
}
30803060
const { scope, parent } = yield* loadThreadCaller(callerScope, "delegate_task");
30813061
// Another project here gets its own thread, recorded and followed as a task there would be.
30823062
const targetProject =
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Orchestrator.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10968,7 +10968,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1096810968
const now = yield* DateTime.now;
1096910969
const updatedTask: OrchestrationV2Subagent = {
1097010970
...task,
10971-
remoteChild,
10971+
remoteChild:
10972+
command.worktree === undefined
10973+
? remoteChild
10974+
: { ...remoteChild!, worktree: command.worktree },
1097210975
status: command.status,
1097310976
result: command.result,
1097410977
...(command.executedModel === undefined ? {} : { executedModel: command.executedModel }),
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/peer/PeerForwarding.ts
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
OrchestratorMcpThreadWaitInput,
1010
OrchestratorMcpThreadWaitResult,
1111
type PeerLinkError,
12+
type PeerLinkWorktreeBaseRequest,
13+
type PeerLinkWorktreeBaseResult,
1214
RuntimeMode,
1315
} from "@t3tools/contracts";
1416
import * as Context from "effect/Context";
@@ -72,6 +74,18 @@ export class PeerForwarding extends Context.Service<
7274
environmentId: EnvironmentId,
7375
input: OrchestratorMcpThreadWaitInput,
7476
) => Effect.Effect<OrchestratorMcpThreadWaitResult, OrchestratorMcpFailure>;
77+
/**
78+
* The base a delegated task's new worktree in a project there starts from, resolved and
79+
* checked there. Starts work, so it holds to the same gates as a launch there.
80+
*/
81+
readonly worktreeBase: (
82+
scope: Scope,
83+
environmentId: EnvironmentId,
84+
request: PeerLinkWorktreeBaseRequest,
85+
) => Effect.Effect<
86+
PeerLinkWorktreeBaseResult | { readonly outcome: "refused"; readonly message: string },
87+
OrchestratorMcpFailure
88+
>;
7589
/** The environments this one links to, as an agent sees them. */
7690
readonly links: (
7791
scope: Scope,
@@ -336,8 +350,25 @@ const make = Effect.gen(function* () {
336350
},
337351
);
338352

353+
const worktreeBase: PeerForwarding["Service"]["worktreeBase"] = Effect.fn(
354+
"PeerForwarding.worktreeBase",
355+
)(function* (scope, environmentId, request) {
356+
yield* requireEnabled;
357+
yield* forwardingCaller(scope);
358+
return yield* links.worktreeBase(environmentId, request).pipe(
359+
Effect.mapError(
360+
(error) =>
361+
new OrchestratorMcpFailure({
362+
code: error.reason === "incompatible" ? "invalid_request" : "orchestration_error",
363+
message: error.message,
364+
}),
365+
),
366+
);
367+
});
368+
339369
return PeerForwarding.of({
340370
call,
371+
worktreeBase,
341372
readThread,
342373
interruptThread,
343374
waitForThread,
Collapse file

‎apps/server/src/peer/PeerLinks.testkit.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/peer/PeerLinks.testkit.ts
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
3131
import * as ServerHttp from "../http.ts";
3232
import * as McpHttpServer from "../mcp/McpHttpServer.ts";
3333
import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts";
34+
import * as ThreadLaunch from "../orchestration-v2/ThreadLaunchService.ts";
3435
import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts";
36+
import * as ProjectService from "../project/ProjectService.ts";
37+
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
3538
import * as Sqlite from "../persistence/Sqlite.ts";
3639
import * as PeerHttp from "./http.ts";
3740
import * as PeerClientPairing from "./PeerClientPairing.ts";
3841
import * as PeerLinks from "./PeerLinks.ts";
42+
import * as PeerWorktreeBase from "./PeerWorktreeBase.ts";
3943
import * as ServerSettings from "../serverSettings.ts";
4044
import * as PeerMcpClient from "./PeerMcpClient.ts";
4145
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
@@ -90,6 +94,14 @@ export const servePeer = <E, R, E2 = never, R2 = never>(
9094
threads: Layer.Layer<ThreadManagement.ThreadManagementService> = Layer.mock(
9195
ThreadManagement.ThreadManagementService,
9296
)({}),
97+
/** Its projects, launches and Git, as its worktree-base route sees them. */
98+
worktrees: Layer.Layer<
99+
ProjectService.ProjectService | ThreadLaunch.ThreadLaunchService | GitVcsDriver.GitVcsDriver
100+
> = Layer.mergeAll(
101+
Layer.mock(ProjectService.ProjectService)({}),
102+
Layer.mock(ThreadLaunch.ThreadLaunchService)({}),
103+
Layer.mock(GitVcsDriver.GitVcsDriver)({}),
104+
),
93105
) =>
94106
Effect.gen(function* () {
95107
const descriptor = yield* Ref.make(initial);
@@ -143,7 +155,11 @@ export const servePeer = <E, R, E2 = never, R2 = never>(
143155
),
144156
),
145157
Layer.provide(
146-
PeerHttp.layer.pipe(Layer.provide(PeerClientPairing.layerIssuer), Layer.provide(threads)),
158+
PeerHttp.layer.pipe(
159+
Layer.provide(PeerClientPairing.layerIssuer),
160+
Layer.provide(threads),
161+
Layer.provide(PeerWorktreeBase.layer.pipe(Layer.provide(worktrees))),
162+
),
147163
),
148164
Layer.provide(ServerHttp.layerServerEnvironmentHttpApi),
149165
Layer.provide(AuthHttp.layerAuthenticatedAuth),
Collapse file

‎apps/server/src/peer/PeerLinks.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/peer/PeerLinks.ts
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
type PeerLinkName,
1313
type PeerLinkParentDoneRequest,
1414
type PeerLinkParentDoneResult,
15+
type PeerLinkWorktreeBaseRequest,
16+
type PeerLinkWorktreeBaseResult,
1517
type PeerLinkSummary,
1618
} from "@t3tools/contracts";
1719
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
@@ -59,6 +61,8 @@ export const probeTimeout = (origin: string) =>
5961
isLocalLoopbackHost(new URL(origin).hostname) ? Duration.seconds(3) : Duration.seconds(10);
6062
/** How long a listing waits on a link's addresses; a real call still gives a waking peer `probeTimeout`. */
6163
const LIST_PROBE_TIMEOUT = Duration.seconds(3);
64+
/** A worktree base there may be fetched from its remote first. */
65+
const WORKTREE_BASE_TIMEOUT = Duration.seconds(60);
6266

6367
/** Node's TLS verification code in a failed request's cause chain, if any. */
6468
export const certificateErrorCode = (error: unknown) => {
@@ -146,6 +150,17 @@ export class PeerLinks extends Context.Service<
146150
environmentId: EnvironmentId,
147151
request: PeerLinkParentDoneRequest,
148152
) => Effect.Effect<PeerLinkParentDoneResult["outcome"] | "refused", PeerLinkError>;
153+
/**
154+
* The base a delegated task's worktree in a project there starts from, checked there.
155+
* `refused`: that environment does not let this link start work in a new checkout there.
156+
*/
157+
readonly worktreeBase: (
158+
environmentId: EnvironmentId,
159+
request: PeerLinkWorktreeBaseRequest,
160+
) => Effect.Effect<
161+
PeerLinkWorktreeBaseResult | { readonly outcome: "refused"; readonly message: string },
162+
PeerLinkError
163+
>;
149164
}
150165
>()("t3/peer/PeerLinks") {}
151166

@@ -874,6 +889,46 @@ const make = Effect.gen(function* () {
874889
);
875890
});
876891

892+
const worktreeBase: PeerLinks["Service"]["worktreeBase"] = Effect.fn("PeerLinks.worktreeBase")(
893+
function* (environmentId, request) {
894+
const peer = yield* resolve(environmentId);
895+
const { label } = peer.link;
896+
if (peer.capabilities.linkWorktreeBase !== true) {
897+
return yield* new PeerLinkError({
898+
reason: "incompatible",
899+
message: `${label} runs a T3 Code version that does not support worktree isolation for a delegated task. Update it, or omit isolation to run in that project's checkout.`,
900+
});
901+
}
902+
const client = yield* clientFor(peer.url);
903+
return yield* client.peerLink
904+
.worktreeBase({ headers: { authorization: `Bearer ${peer.token}` }, payload: request })
905+
.pipe(
906+
Effect.timeout(WORKTREE_BASE_TIMEOUT),
907+
Effect.catchTags({
908+
EnvironmentHttpForbiddenError: (error) =>
909+
Effect.succeed({
910+
outcome: "refused" as const,
911+
message: `${label}: ${error.message}`,
912+
}),
913+
EnvironmentHttpUnauthorizedError: () =>
914+
Effect.fail(
915+
new PeerLinkError({
916+
reason: "expired",
917+
message: `${label} no longer accepts this link's session for this. Link it again with a new pairing code from ${label}.`,
918+
}),
919+
),
920+
}),
921+
Effect.catchIf(
922+
(error) => !isPeerLinkError(error),
923+
() =>
924+
Effect.fail(
925+
new PeerLinkError({ reason: "unreachable", message: `${label} did not answer.` }),
926+
),
927+
),
928+
);
929+
},
930+
);
931+
877932
return PeerLinks.of({
878933
enabled,
879934
link,
@@ -886,6 +941,7 @@ const make = Effect.gen(function* () {
886941
recordOutcome,
887942
recordExpiry,
888943
tellParentDone,
944+
worktreeBase,
889945
});
890946
});
891947

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.