The Open Framework for Building Agents
fix(eve): retry transient agent info probes (#350)
Ruic14b0227af94
diff --git a/.changeset/resilient-agent-info-probe.md b/.changeset/resilient-agent-info-probe.mdnew file mode 100644index 000000000..1aa5e4ad4--- /dev/null+++ b/.changeset/resilient-agent-info-probe.md@@ -0,0 +1,5 @@+---+"eve": patch+---++The `eve dev` TUI retries one transient agent-inspection failure before treating a local or remote agent as unavailable.diff --git a/packages/eve/src/cli/dev/tui/agent-info-probe.test.ts b/packages/eve/src/cli/dev/tui/agent-info-probe.test.tsnew file mode 100644index 000000000..1db0dc95c--- /dev/null+++ b/packages/eve/src/cli/dev/tui/agent-info-probe.test.ts@@ -0,0 +1,121 @@+import { describe, expect, it, vi } from "vitest";++import {+ AgentInfoResponseError,+ ClientError,+ type AgentInfoResult,+ type Client,+} from "#client/index.js";++import { probeAgentInfo } from "./agent-info-probe.js";++const AGENT_INFO = {+ agent: {+ agentRoot: "/tmp/weather-agent/agent",+ appRoot: "/tmp/weather-agent",+ model: { id: "gpt-5" },+ name: "Weather Agent",+ },+ capabilities: { devRoutes: true },+ channels: { authored: [], available: [], disabledFramework: [], framework: [] },+ connections: [],+ diagnostics: { discoveryErrors: 0, discoveryWarnings: 0 },+ hooks: [],+ instructions: { dynamic: [], static: null },+ kind: "eve-agent-info",+ mode: "development",+ sandbox: null,+ schedules: [],+ skills: { dynamic: [], static: [] },+ subagents: { local: [], total: 0 },+ tools: {+ authored: [],+ available: [],+ disabledFramework: [],+ dynamic: [],+ framework: [],+ reserved: [],+ },+ version: 1,+ workflow: { enabled: false, toolName: "Workflow" },+ workspace: { resourceRoot: null, rootEntries: [] },+} satisfies AgentInfoResult;++async function advanceRetry(): Promise<void> {+ await Promise.resolve();+ await Promise.resolve();+ await vi.advanceTimersByTimeAsync(100);+}++describe("probeAgentInfo", () => {+ it("retries a transient server failure and returns inspection once the server is ready", async () => {+ vi.useFakeTimers();+ try {+ const info = vi+ .fn<() => Promise<AgentInfoResult>>()+ .mockRejectedValueOnce(new ClientError(500, "Runner did not become ready in time"))+ .mockResolvedValueOnce(AGENT_INFO);+ const client = { info } satisfies Pick<Client, "info">;++ const probe = probeAgentInfo({ client });+ await advanceRetry();++ await expect(probe).resolves.toEqual({ kind: "ready", info: AGENT_INFO });+ expect(info).toHaveBeenCalledTimes(2);+ } finally {+ vi.useRealTimers();+ }+ });++ it("retries a network failure", async () => {+ vi.useFakeTimers();+ try {+ const info = vi+ .fn<() => Promise<AgentInfoResult>>()+ .mockRejectedValueOnce(new TypeError("fetch failed"))+ .mockResolvedValueOnce(AGENT_INFO);+ const client = { info } satisfies Pick<Client, "info">;++ const probe = probeAgentInfo({ client });+ await advanceRetry();++ await expect(probe).resolves.toEqual({ kind: "ready", info: AGENT_INFO });+ expect(info).toHaveBeenCalledTimes(2);+ } finally {+ vi.useRealTimers();+ }+ });++ it("stops after one retry", async () => {+ vi.useFakeTimers();+ try {+ const firstFailure = new ClientError(500, "Runner did not become ready in time");+ const secondFailure = new ClientError(500, "Still unavailable");+ const info = vi+ .fn<() => Promise<AgentInfoResult>>()+ .mockRejectedValueOnce(firstFailure)+ .mockRejectedValueOnce(secondFailure);+ const client = { info } satisfies Pick<Client, "info">;++ const probe = probeAgentInfo({ client });+ await advanceRetry();++ await expect(probe).resolves.toEqual({ kind: "unavailable", error: secondFailure });+ expect(info).toHaveBeenCalledTimes(2);+ } finally {+ vi.useRealTimers();+ }+ });++ it.each([+ ["authorization failures", new ClientError(401, "Unauthorized")],+ ["unrecognized inspection payloads", new AgentInfoResponseError(["version: Required"])],+ ["unexpected client failures", new Error("unexpected")],+ ])("does not retry %s", async (_name, error) => {+ const info = vi.fn<() => Promise<AgentInfoResult>>().mockRejectedValueOnce(error);+ const client = { info } satisfies Pick<Client, "info">;++ await expect(probeAgentInfo({ client })).resolves.toEqual({ kind: "unavailable", error });+ expect(info).toHaveBeenCalledOnce();+ });+});diff --git a/packages/eve/src/cli/dev/tui/agent-info-probe.ts b/packages/eve/src/cli/dev/tui/agent-info-probe.tsnew file mode 100644index 000000000..877e919b3--- /dev/null+++ b/packages/eve/src/cli/dev/tui/agent-info-probe.ts@@ -0,0 +1,45 @@+import {+ AgentInfoResponseError,+ ClientError,+ type AgentInfoResult,+ type Client,+} from "#client/index.js";++const RETRY_DELAY_MS = 100;++export type AgentInfoProbeResult =+ | { readonly kind: "ready"; readonly info: AgentInfoResult }+ | { readonly kind: "unavailable"; readonly error: unknown };++function isRetryableAgentInfoFailure(error: unknown): boolean {+ if (error instanceof AgentInfoResponseError) return false;+ if (error instanceof ClientError) return error.status >= 500;+ return error instanceof TypeError;+}++function sleep(delayMs: number): Promise<void> {+ return new Promise((resolve) => setTimeout(resolve, delayMs));+}++/**+ * Reads best-effort inspection data from a server whose lifecycle belongs to+ * another process. Transient transport and server failures can occur while+ * that process reloads, but auth and schema failures cannot be fixed by retry.+ */+export async function probeAgentInfo(input: {+ readonly client: Pick<Client, "info">;+}): Promise<AgentInfoProbeResult> {+ try {+ return { kind: "ready", info: await input.client.info() };+ } catch (error) {+ if (!isRetryableAgentInfoFailure(error)) return { kind: "unavailable", error };+ }++ await sleep(RETRY_DELAY_MS);++ try {+ return { kind: "ready", info: await input.client.info() };+ } catch (error) {+ return { kind: "unavailable", error };+ }+}diff --git a/packages/eve/src/cli/dev/tui/remote-connection-probe.ts b/packages/eve/src/cli/dev/tui/remote-connection-probe.tsindex d45e828c7..05d6ee1ff 100644--- a/packages/eve/src/cli/dev/tui/remote-connection-probe.ts+++ b/packages/eve/src/cli/dev/tui/remote-connection-probe.ts@@ -7,6 +7,7 @@ import {import { toErrorMessage } from "#shared/errors.js";import { isObject } from "#shared/guards.js";+import { probeAgentInfo } from "./agent-info-probe.js";import type { RemoteConnectionState } from "./remote-connection-types.js";export type RemoteProbeResult = Extract<@@ -88,20 +89,20 @@ export async function probeRemoteInfo(input: {readonly client: Client;readonly phase: RemoteProbePhase;}): Promise<RemoteProbeResult> {- try {- return { state: "ready", info: await input.client.info() };- } catch (error) {- // Inspection is best-effort: an authorized response we cannot use must not- // block the connection, since the conversation transport does not depend on- // `/eve/v1/info`.- if (- error instanceof AgentInfoResponseError ||- (error instanceof ClientError && error.status === 404)- ) {- // The info route can be missing or use an older payload shape. Only call- // the target ready once the public health route confirms a live Eve server.- if (await probeDeploymentHealth(input.client)) return { state: "ready" };- }- return classifyRemoteError(error, input.phase);+ const probe = await probeAgentInfo({ client: input.client });+ if (probe.kind === "ready") return { state: "ready", info: probe.info };++ const { error } = probe;+ // Inspection is best-effort: an authorized response we cannot use must not+ // block the connection, since the conversation transport does not depend on+ // `/eve/v1/info`.+ if (+ error instanceof AgentInfoResponseError ||+ (error instanceof ClientError && error.status === 404)+ ) {+ // The info route can be missing or use an older payload shape. Only call+ // the target ready once the public health route confirms a live Eve server.+ if (await probeDeploymentHealth(input.client)) return { state: "ready" };}+ return classifyRemoteError(error, input.phase);}diff --git a/packages/eve/src/cli/dev/tui/remote-connection.test.ts b/packages/eve/src/cli/dev/tui/remote-connection.test.tsindex f2c73a7d0..07cc86b3f 100644--- a/packages/eve/src/cli/dev/tui/remote-connection.test.ts+++ b/packages/eve/src/cli/dev/tui/remote-connection.test.ts@@ -197,6 +197,28 @@ describe("createRemoteConnectionController", () => {await expect(checkFailure(error)).resolves.toMatchObject(expected);});+ it("retries a transient info failure before declaring the remote unavailable", async () => {+ vi.useFakeTimers();+ try {+ const { controller, info } = createHarness({+ info: vi+ .fn<() => Promise<AgentInfoResult>>()+ .mockRejectedValueOnce(new ClientError(500, "Runner did not become ready in time"))+ .mockResolvedValueOnce(INFO),+ });++ const check = controller.check();+ await Promise.resolve();+ await Promise.resolve();+ await vi.advanceTimersByTimeAsync(100);++ await expect(check).resolves.toEqual({ state: "ready", info: INFO });+ expect(info).toHaveBeenCalledTimes(2);+ } finally {+ vi.useRealTimers();+ }+ });+it("stays ready after an unusable info payload when health confirms Eve", async () => {const harness = createHarness({info: async () => {diff --git a/packages/eve/src/cli/dev/tui/runner.test.ts b/packages/eve/src/cli/dev/tui/runner.test.tsindex 8d8abbf69..c43598fb8 100644--- a/packages/eve/src/cli/dev/tui/runner.test.ts+++ b/packages/eve/src/cli/dev/tui/runner.test.ts@@ -303,6 +303,39 @@ describe("EveTUIRunner agent header", () => {expect(headers[0]?.name).toBe("Weather Agent");});+ it("retries a transient info failure before rendering the startup header", async () => {+ vi.useFakeTimers();+ const headers: AgentTUIAgentHeader[] = [];+ const renderer = fakeRenderer({+ renderAgentHeader: (header) => headers.push(header),+ });+ const client = stubClient();+ vi.spyOn(client, "info")+ .mockRejectedValueOnce(new ClientError(500, "Runner did not become ready in time"))+ .mockResolvedValueOnce(AGENT_INFO);+ const runner = new EveTUIRunner({+ session: stubSession(),+ client,+ renderer,+ serverUrl: "http://localhost:3000",+ name: "Weather Agent",+ });++ const running = runner.run();+ await settleAsyncWork();+ await vi.advanceTimersByTimeAsync(100);+ await running;++ expect(client.info).toHaveBeenCalledTimes(2);+ expect(headers).toEqual([+ {+ name: "Weather Agent",+ serverUrl: "http://localhost:3000",+ info: AGENT_INFO,+ },+ ]);+ });+it("refreshes the agent header when a dev artifact refresh changes the model", async () => {const headers: AgentTUIAgentHeader[] = [];const prompts: Array<string | undefined> = ["first", "second", undefined];@@ -353,7 +386,7 @@ describe("EveTUIRunner agent header", () => {expect(session.send).toHaveBeenCalledTimes(2);});- it("refreshes the agent header while waiting for prompt input", async () => {+ it("retries a transient info failure while refreshing the agent header", async () => {vi.useFakeTimers();const headers: AgentTUIAgentHeader[] = [];const prompt = createDeferred<string | undefined>();@@ -367,7 +400,10 @@ describe("EveTUIRunner agent header", () => {},};const client = stubClient();- vi.spyOn(client, "info").mockResolvedValueOnce(AGENT_INFO).mockResolvedValueOnce(nextInfo);+ vi.spyOn(client, "info")+ .mockResolvedValueOnce(AGENT_INFO)+ .mockRejectedValueOnce(new ClientError(500, "Runner did not become ready in time"))+ .mockResolvedValueOnce(nextInfo);const revisions = ["snapshot-a", "snapshot-b"];const fetchMock = vi.fn(async () =>Response.json({ revision: revisions.shift() ?? "snapshot-b" }),@@ -396,9 +432,12 @@ describe("EveTUIRunner agent header", () => {await vi.advanceTimersByTimeAsync(500);await settleAsyncWork();+ await vi.advanceTimersByTimeAsync(100);+ await settleAsyncWork();expect(headers).toHaveLength(2);expect(headers[1]?.info?.agent.model.id).toBe("anthropic/claude-sonnet-4.6");+ expect(client.info).toHaveBeenCalledTimes(3);expect(session.send).not.toHaveBeenCalled();prompt.resolve(undefined);diff --git a/packages/eve/src/cli/dev/tui/runner.ts b/packages/eve/src/cli/dev/tui/runner.tsindex 9fb46dceb..e78ad4665 100644--- a/packages/eve/src/cli/dev/tui/runner.ts+++ b/packages/eve/src/cli/dev/tui/runner.ts@@ -41,6 +41,7 @@ import {} from "./errors.js";import { pickAgentHeaderTip } from "./agent-header.js";+import { probeAgentInfo } from "./agent-info-probe.js";import { parseLogDisplayMode } from "./log-display-mode.js";import {formatPromptCommandHelp,@@ -550,14 +551,18 @@ export class EveTUIRunner {const connection = await this.#remoteConnection.check();if (connection.state === "ready") info = connection.info;} else {- try {- info = await devBootPhase(- "connecting to agent",- () => (this.#client ? this.#client.info() : Promise.resolve(undefined)),- this.#onBootProgress,- );- } catch {- info = undefined;+ const client = this.#client;+ if (client !== undefined) {+ try {+ const probe = await devBootPhase(+ "connecting to agent",+ () => probeAgentInfo({ client }),+ this.#onBootProgress,+ );+ if (probe.kind === "ready") info = probe.info;+ } catch {+ info = undefined;+ }}}this.#reportBeforeFirstPaint();@@ -1313,11 +1318,11 @@ export class EveTUIRunner {}async #readAgentInfo(): Promise<AgentInfoResult | undefined> {- try {- return await this.#client?.info();- } catch {- return undefined;- }+ const client = this.#client;+ if (client === undefined) return;++ const probe = await probeAgentInfo({ client });+ return probe.kind === "ready" ? probe.info : undefined;}async #handleRuntimeArtifactsChanged(): Promise<void> {