Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: probe unchecked local agents before reporting connection failure

tianma-if164495646916
diff --git a/apps/desktop/src/main/acp-host.mjs b/apps/desktop/src/main/acp-host.mjs
index 1b7438d2..3b4241fa 100644
--- a/apps/desktop/src/main/acp-host.mjs
+++ b/apps/desktop/src/main/acp-host.mjs
@@ -783,7 +783,7 @@ export function createAcpHostRuntime(options = {}) {
if (installingIds.has(id)) return { ...adapterShell(id), state: "installing" };
const resolved = resolveCommand({ id }, { prepareProxy: false });
return resolved.ok
- ? { ...adapterShell(id), ...(latestStatus.get(id) ?? { state: "failed", detail: "not_probed" }), ...(resolved.version ? { version: resolved.version, managed: true } : {}), ...(updateFailures.has(id) ? { updateError: updateFailures.get(id) } : {}) }
+ ? { ...adapterShell(id), ...(latestStatus.get(id) ?? { state: "not_probed", detail: "not_probed" }), ...(resolved.version ? { version: resolved.version, managed: true } : {}), ...(updateFailures.has(id) ? { updateError: updateFailures.get(id) } : {}) }
: adapterFromResolution(id, resolved);
});
},
diff --git a/apps/desktop/src/main/acp-host.test.mjs b/apps/desktop/src/main/acp-host.test.mjs
index d5ad2b8d..0e48df5a 100644
--- a/apps/desktop/src/main/acp-host.test.mjs
+++ b/apps/desktop/src/main/acp-host.test.mjs
@@ -237,7 +237,7 @@ describe("ACP command allow-list", () => {
expect(listed.find((adapter) => adapter.id === "codex")).toEqual({
id: "codex",
label: "Codex",
- state: "failed",
+ state: "not_probed",
detail: "not_probed",
});
expect(listed.find((adapter) => adapter.id === "antigravity")?.state).toBe("not_installed");
@@ -358,7 +358,7 @@ describe("ACP command allow-list", () => {
const resolved = resolveAcpCommand({ id: "grokBuild" }, { platform: "darwin", pathEnv: "", home: directory });
expect(resolved).toEqual({ ok: true, command: { command: realpathSync(binary), args: ["agent", "stdio"] } });
const runtime = createAcpHostRuntime({ platform: "darwin", pathEnv: "", home: directory });
- expect(runtime.listAdapters().find((adapter) => adapter.id === "grokBuild")?.state).toBe("failed");
+ expect(runtime.listAdapters().find((adapter) => adapter.id === "grokBuild")?.state).toBe("not_probed");
expect(resolveAcpCommand({ id: "grokBuild", path: "../grok" }, { platform: "darwin", home: directory }).detail).toBe("invalid_path");
} finally {
await rm(directory, { recursive: true, force: true });
@@ -649,6 +649,33 @@ describe("ACP stdio session", () => {
}
}, 15_000);
+ sessionTest("a managed Codex connector is unchecked after restart and becomes available after a real probe", async () => {
+ const directory = await mkdtemp(path.join(tmpdir(), "edgeever-acp-restart-"));
+ try {
+ const scriptPath = await writeFakeAgent(directory, {
+ reportPath: path.join(directory, "report.json"),
+ secretPath: path.join(directory, "secret.txt"),
+ hold: false,
+ });
+ const options = {
+ adapterManager: {
+ get: (id) => id === "codex" ? { version: "2.1.1", command: { command: process.execPath, args: [scriptPath] } } : null,
+ },
+ pathEnv: "",
+ };
+ const runtime = createAcpHostRuntime(options);
+ const codex = (host) => host.listAdapters().find((adapter) => adapter.id === "codex");
+ expect(codex(runtime)).toMatchObject({ state: "not_probed", detail: "not_probed", managed: true });
+ expect((await runtime.probeAdapter({ id: "codex" })).state).toBe("available");
+ expect(codex(runtime).state).toBe("available");
+ expect(codex(createAcpHostRuntime(options)).state).toBe("not_probed");
+ const pid = Number(await readFile(path.join(directory, "report.json.pid"), "utf8"));
+ await waitUntilExited(pid);
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+ }, 15_000);
+
sessionTest("provides the signed-in workspace MCP server only during an ACP prompt", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "edgeever-acp-mcp-"));
const reportPath = path.join(directory, "report.json");
diff --git a/apps/web/src/components/ai-sidebar/AiAgentSelector.tsx b/apps/web/src/components/ai-sidebar/AiAgentSelector.tsx
index a24691ba..f2791d95 100644
--- a/apps/web/src/components/ai-sidebar/AiAgentSelector.tsx
+++ b/apps/web/src/components/ai-sidebar/AiAgentSelector.tsx
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
-import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import { useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
import { ChevronDown, Loader2 } from "lucide-react";
import { Link } from "react-router";
import { WORKSPACE_SETTINGS_PATH } from "@/hooks/useWorkspaceRoute";
@@ -10,7 +10,7 @@ import {
} from "@/components/ui/dropdown-menu";
import { api } from "@/lib/api";
import {
- AI_SIDEBAR_ADAPTER_PATH_KEY, aiSidebarAdapterFromStorage,
+ AI_SIDEBAR_ADAPTER_PATH_KEY, desktopAcpAutomaticProbeInput,
desktopAcpAvailable, listDesktopAcpAdapters, probeDesktopAcpAdapter, selectAiSidebarAgent,
type AiSidebarSource, type DesktopAcpAdapterId,
} from "@/lib/desktop-acp";
@@ -32,23 +32,32 @@ export function AiAgentSelector({ source, adapterId, disabled, onPendingChange,
const desktop = desktopAcpAvailable();
const agents = useQuery({
queryKey: ["ai-sidebar-adapters"],
- queryFn: async () => {
- const listed = await listDesktopAcpAdapters();
- const configured = aiSidebarAdapterFromStorage("antigravity", window.localStorage.getItem(AI_SIDEBAR_ADAPTER_PATH_KEY));
- if (configured?.id === "antigravity" && configured.path) {
- const checked = await probeDesktopAcpAdapter(configured);
- return [...listed.filter((agent) => agent.id !== checked.id), checked];
- }
- return listed;
- },
+ queryFn: listDesktopAcpAdapters,
enabled: desktop && open,
staleTime: 0,
});
+ const customPath = desktop && open ? window.localStorage.getItem(AI_SIDEBAR_ADAPTER_PATH_KEY) ?? "" : "";
+ const listedAgents = agents.data ?? [];
+ const probeInputs = listedAgents.map((agent) => desktopAcpAutomaticProbeInput(agent, customPath));
+ const probes = useQueries({
+ queries: listedAgents.map((agent, index) => ({
+ queryKey: ["ai-sidebar-adapter-probe", agent.id, agent.version ?? "", probeInputs[index]?.path ?? ""],
+ queryFn: () => probeDesktopAcpAdapter(probeInputs[index]!),
+ enabled: desktop && open && probeInputs[index] !== null,
+ staleTime: 0,
+ retry: false,
+ refetchOnWindowFocus: false,
+ })),
+ });
+ // Each connector finishes independently, so a slow agent cannot block another.
+ const localAgents = listedAgents.map((agent, index) => probeInputs[index]
+ ? probes[index].isError ? { ...agent, state: "failed" as const, detail: "connection_failed" } : probes[index].data ?? agent
+ : agent);
const mutation = useMutation({
mutationFn: async (value: string) => {
if (value.startsWith("agent:")) {
const id = value.slice(6) as DesktopAcpAdapterId;
- if (!agents.data?.some((agent) => agent.id === id && agent.state === "available")) throw new Error(t("aiAssistant.agentSource.switchUnavailable"));
+ if (!localAgents.some((agent) => agent.id === id && agent.state === "available")) throw new Error(t("aiAssistant.agentSource.switchUnavailable"));
selectAiSidebarAgent("local", id);
} else {
if (value !== "builtin" && value.slice(6) !== settings.data?.defaultModelId) {
@@ -78,7 +87,6 @@ export function AiAgentSelector({ source, adapterId, disabled, onPendingChange,
? t("aiModel.defaultProviderName", { ordinal: formatProviderOrdinal(index + 1, locale) }) : provider.displayName;
return { ...provider, name };
}).filter((provider) => provider.models.length);
- const localAgents = agents.data ?? [];
const choose = (value: string) => {
if (disabled || mutation.isPending) return;
if (value === selected) { setOpen(false); return; }
@@ -124,8 +132,8 @@ export function AiAgentSelector({ source, adapterId, disabled, onPendingChange,
<p className="px-2 pb-1 text-[11px] text-slate-500">{localHint}</p>
{agents.isPending ? <p className="px-2 py-2 text-xs">{t("common.loading")}</p> : null}
{agents.isError ? <p role="alert" className="px-2 py-2 text-xs text-rose-600">{t("aiAssistant.agentSource.switchUnavailable")}</p> : null}
- {localAgents.map((agent) => <DropdownMenuRadioItem key={agent.id} value={`agent:${agent.id}`} disabled={mutation.isPending || agents.isFetching || agent.state !== "available"} onSelect={(event) => event.preventDefault()}>
- <span className="flex min-w-0 flex-1 flex-wrap justify-between gap-x-2"><span>{t(`aiAssistant.agentSource.${agent.id}`)}</span><span className="text-[10px] text-slate-500">{t(`aiAssistant.agentSource.states.${agent.state}`)}</span></span>
+ {localAgents.map((agent, index) => <DropdownMenuRadioItem key={agent.id} value={`agent:${agent.id}`} disabled={mutation.isPending || (probeInputs[index] !== null && probes[index].isFetching) || agent.state !== "available"} onSelect={(event) => event.preventDefault()}>
+ <span className="flex min-w-0 flex-1 flex-wrap justify-between gap-x-2"><span>{t(`aiAssistant.agentSource.${agent.id}`)}</span><span className="text-[10px] text-slate-500">{probeInputs[index] !== null && probes[index].isFetching ? t("aiAssistant.agentSource.probing") : t(`aiAssistant.agentSource.states.${agent.state}`)}</span></span>
</DropdownMenuRadioItem>)}
{!agents.isPending && !agents.isError && !localAgents.length ? <p className="px-2 py-2 text-xs text-slate-500">{t("aiAssistant.agentSource.switchUnavailable")}</p> : null}
</> : null}
diff --git a/apps/web/src/lib/desktop-acp.test.mjs b/apps/web/src/lib/desktop-acp.test.mjs
index 68612052..f1f12e2f 100644
--- a/apps/web/src/lib/desktop-acp.test.mjs
+++ b/apps/web/src/lib/desktop-acp.test.mjs
@@ -75,3 +75,33 @@ test("agent selection reuses preference keys, preserves the custom path and noti
else globalThis.window = previousWindow;
}
});
+
+test("older desktop hosts expose unchecked connectors as unchecked, not failed", async () => {
+ const { listDesktopAcpAdapters, desktopAcpAutomaticProbeInput } = await import("./desktop-acp.ts");
+ const previousWindow = globalThis.window;
+ const unchecked = { id: "codex", label: "Codex", state: "failed", detail: "not_probed", version: "2.1.1", managed: true };
+ const failed = { id: "hermesAgent", label: "Hermes Agent", state: "failed", detail: "connection_timeout" };
+ globalThis.window = { edgeeverDesktop: { listAcpAdapters: async () => [unchecked, failed] } };
+ try {
+ const listed = await listDesktopAcpAdapters();
+ expect(listed[0]).toEqual({ ...unchecked, state: "not_probed" });
+ expect(listed[1]).toEqual(failed);
+ expect(desktopAcpAutomaticProbeInput(listed[0], "")).toEqual({ id: "codex" });
+ expect(desktopAcpAutomaticProbeInput(listed[1], "")).toEqual({ id: "hermesAgent" });
+ } finally {
+ if (previousWindow === undefined) delete globalThis.window;
+ else globalThis.window = previousWindow;
+ }
+});
+
+test("automatic checks skip missing, installing, ready and login-required agents but honor custom Antigravity paths", async () => {
+ const { desktopAcpAutomaticProbeInput } = await import("./desktop-acp.ts");
+ const codex = { id: "codex", label: "Codex" };
+ for (const state of ["not_installed", "installing", "available", "needs_login"]) {
+ expect(desktopAcpAutomaticProbeInput({ ...codex, state }, " /custom/agy ")).toBeNull();
+ }
+ expect(desktopAcpAutomaticProbeInput({ ...codex, state: "not_probed" }, " /custom/agy ")).toEqual({ id: "codex" });
+ const antigravity = { id: "antigravity", label: "Antigravity", state: "not_installed" };
+ expect(desktopAcpAutomaticProbeInput(antigravity, " /custom/agy ")).toEqual({ id: "antigravity", path: "/custom/agy" });
+ expect(desktopAcpAutomaticProbeInput({ ...antigravity, state: "installing" }, "/custom/agy")).toBeNull();
+});
diff --git a/apps/web/src/lib/desktop-acp.ts b/apps/web/src/lib/desktop-acp.ts
index 19f889ef..ea760465 100644
--- a/apps/web/src/lib/desktop-acp.ts
+++ b/apps/web/src/lib/desktop-acp.ts
@@ -1,5 +1,5 @@
export type DesktopAcpAdapterId = "codex" | "claudeCode" | "antigravity" | "openClaw" | "hermesAgent" | "grokBuild" | "deepseekHarness" | "piAgent" | "workbuddyCn" | "workbuddyIntl";
-export type DesktopAcpAdapterState = "not_installed" | "installing" | "needs_login" | "available" | "failed";
+export type DesktopAcpAdapterState = "not_installed" | "not_probed" | "installing" | "needs_login" | "available" | "failed";
export type DesktopAcpPromptCapabilities = {
image?: boolean;
@@ -37,6 +37,13 @@ export const displayedDesktopAcpAdapter = ({
return checked ?? current;
};
+export const desktopAcpAutomaticProbeInput = (adapter: DesktopAcpAdapter, customPath: string) => {
+ if (adapter.state === "installing") return null;
+ if (adapter.id === "antigravity" && customPath.trim()) return { id: adapter.id, path: customPath.trim() };
+ if (adapter.state === "not_probed" || adapter.detail === "not_probed" || adapter.state === "failed") return { id: adapter.id };
+ return null;
+};
+
export type DesktopAcpAttachment = {
filename: string;
mediaType: string;
@@ -145,7 +152,10 @@ export const desktopAcpAvailable = () => Boolean(bridge()?.listAcpAdapters);
export const listDesktopAcpAdapters = async (): Promise<DesktopAcpAdapter[]> => {
const desktop = bridge();
if (!desktop?.listAcpAdapters) return [];
- return desktop.listAcpAdapters();
+ const adapters = await desktop.listAcpAdapters();
+ // Older desktop hosts encoded an unchecked connector as a failed connection.
+ return adapters.map((adapter) => adapter.detail === "not_probed"
+ ? { ...adapter, state: "not_probed" as const } : adapter);
};
export const probeDesktopAcpAdapter = async (input: { id: DesktopAcpAdapterId; path?: string }): Promise<DesktopAcpAdapter> => {
diff --git a/apps/web/src/vite-env.d.ts b/apps/web/src/vite-env.d.ts
index 9d35ef70..6ed28853 100644
--- a/apps/web/src/vite-env.d.ts
+++ b/apps/web/src/vite-env.d.ts
@@ -112,7 +112,7 @@ interface EdgeEverDesktopBridge {
listAcpAdapters?(): Promise<Array<{
id: "codex" | "claudeCode" | "antigravity" | "openClaw" | "hermesAgent" | "grokBuild" | "deepseekHarness" | "piAgent" | "workbuddyCn" | "workbuddyIntl";
label: string;
- state: "not_installed" | "installing" | "needs_login" | "available" | "failed";
+ state: "not_installed" | "not_probed" | "installing" | "needs_login" | "available" | "failed";
detail?: string;
promptCapabilities?: { image?: boolean; embeddedContext?: boolean };
version?: string;
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index fed9fd42..9c914f17 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -1556,6 +1556,7 @@ export const enUS = {
notProbed: "Not checked yet",
invalidPath: "Enter an absolute path to an executable file.",
states: {
+ not_probed: "Not checked yet",
not_installed: "ACP connector not found",
installing: "Installing the ACP connector automatically…",
needs_login: "Needs login",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index 55317453..7cf245ce 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -1556,6 +1556,7 @@ export const ja = {
notProbed: "未確認",
invalidPath: "実行ファイルの絶対パスを入力してください。",
states: {
+ not_probed: "未確認",
not_installed: "ACP 接続コンポーネントが見つかりません",
installing: "ACP 接続コンポーネントを自動インストール中…",
needs_login: "ログインが必要",
diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.ts
index 6e5adbd3..85556f46 100644
--- a/packages/shared/src/i18n/pl.ts
+++ b/packages/shared/src/i18n/pl.ts
@@ -1556,6 +1556,7 @@ export const pl = {
notProbed: "Jeszcze nie sprawdzono",
invalidPath: "Wpisz bezwzględną ścieżkę do pliku wykonywalnego.",
states: {
+ not_probed: "Jeszcze nie sprawdzono",
not_installed: "Nie znaleziono konektora ACP",
installing: "Automatyczne instalowanie konektora ACP…",
needs_login: "Wymaga zalogowania",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 727429aa..9bc24edd 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -1556,6 +1556,7 @@ export const zhCN = {
notProbed: "尚未检查",
invalidPath: "请填写可执行文件的绝对路径。",
states: {
+ not_probed: "尚未检查",
not_installed: "未找到 ACP 连接组件",
installing: "正在自动安装 ACP 连接组件…",
needs_login: "需要登录",