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
186 changes: 183 additions & 3 deletions apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,8 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand")
options?: {
readonly profileDirectory?: string;
readonly initialToolCalls?: ReadonlyArray<EffectAcpSchema.SessionUpdate>;
readonly runtimeMode?: ProviderAdapter.ProviderAdapterV2RuntimePolicy["runtimeMode"];
readonly disableContinuationRequests?: boolean;
},
) {
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
Expand Down Expand Up @@ -1043,7 +1045,13 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand")
const adapterOptions: AntigravityAdapterV2Options = {
instanceId,
selfInvocation,
continuationRequests: { offer: (request) => Effect.sync(() => void offers.push(request)) },
...(options?.disableContinuationRequests
? {}
: {
continuationRequests: {
offer: (request) => Effect.sync(() => void offers.push(request)),
},
}),
makeRuntime: (input) => {
terminate = input.onTermination;
return makeAntigravityAcpRuntime({
Expand Down Expand Up @@ -1137,8 +1145,9 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand")
onDeferredFinalizeScheduled: (debounce) => Queue.offer(scheduledFinalizes, debounce),
},
});
const runtimeMode = options?.runtimeMode ?? "full-access";
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
runtimeMode: "full-access",
runtimeMode,
interactionMode: "default",
cwd: process.cwd(),
});
Expand Down Expand Up @@ -1179,7 +1188,7 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand")
title: "Antigravity wake",
providerInstanceId: instanceId,
modelSelection,
runtimeMode: "full-access",
runtimeMode,
interactionMode: "default",
branch: null,
worktreePath: process.cwd(),
Expand Down Expand Up @@ -2010,6 +2019,177 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => {
assert.equal(opened.cancels(), cancels);
}).pipe(Effect.provide(layerSession)),
);

it.effect(
"auto-approves a detached full-access permission request when its continuation cannot attach",
() =>
Effect.gen(function* () {
const { offers, startTurn, throughTerminal, requestPermission } =
yield* openSessionWithRunningCommand({ IsDaemon: true, WaitMsBeforeAsync: 500 });
yield* startTurn(1, false);
yield* throughTerminal;

const followUp = { toolCallId: "call_git_push", kind: "execute", title: "git push" };
const permission = yield* requestPermission(
{
sessionId: "mock-session-1",
toolCall: { ...followUp, status: "pending" },
options: [
{ optionId: "allow", name: "Allow", kind: "allow_once" },
{ optionId: "deny", name: "Deny", kind: "reject_once" },
],
},
{ requestId: "permission-unattached", method: "session/request_permission" },
).pipe(Effect.forkScoped({ startImmediately: true }));
assert.lengthOf(offers, 1);
assert.isDefined(offers[0]!.onRunEndedWithoutStarting);
yield* offers[0]!.onRunEndedWithoutStarting!();
assert.deepEqual(yield* Fiber.join(permission), {
outcome: { outcome: "selected", optionId: "allow" },
});
}).pipe(Effect.provide(layerSession)),
);

it.effect(
"auto-approves a detached full-access permission request when continuation is unavailable",
() =>
Effect.gen(function* () {
const { startTurn, throughTerminal, requestPermission } =
yield* openSessionWithRunningCommand(
{ IsDaemon: true, WaitMsBeforeAsync: 500 },
undefined,
undefined,
{ disableContinuationRequests: true },
);
yield* startTurn(1, false);
yield* throughTerminal;

const response = yield* requestPermission(
{
sessionId: "mock-session-1",
toolCall: {
toolCallId: "call_no_cont",
kind: "execute",
title: "curl https://example.com",
status: "pending",
},
options: [
{ optionId: "allow", name: "Allow", kind: "allow_once" },
{ optionId: "deny", name: "Deny", kind: "reject_once" },
],
},
{ requestId: "permission-no-cont", method: "session/request_permission" },
);
assert.deepEqual(response, { outcome: { outcome: "selected", optionId: "allow" } });
}).pipe(Effect.provide(layerSession)),
);

it.effect("cancels a detached permission request after Stop even in full-access mode", () =>
Effect.gen(function* () {
const opened = yield* openSessionWithRunningCommand({ WaitMsBeforeAsync: 10000 });
yield* opened.startTurn(1, false);
const started = yield* opened.throughPromptSettled;
const turn = started.find((event) => event.type === "provider_turn.updated");
if (turn?.type !== "provider_turn.updated") return assert.fail("the turn must start");

yield* opened.session.interruptTurn({
providerThread: opened.providerThread,
providerTurnId: turn.providerTurn.id,
requestRuntimeRestart: true,
});
yield* opened.throughTerminal;

const response = yield* opened.requestPermission(
{
sessionId: "mock-session-1",
toolCall: {
toolCallId: "call_after_stop",
kind: "execute",
title: "rm -rf /tmp/unused",
status: "pending",
},
options: [
{ optionId: "allow", name: "Allow", kind: "allow_once" },
{ optionId: "deny", name: "Deny", kind: "reject_once" },
],
},
{ requestId: "permission-stop", method: "session/request_permission" },
);
assert.deepEqual(response, { outcome: { outcome: "cancelled" } });
}).pipe(Effect.provide(layerSession)),
);

