@devries-cameron20 / t3code-1 / commits / abd33b12ce
Fork 0

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

fix(server): t3_thread_send reports why the orchestrator refused a message (#21027)

Co-authored-by: dan <dan@bw-hq-linuxws01.bellwetherit.com>

Dan Donathan committed Oct 18, 2026 at 13:08 UTC abd33b12ce2d4881e5fabb6a1695486c485ee113
2 files changed +85 -1
apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+83
@@ -24,6 +24,7 @@ import * as ServerSettings from "../serverSettings.ts";
24 import * as SecretRequests from "../secrets/SecretRequests.ts";
25 import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
26 import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
27 +import { OrchestratorDispatchError } from "../orchestration-v2/Orchestrator.ts";
28 import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
29 import type * as McpInvocationContext from "./McpInvocationContext.ts";
30 import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
@@ -603,3 +604,85 @@ it("readThread and sendToThread reach threads in other projects", async () => {
604 expect(stopped.code).toBe("parent_not_active");
605 }).pipe(Effect.provide(layer), Effect.runPromise);
606 });
607 +
608 +it("sendToThread reports why the orchestrator refused the message", async () => {
609 + const targetThreadId = ThreadId.make("thread-mcp-orchestrator-dead-session");
610 + const targetProjection = {
611 + thread: baseThread({
612 + threadId: targetThreadId,
613 + title: "Stalled",
614 + instanceId: parentInstanceId,
615 + model: "gpt-5.4",
616 + }),
617 + runs: [],
618 + visibleTurnItems: [],
619 + runtimeRequests: [],
620 + messages: [],
621 + contextTransfers: [],
622 + subagents: [],
623 + updatedAt: now,
624 + } as unknown as OrchestrationV2ThreadProjection;
625 +
626 + const layer = layerOrchestratorService.pipe(
627 + Layer.provide(
628 + Layer.mergeAll(
629 + Layer.mock(ThreadManagementService.ThreadManagementService)({
630 + getThreadShell: (threadId) =>
631 + Effect.succeed(
632 + threadId === targetThreadId
633 + ? (targetProjection.thread as unknown as OrchestrationV2ThreadShell)
634 + : liveThreadShell(parentThreadId),
635 + ),
636 + getThreadRecords: (threadId) =>
637 + Effect.succeed(
638 + threadId === targetThreadId
639 + ? targetProjection
640 + : ({
641 + ...targetProjection,
642 + thread: baseThread({
643 + threadId: parentThreadId,
644 + title: "Parent",
645 + instanceId: parentInstanceId,
646 + model: "gpt-5.4",
647 + }),
648 + runs: [
649 + makeRun({ id: RunId.make("run-parent-live"), ordinal: 1, status: "running" }),
650 + ],
651 + } as unknown as OrchestrationV2ThreadProjection),
652 + ),
653 + getProjectThreadRecords: () => Effect.succeed(targetProjection),
654 + sendToThread: (input) =>
655 + Effect.fail(
656 + new OrchestratorDispatchError({
657 + commandId: input.commandId,
658 + commandType: "message.dispatch",
659 + cause: "Provider session provider-session-dead is not active.",
660 + }),
661 + ),
662 + } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
663 + ServerSettings.layerTest(),
664 + Layer.mock(ProviderRegistry.ProviderRegistry)({
665 + getProviders: Effect.succeed([]),
666 + } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
667 + Layer.mock(ProjectService.ProjectService)({}),
668 + Layer.mock(SecretRequests.SecretRequests)({}),
669 + Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
670 + Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
671 + list: () => Effect.succeed([]),
672 + } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
673 + NodeCrypto.layer,
674 + ),
675 + ),
676 + );
677 +
678 + await Effect.gen(function* () {
679 + const service = yield* OrchestratorMcpService.OrchestratorMcpService;
680 + const failure = yield* service
681 + .sendToThread(makeScope(), { threadId: targetThreadId, message: "restart", mode: "restart" })
682 + .pipe(Effect.flip);
683 + expect(failure.code).toBe("orchestration_error");
684 + expect(failure.message).toBe(
685 + `Unable to send to thread ${targetThreadId}: Provider session provider-session-dead is not active.`,
686 + );
687 + }).pipe(Effect.provide(layer), Effect.runPromise);
688 +});
apps/server/src/mcp/OrchestratorMcpService.ts
+2 -1
@@ -87,6 +87,7 @@ import * as ThreadManagementService from "../orchestration-v2/ThreadManagementSe
87 import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
88 import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
89 import { isSnoozed } from "../orchestration-v2/ThreadSettlementService.ts";
90 +import { userFacingDispatchErrorMessage } from "../orchestration-v2/UserFacingErrors.ts";
91 import * as ProjectService from "../project/ProjectService.ts";
92 import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
93 import * as ScheduledTaskService from "../scheduledTasks/ScheduledTaskService.ts";
@@ -2594,7 +2595,7 @@ const make = Effect.gen(function* () {
2595 ? threadManagementFailure(error)
2596 : failure(
2597 "orchestration_error",
2597 - `Unable to send to thread ${input.threadId}: ${errorMessage(error)}`,
2598 + `Unable to send to thread ${input.threadId}: ${userFacingDispatchErrorMessage(error) ?? errorMessage(error)}`,
2599 ),
2600 ),
2601 );