Skip to content

Commit 119deb7

Browse files
committed
refactor(client): split delayed-send unsupported errors
1 parent eb798bd commit 119deb7

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

‎packages/client-runtime/src/operations/commands.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,9 @@ describe("V2 environment commands", () => {
442442
Effect.flip,
443443
);
444444
expect(refused).toMatchObject({
445-
_tag: "OrchestrationV2DelayedMessageUnsupportedError",
446-
reason: "server",
445+
_tag: "OrchestrationV2DelayedMessageServerUnsupportedError",
446+
threadId: v2ThreadId,
447+
message: "This environment cannot schedule messages. Update it to send later.",
447448
});
448449
expect(oldCommands).toEqual([]);
449450

@@ -482,7 +483,11 @@ describe("V2 environment commands", () => {
482483
Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
483484
Effect.flip,
484485
);
485-
expect(launch).toMatchObject({ reason: "thread_launch" });
486+
expect(launch).toMatchObject({
487+
_tag: "OrchestrationV2DelayedMessageThreadLaunchUnsupportedError",
488+
threadId: v2ThreadId,
489+
message: "The first message of a new thread or worktree cannot be scheduled.",
490+
});
486491
expect(launches).toEqual([]);
487492
expect(commands).toHaveLength(1);
488493
}).pipe(Effect.provide(layerTestCrypto)),
@@ -539,8 +544,9 @@ describe("V2 environment commands", () => {
539544
Effect.flip,
540545
);
541546
expect(refused).toMatchObject({
542-
_tag: "OrchestrationV2DelayedMessageUnsupportedError",
543-
reason: "server",
547+
_tag: "OrchestrationV2DelayedMessageServerUnsupportedError",
548+
threadId: v2ThreadId,
549+
message: "This environment cannot schedule messages. Update it to send later.",
544550
});
545551
expect(oldCommands).toEqual([]);
546552
expect(commands).toEqual([]);

‎packages/client-runtime/src/operations/commands.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
CheckpointScopeId,
77
ORCHESTRATION_V2_WS_METHODS,
88
OrchestrationV2CheckpointUnavailableError,
9-
OrchestrationV2DelayedMessageUnsupportedError,
9+
OrchestrationV2DelayedMessageServerUnsupportedError,
10+
OrchestrationV2DelayedMessageThreadLaunchUnsupportedError,
1011
WS_METHODS,
1112
type ChatAttachment,
1213
type MessageId,
@@ -279,9 +280,7 @@ const getProjection = (threadId: ThreadId) =>
279280
const requireDelayedMessages = (threadId: ThreadId) => (config: ServerConfig) =>
280281
config.environment.capabilities.delayedMessages === true
281282
? Effect.void
282-
: Effect.fail(
283-
new OrchestrationV2DelayedMessageUnsupportedError({ threadId, reason: "server" }),
284-
);
283+
: Effect.fail(new OrchestrationV2DelayedMessageServerUnsupportedError({ threadId }));
285284

286285
const supportsServerResolvedCommandContext = Effect.fn(
287286
"EnvironmentCommands.supportsServerResolvedCommandContext",
@@ -644,9 +643,8 @@ export const startThreadTurn = Effect.fn("EnvironmentCommands.startThreadTurn")(
644643
// Fails fast before uploading attachments; dispatch re-checks on the session that sends it.
645644
yield* getInitialServerConfig().pipe(Effect.flatMap(requireDelayedMessages(input.threadId)));
646645
if (bootstrap !== undefined || prepareWorktree !== undefined) {
647-
return yield* new OrchestrationV2DelayedMessageUnsupportedError({
646+
return yield* new OrchestrationV2DelayedMessageThreadLaunchUnsupportedError({
648647
threadId: input.threadId,
649-
reason: "thread_launch",
650648
});
651649
}
652650
}

‎packages/contracts/src/orchestrationV2.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,17 +1219,25 @@ export class OrchestrationV2CheckpointUnavailableError extends Schema.TaggedErro
12191219
}
12201220
}
12211221

1222-
export class OrchestrationV2DelayedMessageUnsupportedError extends Schema.TaggedError<OrchestrationV2DelayedMessageUnsupportedError>()(
1223-
"OrchestrationV2DelayedMessageUnsupportedError",
1222+
export class OrchestrationV2DelayedMessageServerUnsupportedError extends Schema.TaggedError<OrchestrationV2DelayedMessageServerUnsupportedError>()(
1223+
"OrchestrationV2DelayedMessageServerUnsupportedError",
12241224
{
12251225
threadId: ThreadId,
1226-
reason: Schema.Literals(["server", "thread_launch"]),
12271226
},
12281227
) {
12291228
override get message(): string {
1230-
return this.reason === "server"
1231-
? "This environment cannot schedule messages. Update it to send later."
1232-
: "The first message of a new thread or worktree cannot be scheduled.";
1229+
return "This environment cannot schedule messages. Update it to send later.";
1230+
}
1231+
}
1232+
1233+
export class OrchestrationV2DelayedMessageThreadLaunchUnsupportedError extends Schema.TaggedError<OrchestrationV2DelayedMessageThreadLaunchUnsupportedError>()(
1234+
"OrchestrationV2DelayedMessageThreadLaunchUnsupportedError",
1235+
{
1236+
threadId: ThreadId,
1237+
},
1238+
) {
1239+
override get message(): string {
1240+
return "The first message of a new thread or worktree cannot be scheduled.";
12331241
}
12341242
}
12351243

0 commit comments

Comments
 (0)