@estebanforge/pi-antigravity-bridge 1.10.7 → 1.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +5 -1
- package/extensions/index.ts +35 -2
- package/package.json +1 -1
- package/src/acp/connection.ts +28 -10
- package/src/acp/driver.ts +31 -1
- package/src/acp/jsonrpc.ts +12 -1
- package/src/config.ts +48 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.10.8] - 2026-11-16
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Actionable hint on ACP `session/new` and `session/load` timeouts.** When `session/new` or `session/load` times out after `initialize` succeeded, the error message now notes that `agy acp` is running and points to network/proxy reachability to Google APIs or `agy` sign-in, and the connection logs a `session-op-timeout` warning record.
|
|
10
|
+
- **Configurable ACP session operation timeout (`acp.sessionTimeoutMs` / `AGY_ACP_SESSION_TIMEOUT_MS`).** Defaults to the existing `20000`ms (`20`s) and applies to `session/new`, `session/load`, `session/set_config_option`, and `session/close`. Accepts `1000`-`300000`ms via `config.json`, environment variable, or the `/agy` settings picker.
|
|
11
|
+
- **Optional `session/new` retry on timeout (`acp.sessionRetryOnTimeout` / `AGY_ACP_SESSION_RETRY`).** Disabled by default (`false`). When enabled, `AcpDriver` retries `session/new` once on a silent timeout while `agy acp` is still alive and logs `session-new-retry` (warns in the setting description that it doubles wait time on dead networks and may not clear a wedged internal socket).
|
|
12
|
+
|
|
5
13
|
## [1.10.7] - 2026-11-15
|
|
6
14
|
|
|
7
15
|
### Fixed
|
package/README.md
CHANGED
|
@@ -122,8 +122,10 @@ If `agy models` fails at load (binary missing, auth not done, network stall), a
|
|
|
122
122
|
| `systemPrompt` | `on` (send pi's system prompt - operating instructions plus the global agent-dir `AGENTS.md` and ancestor `AGENTS.md`/`CLAUDE.md` - to the first prompt of each new agy conversation, plus a tool-priority note: Pi Bridge tools win over agy's native interactive ones, which never reach the user. Delivery: stream-json stages it as an agy agent file via `--agent`, off the prompt line - the CLI silently drops single prompts past a ~25KB cap and the dropped turn kills the conversation; the carrier declares the productive toolset explicitly (omitting `tools:` reads as a read-only set upstream, issue #13) plus `subagent: false` + `agents: []` so the native subagent tools stay masked (ACP carries no agent file, so its natives remain and the tool-priority note steers the model to pi delegation). ACP prepends it to the first prompt) or `off` (agy-native behavior) | `on` |
|
|
123
123
|
| `turnTimeoutMin` | Overall cap on ONE agy turn, minutes, both engines. Parked time (pi-tool round-trips, escalated calls, human-gated approvals) does not count against it on either engine: the cap pauses with remaining-budget semantics and resumes on unpark. When it fires, the bridge kills the agy process mid-task ("ACP turn exceeded the 10m deadline" / "agy exceeded the 10m turn timeout") - it is a bridge cap, not a Google server limit. Default is TTY-aware: `0` (no cap) on an interactive pi - you are the backstop with Esc; `20` headless, where nobody can abort and one runaway turn blocks the serialized turn queue. Opt into a gate with 1-1440 (free type via `config.json` or `/agy timeout <1-1440|off>`, or the `/agy` picker's preset list); `0` disables explicitly; anything else falls back to the TTY-aware default. The 5m inactivity stall guard always still bounds a hung server | `0` TTY / `20` headless |
|
|
124
124
|
| `inactivityTimeoutMin` | Silence cap, minutes, both engines: no stream-json stdout / no ACP session/update for this long fails the turn as a stall. `0` disables the guard. Parks (bridge calls, escalated calls, ACP permission dialogs) pause it; agy-native long steps such as builds do not. A false kill costs the whole turn, and on stream-json a stall kill with no result frame clears the conversation binding. Keep `5`; use `2`-`3` only when native steps are known to be short; do not use `1` | `5` |
|
|
125
|
+
| `acp.sessionTimeoutMs` | Timeout in ms for ACP `session/new`, `session/load`, `session/set_config_option`, and `session/close`. Valid range: `1000`-`300000`. Raise only on slow or proxied networks | `20000` |
|
|
126
|
+
| `acp.sessionRetryOnTimeout` | Advanced: transparently retry `session/new` once when it times out while `agy acp` is still alive. **Warning:** doubles total wait time on dead networks and may not recover if `agy`'s internal socket is wedged | `false` |
|
|
125
127
|
|
|
126
|
-
Env overrides: `AGY_BRIDGE_TOOLS`, `AGY_ASK_TOOL`, `AGY_WEB_TOOLS`, `AGY_DIGEST`, `AGY_SYSTEM_PROMPT`, `AGY_TURN_TIMEOUT_MIN`, `AGY_INACTIVITY_TIMEOUT_MIN`. Env wins over the file, so while `AGY_DIGEST` or `AGY_SYSTEM_PROMPT` is set, the matching `/agy digest` or `/agy system-prompt` toggle persists a value that never takes effect.
|
|
128
|
+
Env overrides: `AGY_BRIDGE_TOOLS`, `AGY_ASK_TOOL`, `AGY_WEB_TOOLS`, `AGY_DIGEST`, `AGY_SYSTEM_PROMPT`, `AGY_TURN_TIMEOUT_MIN`, `AGY_INACTIVITY_TIMEOUT_MIN`, `AGY_ACP_SESSION_TIMEOUT_MS`, `AGY_ACP_SESSION_RETRY`. Env wins over the file, so while `AGY_DIGEST` or `AGY_SYSTEM_PROMPT` is set, the matching `/agy digest` or `/agy system-prompt` toggle persists a value that never takes effect.
|
|
127
129
|
|
|
128
130
|
The `activate_skill` catalog mirrors pi's directory-based skill discovery: the two global dirs plus project dirs, the latter only when pi has trusted the project (same gate pi itself applies). Pi's other skill sources - the `skills` settings array, `package.json` entries, and `--skill` CLI paths - are not mirrored and won't appear in the catalog.
|
|
129
131
|
|
|
@@ -184,6 +186,8 @@ For isolation when running any agent that executes commands without a confirmati
|
|
|
184
186
|
| `AGY_READONLY` | `1`/`true`/`on` (or any set value except `0`/`false`/`off`/empty) turns every provider turn and the `AskAntigravity` tool into a visible refusal (fail-closed: the CLI has no review-only enforcement on any path, [#1181](https://github.com/google-antigravity/antigravity-cli/issues/1181)). Wins over the config file. |
|
|
185
187
|
| `AGY_SKIP_PERMISSIONS` | `1`/`true` (default) to pass `--dangerously-skip-permissions` so commands don't hang on an unanswerable prompt in `-p` mode. `0`/`false` to prompt (hangs any `run_command` non-interactively). Wins over the config file. |
|
|
186
188
|
| `AGY_USAGE_ESTIMATE` | Fallback ACP token display when the server omits usage: `estimate` (default; live client-side per-delta estimates), `direct`, `off`. Exact server usage always wins. Wins over the config file. |
|
|
189
|
+
| `AGY_ACP_SESSION_TIMEOUT_MS` | Timeout in ms for ACP `session/new`, `session/load`, `session/set_config_option`, and `session/close` (`1000`-`300000`, default `20000`). Wins over `config.acp.sessionTimeoutMs`. |
|
|
190
|
+
| `AGY_ACP_SESSION_RETRY` | `1`/`true`/`on` to retry ACP `session/new` once on silent timeout while `agy acp` is alive (default off). Warning: doubles wait time on dead networks and may not clear a wedged socket. Wins over `config.acp.sessionRetryOnTimeout`. |
|
|
187
191
|
| `AGY_DEFAULT_MODEL` | Default model for the `AskAntigravity` tool: `flash`/`pro`/`gemini`, or an exact id such as `gemini-4-hydrogen`. Default `gemini-4-hydrogen`; the tier suffix rides `AGY_DEFAULT_THINKING`. Wins over the config file. |
|
|
188
192
|
| `AGY_DEFAULT_THINKING` | Default thinking tier for the `AskAntigravity` tool: `low`/`medium`/`high`. Anything else falls back to `medium`. Wins over the config file. |
|
|
189
193
|
| `AGY_DEBUG` | `1`/`true`/`on` writes the full trail to the daily log (driver lifecycle, raw bridge traffic). Default off: **only `error` records land on disk** - routine disk writes are zero for regular users, and warnings surface as UI toasts instead. |
|
package/extensions/index.ts
CHANGED
|
@@ -65,7 +65,7 @@ import { agyAuthenticationMessage } from "../src/agy-install.js";
|
|
|
65
65
|
import { createAgySetupOffer } from "../src/agy-setup.js";
|
|
66
66
|
import { ensureQueuedMessagesDefaults } from "../src/queued-messages.js";
|
|
67
67
|
import type { TurnDriver, TurnOutcome } from "../src/driver-types.js";
|
|
68
|
-
import { CONFIG_PATH, loadConfig, logsDir, MAX_TURN_CAP_MIN, parseCapMinutes, removeLegacyAcpBin, saveConfig, type AgyMode, type BridgeTools, type Engine, type ThinkingTier } from "../src/config.js";
|
|
68
|
+
import { CONFIG_PATH, loadConfig, logsDir, MAX_TURN_CAP_MIN, parseCapMinutes, removeLegacyAcpBin, saveConfig, type AcpConfig, type AgyMode, type BridgeTools, type Engine, type ThinkingTier } from "../src/config.js";
|
|
69
69
|
import { agyMissingMessage, ENGINE_SETTINGS_ROW_ID, engineSettingsRow, isAgyInstalled, savedEngineMessage, showEnginePicker, shouldOfferEnginePicker } from "../src/engine-picker.js";
|
|
70
70
|
import { agyVersionVerdict, checkAgyCliVersion, describeAgyVersionCheck, MIN_AGY_ACP_VERSION, MIN_AGY_VERSION, MIN_GEMINI_DIR_VERSION, probeGeminiDirFlag, resolveStreamHomeMode } from "../src/agy-version.js";
|
|
71
71
|
import { isValidAgyAgentName, listAgyAgents } from "../src/agents.js";
|
|
@@ -236,7 +236,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
236
236
|
"start-failed", "spawn-error", "parse-error", "write-failed",
|
|
237
237
|
"mode-apply-failed", "timeout", "stall", "auth-required",
|
|
238
238
|
"session-load-failed-creating-fresh", "connection-exited", "cancel-failed",
|
|
239
|
-
"unsupported-server-request",
|
|
239
|
+
"unsupported-server-request", "session-op-timeout", "session-new-retry",
|
|
240
240
|
]);
|
|
241
241
|
const streamDriver = new StreamDriver();
|
|
242
242
|
// Mirror the stream driver's lifecycle ring into the daily file log
|
|
@@ -331,6 +331,8 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
331
331
|
// a restart. Without this the driver defaults to "estimate" and the
|
|
332
332
|
// config knob (incl. "off") is dead.
|
|
333
333
|
usageEstimate: () => loadConfig().acp.usageEstimate,
|
|
334
|
+
sessionOpTimeoutMs: () => loadConfig().acp.sessionTimeoutMs,
|
|
335
|
+
sessionRetryOnTimeout: () => loadConfig().acp.sessionRetryOnTimeout,
|
|
334
336
|
// ACP request_permission parity with the approval gate: skipPermissions
|
|
335
337
|
// turns auto-allow in the driver; approvals.mode allow short-circuits
|
|
336
338
|
// to the same synchronous allow; everything else opens a dialog (esc
|
|
@@ -1189,6 +1191,7 @@ interface PendingConfig {
|
|
|
1189
1191
|
bridgeTools?: BridgeTools;
|
|
1190
1192
|
digest?: boolean;
|
|
1191
1193
|
systemPrompt?: boolean;
|
|
1194
|
+
acp?: Partial<AcpConfig>;
|
|
1192
1195
|
}
|
|
1193
1196
|
|
|
1194
1197
|
function settingsRows(ctx: AgyCommandCtx): string[] {
|
|
@@ -1888,6 +1891,22 @@ async function openAgyPicker(ui: ExtensionUIContext, ctx: AgyCommandCtx): Promis
|
|
|
1888
1891
|
currentValue: config.systemPrompt ? "on" : "off",
|
|
1889
1892
|
values: ["on", "off"],
|
|
1890
1893
|
},
|
|
1894
|
+
{
|
|
1895
|
+
id: "acp-session-timeout",
|
|
1896
|
+
label: "ACP session timeout (ms)",
|
|
1897
|
+
description:
|
|
1898
|
+
"Timeout in ms for ACP session/new, session/load, and session/close. Default 20000 (20s). Raise only on slow/proxied networks; custom values (1000-300000) can be set in config.json or AGY_ACP_SESSION_TIMEOUT_MS.",
|
|
1899
|
+
currentValue: String(config.acp.sessionTimeoutMs),
|
|
1900
|
+
values: ["20000", "30000", "45000", "60000", "90000"],
|
|
1901
|
+
},
|
|
1902
|
+
{
|
|
1903
|
+
id: "acp-session-retry",
|
|
1904
|
+
label: "ACP session/new retry (advanced)",
|
|
1905
|
+
description:
|
|
1906
|
+
"WARNING: disabled by default. Retries session/new once on silent timeout while agy acp is alive. Doubles total wait time on dead networks and may not recover if agy's internal socket is wedged.",
|
|
1907
|
+
currentValue: config.acp.sessionRetryOnTimeout ? "on" : "off",
|
|
1908
|
+
values: ["off", "on"],
|
|
1909
|
+
},
|
|
1891
1910
|
];
|
|
1892
1911
|
|
|
1893
1912
|
const resolved = await ui.custom<string | undefined>(
|
|
@@ -1923,6 +1942,16 @@ async function openAgyPicker(ui: ExtensionUIContext, ctx: AgyCommandCtx): Promis
|
|
|
1923
1942
|
pending.digest = newValue === "on";
|
|
1924
1943
|
} else if (id === "system-prompt") {
|
|
1925
1944
|
pending.systemPrompt = newValue === "on";
|
|
1945
|
+
} else if (id === "acp-session-timeout") {
|
|
1946
|
+
pending.acp = {
|
|
1947
|
+
...pending.acp,
|
|
1948
|
+
sessionTimeoutMs: Number(newValue),
|
|
1949
|
+
};
|
|
1950
|
+
} else if (id === "acp-session-retry") {
|
|
1951
|
+
pending.acp = {
|
|
1952
|
+
...pending.acp,
|
|
1953
|
+
sessionRetryOnTimeout: newValue === "on",
|
|
1954
|
+
};
|
|
1926
1955
|
}
|
|
1927
1956
|
},
|
|
1928
1957
|
},
|
|
@@ -1975,6 +2004,10 @@ async function openAgyPicker(ui: ExtensionUIContext, ctx: AgyCommandCtx): Promis
|
|
|
1975
2004
|
pending.digest !== undefined ? `digest=${next.digest ? "on" : "off"}` : null,
|
|
1976
2005
|
pending.systemPrompt !== undefined ? `system-prompt=${next.systemPrompt ? "on" : "off"}` : null,
|
|
1977
2006
|
pending.turnTimeoutMin !== undefined ? `turn cap=${next.turnTimeoutMin === 0 ? "off" : `${next.turnTimeoutMin}m`}` : null,
|
|
2007
|
+
pending.acp?.sessionTimeoutMs !== undefined ? `ACP session timeout=${next.acp.sessionTimeoutMs}ms` : null,
|
|
2008
|
+
pending.acp?.sessionRetryOnTimeout !== undefined
|
|
2009
|
+
? `ACP session/new retry=${next.acp.sessionRetryOnTimeout ? "on" : "off"}`
|
|
2010
|
+
: null,
|
|
1978
2011
|
]
|
|
1979
2012
|
.filter(Boolean)
|
|
1980
2013
|
.join(", ");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estebanforge/pi-antigravity-bridge",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.8",
|
|
4
4
|
"description": "Gemini provider for Pi on the Antigravity ACP server (official Google ACP) or the stream-json agy CLI. Use antigravity/* models in Pi. Full /model picker support. Models runs Pi's tools. ToS safe to use.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
package/src/acp/connection.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { spawn, type ChildProcess } from "node:child_process";
|
|
|
18
18
|
import { frameCarriesUsage } from "./events.js";
|
|
19
19
|
import type { AgyUsage } from "../driver-types.js";
|
|
20
20
|
import { redactText } from "../redact.js";
|
|
21
|
-
import { JsonRpcResponseError, JsonRpcSession } from "./jsonrpc.js";
|
|
21
|
+
import { JsonRpcResponseError, JsonRpcSession, JsonRpcTimeoutError } from "./jsonrpc.js";
|
|
22
22
|
import { removeStagedAgyHome, stageAgyHome } from "./home.js";
|
|
23
23
|
|
|
24
24
|
export interface AcpMcpServer {
|
|
@@ -70,6 +70,9 @@ export interface AcpConnectionOptions {
|
|
|
70
70
|
onPermissionRequest?: AcpPermissionHandler;
|
|
71
71
|
/** Park budget for one permission dialog. Tests shrink it. */
|
|
72
72
|
permissionParkMs?: number;
|
|
73
|
+
/** Timeout in ms for session/new, session/load, set_config_option, and
|
|
74
|
+
* session/close. Defaults to SESSION_OP_TIMEOUT_MS (20000). */
|
|
75
|
+
sessionOpTimeoutMs?: number | (() => number);
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
const INIT_TIMEOUT_MS = 30_000;
|
|
@@ -258,11 +261,19 @@ export class AcpConnection {
|
|
|
258
261
|
return typeof v === "string" ? v : undefined;
|
|
259
262
|
}
|
|
260
263
|
|
|
264
|
+
#sessionOpTimeoutMs(): number {
|
|
265
|
+
const opt = this.#opts.sessionOpTimeoutMs;
|
|
266
|
+
const resolved = typeof opt === "function" ? opt() : opt;
|
|
267
|
+
return typeof resolved === "number" && Number.isFinite(resolved) && resolved > 0
|
|
268
|
+
? resolved
|
|
269
|
+
: SESSION_OP_TIMEOUT_MS;
|
|
270
|
+
}
|
|
271
|
+
|
|
261
272
|
async newSession(cwd: string): Promise<AcpSessionInfo> {
|
|
262
273
|
const result = (await this.guarded(
|
|
263
274
|
"session/new",
|
|
264
275
|
{ cwd, mcpServers: this.#mcpServers() },
|
|
265
|
-
|
|
276
|
+
this.#sessionOpTimeoutMs(),
|
|
266
277
|
)) as Record<string, unknown>;
|
|
267
278
|
const sessionId = result.sessionId;
|
|
268
279
|
if (typeof sessionId !== "string" || sessionId.length === 0) {
|
|
@@ -282,7 +293,7 @@ export class AcpConnection {
|
|
|
282
293
|
const result = (await this.request(
|
|
283
294
|
"session/load",
|
|
284
295
|
{ sessionId, cwd, mcpServers: this.#mcpServers() },
|
|
285
|
-
|
|
296
|
+
this.#sessionOpTimeoutMs(),
|
|
286
297
|
)) as Record<string, unknown> | undefined;
|
|
287
298
|
this.lastConfigOptions = result?.configOptions;
|
|
288
299
|
} finally {
|
|
@@ -294,7 +305,7 @@ export class AcpConnection {
|
|
|
294
305
|
const result = (await this.guarded(
|
|
295
306
|
"session/set_config_option",
|
|
296
307
|
{ sessionId, configId, value },
|
|
297
|
-
|
|
308
|
+
this.#sessionOpTimeoutMs(),
|
|
298
309
|
)) as Record<string, unknown> | undefined;
|
|
299
310
|
this.lastConfigOptions = result?.configOptions;
|
|
300
311
|
}
|
|
@@ -350,7 +361,7 @@ export class AcpConnection {
|
|
|
350
361
|
}
|
|
351
362
|
|
|
352
363
|
async closeSession(sessionId: string): Promise<void> {
|
|
353
|
-
await this.guarded("session/close", { sessionId },
|
|
364
|
+
await this.guarded("session/close", { sessionId }, this.#sessionOpTimeoutMs());
|
|
354
365
|
}
|
|
355
366
|
|
|
356
367
|
/** Protocol-level permission answering: policy "auto" selects the first
|
|
@@ -468,11 +479,7 @@ export class AcpConnection {
|
|
|
468
479
|
/** Wrap a request: -32000 family becomes AcpAuthError with the remediation
|
|
469
480
|
* the server provided. */
|
|
470
481
|
private async guarded(method: string, params: unknown, timeoutMs: number): Promise<unknown> {
|
|
471
|
-
|
|
472
|
-
return await this.request(method, params, timeoutMs);
|
|
473
|
-
} catch (err) {
|
|
474
|
-
throw translateError(method, err);
|
|
475
|
-
}
|
|
482
|
+
return await this.request(method, params, timeoutMs);
|
|
476
483
|
}
|
|
477
484
|
|
|
478
485
|
async request(method: string, params?: unknown, timeoutMs?: number): Promise<unknown> {
|
|
@@ -480,6 +487,9 @@ export class AcpConnection {
|
|
|
480
487
|
try {
|
|
481
488
|
return await this.#rpc.request(method, params, timeoutMs);
|
|
482
489
|
} catch (err) {
|
|
490
|
+
if (err instanceof JsonRpcTimeoutError) {
|
|
491
|
+
this.#opts.log("session-op-timeout", { method, timeoutMs: err.timeoutMs });
|
|
492
|
+
}
|
|
483
493
|
throw translateError(method, err);
|
|
484
494
|
}
|
|
485
495
|
}
|
|
@@ -579,6 +589,14 @@ export function parseAcpTurnUsage(value: unknown): AgyUsage | undefined {
|
|
|
579
589
|
|
|
580
590
|
export function translateError(method: string, err: unknown): Error {
|
|
581
591
|
if (err instanceof AcpAuthError) return err;
|
|
592
|
+
if (err instanceof JsonRpcTimeoutError) {
|
|
593
|
+
if (method === "session/new" || method === "session/load") {
|
|
594
|
+
const hint = "initialize succeeded, so agy acp is running; check network/proxy reachability to Google APIs or agy sign-in";
|
|
595
|
+
if (err.message.includes(hint)) return err;
|
|
596
|
+
return new JsonRpcTimeoutError(err.method, err.timeoutMs, `${err.message} (${hint})`);
|
|
597
|
+
}
|
|
598
|
+
return err;
|
|
599
|
+
}
|
|
582
600
|
if (err instanceof JsonRpcResponseError) {
|
|
583
601
|
if (err.code === -32000) {
|
|
584
602
|
const detail = typeof err.data === "object" && err.data !== null ? (err.data as { message?: unknown }).message : undefined;
|
package/src/acp/driver.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { randomUUID } from "node:crypto";
|
|
|
22
22
|
import type { UsageEstimate } from "../config.js";
|
|
23
23
|
import { AcpConnection, type AcpMcpServer, type AcpPermissionRequest } from "./connection.js";
|
|
24
24
|
import type { AcpPermissionHandler } from "./connection.js";
|
|
25
|
+
import { JsonRpcTimeoutError } from "./jsonrpc.js";
|
|
25
26
|
import { mapStopReason, mapUpdate, TextAccumulator, type AcpEditDiff } from "./events.js";
|
|
26
27
|
import { estimateTokens, synthesizeUsage } from "./usage-estimate.js";
|
|
27
28
|
import type {
|
|
@@ -61,6 +62,12 @@ export interface AcpDriverOptions {
|
|
|
61
62
|
* "auto" answers the first allow option synchronously, "deny" consults
|
|
62
63
|
* the human handler or fail-closes. Default deny. */
|
|
63
64
|
permissionPolicy?: () => "auto" | "deny";
|
|
65
|
+
/** Timeout in ms for session/new, session/load, set_config_option, and
|
|
66
|
+
* session/close. Defaults to AcpConnection's 20000ms. */
|
|
67
|
+
sessionOpTimeoutMs?: number | (() => number);
|
|
68
|
+
/** Advanced: transparently retry session/new once on timeout while the
|
|
69
|
+
* connection is still alive. Default false. */
|
|
70
|
+
sessionRetryOnTimeout?: boolean | (() => boolean);
|
|
64
71
|
log?: (msg: string, data?: unknown) => void;
|
|
65
72
|
}
|
|
66
73
|
|
|
@@ -288,7 +295,7 @@ export class AcpDriver implements TurnDriver {
|
|
|
288
295
|
await conn.loadSession(request.conversationId, request.cwd);
|
|
289
296
|
turn.sessionId = request.conversationId;
|
|
290
297
|
} else {
|
|
291
|
-
const created = await conn
|
|
298
|
+
const created = await this.#newSessionWithOptionalRetry(conn, turn);
|
|
292
299
|
turn.sessionId = created.sessionId;
|
|
293
300
|
this.#stats.sessionsCreated += 1;
|
|
294
301
|
this.#log("session-new", { sessionId: created.sessionId });
|
|
@@ -555,6 +562,7 @@ export class AcpDriver implements TurnDriver {
|
|
|
555
562
|
? (req) => this.#parkForPermission(req)
|
|
556
563
|
: undefined,
|
|
557
564
|
permissionParkMs: this.#opts.permissionParkMs,
|
|
565
|
+
sessionOpTimeoutMs: this.#opts.sessionOpTimeoutMs,
|
|
558
566
|
onUpdate: (sessionId, update) => this.#onConnectionUpdate(sessionId, update),
|
|
559
567
|
onExit: (info) => this.#onConnectionExit(conn, info),
|
|
560
568
|
});
|
|
@@ -799,6 +807,28 @@ export class AcpDriver implements TurnDriver {
|
|
|
799
807
|
});
|
|
800
808
|
}
|
|
801
809
|
|
|
810
|
+
#sessionRetryOnTimeout(): boolean {
|
|
811
|
+
const opt = this.#opts.sessionRetryOnTimeout;
|
|
812
|
+
return (typeof opt === "function" ? opt() : opt) === true;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
async #newSessionWithOptionalRetry(conn: AcpConnection, turn: ActiveTurn): Promise<{ sessionId: string }> {
|
|
816
|
+
try {
|
|
817
|
+
return await conn.newSession(turn.request.cwd);
|
|
818
|
+
} catch (err) {
|
|
819
|
+
if (
|
|
820
|
+
err instanceof JsonRpcTimeoutError &&
|
|
821
|
+
!turn.aborted &&
|
|
822
|
+
conn.alive &&
|
|
823
|
+
this.#sessionRetryOnTimeout()
|
|
824
|
+
) {
|
|
825
|
+
this.#log("session-new-retry", { timeoutMs: err.timeoutMs });
|
|
826
|
+
return await conn.newSession(turn.request.cwd);
|
|
827
|
+
}
|
|
828
|
+
throw err;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
802
832
|
/** Usage synthesis mode, resolved per turn (follows live config). */
|
|
803
833
|
#usageMode(): UsageEstimate {
|
|
804
834
|
const opt = this.#opts.usageEstimate;
|
package/src/acp/jsonrpc.ts
CHANGED
|
@@ -189,7 +189,7 @@ export class JsonRpcSession {
|
|
|
189
189
|
if (effective > 0) {
|
|
190
190
|
pending.timer = setTimeout(() => {
|
|
191
191
|
this.#pending.delete(id);
|
|
192
|
-
reject(new
|
|
192
|
+
reject(new JsonRpcTimeoutError(method, effective));
|
|
193
193
|
}, effective);
|
|
194
194
|
}
|
|
195
195
|
this.#pending.set(id, pending);
|
|
@@ -218,6 +218,17 @@ export class JsonRpcSession {
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
export class JsonRpcTimeoutError extends Error {
|
|
222
|
+
readonly method: string;
|
|
223
|
+
readonly timeoutMs: number;
|
|
224
|
+
constructor(method: string, timeoutMs: number, message?: string) {
|
|
225
|
+
super(message ?? `ACP request timed out after ${timeoutMs}ms: ${method}`);
|
|
226
|
+
this.name = "JsonRpcTimeoutError";
|
|
227
|
+
this.method = method;
|
|
228
|
+
this.timeoutMs = timeoutMs;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
221
232
|
/** A JSON-RPC `error` result, preserving code + data (the -32602 `loc` paths
|
|
222
233
|
* and the -32601 method name are correction oracles; see the reference doc). */
|
|
223
234
|
export class JsonRpcResponseError extends Error {
|
package/src/config.ts
CHANGED
|
@@ -84,6 +84,16 @@ export interface AcpConfig {
|
|
|
84
84
|
* usage surfaces show nonzero numbers. Estimates are labeled as such in
|
|
85
85
|
* /agy doctor and auto-disable when the server sends real usage. */
|
|
86
86
|
usageEstimate: UsageEstimate;
|
|
87
|
+
/** Timeout in ms for ACP session operations (session/new, session/load,
|
|
88
|
+
* session/set_config_option, session/close). Default 20000 (20s); valid
|
|
89
|
+
* range 1000..300000. Env AGY_ACP_SESSION_TIMEOUT_MS wins over the file. */
|
|
90
|
+
sessionTimeoutMs: number;
|
|
91
|
+
/** Advanced: transparently retry session/new once when it times out while
|
|
92
|
+
* the ACP server is still alive. Default false. Warning: doubles the wait
|
|
93
|
+
* on genuinely dead networks (e.g. 40s at default 20s timeout) and may not
|
|
94
|
+
* recover if the server process itself has a wedged socket.
|
|
95
|
+
* Env AGY_ACP_SESSION_RETRY wins over the file. */
|
|
96
|
+
sessionRetryOnTimeout: boolean;
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
export interface AgyConfig {
|
|
@@ -211,9 +221,23 @@ const DEFAULTS: AgyConfig = {
|
|
|
211
221
|
turnTimeoutMin: 0, // placeholder: the real default is resolved per loadConfig call (defaultTurnTimeoutMin)
|
|
212
222
|
inactivityTimeoutMin: 5,
|
|
213
223
|
approvals: { gateMode: "auto", mode: "ask" },
|
|
214
|
-
acp: {
|
|
224
|
+
acp: {
|
|
225
|
+
usageEstimate: "estimate",
|
|
226
|
+
sessionTimeoutMs: 20_000,
|
|
227
|
+
sessionRetryOnTimeout: false,
|
|
228
|
+
},
|
|
215
229
|
};
|
|
216
230
|
|
|
231
|
+
const MIN_ACP_SESSION_TIMEOUT_MS = 1_000;
|
|
232
|
+
const MAX_ACP_SESSION_TIMEOUT_MS = 300_000;
|
|
233
|
+
|
|
234
|
+
function parseSessionTimeoutMs(raw: unknown, fallback: number): number {
|
|
235
|
+
if (raw === undefined || raw === null || String(raw).trim() === "") return fallback;
|
|
236
|
+
const n = typeof raw === "number" ? raw : Number(String(raw).trim());
|
|
237
|
+
if (!Number.isSafeInteger(n)) return fallback;
|
|
238
|
+
return n >= MIN_ACP_SESSION_TIMEOUT_MS && n <= MAX_ACP_SESSION_TIMEOUT_MS ? n : fallback;
|
|
239
|
+
}
|
|
240
|
+
|
|
217
241
|
/** Hard ceiling for a free-typed turn cap: one day, in minutes. */
|
|
218
242
|
export const MAX_TURN_CAP_MIN = 1440;
|
|
219
243
|
|
|
@@ -389,7 +413,15 @@ export function loadConfig(configPath: string = CONFIG_PATH): AgyConfig {
|
|
|
389
413
|
).toLowerCase();
|
|
390
414
|
const usageEstimate: UsageEstimate =
|
|
391
415
|
usageRaw === "direct" || usageRaw === "off" ? usageRaw : "estimate";
|
|
392
|
-
const
|
|
416
|
+
const sessionTimeoutMs = parseSessionTimeoutMs(
|
|
417
|
+
process.env.AGY_ACP_SESSION_TIMEOUT_MS ?? fileAcp.sessionTimeoutMs,
|
|
418
|
+
DEFAULTS.acp.sessionTimeoutMs,
|
|
419
|
+
);
|
|
420
|
+
const envSessionRetry = process.env.AGY_ACP_SESSION_RETRY;
|
|
421
|
+
const sessionRetryOnTimeout = envSessionRetry !== undefined
|
|
422
|
+
? ["1", "true", "on"].includes(envSessionRetry.toLowerCase())
|
|
423
|
+
: fileAcp.sessionRetryOnTimeout === true;
|
|
424
|
+
const acp: AcpConfig = { usageEstimate, sessionTimeoutMs, sessionRetryOnTimeout };
|
|
393
425
|
|
|
394
426
|
// Custom agent for stream-json turns (--agent). Env wins over the file
|
|
395
427
|
// (same pattern as mode). Normalized (trim/cap/control-strip); an empty
|
|
@@ -450,7 +482,9 @@ function writeConfigJson(configPath: string, value: unknown): void {
|
|
|
450
482
|
* disk on any unrelated save, outliving the env var). Nested objects are
|
|
451
483
|
* re-normalized to their known keys: a raw passthrough would resurrect
|
|
452
484
|
* legacy keys (acp.permissions) that loadConfig normalization drops. */
|
|
453
|
-
export
|
|
485
|
+
export type ConfigPatch = Partial<Omit<AgyConfig, "acp">> & { acp?: Partial<AcpConfig> };
|
|
486
|
+
|
|
487
|
+
export function saveConfig(patch: ConfigPatch, configPath: string = CONFIG_PATH): AgyConfig {
|
|
454
488
|
const file = readConfigFile(configPath);
|
|
455
489
|
// Null-safe on nested objects: a hand-edited or legacy file can carry
|
|
456
490
|
// "acp": null; loadConfig tolerates it, so must saveConfig. Key presence
|
|
@@ -464,16 +498,23 @@ export function saveConfig(patch: Partial<AgyConfig>, configPath: string = CONFI
|
|
|
464
498
|
// save, switching an existing install to ACP on the next start.
|
|
465
499
|
const persistedEngine = patch.engine ?? file.engine
|
|
466
500
|
?? (fs.existsSync(configPath) ? "stream-json" : DEFAULT_ENGINE);
|
|
501
|
+
const { acp: patchAcp, ...restPatch } = patch;
|
|
502
|
+
const mergedAcp: AcpConfig = {
|
|
503
|
+
usageEstimate: patchAcp?.usageEstimate ?? fileAcp.usageEstimate ?? DEFAULTS.acp.usageEstimate,
|
|
504
|
+
sessionTimeoutMs: parseSessionTimeoutMs(
|
|
505
|
+
patchAcp?.sessionTimeoutMs ?? fileAcp.sessionTimeoutMs,
|
|
506
|
+
DEFAULTS.acp.sessionTimeoutMs,
|
|
507
|
+
),
|
|
508
|
+
sessionRetryOnTimeout: patchAcp?.sessionRetryOnTimeout ?? (fileAcp.sessionRetryOnTimeout === true),
|
|
509
|
+
};
|
|
467
510
|
const next: AgyConfig = {
|
|
468
511
|
...DEFAULTS,
|
|
469
512
|
...file,
|
|
470
|
-
...(file.acp !== undefined
|
|
471
|
-
? { acp: { usageEstimate: fileAcp.usageEstimate ?? DEFAULTS.acp.usageEstimate } }
|
|
472
|
-
: {}),
|
|
473
513
|
...(file.approvals !== undefined
|
|
474
514
|
? { approvals: { gateMode: fileApprovals.gateMode ?? DEFAULTS.approvals.gateMode, mode: fileApprovals.mode ?? DEFAULTS.approvals.mode } }
|
|
475
515
|
: {}),
|
|
476
|
-
...
|
|
516
|
+
...restPatch,
|
|
517
|
+
acp: mergedAcp,
|
|
477
518
|
engine: narrowEngine(String(persistedEngine).toLowerCase()),
|
|
478
519
|
};
|
|
479
520
|
writeConfigJson(configPath, next);
|