Skip to content

Commit e9ce631

Browse files
author
Valentin De Matos
committed
fix(acp): scope pending prompt cancellation
1 parent b043ad4 commit e9ce631

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎apps/server/src/provider/Layers/OmpAdapter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ export function makeOmpAdapter(ompSettings: OmpSettings, options?: OmpAdapterLiv
11221122
yield* settlePendingUserInputsAsEmptyAnswers(ctx.pendingUserInputs);
11231123
if (ctx.promptInFlight) {
11241124
yield* Effect.ignore(
1125-
ctx.acp.cancel.pipe(
1125+
ctx.acp.cancelPendingPrompt.pipe(
11261126
Effect.mapError((error) => mapOmpAcpToAdapterError("session/cancel", error)),
11271127
),
11281128
);

‎apps/server/src/provider/acp/AcpSessionRuntime.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ export class AcpSessionRuntime extends Context.Service<
210210
* @see https://agentclientprotocol.com/protocol/schema#session/cancel
211211
*/
212212
readonly cancel: Effect.Effect<void, EffectAcpErrors.AcpError>;
213+
/** Queues cancellation across the prompt-start handshake, then sends `session/cancel`. */
214+
readonly cancelPendingPrompt: Effect.Effect<void, EffectAcpErrors.AcpError>;
213215
/** Clears a queued cancel after the caller has observed prompt settlement. */
214216
readonly clearPendingCancel: Effect.Effect<void>;
215217
/**
@@ -806,6 +808,19 @@ export const make = (
806808
}),
807809
),
808810
cancel: getStartedState.pipe(
811+
Effect.flatMap((started) =>
812+
Effect.gen(function* () {
813+
const activePromptFiber = yield* Ref.get(activePromptFiberRef);
814+
if (Option.isSome(activePromptFiber)) {
815+
yield* Fiber.interrupt(activePromptFiber.value).pipe(Effect.ignore);
816+
}
817+
yield* acp.agent
818+
.cancel({ sessionId: started.sessionId })
819+
.pipe(Effect.ignore, Effect.forkIn(runtimeScope));
820+
}),
821+
),
822+
),
823+
cancelPendingPrompt: getStartedState.pipe(
809824
Effect.flatMap((started) =>
810825
Effect.gen(function* () {
811826
yield* Ref.set(cancelRequestedRef, true);

0 commit comments

Comments
 (0)