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
43 changes: 41 additions & 2 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11533,7 +11533,10 @@ describe("AcpAdapterV2", () => {
);

// A dev server started as a background shell never exits, so it must not hold the root turn.
const startGrokBackgroundShellTurn = Effect.fnUntraced(function* (name: string) {
const startGrokBackgroundShellTurn = Effect.fnUntraced(function* (
name: string,
requiresRuntimeRestartForPolicy?: AcpAdapterV2Flavor["requiresRuntimeRestartForPolicy"],
) {
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const path = yield* Path.Path;
const selfInvocation = yield* resolveSelfInvocation();
Expand Down Expand Up @@ -11578,6 +11581,9 @@ describe("AcpAdapterV2", () => {
extractBackgroundTaskId: grokFlavor.extractBackgroundTaskId!,
isBackgroundCommandTool: grokFlavor.isBackgroundCommandTool!,
isPersistentBackgroundTool: grokFlavor.isPersistentBackgroundTool!,
...(requiresRuntimeRestartForPolicy === undefined
? {}
: { requiresRuntimeRestartForPolicy }),
registerExtensions: ({ runtime, applyBackgroundTaskMutation }) =>
registerXAiBackgroundTaskTracking(runtime, applyBackgroundTaskMutation),
makeRuntime: makeMockRuntime({
Expand All @@ -11602,6 +11608,7 @@ describe("AcpAdapterV2", () => {
}),
}),
},
continuationRequests: { offer: () => Effect.void },
});
const threadId = ThreadId.make(`thread-acp-${name}`);
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
Expand Down Expand Up @@ -11706,7 +11713,17 @@ describe("AcpAdapterV2", () => {
rows.push(event.turnItem);
}
});
return { update, complete, startDevServer, settle, takeRows, runId: turnInput.runId };
return {
update,
complete,
startDevServer,
settle,
takeRows,
runId: turnInput.runId,
runtime,
providerThread,
modelSelection,
};
});

it.effect("completes a settled Grok turn while a background shell keeps running", () =>
Expand All @@ -11721,6 +11738,28 @@ describe("AcpAdapterV2", () => {
}).pipe(Effect.provide(layerTest), Effect.scoped),
);

it.effect("a policy restart drops background tasks the old process was running", () =>
Effect.gen(function* () {
const harness = yield* startGrokBackgroundShellTurn(
"grok-dev-server-policy-restart",
(launched, next) => launched.runtimeMode !== next.runtimeMode,
);
yield* harness.startDevServer;
yield* harness.settle;
assert.isTrue(yield* harness.runtime.hasPendingBackgroundWork!);
yield* harness.runtime.resumeThread({
providerThread: harness.providerThread,
modelSelection: harness.modelSelection,
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
runtimeMode: "approval-required",
interactionMode: "default",
cwd: process.cwd(),
}),
});
assert.isFalse(yield* harness.runtime.hasPendingBackgroundWork!);
}).pipe(Effect.provide(layerTest), Effect.scoped),
);

