diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index bdea5401cf..53daae3d96 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -602,22 +602,24 @@ export const claudeAgentSdkQueryRunnerLiveLayer: Layer.Layer< ), ), stopTask: (taskId) => - Effect.tryPromise({ - try: () => { - // stopTask is deliberate wire surface (the CLI's own - // /workflows view stops through it) but absent from the - // published SDK types — this cast is the single place the - // undocumented method is read. - const stop = (queryRuntime as { stopTask?: (taskId: string) => Promise }) - .stopTask; - if (stop === undefined) { - throw new Error( - "The Claude SDK runtime for this session does not expose stopTask.", - ); - } - return stop.call(queryRuntime, taskId); - }, - catch: (cause) => queryRunnerError(cause, "stopTask"), + Effect.suspend(() => { + // stopTask is deliberate wire surface (the CLI's own + // /workflows view stops through it) but absent from the + // published SDK types — this cast is the single place the + // undocumented method is read. + const stop = (queryRuntime as { stopTask?: (taskId: string) => Promise }) + .stopTask; + return stop === undefined + ? Effect.fail( + new ClaudeAgentSdkQueryRunnerError({ + method: "stopTask", + cause: "The Claude SDK runtime for this session does not expose stopTask.", + }), + ) + : Effect.tryPromise({ + try: () => stop.call(queryRuntime, taskId), + catch: (cause) => queryRunnerError(cause, "stopTask"), + }); }).pipe( Effect.tap(() => logProtocolEvent({ diff --git a/apps/server/src/orchestration-v2/ProviderTurnControlService.ts b/apps/server/src/orchestration-v2/ProviderTurnControlService.ts index 732635ab47..507c748303 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnControlService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnControlService.ts @@ -47,6 +47,7 @@ export class ProviderTaskStopError extends Schema.TaggedErrorClass - Schema.is(ProviderTaskStopError)(cause) + isProviderTaskStopError(cause) ? cause : new ProviderTaskStopError({ threadId: input.threadId,