Skip to content

Commit 6b3bdce

Browse files
fix(server): a busy provider switch fails with its own tagged error
The active-turn guard stored its reason as a synthetic cause on a generic dispatch error. It now raises OrchestratorProviderSelectionBusyError, whose message comes from its attributes, and intake treats it as not accepted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 896c0e1 commit 6b3bdce

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,9 @@ it.effect.each(
213213
Result.isFailure(outcome),
214214
"retry the instance switch after the active turn finishes",
215215
);
216-
assert.instanceOf(outcome.failure, Orchestrator.OrchestratorDispatchError);
217-
const reason = String(outcome.failure.cause);
218-
assert.match(reason, /(?:active|running).*turn|turn.*(?:active|running)/i);
219-
assert.match(reason, /(?:retry|try again|wait|finish|complete)/i);
216+
assert.instanceOf(outcome.failure, Orchestrator.OrchestratorProviderSelectionBusyError);
217+
assert.match(outcome.failure.message, /active turn/i);
218+
assert.match(outcome.failure.message, /retry/i);
220219
} else {
221220
assert.ok(Result.isSuccess(outcome));
222221
assert.deepEqual(after.thread.modelSelection, target);

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ export class OrchestratorThreadAboveModeLimitError extends Schema.TaggedError<Or
240240
}
241241
}
242242

243+
export class OrchestratorProviderSelectionBusyError extends Schema.TaggedError<OrchestratorProviderSelectionBusyError>()(
244+
"OrchestratorProviderSelectionBusyError",
245+
{ commandId: CommandId, threadId: ThreadId },
246+
) {
247+
override get message(): string {
248+
return `Thread ${this.threadId} has an active turn. Wait for it to finish, then retry the provider selection change.`;
249+
}
250+
}
251+
243252
export class OrchestratorCommandPreviouslyRejectedError extends Schema.TaggedError<OrchestratorCommandPreviouslyRejectedError>()(
244253
"OrchestratorCommandPreviouslyRejectedError",
245254
{
@@ -288,6 +297,7 @@ export const OrchestratorV2Error = Schema.Union([
288297
OrchestratorCommandIdConflictError,
289298
OrchestratorSubagentThreadReadOnlyError,
290299
OrchestratorThreadAboveModeLimitError,
300+
OrchestratorProviderSelectionBusyError,
291301
]);
292302
export type OrchestratorV2Error = typeof OrchestratorV2Error.Type;
293303

@@ -2958,11 +2968,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
29582968
turnItemTypes: [],
29592969
});
29602970
if (projection.runs.some(isBlockingRun)) {
2961-
return yield* new OrchestratorDispatchError({
2971+
return yield* new OrchestratorProviderSelectionBusyError({
29622972
commandId: command.commandId,
2963-
commandType: command.type,
2964-
cause:
2965-
"Wait for the active turn to finish, then retry the provider selection change.",
2973+
threadId: command.threadId,
29662974
});
29672975
}
29682976
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function dispatchWasNotAccepted(
2525
case "OrchestratorCommandIdConflictError":
2626
case "OrchestratorSubagentThreadReadOnlyError":
2727
case "OrchestratorThreadAboveModeLimitError":
28+
case "OrchestratorProviderSelectionBusyError":
2829
case "ThreadManagementProviderInstanceDisabledError":
2930
return true;
3031
default:

0 commit comments

Comments
 (0)