diff --git a/ui/src/components/new-agent/AgentProviderConnection.test.tsx b/ui/src/components/new-agent/AgentProviderConnection.test.tsx index 6b06006e0ae..fdca64942ab 100644 --- a/ui/src/components/new-agent/AgentProviderConnection.test.tsx +++ b/ui/src/components/new-agent/AgentProviderConnection.test.tsx @@ -378,6 +378,36 @@ describe("AgentProviderConnection reuse", () => { }); expect(host.textContent).toContain("New subscription login"); }); + it("lets a visible saved subscription be used without opening the provider first", async () => { + const { test, connected } = await mount("codex_local", false, true, true); + expect(host.querySelector("select")).not.toBeNull(); + const use = [...host.querySelectorAll("button")].find((b) => + b.textContent?.includes("Use saved subscription"), + )!; + expect(use.disabled).toBe(false); + click("Use saved subscription"); + await vi.waitFor(() => + expect(connected).toHaveBeenCalledWith({ + env: { + CODEX_HOME: { type: "secret_ref", secretId: "codex-home", version: "latest" }, + }, + }), + ); + expect(test).toHaveBeenCalledWith(connected.mock.calls[0][0]); + }); + it("still requires opening the provider before starting a new subscription login", async () => { + await mount("codex_local", false, true, true); + flushSync(() => { + const select = host.querySelector("select")!; + select.value = ""; + select.dispatchEvent(new Event("change", { bubbles: true })); + }); + const primary = [...host.querySelectorAll("button")].find((b) => + b.textContent?.includes("Connect"), + )!; + expect(primary.disabled).toBe(true); + expect(mocks.loginPanel).not.toHaveBeenCalled(); + }); it.each(["claude_local", "codex_local"] as const)( "passes a personal reference without credentials for %s", async (adapter) => { diff --git a/ui/src/components/new-agent/AgentProviderConnection.tsx b/ui/src/components/new-agent/AgentProviderConnection.tsx index 391330fdb76..9cd1c12b7ed 100644 --- a/ui/src/components/new-agent/AgentProviderConnection.tsx +++ b/ui/src/components/new-agent/AgentProviderConnection.tsx @@ -419,7 +419,9 @@ export function AgentProviderConnection({ (!managedAccount && auth.isPending) || savedKeys.loading || (adapterType === "claude_local" && storedLogin.isPending) || - !opened || + // The saved-subscription chooser renders outside the opened section, + // so reusing the visible choice must not wait for a tile click. + (!opened && !(method === "subscription" && savedSubscription)) || (Boolean(needsLogin) && (!authorizationUrl || loginPhase !== "ready")) || (method === "api" && !apiKey.trim() &&