it.effect("keeps a streaming Grok background shell running on its run after settling", () =>
Effect.gen(function* () {
const harness = yield* startGrokBackgroundShellTurn("grok-dev-server-progress");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2308,12 +2308,14 @@ describe("AntigravityAdapterV2 runtime mode ceiling", () => {
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
);
let runtime: AcpSessionRuntime.AcpSessionRuntime["Service"] | undefined;
const launchModes: Array<string | undefined> = [];
const instanceId = ProviderInstanceId.make("antigravity-plan-exit-test");
const adapter = yield* makeAntigravityAdapterV2({
instanceId,
selfInvocation: yield* resolveSelfInvocation(),
makeRuntime: (input) =>
makeAntigravityAcpRuntime({
makeRuntime: (input) => {
launchModes.push(input.runtimePolicy?.runtimeMode);
return makeAntigravityAcpRuntime({
...input,
childProcessSpawner,
spawn: {
Expand All @@ -2329,7 +2331,8 @@ describe("AntigravityAdapterV2 runtime mode ceiling", () => {
runtime = made;
}),
),
),
);
},
withProcess: (_stop, task) => task,
defaultModel: Effect.undefined,
});
Expand Down Expand Up @@ -2376,6 +2379,7 @@ describe("AntigravityAdapterV2 runtime mode ceiling", () => {
Stream.runHead,
);
assert.equal((yield* runtime!.getModeState)?.currentModeId, "default");
assert.deepEqual(launchModes, ["full-access", "approval-required"]);
}).pipe(Effect.provide(layerSession), Effect.scoped),
);
});
Expand Down
15 changes: 12 additions & 3 deletions apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import {
antigravityPermissionDisposition,
antigravityPermissionMode,
antigravityRuntimeModeForSessionMode,
antigravitySkipsPermissions,
antigravitySteersWithPrompt,
applyAntigravityAcpModelSelection,
buildAntigravityPrompt,
type AntigravityAcpRuntimeInput,
type AntigravityLaunchPermissionPolicy,
} from "../../provider/acp/AntigravityAcpSupport.ts";
import {
ANTIGRAVITY_SUBAGENT_BATCH_TITLE,
Expand Down Expand Up @@ -63,7 +65,9 @@ const AntigravityProviderCapabilitiesV2 = {
sessions: {
...AcpProviderCapabilitiesV2.sessions,
supportsModelSwitchInSession: true,
supportsRuntimeModeSwitchInSession: true,
// Unrestricted Full access passes `--dangerously-skip-permissions` at launch, so switching
// across permission modes respawns `agy acp` and resumes the session via `session/resume`.
supportsRuntimeModeSwitchInSession: false,
},
tools: {
...AcpProviderCapabilitiesV2.tools,
Expand All @@ -75,11 +79,14 @@ const AntigravityProviderCapabilitiesV2 = {
},
} satisfies OrchestrationV2ProviderCapabilities;

/** Thread variables reach the driver here; `makeAntigravityAcpRuntime` never reads them. */
/** Thread variables and launch-time permission policy reach the driver here; `makeAntigravityAcpRuntime` never reads them. */
export type AntigravityAdapterV2RuntimeInput = Omit<
AntigravityAcpRuntimeInput,
"spawn" | "childProcessSpawner"
> & { readonly processEnvironment?: NodeJS.ProcessEnv };
> & {
readonly processEnvironment?: NodeJS.ProcessEnv;
readonly runtimePolicy?: AntigravityLaunchPermissionPolicy;
};

export interface AntigravityAdapterV2Options {
readonly instanceId: ProviderInstanceId;
Expand Down Expand Up @@ -265,6 +272,8 @@ export function makeAntigravityAcpAdapterFlavor(
}),
sessionModeForPolicy: (policy) => antigravityPermissionMode(policy.runtimeMode),
runtimeModeForSessionMode: antigravityRuntimeModeForSessionMode,
requiresRuntimeRestartForPolicy: (launchedPolicy, nextPolicy) =>
antigravitySkipsPermissions(launchedPolicy) !== antigravitySkipsPermissions(nextPolicy),
clientFileSystem: {
readTextFile: (request, cwd) =>
readAntigravityClientTextFile({
Expand Down
86 changes: 81 additions & 5 deletions apps/server/src/provider/Drivers/AntigravityDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,19 +420,36 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
},
]);

// The agy CLI rejects `yolo` and `auto_edit`; it stays in `default` and T3 answers its requests.
// Unrestricted Full access passes `--dangerously-skip-permissions` so detached subagents do
// not time out on unforwarded prompts; restricted Full access and Auto-accept edits omit it.
h.controls.selected = yield* h.makeExecutable("runtime cli", { initialMode: "auto_edit" });
for (const runtimeMode of ["full-access", "auto-accept-edits"] as const) {
for (const scenario of [
{
name: "full-access",
policy: { runtimeMode: "full-access" as const },
skipPermissions: true,
},
{
name: "full-access-restricted",
policy: { runtimeMode: "full-access" as const, approvalPolicy: "on-request" },
skipPermissions: false,
},
{
name: "auto-accept-edits",
policy: { runtimeMode: "auto-accept-edits" as const },
skipPermissions: false,
},
]) {
const requestsBefore = (yield* h.readRequests).length;
const cliThreadId = ThreadId.make(`thread-antigravity-cli-${runtimeMode}`);
const cliThreadId = ThreadId.make(`thread-antigravity-cli-${scenario.name}`);
const cliPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
runtimeMode,
...scenario.policy,
interactionMode: "default",
cwd: workspace,
});
const cliSession = yield* h.instance.orchestrationAdapter.openSession({
threadId: cliThreadId,
providerSessionId: ProviderSessionId.make(`provider-session-cli-${runtimeMode}`),
providerSessionId: ProviderSessionId.make(`provider-session-cli-${scenario.name}`),
modelSelection,
runtimePolicy: cliPolicy,
});
Expand All @@ -447,6 +464,7 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
h.profileDirectory,
"--app-data-dir",
"antigravity-acp",
...(scenario.skipPermissions ? ["--dangerously-skip-permissions"] : []),
]);
expect(
(yield* h.readRequests)
Expand All @@ -462,6 +480,64 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
}),
);

