Skip to content

Commit 36d5f86

Browse files
fix(server): a continuation cannot message a provider-run subagent thread
A thread.metadata.update carrying a continuation queued a message without the read-only check message.dispatch applies to provider-native subagent threads. Both paths now share that check, and it runs before the binding so a refused command writes nothing. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 744a84e commit 36d5f86

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6552,6 +6552,26 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
65526552
]);
65536553
});
65546554

6555+
// Providers own native subagent conversations; messages cannot target them, and adapters ask questions on the parent.
6556+
const refuseNativeSubagentMessage = Effect.fnUntraced(function* (
6557+
command: Pick<OrchestrationV2Command, "commandId"> & { readonly threadId: ThreadId },
6558+
) {
6559+
const thread = yield* projectionStore
6560+
.getThread(command.threadId)
6561+
.pipe(
6562+
Effect.mapError(
6563+
(cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
6564+
),
6565+
);
6566+
if (isProviderNativeSubagentThread(thread)) {
6567+
return yield* new OrchestratorSubagentThreadReadOnlyError({
6568+
commandId: command.commandId,
6569+
threadId: command.threadId,
6570+
});
6571+
}
6572+
return thread;
6573+
});
6574+
65556575
const dispatchMessage = Effect.fn("Orchestrator.dispatchMessage")(function* (
65566576
command: Extract<OrchestrationV2Command, { readonly type: "message.dispatch" }>,
65576577
events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
@@ -14743,8 +14763,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1474314763
yield* dispatchThreadMutation(command, events, effects);
1474414764
break;
1474514765
case "thread.metadata.update": {
14746-
yield* dispatchThreadMutation(command, events, effects);
1474714766
const continuation = metadataUpdateContinuation(command);
14767+
if (continuation !== undefined) yield* refuseNativeSubagentMessage(command);
14768+
yield* dispatchThreadMutation(command, events, effects);
1474814769
if (continuation !== undefined) {
1474914770
cancelUnsettledEffects = yield* dispatchMessage(continuation, events, effects);
1475014771
yield* recordSubagentFollowup(continuation, events).pipe(mapDispatchError(command));
@@ -14771,20 +14792,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1477114792
yield* dispatchThreadProjectAdoptFolder(command, events);
1477214793
break;
1477314794
case "message.dispatch": {
14774-
// Providers own native subagent conversations; messages cannot target them, and adapters ask questions on the parent.
14775-
const thread = yield* projectionStore
14776-
.getThread(command.threadId)
14777-
.pipe(
14778-
Effect.mapError(
14779-
(cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
14780-
),
14781-
);
14782-
if (isProviderNativeSubagentThread(thread)) {
14783-
return yield* new OrchestratorSubagentThreadReadOnlyError({
14784-
commandId: command.commandId,
14785-
threadId: command.threadId,
14786-
});
14787-
}
14795+
const thread = yield* refuseNativeSubagentMessage(command);
1478814796
const guestSend =
1478914797
command.guestMessageId === undefined
1479014798
? undefined

‎apps/server/src/orchestration-v2/testkit/ClaudeReplayFixtures.integration.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ describe("Claude Agent SDK replay fixtures", () => {
9595
userFacingDispatchErrorMessage(refused),
9696
"This subagent is run by its provider and cannot take messages. Message the parent thread instead.",
9797
);
98+
const refusedContinuation = yield* orchestrator
99+
.dispatch({
100+
type: "thread.metadata.update",
101+
commandId: CommandId.make("command:subagent:continue-native-child"),
102+
threadId: child.thread.id,
103+
title: "Renamed",
104+
continuation: {
105+
messageId: MessageId.make("message:subagent:continue-native-child"),
106+
text: "Also check the tests.",
107+
},
108+
})
109+
.pipe(Effect.flip);
110+
assert.equal(refusedContinuation._tag, "OrchestratorSubagentThreadReadOnlyError");
98111
assert.equal(yield* orchestrator.getThreadEventSequence(child.thread.id), before);
99112
const after = yield* orchestrator.getThreadProjection(child.thread.id);
100113
assert.lengthOf(after.runs, 0);

0 commit comments

Comments
 (0)