@devries-cameron20 / t3code Mirror · read-only / commits / 6ef2c05410
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 08:30 UTC

fix(server): t3_thread_send_attachments says why a send was refused (#38058)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Fuksss committed Nov 17, 2026 at 11:49 UTC 6ef2c05410b43a06eea6493a0dc66c1c92f5592f
3 files changed +101 -4
apps/server/src/mcp/OrchestratorMcpService.ts
+2 -2
@@ -240,13 +240,13 @@ export class OrchestratorMcpService extends Context.Service<
240 OrchestratorMcpServiceShape
241 >()("t3/mcp/OrchestratorMcpService") {}
242
243 -const isThreadManagementError = Schema.is(ThreadManagementService.ThreadManagementError);
243 +export const isThreadManagementError = Schema.is(ThreadManagementService.ThreadManagementError);
244
245 function failure(code: OrchestratorMcpFailure["code"], message: string): OrchestratorMcpFailure {
246 return new OrchestratorMcpFailure({ code, message });
247 }
248
249 -function threadManagementFailure(error: unknown): OrchestratorMcpFailure {
249 +export function threadManagementFailure(error: unknown): OrchestratorMcpFailure {
250 if (!isThreadManagementError(error)) return failure("orchestration_error", errorMessage(error));
251 switch (error._tag) {
252 case "ThreadManagementThreadNotFoundError":
apps/server/src/mcp/toolkits/attachment/handlers.ts
+5 -2
@@ -12,7 +12,8 @@ import * as Upload from "../../../assets/AttachmentUpload.ts";
12 import * as Claims from "../../../orchestration-v2/AttachmentClaims.ts";
13 import * as ThreadMessageIntake from "../../../orchestration-v2/ThreadMessageIntake.ts";
14 import * as McpToolAccess from "../../McpToolAccess.ts";
15 -import { newCommandId, readThread, unavailable } from "../../threadAccess.ts";
15 +import { isThreadManagementError, threadManagementFailure } from "../../OrchestratorMcpService.ts";
16 +import { dispatchFailure, newCommandId, readThread, unavailable } from "../../threadAccess.ts";
17 import { AttachmentToolkit } from "./tools.ts";
18
19 export function resolveAttachmentReferences(
@@ -118,7 +119,9 @@ export const layer = McpToolAccess.toLayer(
119 code: "orchestration_error",
120 message: error.message,
121 })
121 - : unavailable(),
122 + : isThreadManagementError(error)
123 + ? threadManagementFailure(error)
124 + : dispatchFailure(error),
125 ),
126 );
127 return {
apps/server/src/mcp/toolkits/core.test.ts
+94
@@ -1420,6 +1420,100 @@ it.effect("only the caller that prepared a pending upload can discard it", () =>
1420 ),
1421 );
1422
1423 +const sendTargetId = ThreadId.make("send-target-thread");
1424 +const sendCommand = {
1425 + commandId: CommandId.make("mcp-core-send"),
1426 + commandType: "message.dispatch",
1427 +};
1428 +
1429 +it.effect.each([
1430 + {
1431 + outcome: "says that the missing workspace could not be recreated",
1432 + refusal: new ThreadManagement.ThreadManagementWorktreeRestoreError({
1433 + threadId: sendTargetId,
1434 + cause: new Error("The branch no longer exists."),
1435 + }),
1436 + reply: {
1437 + _tag: "OrchestratorMcpFailure",
1438 + code: "thread_not_sendable",
1439 + message:
1440 + "Couldn't recreate the missing workspace of thread send-target-thread, so the message was not sent. The branch no longer exists.",
1441 + },
1442 + },
1443 + {
1444 + outcome: "passes on the text reason of an orchestrator rejection",
1445 + refusal: new OrchestratorCommandRejectedError({
1446 + ...sendCommand,
1447 + cause: "Thread send-target-thread is deleted.",
1448 + }),
1449 + reply: {
1450 + _tag: "OrchestratorMcpFailure",
1451 + code: "orchestration_error",
1452 + message: "Thread send-target-thread is deleted.",
1453 + },
1454 + },
1455 + {
1456 + outcome: "keeps an internal dispatch cause private",
1457 + refusal: new OrchestratorDispatchError({
1458 + ...sendCommand,
1459 + cause: new Error("private-storage-path"),
1460 + }),
1461 + reply: {
1462 + _tag: "OrchestratorMcpFailure",
1463 + code: "orchestration_error",
1464 + message: "The operation could not be completed.",
1465 + },
1466 + },
1467 +])("t3_thread_send_attachments $outcome", ({ refusal, reply }) => {
1468 + const stored = ChatImageAttachment.make({
1469 + type: "image",
1470 + id: "owned-image",
1471 + name: "original.png",
1472 + mimeType: "image/png",
1473 + sizeBytes: 12,
1474 + });
1475 + return Effect.gen(function* () {
1476 + const server = yield* McpServer.McpServer;
1477 + const result = yield* server
1478 + .callTool({
1479 + name: "t3_thread_send_attachments",
1480 + arguments: { threadId: sendTargetId, message: "See the file.", attachments: [stored] },
1481 + })
1482 + .pipe(
1483 + Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
1484 + Effect.provideService(McpSchema.McpServerClient, client),
1485 + );
1486 + expect(declaredFailure(result)).toEqual(reply);
1487 + }).pipe(
1488 + Effect.provide(
1489 + McpHttpServer.layerAttachmentToolkit.pipe(
1490 + Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
1491 + Layer.provide(
1492 + Layer.mock(ThreadManagement.ThreadManagementService)({
1493 + getThreadShell: (id) => Effect.succeed(McpToolAccessTestkit.liveThreadShell(id)),
1494 + getProjectThreadRecords: () =>
1495 + Effect.succeed({
1496 + ...McpToolAccessTestkit.idleThreadProjection(
1497 + McpToolAccessTestkit.liveThreadShell(sendTargetId),
1498 + ),
1499 + messages: [{ attachments: [stored] }],
1500 + } as never),
1501 + sendToThread: () => Effect.fail(refusal),
1502 + }),
1503 + ),
1504 + Layer.provide(AssetSigner.layer.pipe(Layer.provideMerge(ServerSecretStore.layer))),
1505 + Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-attachment-" })),
1506 + Layer.provide(
1507 + DocumentText.layer.pipe(
1508 + Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1509 + ),
1510 + ),
1511 + Layer.provide(NodeCrypto.layer),
1512 + ),
1513 + ),
1514 + );
1515 +});
1516 +
1517 it.effect(
1518 "t3_thread_list settled:false with an empty statuses list lists the unsettled threads",
1519 () => {