GeezerVison is showing github.com — fix(server): t3_thread_send_attachments says why a send was refused (… · pingdotgg/t3code@6ef2c05
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -240,13 +240,13 @@ export class OrchestratorMcpService extends Context.Service< | 240 | 240 | OrchestratorMcpServiceShape | 241 | 241 | >()("t3/mcp/OrchestratorMcpService") {} | 242 | 242 |
| 243 | | -const isThreadManagementError = Schema.is(ThreadManagementService.ThreadManagementError); | | 243 | +export const isThreadManagementError = Schema.is(ThreadManagementService.ThreadManagementError); | 244 | 244 |
| 245 | 245 | function failure(code: OrchestratorMcpFailure["code"], message: string): OrchestratorMcpFailure { | 246 | 246 | return new OrchestratorMcpFailure({ code, message }); | 247 | 247 | } | 248 | 248 |
| 249 | | -function threadManagementFailure(error: unknown): OrchestratorMcpFailure { | | 249 | +export function threadManagementFailure(error: unknown): OrchestratorMcpFailure { | 250 | 250 | if (!isThreadManagementError(error)) return failure("orchestration_error", errorMessage(error)); | 251 | 251 | switch (error._tag) { | 252 | 252 | case "ThreadManagementThreadNotFoundError": | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/attachment/handlers.ts +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,8 @@ import * as Upload from "../../../assets/AttachmentUpload.ts"; | 12 | 12 | import * as Claims from "../../../orchestration-v2/AttachmentClaims.ts"; | 13 | 13 | import * as ThreadMessageIntake from "../../../orchestration-v2/ThreadMessageIntake.ts"; | 14 | 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"; | 16 | 17 | import { AttachmentToolkit } from "./tools.ts"; | 17 | 18 |
| 18 | 19 | export function resolveAttachmentReferences( | @@ -118,7 +119,9 @@ export const layer = McpToolAccess.toLayer( | 118 | 119 | code: "orchestration_error", | 119 | 120 | message: error.message, | 120 | 121 | }) | 121 | | - : unavailable(), | | 122 | + : isThreadManagementError(error) | | 123 | + ? threadManagementFailure(error) | | 124 | + : dispatchFailure(error), | 122 | 125 | ), | 123 | 126 | ); | 124 | 127 | return { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/core.test.ts +94Lines changed: 94 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1420,6 +1420,100 @@ it.effect("only the caller that prepared a pending upload can discard it", () => | 1420 | 1420 | ), | 1421 | 1421 | ); | 1422 | 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 | + | 1423 | 1517 | it.effect( | 1424 | 1518 | "t3_thread_list settled:false with an empty statuses list lists the unsettled threads", | 1425 | 1519 | () => { | |
|