it.effect.skipIf(windowsHost)(
"respawns without --dangerously-skip-permissions when a Full access session downgrades before a turn",
() =>
Effect.gen(function* () {
const h = yield* makeHarness();
const threadId = ThreadId.make("thread-antigravity-downgrade");
const modelSelection = { instanceId: h.instance.instanceId, model: "gemini-test-low" };

yield* Effect.scoped(
Effect.gen(function* () {
const workspace = yield* h.fs.makeTempDirectoryScoped({ prefix: "t3-ag-downgrade-" });
const fullAccessPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
runtimeMode: "full-access",
interactionMode: "default",
cwd: workspace,
});
const supervisedPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
runtimeMode: "approval-required",
interactionMode: "default",
cwd: workspace,
});
const session = yield* h.instance.orchestrationAdapter.openSession({
threadId,
providerSessionId: ProviderSessionId.make("provider-session-antigravity-downgrade"),
modelSelection,
runtimePolicy: fullAccessPolicy,
});
const providerThread = yield* session.ensureThread({
threadId,
modelSelection,
runtimePolicy: fullAccessPolicy,
});
yield* session.resumeThread({
providerThread,
modelSelection,
runtimePolicy: supervisedPolicy,
});
}),
);

const agentLaunches = h.launches.filter(
(launch) => launch.command === h.first.executablePath,
);
expect(agentLaunches.map((launch) => launch.args)).toEqual([
[
"acp",
"--gemini-dir",
h.profileDirectory,
"--app-data-dir",
"antigravity-acp",
"--dangerously-skip-permissions",
],
["acp", "--gemini-dir", h.profileDirectory, "--app-data-dir", "antigravity-acp"],
]);
yield* h.assertClosed;
}),
);

it.effect.skipIf(windowsHost)(
"gives a thread session its own T3 thread and MCP fallback environment",
() =>
Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
import {
antigravityModelOptions,
antigravitySessionMode,
antigravitySkipsPermissions,
antigravityThinkingConfig,
makeAntigravityAcpRuntime,
type AntigravityAcpRuntimeInput,
Expand Down Expand Up @@ -207,6 +208,7 @@ export const AntigravityDriver: ProviderDriver<
const prepareSpawn = Effect.fn("AntigravityDriver.prepareSpawn")(function* (
cwd: string,
baseEnv: NodeJS.ProcessEnv,
options?: { readonly skipPermissions?: boolean },
): Effect.fn.Return<
{
readonly executable: AntigravityInstallation.AntigravityExecutable;
Expand Down Expand Up @@ -287,6 +289,7 @@ export const AntigravityDriver: ProviderDriver<
baseEnv,
auth,
runtimeTempDirectory,
...(options?.skipPermissions === true ? { skipPermissions: true } : {}),
}),
};
});
Expand All @@ -300,12 +303,13 @@ export const AntigravityDriver: ProviderDriver<
> {
// `buildAntigravityAcpSpawnInput` sets `extendEnv: false`, so thread variables only reach the
// agent's shell through `baseEnv`.
const { processEnvironment: threadEnvironment, ...runtimeInput } = input;
const { processEnvironment: threadEnvironment, runtimePolicy, ...runtimeInput } = input;
const { executable, spawn } = yield* prepareSpawn(
runtimeInput.cwd,
threadEnvironment === undefined
? processEnvironment
: { ...processEnvironment, ...threadEnvironment },
{ skipPermissions: antigravitySkipsPermissions(runtimePolicy) },
);
const runtime = yield* makeAntigravityAcpRuntime({
...runtimeInput,
Expand Down
35 changes: 35 additions & 0 deletions apps/server/src/provider/acp/AntigravityAcpSupport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
antigravityPermissionDisposition,
antigravitySessionMeta,
antigravitySessionMode,
antigravitySkipsPermissions,
buildAntigravityPrompt,
} from "./AntigravityAcpSupport.ts";

Expand Down Expand Up @@ -89,6 +90,40 @@ describe("Antigravity release gates", () => {
);
});

describe("antigravitySkipsPermissions", () => {
it.each([
{ label: "undefined policy", policy: undefined, expected: false },
{
label: "unrestricted full-access",
policy: { runtimeMode: "full-access" as const },
expected: true,
},
{
label: "full-access with matching maxRuntimeMode",
policy: { runtimeMode: "full-access" as const, maxRuntimeMode: "full-access" as const },
expected: true,
},
{
label: "full-access with narrower maxRuntimeMode",
policy: { runtimeMode: "full-access" as const, maxRuntimeMode: "auto" as const },
expected: false,
},
{
label: "full-access with explicit approvalPolicy",
policy: { runtimeMode: "full-access" as const, approvalPolicy: "on-request" },
expected: false,
},
{
label: "full-access with explicit sandboxPolicy",
policy: { runtimeMode: "full-access" as const, sandboxPolicy: { type: "readOnly" } },
expected: false,
},
{ label: "auto", policy: { runtimeMode: "auto" as const }, expected: false },
])("returns $expected for $label", ({ policy, expected }) => {
expect(antigravitySkipsPermissions(policy)).toBe(expected);
});
});

describe("Antigravity Auto", () => {
it.each([
{ offered: ["default", "accept-edits", "auto", "plan"], expected: "auto" },
Expand Down
Loading
Loading