@devries-cameron20 / t3code Mirror · read-only / commits / afc12ab70a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 04:15 UTC

fix(server): a steered send no longer leaves a subagent task running (#19019)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Scott Norteman committed Oct 18, 2026 at 15:20 UTC afc12ab70aede492efc1f92b12f48afc9dfd4a6a
3 files changed +149 -2
apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
+139 -1
@@ -198,6 +198,9 @@ function makeDeterministicAdapter(input: {
198 turn: ProviderAdapter.ProviderAdapterV2TurnInput,
199 ) => Deferred.Deferred<void> | undefined;
200 readonly response: (turn: ProviderAdapter.ProviderAdapterV2TurnInput) => string;
201 + readonly steerReceived?: (
202 + steer: ProviderAdapter.ProviderAdapterV2SteerInput,
203 + ) => Deferred.Deferred<void> | undefined;
204 }): ProviderAdapter.ProviderAdapterV2["Service"] {
205 return {
206 instanceId: input.instanceId,
@@ -365,7 +368,12 @@ function makeDeterministicAdapter(input: {
368 },
369 ]);
370 }),
368 - steerTurn: () => Effect.void,
371 + steerTurn: (steer) => {
372 + const received = input.steerReceived?.(steer);
373 + return received === undefined
374 + ? Effect.void
375 + : Deferred.succeed(received, undefined).pipe(Effect.asVoid);
376 + },
377 interruptTurn: ({ providerThread, providerTurnId }) =>
378 Effect.gen(function* () {
379 const turnInput = turnInputs.get(providerTurnId);
@@ -529,6 +537,7 @@ describe("orchestrator MCP toolkit", () => {
537 Effect.gen(function* () {
538 const cwd = yield* checkpointWorkspace("orchestrator-mcp-toolkit");
539 const capturedTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
540 + const steerReceivedGates = new Map<string, Deferred.Deferred<void>>();
541 const parentTerminalGates = new Map<ThreadId, Deferred.Deferred<void>>();
542 const deliveryTerminalGates = new Map<ThreadId, Deferred.Deferred<void>>();
543 const layerRegistry = ProviderAdapterRegistry.layerFromAdapters([
@@ -564,6 +573,7 @@ describe("orchestrator MCP toolkit", () => {
573 turn.message.text === delegatedPrompt
574 ? delegatedResult
575 : `Claude completed: ${turn.message.text}`,
576 + steerReceived: (steer) => steerReceivedGates.get(steer.message.text),
577 }),
578 ]);
579 const continuationOffers = yield* Ref.make<
@@ -1902,6 +1912,134 @@ describe("orchestrator MCP toolkit", () => {
1912 yield* invoke("task_status", { taskId: activeChildFollowup.taskId });
1913 yield* Ref.set(continuationOffers, []);
1914
1915 + // A send into a child run the server started has no task to join.
1916 + // It gets its own task only when it starts a new attempt; a steer
1917 + // into the running attempt leaves no run that could settle one.
1918 + const childSteerText = "Include the parent's latest guidance before finishing.";
1919 + const steerIntoUntaskedChildRun = (
1920 + target: { readonly providerInstanceId: ProviderInstanceId; readonly model: string },
1921 + name: string,
1922 + ) =>
1923 + Effect.gen(function* () {
1924 + const delegateCall = yield* invoke("delegate_task", {
1925 + task: "Inspect the steering boundary and return the result.",
1926 + target,
1927 + mode: "wait",
1928 + timeoutMs: 10_000,
1929 + clientRequestId: `${name}-delegate`,
1930 + });
1931 + const child = yield* decodeDelegateTaskResult(delegateCall.structuredContent).pipe(
1932 + Effect.orDie,
1933 + );
1934 + expect(child.status).toBe("completed");
1935 + const messageId = MessageId.make(`message:mcp-child:${name}`);
1936 + yield* orchestrator.dispatch({
1937 + type: "message.dispatch",
1938 + createdBy: "agent",
1939 + creationSource: "server",
1940 + commandId: CommandId.make(`command:mcp-child:${name}`),
1941 + threadId: child.childThreadId,
1942 + messageId,
1943 + text: cancellationPrompt,
1944 + attachments: [],
1945 + modelSelection: { instanceId: target.providerInstanceId, model: target.model },
1946 + dispatchMode: { type: "start_immediately" },
1947 + });
1948 + const running = yield* waitForProjection(
1949 + orchestrator,
1950 + child.childThreadId,
1951 + (projection) => {
1952 + const run = projection.runs.find((row) => row.userMessageId === messageId);
1953 + return (
1954 + run?.status === "running" &&
1955 + projection.providerTurns.some(
1956 + (turn) => turn.nodeId === run.rootNodeId && turn.status === "running",
1957 + )
1958 + );
1959 + },
1960 + );
1961 + const run = running.runs.find((row) => row.userMessageId === messageId)!;
1962 + expect(run.delegatedTaskId).toBeUndefined();
1963 + const sendCall = yield* invoke("t3_thread_send", {
1964 + threadId: child.childThreadId,
1965 + message: childSteerText,
1966 + mode: "steer",
1967 + clientRequestId: `${name}-steer`,
1968 + });
1969 + const sent = yield* decodeThreadSendResult(sendCall.structuredContent).pipe(
1970 + Effect.orDie,
1971 + );
1972 + expect(sent).toMatchObject({ runId: run.id, delivery: "steered" });
1973 + return { child, sent };
1974 + });
1975 + const waitForChildRun = (
1976 + childThreadId: ThreadId,
1977 + runId: string,
1978 + status: "completed" | "interrupted",
1979 + ) =>
1980 + waitForProjection(orchestrator, childThreadId, (projection) =>
1981 + projection.runs.some((run) => run.id === runId && run.status === status),
1982 + );
1983 +
1984 + // Claude steers into the running turn, which then ends.
1985 + const steerReceived = yield* Deferred.make<void>();
1986 + steerReceivedGates.set(childSteerText, steerReceived);
1987 + const steeredSend = yield* steerIntoUntaskedChildRun(
1988 + { providerInstanceId: claudeInstanceId, model: claudeModel },
1989 + "steer-untasked-run",
1990 + );
1991 + // A steer that misses the turn is sent again as its own run, so
1992 + // end the turn only once the steer reached it.
1993 + yield* Deferred.await(steerReceived);
1994 + steerReceivedGates.delete(childSteerText);
1995 + yield* invoke("t3_thread_interrupt", {
1996 + threadId: steeredSend.child.childThreadId,
1997 + runId: steeredSend.sent.runId,
1998 + clientRequestId: "steer-untasked-run-interrupt",
1999 + });
2000 + yield* waitForChildRun(
2001 + steeredSend.child.childThreadId,
2002 + steeredSend.sent.runId,
2003 + "interrupted",
2004 + );
2005 + expect(
2006 + (yield* orchestrator.getThreadProjection(parentThreadId)).subagents.filter(
2007 + (task) =>
2008 + task.origin === "app_owned" &&
2009 + task.childThreadId === steeredSend.child.childThreadId &&
2010 + task.status === "running",
2011 + ),
2012 + ).toEqual([]);
2013 + expect(steeredSend.sent.taskId).toBeUndefined();
2014 +
2015 + // This Codex session has active steering off, so the send restarts the
2016 + // turn as a new attempt that owns the follow-up task and settles it.
2017 + const restarted = yield* steerIntoUntaskedChildRun(
2018 + { providerInstanceId: codexInstanceId, model: codexModel },
2019 + "restart-untasked-run",
2020 + );
2021 + const restartedTaskId = restarted.sent.taskId;
2022 + expect(restartedTaskId).toBeDefined();
2023 + yield* waitForChildRun(
2024 + restarted.child.childThreadId,
2025 + restarted.sent.runId,
2026 + "completed",
2027 + );
2028 + yield* waitForProjection(orchestrator, parentThreadId, (projection) =>
2029 + projection.subagents.some(
2030 + (task) => task.id === restartedTaskId && task.status === "completed",
2031 + ),
2032 + );
2033 + expect(
2034 + (yield* orchestrator.getThreadProjection(restarted.child.childThreadId)).runs.find(
2035 + (run) => run.id === restarted.sent.runId,
2036 + )?.delegatedTaskId,
2037 + ).toBe(restartedTaskId);
2038 + yield* invoke("task_status", { taskId: steeredSend.child.taskId });
2039 + yield* invoke("task_status", { taskId: restarted.child.taskId });
2040 + yield* invoke("task_status", { taskId: restartedTaskId });
2041 + yield* Ref.set(continuationOffers, []);
2042 +
2043 const repeatedDelegatedCall = yield* invoke("delegate_task", {
2044 task: delegatedPrompt,
2045 target: {
apps/server/src/mcp/toolkits/orchestrator/tools.ts
+1 -1
@@ -234,7 +234,7 @@ export const ThreadUpdateTool = Tool.make("t3_thread_update", {
234
235 const ThreadSendTool = Tool.make("t3_thread_send", {
236 description:
237 - "Send a message to any T3 thread in this environment. The target cannot have broader permission modes than the caller. Use delegate_task with the full review context and a new clientRequestId for independent review rounds. For a follow-up that needs the same child's conversation, send to its childThreadId. After the original task completes, a requested follow-up creates a fresh task in that child thread and returns taskId; its completion notifies the parent, and the original result stays unchanged. mode='auto' starts an idle thread, steers a fully active turn, or queues behind a turn that is not yet steerable. Use queue for a separate follow-up turn, steer for an in-flight update, or restart to interrupt-and-restart the active turn. clientRequestId makes retries idempotent.",
237 + "Send a message to any T3 thread in this environment. The target cannot have broader permission modes than the caller. Use delegate_task with the full review context and a new clientRequestId for independent review rounds. For a follow-up that needs the same child's conversation, send to its childThreadId. After the original task completes, a requested follow-up creates a fresh task in that child thread and returns taskId when it starts a turn or restarts a turn without its own task; its completion notifies the parent, and the original result stays unchanged. A steer that joins a running turn returns that turn's task, if it has one. mode='auto' starts an idle thread, steers a fully active turn, or queues behind a turn that is not yet steerable. Use queue for a separate follow-up turn, steer for an in-flight update, or restart to interrupt-and-restart the active turn. clientRequestId makes retries idempotent.",
238 parameters: OrchestratorMcpThreadSendInput,
239 success: OrchestratorMcpThreadSendResult,
240 failure: OrchestratorMcpFailure,
apps/server/src/orchestration-v2/Orchestrator.ts
+9
@@ -6838,6 +6838,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6838 )
6839 .at(-1);
6840 if (message?.runId == null) return;
6841 + // Only a message that starts a run or a new attempt can own a task. A
6842 + // steer joins the running attempt, which finalizes its run from the
6843 + // snapshot taken when it started, so a task bound to it would never settle.
6844 + const startsAttempt = pending.some(
6845 + (event) =>
6846 + (event.type === "run.created" && event.payload.id === message.runId) ||
6847 + (event.type === "run-attempt.created" && event.payload.runId === message.runId),
6848 + );
6849 + if (!startsAttempt) return;
6850 const child = yield* projectionStore.getThread(command.threadId);
6851 const parentThreadId = child.lineage.parentThreadId;
6852 if (