fix(onboarding): drop the sign-in card's Cancel, and resume after Back (#12958)

The card carried a Cancel beside its instruction, directly above the step's own Back. Two ways out of one screen is one too many.

Removing it was only safe if returning genuinely resumed the running session, and writing the test for that disproved the premise: coming back started a second login rather than adopting the first, which the server's per-owner lease rejects. Cancel was not duplicative — it was the only way out of a login the customer could no longer reach.

The cause was the cache. The active-session read is a useQuery with no staleTime, so on the second mount it answered instantly from the first mount's cached null: isFetched was true, the resume effect concluded there was nothing to adopt, and autoStart began a new login while the refetch was still in flight. Both panels did it, and it was pre-existing on master. Both reads now refuse the cache, so the resume works and the removal is safe because of it.

Removing the button also stranded the chain behind it: handleCancel in both panels, the onCancel prop on AdapterLoginPanel, and the wizard's wiring. The panel chrome's own Cancel is untouched.

An abandoned login is collected on a five-minute timer (DEVICE_LOGIN_TIMEOUT_MS) with the reaper as the restart-safe backstop, and the lease is keyed on adapterType, so a source switch does not contend. Both covered by tests.
This commit is contained in:
Tonio authored and GitHub committed 2026-09-07 00:20:31 -07:00
1 parent 856813ba3a
commit ae03465ad4
5 files changed
+178 -89

No files matched your search

@@ -1640,10 +1640,13 @@ describe("AgentConfigForm environment selector", () => {
expect(mockAgentsApi.cancelAdapterAuthLogin).not.toHaveBeenCalled();
});
it("shows a reachable Cancel control in the onboarding chrome and cancels the session", async () => {
mockAgentsApi.testEnvironment.mockResolvedValue(AUTH_MISSING_RESULT);
const onCancel = vi.fn();
it("offers no Cancel in the onboarding chrome", async () => {
// The card carried a Cancel beside its instruction, directly above the
// step's own Back. Two ways out of one screen is one too many, so the
// button went — and with it the only explicit release, since unmounting
// deliberately keeps the session alive for a later resume. An abandoned
// login is now collected by the server deadline, the same as one abandoned
// by closing the tab.
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
@@ -1663,25 +1666,20 @@ describe("AgentConfigForm environment selector", () => {
environmentId="sandbox-1"
chrome="onboarding"
autoStart
onCancel={onCancel}
/>
</TooltipProvider>
</ToastProvider>
</QueryClientProvider>,
);
});
await flushUntil(() => Boolean(findButton(container, "Cancel")));
// Wait for the card itself, then assert it is actually there: an absence
// check over an empty render passes for the wrong reason.
await flushUntil(() => container.textContent?.includes("authorization code") ?? false);
expect(container.textContent).toContain("authorization code");
await clickByText(container, "Cancel");
expect(mockAgentsApi.cancelAdapterAuthLogin).toHaveBeenCalledWith(
"company-1",
"codex_local",
"session-1",
);
expect(onCancel).toHaveBeenCalledTimes(1);
expect(findButton(container, "Cancel")).toBeFalsy();
expect(mockAgentsApi.cancelAdapterAuthLogin).not.toHaveBeenCalled();
});
it("resumes an active login session on mount, adopting its session id and prompt", async () => {
// A page reload loses every piece of local state, so the panel must read
// the caller's active session and adopt it instead of starting a new one.
@@ -2191,9 +2189,13 @@ describe("AgentConfigForm environment selector", () => {
expect(onStored).toHaveBeenCalledWith("stored-session-1");
});
it("shows a reachable Cancel control in the onboarding chrome and cancels the session", async () => {
const onCancel = vi.fn();
it("offers no Cancel in the onboarding chrome", async () => {
// The card carried a Cancel beside its instruction, directly above the
// step's own Back. Two ways out of one screen is one too many, so the
// button went — and with it the only explicit release, since unmounting
// deliberately keeps the session alive for a later resume. An abandoned
// login is now collected by the server deadline, the same as one abandoned
// by closing the tab.
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
@@ -2213,24 +2215,20 @@ describe("AgentConfigForm environment selector", () => {
environmentId="sandbox-1"
chrome="onboarding"
autoStart
onCancel={onCancel}
/>
</TooltipProvider>
</ToastProvider>
</QueryClientProvider>,
);
});
await flushUntil(() => Boolean(findButton(container, "Cancel")));
// Wait for the card itself, then assert it is actually there: an absence
// check over an empty render passes for the wrong reason.
await flushUntil(() => container.textContent?.includes("authorization code") ?? false);
expect(container.textContent).toContain("authorization code");
await clickByText(container, "Cancel");
expect(mockAgentsApi.cancelClaudeSetupTokenLogin).toHaveBeenCalledWith(
"company-1",
"claude-session-1",
);
expect(onCancel).toHaveBeenCalledTimes(1);
expect(findButton(container, "Cancel")).toBeFalsy();
expect(mockAgentsApi.cancelClaudeSetupTokenLogin).not.toHaveBeenCalled();
});
it("offers an apply-existing affordance when the status route reports a stored value", async () => {
mockAgentsApi.getClaudeOAuthTokenStatus.mockResolvedValue({
secretId: "secret-1",