Skip to content

Commit 3ce9d3b

Browse files
StiensWoutclaude
andcommitted
fix(server): Antigravity model refresh failures show the runtime's reason
When Antigravity's runtime fails `session/new`, it answers with a generic "Internal error" and puts the reason in `data.details`, for example "python-socks is required to use a SOCKS proxy" on macOS with a system SOCKS proxy. Model refresh replaced that with a fixed "Could not refresh Antigravity models" message, so the reason never reached the client. Append the agent's `data.details` (single line, at most 300 characters) to the refresh failure when the error came back from the agent over the wire. Sign-in, setup, local, and transport failures keep their existing text. Refs #16911 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5a4e998 commit 3ce9d3b

3 files changed

Lines changed: 107 additions & 6 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ const emitStaleXAiPromptCompleteBeforeSecondHang =
9393
const emitOverlappingXAiPromptCompleteOutOfOrder =
9494
process.env.T3_ACP_EMIT_OVERLAPPING_XAI_PROMPT_COMPLETE_OUT_OF_ORDER === "1";
9595
const failPrompt = process.env.T3_ACP_FAIL_PROMPT === "1";
96+
// JSON for the `data` of an "Internal error" response to `session/new`, as
97+
// Antigravity sends when its runtime cannot reach its local harness.
98+
const newSessionErrorData =
99+
process.env.T3_ACP_NEW_SESSION_ERROR_DATA === undefined
100+
? undefined
101+
: Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown))(
102+
process.env.T3_ACP_NEW_SESSION_ERROR_DATA,
103+
);
96104
const failSetConfigOption = process.env.T3_ACP_FAIL_SET_CONFIG_OPTION === "1";
97105
const failSetModeConfigOption = process.env.T3_ACP_FAIL_SET_MODE_CONFIG_OPTION === "1";
98106
const exitOnSetConfigOption = process.env.T3_ACP_EXIT_ON_SET_CONFIG_OPTION === "1";
@@ -573,6 +581,9 @@ const program = Effect.gen(function* () {
573581
yield* agent.handleCreateSession(() =>
574582
Effect.gen(function* () {
575583
yield* requireAuthentication();
584+
if (newSessionErrorData !== undefined) {
585+
return yield* AcpError.AcpRequestError.internalError("Internal error", newSessionErrorData);
586+
}
576587
if (antigravityProfile) {
577588
yield* publishAntigravityCommands(sessionId);
578589
}

‎apps/server/src/provider/Drivers/AntigravityDriver.test.ts‎

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
7575

7676
const makeExecutable = Effect.fn("AntigravityDriverTest.makeExecutable")(function* (
7777
name: string,
78-
loginRequired = false,
78+
options: {
79+
readonly loginRequired?: boolean;
80+
/** `data` of the agent's "Internal error" response to `session/new`. */
81+
readonly newSessionErrorData?: unknown;
82+
} = {},
7983
) {
8084
const directory = path.join(root, name);
8185
const executablePath = path.join(directory, "agy_acp_server.par");
@@ -87,9 +91,14 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
8791
executablePath,
8892
[
8993
"#!/bin/sh",
90-
...(loginRequired
94+
...(options.loginRequired
9195
? [`printf '%s\\n' ${shellQuote(ANTIGRAVITY_AUTH_STDOUT_PREFIX + authorizationUrl)}`]
9296
: []),
97+
...(options.newSessionErrorData === undefined
98+
? []
99+
: [
100+
`export T3_ACP_NEW_SESSION_ERROR_DATA=${shellQuote(JSON.stringify(options.newSessionErrorData))}`,
101+
]),
93102
`exec ${shellQuote(nodePath)} ${shellQuote(mockAgentPath)} "$@"`,
94103
"",
95104
].join("\n"),
@@ -108,7 +117,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
108117

109118
const first = yield* makeExecutable("runtime 'one");
110119
const second = yield* makeExecutable("runtime two");
111-
const signedOut = yield* makeExecutable("runtime signed-out", true);
120+
const signedOut = yield* makeExecutable("runtime signed-out", { loginRequired: true });
112121
const controls = { selected: first, failResolution: false, beforeAcquire: Effect.void };
113122
const acquisitions: Array<{ binaryPath: string | undefined; path: string | undefined }> = [];
114123
const releases: Array<string | null> = [];
@@ -226,6 +235,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
226235
return {
227236
instance,
228237
refresh,
238+
makeExecutable,
229239
fs,
230240
path,
231241
profileDirectory,
@@ -482,6 +492,58 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
482492
}).pipe(Effect.scoped),
483493
);
484494

495+
it.effect.skipIf(windowsHost)(
496+
"shows the agent's error details when session creation fails and keeps the catalog",
497+
() =>
498+
Effect.gen(function* () {
499+
const h = yield* makeHarness();
500+
yield* h.refresh();
501+
const before = yield* h.instance.snapshot.getSnapshot;
502+
h.controls.selected = yield* h.makeExecutable("runtime socks", {
503+
newSessionErrorData: { details: "python-socks is required to use a SOCKS proxy" },
504+
});
505+
const error = yield* h.refresh().pipe(Effect.flip);
506+
expect(error.detail).toBe(
507+
"Could not refresh Antigravity models. The previous model list is unchanged. Antigravity reported: python-socks is required to use a SOCKS proxy",
508+
);
509+
const after = yield* h.instance.snapshot.getSnapshot;
510+
expect(after.models).toEqual(before.models);
511+
expect(after.auth).toEqual(before.auth);
512+
yield* h.assertClosed;
513+
}).pipe(Effect.scoped),
514+
);
515+
516+
it.effect.skipIf(windowsHost)(
517+
"bounds agent error details to one line and ignores details that are not text",
518+
() =>
519+
Effect.gen(function* () {
520+
const h = yield* makeHarness();
521+
const generic =
522+
"Could not refresh Antigravity models. The previous model list is unchanged.";
523+
h.controls.selected = yield* h.makeExecutable("runtime traceback", {
524+
newSessionErrorData: {
525+
details: `Traceback (most recent call last):\n File "agent.py"\n${"x".repeat(2_000)}`,
526+
},
527+
});
528+
const bounded = yield* h.refresh().pipe(Effect.flip);
529+
expect(bounded.detail.startsWith(`${generic} Antigravity reported: Traceback`)).toBe(true);
530+
expect(bounded.detail).not.toContain("\n");
531+
expect(bounded.detail.length).toBeLessThanOrEqual(generic.length + 330);
532+
expect(bounded.detail.endsWith("…")).toBe(true);
533+
534+
for (const [name, data] of [
535+
["runtime object details", { details: { stack: "secret frame", env: { HOME: "/" } } }],
536+
["runtime blank details", { details: " \n " }],
537+
["runtime no details", ["python-socks"]],
538+
] as const) {
539+
h.controls.selected = yield* h.makeExecutable(name, { newSessionErrorData: data });
540+
const error = yield* h.refresh().pipe(Effect.flip);
541+
expect(error.detail).toBe(generic);
542+
}
543+
yield* h.assertClosed;
544+
}).pipe(Effect.scoped),
545+
);
546+
485547
it.effect.skipIf(windowsHost)(
486548
"gives each process its own temp directory and removes it when the process closes",
487549
() =>

‎apps/server/src/provider/Drivers/AntigravityDriver.ts‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as Scope from "effect/Scope";
1818
import * as Stream from "effect/Stream";
1919
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
2020
import { HttpClient } from "effect/http";
21-
import type { AcpError } from "effect-acp/errors";
21+
import * as AcpErrors from "effect-acp/errors";
2222

2323
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
2424
import {
@@ -69,6 +69,31 @@ import { discoverAntigravitySkills, resolveAntigravityUserHome } from "./Antigra
6969
const DRIVER = ProviderDriverKind.make("antigravity");
7070
const decodeSettings = Schema.decodeSync(AntigravitySettings);
7171
const isNodeRuntimeUnavailableError = Schema.is(NodeRuntimeUnavailableError);
72+
const isAcpRequestError = Schema.is(AcpErrors.AcpRequestError);
73+
const isAcpErrorDetails = Schema.is(Schema.Struct({ details: Schema.String }));
74+
const MAX_AGENT_DETAILS_LENGTH = 300;
75+
76+
/**
77+
* Appends the reason Antigravity sent with a JSON-RPC error, bounded to one
78+
* line. Its runtime answers "Internal error" and explains only in
79+
* `data.details`, for example "python-socks is required to use a SOCKS proxy".
80+
* Local and transport failures keep the given detail.
81+
*/
82+
function withAgentDetails(detail: string, cause: unknown) {
83+
if (
84+
!isAcpRequestError(cause) ||
85+
cause.operation !== "receive-response" ||
86+
!isAcpErrorDetails(cause.data)
87+
)
88+
return detail;
89+
const details = cause.data.details.replace(/\s+/gu, " ").trim();
90+
if (!details) return detail;
91+
const bounded =
92+
details.length > MAX_AGENT_DETAILS_LENGTH
93+
? `${details.slice(0, MAX_AGENT_DETAILS_LENGTH - 1)}…`
94+
: details;
95+
return `${detail} Antigravity reported: ${bounded}`;
96+
}
7297

7398
export type AntigravityDriverEnv =
7499
| AntigravityInstallation.AntigravityInstallation
@@ -171,7 +196,7 @@ export const AntigravityDriver: ProviderDriver<
171196
input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
172197
): Effect.fn.Return<
173198
AcpSessionRuntime.AcpSessionRuntime["Service"],
174-
AcpError | ProviderSetupError,
199+
AcpErrors.AcpError | ProviderSetupError,
175200
Scope.Scope
176201
> {
177202
if (authConfigIssue !== null) {
@@ -496,7 +521,10 @@ export const AntigravityDriver: ProviderDriver<
496521
: cause._tag === "ProviderSetupError" &&
497522
(cause.operation === "configure" || cause.operation === "start")
498523
? cause.detail
499-
: "Could not refresh Antigravity models. The previous model list is unchanged.",
524+
: withAgentDetails(
525+
"Could not refresh Antigravity models. The previous model list is unchanged.",
526+
cause,
527+
),
500528
cause,
501529
}),
502530
),

0 commit comments

Comments
 (0)