@devries-cameron20 / t3code-1 / commits / 009c9e6bd7
Fork 0

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

fix(server): an agent's Stop no longer reads as the user's (#33420)

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

Jackson Miller committed Nov 11, 2026 at 18:14 UTC 009c9e6bd70737aea4d9baf1e30db2d54577e7f1
2 files changed +58 -5
apps/server/src/mcp/OrchestratorMcpService.test.ts
+55 -3
@@ -4029,9 +4029,17 @@ describe("OrchestratorMcpService thread stop", () => {
4029 });
4030
4031 it.effect.each([
4032 - { name: "a running turn", queued: false },
4033 - { name: "a running turn with a queued message", queued: true },
4034 - ])("t3_thread_interrupt stop reports the run it interrupted on $name", ({ queued }) =>
4032 + {
4033 + name: "a running turn",
4034 + queued: false,
4035 + stop: { reason: undefined, message: "Stopped by an agent" },
4036 + },
4037 + {
4038 + name: "a running turn with a queued message",
4039 + queued: true,
4040 + stop: { reason: "Make room", message: "Stopped by an agent: Make room" },
4041 + },
4042 + ])("t3_thread_interrupt stop reports the run it interrupted on $name", ({ queued, stop }) =>
4043 Effect.scoped(
4044 Effect.gen(function* () {
4045 const cwd = yield* checkpointWorkspace("mcp-thread-stop");
@@ -4109,17 +4117,61 @@ describe("OrchestratorMcpService thread stop", () => {
4117 const before = yield* orchestrator.getThreadProjection(threadId);
4118 const runningRun = before.runs.find((run) => run.status === "running")!;
4119 assert.equal(before.runs.filter((run) => run.status === "queued").length, queued ? 1 : 0);
4120 + // A task the thread delegated, running when the thread is stopped.
4121 + const childRunning = yield* orchestrator.streamDomainEvents.pipe(
4122 + Stream.filter(
4123 + (event) =>
4124 + event.type === "provider-turn.updated" &&
4125 + event.threadId !== threadId &&
4126 + event.payload.status === "running",
4127 + ),
4128 + Stream.take(1),
4129 + Stream.runDrain,
4130 + Effect.forkScoped,
4131 + );
4132 + yield* orchestrator.dispatch({
4133 + type: "delegated_task.request",
4134 + commandId: CommandId.make("delegate"),
4135 + parentThreadId: threadId,
4136 + parentRunId: runningRun.id,
4137 + parentNodeId: runningRun.rootNodeId!,
4138 + task: "child work",
4139 + modelSelection,
4140 + runtimeMode: "full-access",
4141 + interactionMode: "default",
4142 + completionWake: "always",
4143 + createdBy: "agent",
4144 + creationSource: "mcp",
4145 + });
4146 + yield* worker.drain();
4147 + yield* Fiber.join(childRunning);
4148 + const childThreadId = (yield* orchestrator.getThreadProjection(threadId)).subagents[0]!
4149 + .childThreadId!;
4150
4151 const stopped = yield* service.interruptThread(client, {
4152 threadId,
4153 stop: true,
4154 clientRequestId: "stop",
4155 + ...(stop.reason === undefined ? {} : { reason: stop.reason }),
4156 });
4157 assert.deepEqual(stopped, {
4158 threadId,
4159 runId: runningRun.id,
4160 status: "interrupt_requested",
4161 });
4162 + // An agent's Stop must not read as the user's, on its thread or a task it delegated.
4163 + const interruptMessages = (id: ThreadId) =>
4164 + orchestrator
4165 + .getThreadProjection(id)
4166 + .pipe(
4167 + Effect.map(({ turnItems }) =>
4168 + turnItems.flatMap((item) =>
4169 + item.type === "run_interrupt_request" ? [item.message] : [],
4170 + ),
4171 + ),
4172 + );
4173 + assert.deepEqual(yield* interruptMessages(threadId), [stop.message]);
4174 + assert.deepEqual(yield* interruptMessages(childThreadId), [stop.message]);
4175 }).pipe(Effect.provide(layerTest));
4176 }),
4177 ),
apps/server/src/mcp/OrchestratorMcpService.ts
+3 -2
@@ -3225,6 +3225,7 @@ const make = Effect.gen(function* () {
3225 // the run instead, as this call did then.
3226 if (input.stop === true) {
3227 const commandId = stableCommandId({ scope, requestKey: key, operation: "thread-stop" });
3228 + const reason = agentStopReason(input.reason);
3229 // The cause goes to the log; the caller learns only that the stop failed.
3230 const stopFailed = (error: unknown) =>
3231 Effect.logWarning("orchestrator-mcp.thread-stop-failed", {
@@ -3242,12 +3243,12 @@ const make = Effect.gen(function* () {
3243 type: "thread.stop",
3244 commandId,
3245 threadId: input.threadId,
3245 - ...(input.reason === undefined ? {} : { reason: input.reason }),
3246 + reason,
3247 })
3248 .pipe(Effect.catch(stopFailed));
3249 // A retry with the same clientRequestId repeats only the stops that failed.
3250 yield* threadManagement
3250 - .stopDelegatedTasks({ threadId: input.threadId, commandId, reason: input.reason })
3251 + .stopDelegatedTasks({ threadId: input.threadId, commandId, reason })
3252 .pipe(Effect.catch(stopFailed));
3253 // The run this stop interrupted, from its own events, so a retry
3254 // reports the same run even if another has started since. Stop also