it.effect(
"cancels a detached approval-required permission request when its continuation cannot attach",
() =>
Effect.gen(function* () {
const { offers, startTurn, throughTerminal, requestPermission } =
yield* openSessionWithRunningCommand(
{ IsDaemon: true, WaitMsBeforeAsync: 500 },
undefined,
undefined,
{ runtimeMode: "approval-required" },
);
yield* startTurn(1, false);
yield* throughTerminal;

const permission = yield* requestPermission(
{
sessionId: "mock-session-1",
toolCall: {
toolCallId: "call_ask_unattached",
kind: "execute",
title: "git push",
status: "pending",
},
options: [
{ optionId: "allow", name: "Allow", kind: "allow_once" },
{ optionId: "deny", name: "Deny", kind: "reject_once" },
],
},
{ requestId: "permission-ask-unattached", method: "session/request_permission" },
).pipe(Effect.forkScoped({ startImmediately: true }));
assert.lengthOf(offers, 1);
yield* offers[0]!.clearIfCurrent!();
assert.deepEqual(yield* Fiber.join(permission), {
outcome: { outcome: "cancelled" },
});
}).pipe(Effect.provide(layerSession)),
);

it.effect(
"cancels a detached approval-required permission request when continuation is unavailable",
() =>
Effect.gen(function* () {
const { startTurn, throughTerminal, requestPermission } =
yield* openSessionWithRunningCommand(
{ IsDaemon: true, WaitMsBeforeAsync: 500 },
undefined,
undefined,
{ runtimeMode: "approval-required", disableContinuationRequests: true },
);
yield* startTurn(1, false);
yield* throughTerminal;

const response = yield* requestPermission(
{
sessionId: "mock-session-1",
toolCall: {
toolCallId: "call_ask_no_cont",
kind: "execute",
title: "git push",
status: "pending",
},
options: [
{ optionId: "allow", name: "Allow", kind: "allow_once" },
{ optionId: "deny", name: "Deny", kind: "reject_once" },
],
},
{ requestId: "permission-ask-no-cont", method: "session/request_permission" },
);
assert.deepEqual(response, { outcome: { outcome: "cancelled" } });
}).pipe(Effect.provide(layerSession)),
);
});

describe("AntigravityAdapterV2 subagent reads", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type OrchestrationV2Notification,
} from "@t3tools/contracts";
import * as Clock from "effect/Clock";
import * as DateTime from "effect/DateTime";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
Expand All @@ -20,6 +21,7 @@ import * as Option from "effect/Option";
import * as Queue from "effect/Queue";
import * as Ref from "effect/Ref";
import * as Semaphore from "effect/Semaphore";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";

import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
Expand Down Expand Up @@ -661,4 +663,62 @@ describe("ProviderContinuationService", () => {
});
},
);

it.effect(
"calls onRunEndedWithoutStarting when a started continuation run fails before attaching a turn",
() =>
Effect.gen(function* () {
const continuationRunId = RunId.make("run-provider-continuation-start-failed");
const released = yield* Deferred.make<void>();
const startedAt = DateTime.makeUnsafe("2026-11-22T05:00:00.000Z");
const layerThreads = Layer.mock(ThreadManagementService.ThreadManagementService)({
getThreadRecords: () => Effect.succeed(projection),
dispatch: (command) =>
Effect.succeed({
sequence: 10,
storedEvents: [
{
sequence: 10,
event: {
type: "run.created",
payload: {
id: continuationRunId,
userMessageId: "messageId" in command ? command.messageId : undefined,
},
},
},
],
} as never),
streamStoredEventsFrom: () =>
Stream.make({
sequence: 11,
event: {
type: "run.updated",
payload: {
id: continuationRunId,
status: "failed",
startedAt,
},
},
} as never),
});
const layerWorker = ProviderContinuationService.layer.pipe(
Layer.provide(
Layer.mergeAll(IdAllocator.layer, ProviderContinuationRequests.layer, layerThreads),
),
);

yield* Effect.gen(function* () {
const requests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
yield* requests.offer({
...request(),
onRunEndedWithoutStarting: () => Deferred.succeed(released, undefined),
});
yield* Deferred.await(released);
}).pipe(
Effect.provide(Layer.merge(ProviderContinuationRequests.layer, layerWorker)),
Effect.scoped,
);
}),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export const layer = Layer.effectDiscard(
return [Math.min(100 * 2 ** Math.min(attempt, 6), 5_000), updated] as const;
});

// Cancelling or stopping a queued continuation ends it unstarted; only the request can release the adapter's wake latch.
// Cancelling a queued continuation or failing a started run before a provider turn attaches leaves only the
// request able to release the adapter's wake latch; adapters guard by generation/token once a turn attaches.
const releaseIfNeverStarted = Effect.fn("ProviderContinuationService.releaseIfNeverStarted")(
function* (
request: ProviderContinuationRequests.ProviderContinuationRequest,
Expand Down Expand Up @@ -113,11 +114,7 @@ export const layer = Layer.effectDiscard(
),
Stream.runHead,
Effect.flatMap((ended) =>
Option.isSome(ended) &&
ended.value.event.type === "run.updated" &&
ended.value.event.payload.startedAt === null
? onRunEndedWithoutStarting()
: Effect.void,
Option.isSome(ended) ? onRunEndedWithoutStarting() : Effect.void,
),
Effect.catchCause((cause) =>
Effect.logWarning("orchestration-v2.provider-continuation.run-watch-failed", {
Expand Down
Loading
Loading