@@ -758,6 +758,26 @@ function cancelledAppOwnedTask(
758758 };
759759}
760760
761+ // A workspace change detaches the session, which can settle the calling run at once. Queuing its
762+ // follow-up in a later command would let a delegated task report its result before that exists.
763+ function metadataUpdateContinuation(
764+ command: Extract<OrchestrationV2Command, { readonly type: "thread.metadata.update" }>,
765+ ): Extract<OrchestrationV2Command, { readonly type: "message.dispatch" }> | undefined {
766+ return command.continuation === undefined
767+ ? undefined
768+ : {
769+ type: "message.dispatch",
770+ commandId: command.commandId,
771+ threadId: command.threadId,
772+ messageId: command.continuation.messageId,
773+ text: command.continuation.text,
774+ attachments: [],
775+ dispatchMode: { type: "queue_after_active" },
776+ createdBy: "agent",
777+ creationSource: "mcp",
778+ };
779+ }
780+
761781// Provider wakes can start follow-up work; monitor updates only report progress.
762782// Dispatch takes the parent's lock for follow-ups because intake writes the parent.
763783function mayStartSubagentFollowup(
@@ -6532,6 +6552,26 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
65326552 ]);
65336553 });
65346554
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+
65356575 const dispatchMessage = Effect.fn("Orchestrator.dispatchMessage")(function* (
65366576 command: Extract<OrchestrationV2Command, { readonly type: "message.dispatch" }>,
65376577 events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
@@ -14710,7 +14750,6 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1471014750 case "thread.active.reorder":
1471114751 case "thread.tag.set":
1471214752 case "thread.mark-unread":
14713- case "thread.metadata.update":
1471414753 case "thread.pull-request.link":
1471514754 case "thread.pull-request.unlink":
1471614755 case "thread.pull-request-link.sync":
@@ -14723,6 +14762,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1472314762 case "provider.switch":
1472414763 yield* dispatchThreadMutation(command, events, effects);
1472514764 break;
14765+ case "thread.metadata.update": {
14766+ const continuation = metadataUpdateContinuation(command);
14767+ if (continuation !== undefined) yield* refuseNativeSubagentMessage(command);
14768+ yield* dispatchThreadMutation(command, events, effects);
14769+ if (continuation !== undefined) {
14770+ cancelUnsettledEffects = yield* dispatchMessage(continuation, events, effects);
14771+ yield* recordSubagentFollowup(continuation, events).pipe(mapDispatchError(command));
14772+ }
14773+ break;
14774+ }
1472614775 case "thread.pull-request-watch.checks-reopen":
1472714776 yield* dispatchThreadMutation(command, events, effects);
1472814777 break;
@@ -14743,20 +14792,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1474314792 yield* dispatchThreadProjectAdoptFolder(command, events);
1474414793 break;
1474514794 case "message.dispatch": {
14746- // Providers own native subagent conversations; messages cannot target them, and adapters ask questions on the parent.
14747- const thread = yield* projectionStore
14748- .getThread(command.threadId)
14749- .pipe(
14750- Effect.mapError(
14751- (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
14752- ),
14753- );
14754- if (isProviderNativeSubagentThread(thread)) {
14755- return yield* new OrchestratorSubagentThreadReadOnlyError({
14756- commandId: command.commandId,
14757- threadId: command.threadId,
14758- });
14759- }
14795+ const thread = yield* refuseNativeSubagentMessage(command);
1476014796 const guestSend =
1476114797 command.guestMessageId === undefined
1476214798 ? undefined
@@ -15339,11 +15375,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1533915375 );
1534015376 // Taken before the lineage read, so a message whose read yields keeps its
1534115377 // place ahead of later messages to the same thread.
15342- if (command.type === "message.dispatch")
15378+ const message =
15379+ command.type === "thread.metadata.update" ? metadataUpdateContinuation(command) : command;
15380+ if (message?.type === "message.dispatch")
1534315381 return yield* messageIntake.withLock(
15344- command .threadId,
15345- mayStartSubagentFollowup(command )
15346- ? withSubagentParentLock(command .threadId, dispatch)
15382+ message .threadId,
15383+ mayStartSubagentFollowup(message )
15384+ ? withSubagentParentLock(message .threadId, dispatch)
1534715385 : dispatch,
1534815386 );
1534915387 // Answering a message-mode question can also start a follow-up.
0 commit comments