Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,10 @@ function fakeRuntimeFactory(
captures.order.push("abort");
expect(captures.prompts.at(-1)?.signal?.aborted).toBe(true);
}),
abortAndSendQueued: Effect.sync(() => {
captures.order.push("abortAndSendQueued");
expect(captures.prompts.at(-1)?.signal?.aborted).toBe(true);
}),
abortAndClearQueue: captures.abortClearFailure
? Effect.fail(
new PrimeAgentDaemonSessionRuntimeError({
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/provider/prime/PrimeAgentDaemonBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export interface PrimeAgentDaemonAgentConnection {
) => Promise<unknown>;
readonly abort: () => Promise<unknown>;
readonly abortAndClearQueue?: () => Promise<unknown>;
readonly abortAndSendQueued?: () => Promise<unknown>;
readonly startSideQuestion?: (nativeId: string, question: string) => Promise<unknown>;
readonly abortSideQuestion?: (nativeId: string) => Promise<unknown>;
readonly cancelRlmChild?: (childId: string) => Promise<unknown>;
Expand Down
113 changes: 113 additions & 0 deletions apps/server/src/provider/prime/PrimeAgentDaemonSessionRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ function fixture(options?: {
readonly setRlmImpl?: (maxDepth: number) => Promise<unknown>;
readonly cancelRlmImpl?: (agentId: string) => Promise<unknown>;
readonly sendAgentMessageImpl?: (activeSessionId: string, message: string) => Promise<unknown>;
readonly abortAndSendQueuedImpl?: () => Promise<unknown>;
readonly abortAndSendQueuedSupported?: boolean;
readonly omitAbortAndSendQueued?: boolean;
readonly omitSendAgentMessage?: boolean;
readonly omitWatchSession?: boolean;
readonly watchSessionUndefined?: boolean;
Expand Down Expand Up @@ -572,6 +575,9 @@ function fixture(options?: {
if (options?.omitNegotiatedCapabilityAccessor === true) {
Object.defineProperty(this, "supportsNegotiatedCapability", { value: undefined });
}
if (options?.omitAbortAndSendQueued === true) {
Object.defineProperty(this, "abortAndSendQueued", { value: undefined });
}
}
static attach(
_client: PrimeAgentDaemonClient,
Expand Down Expand Up @@ -672,6 +678,9 @@ function fixture(options?: {
return options?.getPromptLifecyclesImpl?.() ?? Promise.resolve({ records: [], expired: [] });
}
supportsNegotiatedCapability(capability: string): boolean {
if (capability === "abort_and_send_queued_v1") {
return options?.abortAndSendQueuedSupported ?? false;
}
return capability === "caller_owned_session_environment_cleanup_v1"
? true
: capability === "correlated_prompt_lifecycle_v1" &&
Expand Down Expand Up @@ -730,6 +739,10 @@ function fixture(options?: {
captures.connectionCalls.push({ method: "abort", args: [] });
return Promise.resolve(undefined);
}
abortAndSendQueued(): Promise<unknown> {
captures.connectionCalls.push({ method: "abortAndSendQueued", args: [] });
return options?.abortAndSendQueuedImpl?.() ?? Promise.resolve(undefined);
}
abortAndClearQueue(): Promise<unknown> {
captures.connectionCalls.push({ method: "abortAndClearQueue", args: [] });
queuedInputSuspended = true;
Expand Down Expand Up @@ -14250,6 +14263,106 @@ describe("Prime Agent live activity privacy boundary", () => {
),
);

it.effect(
"invokes connection.abortAndSendQueued when abort_and_send_queued_v1 is negotiated",
() =>
Effect.scoped(
Effect.gen(function* () {
const { captures, make } = fixture({ abortAndSendQueuedSupported: true });
const runtime = yield* make();

yield* runtime.abort;
expect(captures.connectionCalls).toContainEqual({
method: "abortAndSendQueued",
args: [],
});
expect(captures.connectionCalls).not.toContainEqual({
method: "abort",
args: [],
});

yield* runtime.abortAndSendQueued;
expect(
captures.connectionCalls.filter((call) => call.method === "abortAndSendQueued"),
).toHaveLength(2);
}),
),
);

it.effect("falls back to connection.abort when abort_and_send_queued_v1 is not negotiated", () =>
Effect.scoped(
Effect.gen(function* () {
const { captures, make } = fixture({ abortAndSendQueuedSupported: false });
const runtime = yield* make();

yield* runtime.abort;
expect(captures.connectionCalls).toContainEqual({
method: "abort",
args: [],
});
expect(captures.connectionCalls).not.toContainEqual({
method: "abortAndSendQueued",
args: [],
});

yield* runtime.abortAndSendQueued;
expect(captures.connectionCalls.filter((call) => call.method === "abort")).toHaveLength(2);
expect(captures.connectionCalls).not.toContainEqual({
method: "abortAndSendQueued",
args: [],
});
}),
),
);

it.effect(
"falls back to connection.abort when abort_and_send_queued_v1 is negotiated but method is missing",
() =>
Effect.scoped(
Effect.gen(function* () {
const { captures, make } = fixture({
abortAndSendQueuedSupported: true,
omitAbortAndSendQueued: true,
});
const runtime = yield* make();

yield* runtime.abort;
expect(captures.connectionCalls).toContainEqual({
method: "abort",
args: [],
});
expect(captures.connectionCalls).not.toContainEqual({
method: "abortAndSendQueued",
args: [],
});

yield* runtime.abortAndSendQueued;
expect(captures.connectionCalls.filter((call) => call.method === "abort")).toHaveLength(
2,
);
}),
),
);

it.effect("propagates failure when abortAndSendQueued rejects", () =>
Effect.scoped(
Effect.gen(function* () {
const { make } = fixture({
abortAndSendQueuedSupported: true,
abortAndSendQueuedImpl: () => Promise.reject(new Error("abort_and_send_queued failed")),
});
const runtime = yield* make();

const error = yield* runtime.abort.pipe(Effect.flip);
expect(error).toMatchObject({
operation: "abort",
reason: "request-failed",
detail: "The daemon operation failed.",
});
}),
),
);

it.effect("deduplicates explicit abort, dispose, and ask finalization", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down
14 changes: 13 additions & 1 deletion apps/server/src/provider/prime/PrimeAgentDaemonSessionRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ export interface PrimeAgentDaemonSessionRuntime {
}) => Effect.Effect<void, PrimeAgentDaemonSessionRuntimeError>;
readonly abort: Effect.Effect<void, PrimeAgentDaemonSessionRuntimeError>;
readonly abortAndClearQueue: Effect.Effect<void, PrimeAgentDaemonSessionRuntimeError>;
readonly abortAndSendQueued: Effect.Effect<void, PrimeAgentDaemonSessionRuntimeError>;
readonly sideQuestionsAvailable: boolean;
/** Runs one requester-scoped unary question; native prompt/error/id fields never escape. */
readonly askSideQuestion: (
Expand Down Expand Up @@ -8199,9 +8200,19 @@ export const makePrimeAgentDaemonSessionRuntime = Effect.fn("makePrimeAgentDaemo
if (correlatedPromptLifecycleAvailable) {
yield* requireCorrelatedPromptLifecycleAdmission("abort");
}
yield* callVoid("abort", () => connection!.abort());
const canAbortAndSendQueued =
Predicate.isFunction(connection?.supportsNegotiatedCapability) &&
connection.supportsNegotiatedCapability("abort_and_send_queued_v1") === true &&
Predicate.isFunction(connection?.abortAndSendQueued);
if (canAbortAndSendQueued) {
yield* callVoid("abort", () => connection!.abortAndSendQueued!());
} else {
yield* callVoid("abort", () => connection!.abort());
}
});

const abortAndSendQueued = abort;

const abortAndClearQueue = Effect.gen(function* () {
yield* ensureOpen("abort-and-clear-queue");
if (correlatedPromptLifecycleAvailable) {
Expand Down Expand Up @@ -9020,6 +9031,7 @@ export const makePrimeAgentDaemonSessionRuntime = Effect.fn("makePrimeAgentDaemo
setInputQueueMode,
abort,
abortAndClearQueue,
abortAndSendQueued,
sideQuestionsAvailable,
askSideQuestion,
abortSideQuestion,
Expand Down
Loading