refactor(orchestration): split thread-not-sendable into typed errors
Effect service conventions: ThreadManagementThreadNotSendableError carried an Archived/NoSteerableRun reason union and switched on reason._tag inside the message getter. Modelled as two error classes (ThreadManagementThreadArchivedError, ThreadManagementNoSteerableRunError); both still map to the MCP thread_not_sendable failure code. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
e6b3d3d3ed
commit
39929faaee
4 files changed
+31
-32
No files matched your search
@@ -165,7 +165,8 @@ function threadManagementFailure(error: ThreadManagementError): OrchestratorMcpF
|
||||
return failure("thread_not_found", error.message);
|
||||
case "ThreadManagementRunNotFoundError":
|
||||
return failure("run_not_found", error.message);
|
||||
case "ThreadManagementThreadNotSendableError":
|
||||
case "ThreadManagementThreadArchivedError":
|
||||
case "ThreadManagementNoSteerableRunError":
|
||||
return failure("thread_not_sendable", error.message);
|
||||
case "ThreadManagementThreadNotInterruptibleError":
|
||||
return failure("thread_not_interruptible", error.message);
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
} from "../orchestration-v2/Orchestrator.ts";
|
||||
import {
|
||||
ThreadManagementService,
|
||||
ThreadManagementThreadNotSendableError,
|
||||
ThreadManagementThreadArchivedError,
|
||||
type ThreadManagementSendResult,
|
||||
} from "../orchestration-v2/ThreadManagementService.ts";
|
||||
import * as ProjectService from "../project/ProjectService.ts";
|
||||
@@ -177,9 +177,8 @@ const makeHarness = (options: HarnessOptions = {}) => {
|
||||
switch (options.continuation ?? "queued") {
|
||||
case "fails":
|
||||
return Effect.fail(
|
||||
new ThreadManagementThreadNotSendableError({
|
||||
new ThreadManagementThreadArchivedError({
|
||||
threadId,
|
||||
reason: { _tag: "Archived" },
|
||||
}),
|
||||
);
|
||||
case "dies":
|
||||
|
||||
@@ -24,7 +24,8 @@ import {
|
||||
ThreadManagementService,
|
||||
ThreadManagementThreadNotFoundError,
|
||||
ThreadManagementThreadNotInterruptibleError,
|
||||
ThreadManagementThreadNotSendableError,
|
||||
ThreadManagementThreadArchivedError,
|
||||
ThreadManagementNoSteerableRunError,
|
||||
withCreationProvenance,
|
||||
} from "./ThreadManagementService.ts";
|
||||
|
||||
@@ -216,20 +217,19 @@ it("derives thread management messages from structural error attributes", () =>
|
||||
expect(runNotFound).toMatchObject({ threadId, runId });
|
||||
expect(runNotFound.message).toBe(`Run ${runId} does not belong to thread ${threadId}.`);
|
||||
|
||||
const archived = new ThreadManagementThreadNotSendableError({
|
||||
const archived = new ThreadManagementThreadArchivedError({
|
||||
threadId,
|
||||
reason: { _tag: "Archived" },
|
||||
});
|
||||
expect(archived).toMatchObject({ threadId, reason: { _tag: "Archived" } });
|
||||
expect(archived).toMatchObject({ threadId });
|
||||
expect(archived.message).toBe(`Thread ${threadId} is archived and cannot receive messages.`);
|
||||
|
||||
const notSteerable = new ThreadManagementThreadNotSendableError({
|
||||
const notSteerable = new ThreadManagementNoSteerableRunError({
|
||||
threadId,
|
||||
reason: { _tag: "NoSteerableRun", mode: "restart" },
|
||||
mode: "restart",
|
||||
});
|
||||
expect(notSteerable).toMatchObject({
|
||||
threadId,
|
||||
reason: { _tag: "NoSteerableRun", mode: "restart" },
|
||||
mode: "restart",
|
||||
});
|
||||
expect(notSteerable.message).toBe(
|
||||
`Thread ${threadId} has no running turn that can be restarted.`,
|
||||
|
||||
@@ -176,27 +176,26 @@ export class ThreadManagementRunNotFoundError extends Schema.TaggedErrorClass<Th
|
||||
}
|
||||
}
|
||||
|
||||
const ThreadManagementThreadNotSendableReason = Schema.Union([
|
||||
Schema.TaggedStruct("Archived", {}),
|
||||
Schema.TaggedStruct("NoSteerableRun", {
|
||||
mode: Schema.Literals(["steer", "restart"]),
|
||||
}),
|
||||
]);
|
||||
|
||||
export class ThreadManagementThreadNotSendableError extends Schema.TaggedErrorClass<ThreadManagementThreadNotSendableError>()(
|
||||
"ThreadManagementThreadNotSendableError",
|
||||
export class ThreadManagementThreadArchivedError extends Schema.TaggedErrorClass<ThreadManagementThreadArchivedError>()(
|
||||
"ThreadManagementThreadArchivedError",
|
||||
{
|
||||
threadId: ThreadId,
|
||||
reason: ThreadManagementThreadNotSendableReason,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
switch (this.reason._tag) {
|
||||
case "Archived":
|
||||
return `Thread ${this.threadId} is archived and cannot receive messages.`;
|
||||
case "NoSteerableRun":
|
||||
return `Thread ${this.threadId} has no running turn that can be ${this.reason.mode === "steer" ? "steered" : "restarted"}.`;
|
||||
}
|
||||
return `Thread ${this.threadId} is archived and cannot receive messages.`;
|
||||
}
|
||||
}
|
||||
|
||||
export class ThreadManagementNoSteerableRunError extends Schema.TaggedErrorClass<ThreadManagementNoSteerableRunError>()(
|
||||
"ThreadManagementNoSteerableRunError",
|
||||
{
|
||||
threadId: ThreadId,
|
||||
mode: Schema.Literals(["steer", "restart"]),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `Thread ${this.threadId} has no running turn that can be ${this.mode === "steer" ? "steered" : "restarted"}.`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +251,8 @@ export class ThreadManagementDurableRunProjectionError extends Schema.TaggedErro
|
||||
export const ThreadManagementError = Schema.Union([
|
||||
ThreadManagementThreadNotFoundError,
|
||||
ThreadManagementRunNotFoundError,
|
||||
ThreadManagementThreadNotSendableError,
|
||||
ThreadManagementThreadArchivedError,
|
||||
ThreadManagementNoSteerableRunError,
|
||||
ThreadManagementThreadNotInterruptibleError,
|
||||
ThreadManagementProjectionLoadError,
|
||||
ThreadManagementProjectThreadsListError,
|
||||
@@ -466,9 +466,8 @@ const make = Effect.gen(function* () {
|
||||
Effect.gen(function* () {
|
||||
const target = yield* getProjectThread(input);
|
||||
if (target.thread.archivedAt !== null) {
|
||||
return yield* new ThreadManagementThreadNotSendableError({
|
||||
return yield* new ThreadManagementThreadArchivedError({
|
||||
threadId: input.threadId,
|
||||
reason: { _tag: "Archived" },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -479,9 +478,9 @@ const make = Effect.gen(function* () {
|
||||
>["dispatchMode"];
|
||||
if (input.mode === "steer" || input.mode === "restart") {
|
||||
if (steerableRun === undefined) {
|
||||
return yield* new ThreadManagementThreadNotSendableError({
|
||||
return yield* new ThreadManagementNoSteerableRunError({
|
||||
threadId: input.threadId,
|
||||
reason: { _tag: "NoSteerableRun", mode: input.mode },
|
||||
mode: input.mode,
|
||||
});
|
||||
}
|
||||
dispatchMode = {
|
||||
|
||||
Reference in new issue
Block a user