Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ function threadDetail(

function threadRun(run: OrchestrationV2Run): OrchestratorMcpThreadRun {
return {
...(run.workAffiliation === undefined ? {} : { workAffiliation: run.workAffiliation }),
runId: run.id,
ordinal: run.ordinal,
status: run.status,
Expand Down Expand Up @@ -2600,6 +2601,8 @@ const make = Effect.gen(function* () {
...(parent === undefined ? {} : { senderThreadId: parent.thread.id }),
messageId,
text: input.message,
...(input.workReference === undefined ? {} : { workReference: input.workReference }),
...(input.workSource === undefined ? {} : { workSource: input.workSource }),
attachments: [],
mode,
createdBy: "agent",
Expand Down
41 changes: 41 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function makeDeterministicAdapter(input: {
readonly driver: ProviderDriverKind;
readonly capabilities: OrchestrationV2ProviderCapabilities;
readonly capturedTurns: Ref.Ref<ReadonlyArray<CapturedTurn>>;
readonly beforeStart?: (turn: ProviderAdapter.ProviderAdapterV2TurnInput) => Effect.Effect<void>;
readonly shouldComplete: (turn: ProviderAdapter.ProviderAdapterV2TurnInput) => boolean;
readonly terminalGate?: (
turn: ProviderAdapter.ProviderAdapterV2TurnInput,
Expand Down Expand Up @@ -262,6 +263,7 @@ function makeDeterministicAdapter(input: {
resumeThread: ({ providerThread }) => Effect.succeed(providerThread),
startTurn: (turnInput) =>
Effect.gen(function* () {
if (input.beforeStart !== undefined) yield* input.beforeStart(turnInput);
yield* Ref.update(input.capturedTurns, (turns) => [
...turns,
{
Expand Down Expand Up @@ -530,11 +532,15 @@ describe("orchestrator MCP toolkit", () => {
Effect.gen(function* () {
const cwd = yield* checkpointWorkspace("orchestrator-mcp-toolkit");
const capturedTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
let beforeWorkStart: (
turn: ProviderAdapter.ProviderAdapterV2TurnInput,
) => Effect.Effect<void> = () => Effect.void;
const parentTerminalGates = new Map<ThreadId, Deferred.Deferred<void>>();
const deliveryTerminalGates = new Map<ThreadId, Deferred.Deferred<void>>();
const layerRegistry = ProviderAdapterRegistry.layerFromAdapters([
makeDeterministicAdapter({
instanceId: codexInstanceId,
beforeStart: (turn) => beforeWorkStart(turn),
driver: ProviderDriverKind.make("codex"),
// Exercise queued completion ownership on a session without native steering.
// Native mailbox delivery and its completion races have dedicated integration tests.
Expand All @@ -554,6 +560,7 @@ describe("orchestrator MCP toolkit", () => {
}),
makeDeterministicAdapter({
instanceId: claudeInstanceId,
beforeStart: (turn) => beforeWorkStart(turn),
driver: ProviderDriverKind.make("claudeAgent"),
capabilities: ClaudeProviderCapabilitiesV2,
capturedTurns,
Expand Down Expand Up @@ -721,6 +728,20 @@ describe("orchestrator MCP toolkit", () => {
yield* Effect.gen(function* () {
const orchestrator = yield* Orchestrator.OrchestratorV2;
const server = yield* McpServer.McpServer;
beforeWorkStart = (turn) =>
turn.message.text !== parentPrompt && turn.message.text !== delegatedPrompt
? Effect.void
: orchestrator.getThreadProjection(turn.threadId).pipe(
Effect.orDie,
Effect.tap((projection) =>
Effect.sync(() => {
expect(
projection.runs.find((run) => run.id === turn.runId)?.workAffiliation
?.reference,
).toEqual({ kind: "obligation", ref: "github:fixture/repo#42" });
}),
),
);
yield* orchestrator.dispatch({
type: "thread.create",
createdBy: "user",
Expand All @@ -743,6 +764,7 @@ describe("orchestrator MCP toolkit", () => {
threadId: parentThreadId,
messageId: MessageId.make("message:mcp-parent:start"),
text: parentPrompt,
workReference: { kind: "obligation", ref: "github:fixture/repo#42" },
attachments: [],
modelSelection: codexSelection,
dispatchMode: { type: "start_immediately" },
Expand Down Expand Up @@ -999,6 +1021,10 @@ describe("orchestrator MCP toolkit", () => {
(run) => run.userMessageId === coalescedDelivery.messageId,
);
expect(queuedCoalescedRun?.status).toBe("queued");
expect(queuedCoalescedRun?.workAffiliation).toEqual({
...parentRun.workAffiliation!,
inheritedFrom: { threadId: parentThreadId, runId: parentRun.id },
});
if (queuedCoalescedRun === undefined) {
return yield* Effect.die(new Error("Queued coalesced delivery missing."));
}
Expand Down Expand Up @@ -1711,6 +1737,21 @@ describe("orchestrator MCP toolkit", () => {
const delegatedSource = yield* orchestrator.getThreadProjection(
delegated.childThreadId,
);
expect(delegatedSource.runs[0]?.workAffiliation).toEqual({
...parentRun.workAffiliation!,
inheritedFrom: { threadId: parentThreadId, runId: parentRun.id },
});
const affiliatedRead = yield* invoke("t3_thread_read", {
threadId: delegated.childThreadId,
limit: 1,
runLimit: 1,
});
const readWork = yield* decodeThreadReadResult(affiliatedRead.structuredContent).pipe(
Effect.orDie,
);
expect(readWork.recentRuns[0]?.workAffiliation).toEqual(
delegatedSource.runs[0]?.workAffiliation,
);
expect(delegatedSource.messages[0]).toMatchObject({
senderThreadId: parentThreadId,
});
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/mcp/toolkits/project/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
messageId,
...(caller === undefined ? {} : { senderThreadId: caller.id }),
text: input.message ?? "",
...(input.workReference === undefined
? {}
: { workReference: input.workReference }),
...(input.workSource === undefined ? {} : { workSource: input.workSource }),
attachments,
},
}),
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/mcp/toolkits/project/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
ThreadId,
RunId,
OrchestrationV2RunStatus,
OrchestrationV2WorkReference,
OrchestrationV2WorkSource,
OrchestrationV2ThreadLaunchWorkspaceStrategy,
RuntimeMode,
ProviderInteractionMode,
Expand Down Expand Up @@ -113,6 +115,8 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", {
"Launch without a project, in its own folder under the environment's Scratch project. Not with projectId or workspaceStrategy.",
}),
),
workReference: Schema.optional(OrchestrationV2WorkReference),
workSource: Schema.optional(OrchestrationV2WorkSource),
title: TrimmedNonEmptyString,
modelSelection: Schema.optional(ModelSelection),
runtimeMode: Schema.optional(RuntimeMode),
Expand Down
Loading