Skip to content
Open
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 @@ -1414,6 +1414,61 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => {
}).pipe(Effect.provide(layerSession)),
);

// agy 1.5.13 answers a prompt sent while ask_question waits with "Can't add this prompt to
// session ...: the running prompt is waiting for a permission or question answer".
it.effect("declines a steer while the agent waits on a question", () =>
Effect.gen(function* () {
const opened = yield* openSessionWithRunningCommand({}, undefined, {
agentVersion: "1.5.13",
holdsFirstPrompt: true,
});
const { session, providerThread, command, startTurn, until, requestPermission } = opened;
yield* startTurn(1, false);
const started = yield* until(
(event) =>
event.type === "turn_item.updated" &&
event.turnItem.nativeItemRef?.nativeId === command.toolCallId,
);
const providerTurnId = started.flatMap((event) =>
event.type === "provider_turn.updated" ? [event.providerTurn.id] : [],
)[0]!;
const answer = yield* requestPermission(
{
...permissionRequest("interaction_1", [
{ optionId: "red", name: "Red", kind: "allow_once" },
{ optionId: "blue", name: "Blue", kind: "allow_once" },
]),
sessionId: "mock-session-1",
},
{ requestId: "question-1", method: "session/request_permission" },
).pipe(Effect.forkScoped({ startImmediately: true }));
yield* until(
(event) =>
event.type === "turn_item.updated" && event.turnItem.type === "user_input_request",
);

const steer = yield* session
.steerTurn({
threadId: ThreadId.make("thread-antigravity-wake"),
runId: RunId.make("run-antigravity-wake-1"),
providerThread,
providerTurnId,
message: {
messageId: MessageId.make("message-antigravity-steer"),
text: "Pick whichever you like",
attachments: [],
createdBy: "user",
creationSource: "web",
},
})
.pipe(Effect.flip);
assert.equal(steer._tag, "ProviderAdapterSteerDeclinedError");
assert.lengthOf(opened.prompts, 1, "the steer must not reach the waiting agent");
assert.equal(opened.cancels(), 0, "a declined steer must not cancel the question");
assert.isUndefined(answer.pollUnsafe(), "the question stays open for the user");
}).pipe(Effect.provide(layerSession)),
);

// A wake run has no prompt of its own, yet agy can keep working in it for minutes.
it.effect("steers a continuation run that keeps working after its wake", () =>
Effect.gen(function* () {
Expand Down
13 changes: 12 additions & 1 deletion packages/provider-acp/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9620,6 +9620,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
generation,
Effect.gen(function* () {
if (context.finalized || context.interrupted) return false;
// `agy acp` rejects a prompt while the running one waits on a question or
// approval, so the message waits as a follow-up until the user answers. Checked
// under the callback permit, which also guards registering those requests.
if ((yield* Ref.get(pendingRuntimeRequests)).size > 0) {
return yield* new ProviderAdapter.ProviderAdapterSteerDeclinedError({
driver,
providerThreadId: turnInput.providerThread.id,
providerTurnId: turnInput.providerTurnId,
});
}
// The steer prompt carries the turn on, also past a prompt that already settled.
const released = context.foregroundIdle;
context.foregroundIdle = yield* Deferred.make<void>();
Expand Down Expand Up @@ -10018,7 +10028,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
(effect, turnInput) =>
effect.pipe(
Effect.mapError((cause) =>
cause._tag === "ProviderAdapterSteerRunUnsupportedError"
cause._tag === "ProviderAdapterSteerRunUnsupportedError" ||
cause._tag === "ProviderAdapterSteerDeclinedError"
? cause
: new ProviderAdapter.ProviderAdapterSteerRunError({
driver,
Expand Down
Loading