Skip to content

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

fix(desktop): restore WorkBuddy sign-in after connection failure

tianma-ifc78f17a80074
diff --git a/apps/desktop/src/main/acp-host.mjs b/apps/desktop/src/main/acp-host.mjs
index c1822012..e86e95da 100644
--- a/apps/desktop/src/main/acp-host.mjs
+++ b/apps/desktop/src/main/acp-host.mjs
@@ -952,7 +952,7 @@ export function createAcpHostRuntime(options = {}) {
try {
connected = await withHandshakeTimeout((signal) => connect(resolved.command, `probe-${id}`, () => {}, signal, undefined, [], false, null, id === "workbuddyCn" || id === "workbuddyIntl"));
} catch (error) {
- const failure = { ...adapterShell(id), ...failureFields(classifyAcpFailure(error)), ...(isAuthRequiredError(error) ? { authMethods: error.authMethods ?? [] } : {}), ...(resolved.version ? { version: resolved.version, managed: true } : {}) };
+ const failure = { ...adapterShell(id), ...failureFields(classifyAcpFailure(error)), ...(error.authMethods?.length ? { authMethods: error.authMethods } : {}), ...(resolved.version ? { version: resolved.version, managed: true } : {}) };
latestStatus.set(id, failure);
return failure;
}
@@ -996,7 +996,7 @@ export function createAcpHostRuntime(options = {}) {
const adapter = {
...adapterShell(id),
...(timedOut ? { state: "needs_login", detail: "authentication_timeout" } : error?.message === "authentication_failed" ? { state: "needs_login", detail: "authentication_failed" } : failureFields(classifyAcpFailure(error))),
- ...((timedOut || isAuthRequiredError(error)) ? { authMethods: error.authMethods ?? latestStatus.get(id)?.authMethods ?? [] } : {}),
+ ...(error.authMethods?.length || timedOut || isAuthRequiredError(error) ? { authMethods: error.authMethods ?? latestStatus.get(id)?.authMethods ?? [] } : {}),
...(resolved.version ? { version: resolved.version, managed: true } : {}),
};
latestStatus.set(id, adapter);
diff --git a/apps/desktop/src/main/acp-host.test.mjs b/apps/desktop/src/main/acp-host.test.mjs
index 6d499159..930b03f8 100644
--- a/apps/desktop/src/main/acp-host.test.mjs
+++ b/apps/desktop/src/main/acp-host.test.mjs
@@ -84,7 +84,7 @@ const collector = () => {
};
};
-const fakeAgentSource = ({ reportPath, secretPath, allowImage, allowEmbedded, hold, requireAuth, advertiseAuth, promptRefusal, hangAuth, hangSession, workBuddyAccountApi, workBuddyLoginFailure, workBuddyUnreadable, workBuddyUnreadableAfterLogin, authMethodId = "browser", authStatusKind, advertiseAuthStatus = false, authStatusDelay = 20, stderrText, promptAuthStatusKind }) => `#!/usr/bin/env bun
+const fakeAgentSource = ({ reportPath, secretPath, allowImage, allowEmbedded, hold, requireAuth, advertiseAuth, promptRefusal, hangAuth, hangSession, failSessionBeforeLogin, workBuddyAccountApi, workBuddyLoginFailure, workBuddyUnreadable, workBuddyUnreadableAfterLogin, authMethodId = "browser", authStatusKind, advertiseAuthStatus = false, authStatusDelay = 20, stderrText, promptAuthStatusKind }) => `#!/usr/bin/env bun
import * as acp from ${JSON.stringify(sdkHref)};
import { writeFileSync, readFileSync } from "node:fs";
@@ -190,6 +190,7 @@ acp.agent({ name: "edgeever-fake-agent" })
return {};
})
.onRequest("session/new", (ctx) => {
+ if (${failSessionBeforeLogin ? "true" : "false"} && !authenticated) throw new acp.RequestError(-32603, "connection_failed");
if (requireAuth && !authenticated) throw new acp.RequestError(-32000, "auth_required");
report.newSession = { cwd: ctx.params.cwd, mcpServers: ctx.params.mcpServers };
save();
@@ -1022,6 +1023,24 @@ describe("ACP stdio session", () => {
}
}, 15_000);
+ for (const id of ["workbuddyCn", "workbuddyIntl"]) sessionTest(`${id} keeps login methods after connection failure and can reconnect`, async () => {
+ const directory = await mkdtemp(path.join(tmpdir(), "edgeever-acp-retry-"));
+ const reportPath = path.join(directory, "report.json");
+ const methodId = id === "workbuddyCn" ? "internal" : "external";
+ try {
+ const scriptPath = await writeFakeAgent(directory, {
+ reportPath, advertiseAuth: true, failSessionBeforeLogin: true,
+ workBuddyAccountApi: true, authMethodId: methodId,
+ });
+ const runtime = createAcpHostRuntime({ adapterManager: { get: () => ({ command: { command: process.execPath, args: [scriptPath] } }) } });
+ const expected = { state: "failed", authMethods: [{ id: methodId, name: "Browser" }] };
+ expect(await runtime.probeAdapter({ id })).toMatchObject(expected);
+ expect(runtime.listAdapters().find((adapter) => adapter.id === id)).toMatchObject(expected);
+ expect(await runtime.authenticateAdapter({ id, methodId })).toMatchObject({ state: "available" });
+ expect(await runtime.probeAdapter({ id })).toMatchObject({ state: "available" });
+ } finally { await rm(directory, { recursive: true, force: true }); }
+ }, 10_000);
+
sessionTest("WorkBuddy encrypted metadata cannot count as a usable connection or successful login", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "edgeever-acp-unreadable-auth-"));
const reportPath = path.join(directory, "report.json");
@@ -1118,6 +1137,7 @@ describe("ACP stdio session", () => {
expect((await readReport(reportPath)).newSession).not.toBeNull();
expect(result.state).toBe("failed");
expect(result.detail).toBe("connection_timeout");
+ expect(result.authMethods).toEqual([{ id: "browser", name: "Browser" }]);
} finally {
await rm(directory, { recursive: true, force: true });
}
diff --git a/apps/web/src/components/settings/DesktopAcpAgentCard.tsx b/apps/web/src/components/settings/DesktopAcpAgentCard.tsx
index 9f5242f8..f45cb89a 100644
--- a/apps/web/src/components/settings/DesktopAcpAgentCard.tsx
+++ b/apps/web/src/components/settings/DesktopAcpAgentCard.tsx
@@ -12,6 +12,7 @@ import {
AI_SIDEBAR_SOURCE_KEY,
AI_SIDEBAR_SELECTION_EVENT,
displayedDesktopAcpAdapter,
+ desktopAcpLoginRetryAvailable,
listDesktopAcpAdapters,
installDesktopAcpAdapter,
authenticateDesktopAcpAdapter,
@@ -154,7 +155,9 @@ const DesktopAcpAgentCardBody = ({ bridge }: { bridge: boolean }) => {
const authMethods = shown?.authMethods?.filter((method) => (
adapterId === "workbuddyCn" ? method.id !== "external" : adapterId === "workbuddyIntl" ? method.id !== "internal" : true
)) ?? [];
+ const canRetryLogin = desktopAcpLoginRetryAvailable(shown);
const hasDetails = Boolean(
+ canRetryLogin ||
shown?.state === "not_installed" ||
shown?.state === "needs_login" ||
(shown?.state === "available" && (isWorkBuddy || authMethods.length > 0)) ||
@@ -167,7 +170,7 @@ const DesktopAcpAgentCardBody = ({ bridge }: { bridge: boolean }) => {
const authButtons = (
<div className="flex flex-wrap gap-2 pt-0.5">
{authMethods.map((method) => (
- <Button key={method.id} type="button" variant="outline" size="sm" className="h-8 bg-card text-xs font-normal" disabled={Boolean(authenticating)} onClick={() => void authenticate(method.id)}>
+ <Button key={method.id} type="button" variant="outline" size="sm" className="h-8 bg-card text-xs font-normal" disabled={probing || installing || Boolean(authenticating)} onClick={() => void authenticate(method.id)}>
{authenticating === method.id ? t("aiAssistant.agentSource.authenticating") : isWorkBuddy
? t("aiAssistant.agentSource.workbuddyAuthenticateWith", { method: method.name.replace(/^Login with\s+/i, "").replace(/Google\/Github/gi, "Google / GitHub") })
: t("aiAssistant.agentSource.authenticateWith", { method: method.name })}
@@ -420,7 +423,7 @@ const DesktopAcpAgentCardBody = ({ bridge }: { bridge: boolean }) => {
{shown?.state === "available" && isWorkBuddy ? (
<p>{t("aiAssistant.agentSource.workbuddyConnectedHint")}</p>
) : null}
- {shown?.state === "needs_login" && isWorkBuddy ? (
+ {(shown?.state === "needs_login" || canRetryLogin) && isWorkBuddy ? (
<p>{t(adapterId === "workbuddyCn" ? "aiAssistant.agentSource.workbuddyCnLoginHint" : "aiAssistant.agentSource.workbuddyIntlLoginHint")}</p>
) : null}
{shown?.state === "available" && !isWorkBuddy && authMethods.length ? (
@@ -436,7 +439,7 @@ const DesktopAcpAgentCardBody = ({ bridge }: { bridge: boolean }) => {
</CollapsibleTrigger>
<CollapsibleContent>{authButtons}</CollapsibleContent>
</Collapsible>
- ) : (shown?.state === "needs_login" || shown?.state === "available") && authMethods.length ? authButtons : null}
+ ) : (shown?.state === "needs_login" || shown?.state === "available" || canRetryLogin) && authMethods.length ? authButtons : null}
{shown?.state === "needs_login" && !authMethods.length && adapterId !== "piAgent" ? (
<p className="text-xs text-amber-700" role="status">{t("aiAssistant.agentSource.loginUnavailable")}</p>
) : null}
diff --git a/apps/web/src/lib/desktop-acp.test.mjs b/apps/web/src/lib/desktop-acp.test.mjs
index 0ca2a1a1..2a1351ba 100644
--- a/apps/web/src/lib/desktop-acp.test.mjs
+++ b/apps/web/src/lib/desktop-acp.test.mjs
@@ -1,5 +1,5 @@
import { expect, test } from "bun:test";
-import { desktopAcpNoteAccessErrorKey, aiSidebarAdapterFromStorage, aiSidebarSourceFromStorage, displayedDesktopAcpAdapter } from "./desktop-acp.ts";
+import { desktopAcpLoginRetryAvailable, desktopAcpNoteAccessErrorKey, aiSidebarAdapterFromStorage, aiSidebarSourceFromStorage, displayedDesktopAcpAdapter } from "./desktop-acp.ts";
test("a checked custom Antigravity executable takes priority over the managed connector status", () => {
const managed = { id: "antigravity", label: "Antigravity", state: "failed", version: "1.2.1", managed: true };
@@ -143,3 +143,16 @@ test("note access failures distinguish network, EdgeEver sign-in, and account ch
expect(desktopAcpNoteAccessErrorKey("note_access_unavailable")).toBe("aiAssistant.sidebar.noteAccessUnavailable");
expect(desktopAcpNoteAccessErrorKey("needs_login")).toBeNull();
});
+
+test("WorkBuddy connection failures keep an edition-specific sign-in recovery path", () => {
+ for (const id of ["workbuddyCn", "workbuddyIntl"]) {
+ const methodId = id === "workbuddyCn" ? "internal" : "external";
+ const adapter = { id, state: "failed", authMethods: [{ id: methodId, name: "Browser" }] };
+ expect(desktopAcpLoginRetryAvailable(adapter)).toBe(true);
+ expect(desktopAcpLoginRetryAvailable({ ...adapter, detail: "workbuddy_credentials_unavailable" })).toBe(false);
+ expect(desktopAcpLoginRetryAvailable({ ...adapter, authMethods: [] })).toBe(false);
+ expect(desktopAcpLoginRetryAvailable({ ...adapter, authMethods: [{ id: methodId === "internal" ? "external" : "internal" }] })).toBe(false);
+ }
+ expect(desktopAcpLoginRetryAvailable(undefined)).toBe(false);
+ expect(desktopAcpLoginRetryAvailable({ id: "codex", state: "failed", authMethods: [{ id: "browser" }] })).toBe(false);
+});
diff --git a/apps/web/src/lib/desktop-acp.ts b/apps/web/src/lib/desktop-acp.ts
index 20c61092..1ef5f6f1 100644
--- a/apps/web/src/lib/desktop-acp.ts
+++ b/apps/web/src/lib/desktop-acp.ts
@@ -19,6 +19,15 @@ export type DesktopAcpAdapter = {
authMethods?: Array<{ id: string; name: string }>;
};
+// Offer only login methods advertised by the agent. Unreadable saved tokens
+// require a different remedy and must not invite a futile sign-in loop.
+export const desktopAcpLoginRetryAvailable = (adapter: DesktopAcpAdapter | undefined) => Boolean(
+ adapter?.state === "failed" &&
+ (adapter.id === "workbuddyCn" || adapter.id === "workbuddyIntl") &&
+ adapter.detail !== "workbuddy_credentials_unavailable" &&
+ adapter.authMethods?.some((method) => adapter.id === "workbuddyCn" ? method.id !== "external" : method.id !== "internal")
+);
+
export const displayedDesktopAcpAdapter = ({
id,
path,