:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): skip the boot claude login probe unless the flag is on (#92981)
Charles Vien9baa7bfc60ef
diff --git a/products/desktop/packages/agent/src/adapters/claude/subscription-login.test.ts b/products/desktop/packages/agent/src/adapters/claude/subscription-login.test.tsindex 93404036540b..f7ca5413bec8 100644--- a/products/desktop/packages/agent/src/adapters/claude/subscription-login.test.ts+++ b/products/desktop/packages/agent/src/adapters/claude/subscription-login.test.ts@@ -219,19 +219,30 @@ describe("hasClaudeLogin", () => {]);});- it("reports unknown when the status check times out", async () => {- vi.useFakeTimers();- try {- const result = hasClaudeLogin({- claudeCliPath: "/bundled/claude",- machineAuth: {},- timeoutMs: 100,- });- vi.advanceTimersByTime(200);- await expect(result).resolves.toBe("unknown");- expect(child.kill).toHaveBeenCalledWith("SIGTERM");- } finally {- vi.useRealTimers();- }- });+ it.each([+ { exitsAfterTerm: true, expectKill: false },+ { exitsAfterTerm: false, expectKill: true },+ ])(+ "reports unknown on timeout and escalates to SIGKILL only if the CLI ignores SIGTERM (exitsAfterTerm: $exitsAfterTerm)",+ async ({ exitsAfterTerm, expectKill }) => {+ vi.useFakeTimers();+ try {+ const result = hasClaudeLogin({+ claudeCliPath: "/bundled/claude",+ machineAuth: {},+ timeoutMs: 100,+ });+ vi.advanceTimersByTime(200);+ await expect(result).resolves.toBe("unknown");+ expect(child.kill).toHaveBeenCalledWith("SIGTERM");+ if (exitsAfterTerm) child.emit("exit", null);+ vi.advanceTimersByTime(5000);+ expect(child.kill.mock.calls).toEqual(+ expectKill ? [["SIGTERM"], ["SIGKILL"]] : [["SIGTERM"]],+ );+ } finally {+ vi.useRealTimers();+ }+ },+ );});diff --git a/products/desktop/packages/agent/src/adapters/claude/subscription-login.ts b/products/desktop/packages/agent/src/adapters/claude/subscription-login.tsindex 2055357044ee..fa62e6dce8ae 100644--- a/products/desktop/packages/agent/src/adapters/claude/subscription-login.ts+++ b/products/desktop/packages/agent/src/adapters/claude/subscription-login.ts@@ -42,6 +42,7 @@ export interface ClaudeLoginCheckLogger {}const STATUS_TIMEOUT_MS = 15_000;+const STATUS_KILL_GRACE_MS = 2_000;export interface ClaudeLoginCheckOptions {claudeCliPath: string;@@ -115,6 +116,11 @@ export async function hasClaudeLogin(const timer = setTimeout(() => {child.kill("SIGTERM");+ const killTimer = setTimeout(+ () => child.kill("SIGKILL"),+ STATUS_KILL_GRACE_MS,+ );+ child.once("exit", () => clearTimeout(killTimer));finish("unknown");}, options.timeoutMs ?? STATUS_TIMEOUT_MS);diff --git a/products/desktop/packages/ui/src/features/settings/adapterSubscription.test.ts b/products/desktop/packages/ui/src/features/settings/adapterSubscription.test.tsindex f72ba7bd3f8c..5040d2202c26 100644--- a/products/desktop/packages/ui/src/features/settings/adapterSubscription.test.ts+++ b/products/desktop/packages/ui/src/features/settings/adapterSubscription.test.ts@@ -166,6 +166,20 @@ describe("adapter subscription gating", () => {});});+ it("does not run the login check when the flag is off", async () => {+ const fetchStatus = vi.fn(+ (): Promise<SubscriptionStatus> =>+ Promise.resolve({ loginState: "logged-in" }),+ );+ await registerSubscriptionAtBoot("claude", fetchStatus, false);++ expect(fetchStatus).not.toHaveBeenCalled();+ expect(registerAdapterSubscription).toHaveBeenLastCalledWith("claude", {+ access: "posthog-gateway",+ connected: false,+ });+ });+it("re-reads the setting after the probe so a toggle change is not stale", async () => {useSettingsStore.setState({_hasHydrated: true,diff --git a/products/desktop/packages/ui/src/features/settings/adapterSubscription.ts b/products/desktop/packages/ui/src/features/settings/adapterSubscription.tsindex c68e871791ea..ff809b5ecea4 100644--- a/products/desktop/packages/ui/src/features/settings/adapterSubscription.ts+++ b/products/desktop/packages/ui/src/features/settings/adapterSubscription.ts@@ -110,16 +110,18 @@ export async function registerSubscriptionAtBoot(flagEnabled: boolean,): Promise<void> {await settingsHydrated();- const access: ModelAccess = flagEnabled- ? SPECS[adapter].readAccess(useSettingsStore.getState())- : "posthog-gateway";+ if (!flagEnabled) {+ registerAdapterSubscription(adapter, {+ access: "posthog-gateway",+ connected: false,+ });+ return;+ }+ const access = SPECS[adapter].readAccess(useSettingsStore.getState());registerAdapterSubscription(adapter, { access, connected: false });const status = await fetchStatus();- const freshAccess = flagEnabled- ? SPECS[adapter].readAccess(useSettingsStore.getState())- : "posthog-gateway";registerAdapterSubscription(adapter, {- access: freshAccess,+ access: SPECS[adapter].readAccess(useSettingsStore.getState()),connected: status.loginState === "logged-in",});}