From 429a004da515c6b1bd23c138c6b0ef203e54887e Mon Sep 17 00:00:00 2001 From: Tonio Date: Mon, 30 Nov 2026 08:34:29 +0000 Subject: [PATCH] Honor device sign-in expiry during onboarding (#23270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip connects agents to model providers. > - Onboarding starts a device login for OpenAI. > - The login starts its session clock before it acquires a sandbox. > - The command must stop by the deadline shown for the session. > - The wizard can then offer a fresh code when that session expires. ## Linked Issues or Issue Description **Subsystem affected** Subscription onboarding and displayed-code login. Refs #23268. **Current behavior** An unattended OpenAI login can show a generic failure at expiry. **Proposed behavior** Use the session deadline and show the same expiry message as Claude. Show “Waiting…” for OpenAI and “Waiting for code…” for Claude. ## What Changed Bound the command timer to the remaining session lifetime. Arm the host timer before the command can schedule its own timeout. Keep the outcome fixed during cleanup. Updated the OpenAI waiting label. ## Verification All 79 tests in the device login service, runner, and login card suites passed. These cover delayed sandbox setup, failure before expiry, and timeout at the deadline. ## Risks Early command failures still need their own failure state. The change preserves those failures and explicit cancellation. ## Model Used OpenAI GPT-6 with Codex repository and test tools. ## Checklist - [ ] I have included a thinking path that traces from project context to this change - [ ] I have specified the model used (with version and capability details) - [ ] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [ ] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [ ] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [ ] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [ ] I have run tests locally and they pass - [ ] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [ ] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge --- .../src/server/device-login-runner.ts | 3 +- .../__tests__/device-login-service.test.ts | 35 +++++++++++++++++++ server/src/services/device-login-service.ts | 5 +-- ui/src/components/AdapterLoginChrome.test.tsx | 2 +- ui/src/components/AdapterLoginChrome.tsx | 2 +- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/packages/adapters/codex-local/src/server/device-login-runner.ts b/packages/adapters/codex-local/src/server/device-login-runner.ts index 9f488cebee5..53175356098 100644 --- a/packages/adapters/codex-local/src/server/device-login-runner.ts +++ b/packages/adapters/codex-local/src/server/device-login-runner.ts @@ -142,7 +142,8 @@ export async function runDeviceLogin( return { outcome: "cancelled", exitCode: null, promptSurfaced }; } - const started = driver.start(command, onStdout); + // Arm the session timer before the transport can schedule its own timeout. + const started = Promise.resolve().then(() => driver.start(command, onStdout)); const raced = await raceLoginRunnerExit(started, timeoutMs, signal); if (raced.kind === "timeout") { diff --git a/server/src/__tests__/device-login-service.test.ts b/server/src/__tests__/device-login-service.test.ts index decd3560b68..18d46cbc92f 100644 --- a/server/src/__tests__/device-login-service.test.ts +++ b/server/src/__tests__/device-login-service.test.ts @@ -1250,6 +1250,41 @@ describe("device login service", () => { }); describe("five-minute host timeout", () => { + it.each([ + [39_999, "failed"], + [40_000, "timed_out"], + [45_000, "timed_out"], + ] as const)("classifies a command ending %i ms after sandbox setup as %s", async (exitAfter, expected) => { + vi.useFakeTimers(); + try { + const store = createMemoryStore(); + const { runtime } = createFakeRuntime({ + exec: () => new Promise(resolve => setTimeout(() => resolve({ exitCode: 1 }), exitAfter)), + }); + const acquire = runtime.acquireLoginLease.bind(runtime); + runtime.acquireLoginLease = async input => { + await new Promise(resolve => setTimeout(resolve, 20_000)); + const lease = await acquire(input); + lease.driver.dispose = () => new Promise(resolve => setTimeout(resolve, 1_000)); + return lease; + }; + const service = makeService({ store, runtime }); + const started = service.start({ + companyId: randomUUID(), + environmentId: randomUUID(), + adapterType: ADAPTER_TYPE, + startedByUserId: OWNER_A, + ttlSeconds: 60, + }); + await vi.advanceTimersByTimeAsync(20_000); + const { completed } = await started; + await vi.advanceTimersByTimeAsync(41_000); + expect((await completed).status).toBe(expected); + } finally { + vi.useRealTimers(); + } + }); + it("holds the session active until exactly five minutes, then times out and deletes", async () => { vi.useFakeTimers(); try { diff --git a/server/src/services/device-login-service.ts b/server/src/services/device-login-service.ts index 99d066892ec..d0025f7bcce 100644 --- a/server/src/services/device-login-service.ts +++ b/server/src/services/device-login-service.ts @@ -1032,11 +1032,12 @@ export function createDeviceLoginService(deps: DeviceLoginServiceDeps) { failure: null, }; - const completed = runLogin({ input, sessionId, lease, base, activity }); + const completed = runLogin({ input, sessionId, expiresAt, lease, base, activity }); return { session, completed }; } async function runLogin(ctx: { + expiresAt: Date; input: StartDeviceLoginInput; sessionId: string; lease: LoginSessionLease; @@ -1083,7 +1084,7 @@ export function createDeviceLoginService(deps: DeviceLoginServiceDeps) { try { const result = await runDeviceLogin(lease.driver, { command: profile.command, - timeoutMs: profile.timeoutMs, + timeoutMs: Math.max(0, Math.min(profile.timeoutMs, ctx.expiresAt.getTime() - now().getTime())), // `RunDeviceLoginOptions.parsePrompt` keeps the runner's own required-code // prompt shape. The profile parser returns the wider adapter-neutral // shape, so this adapts one call's result without widening the runner's diff --git a/ui/src/components/AdapterLoginChrome.test.tsx b/ui/src/components/AdapterLoginChrome.test.tsx index ac998c56ac9..5afef715778 100644 --- a/ui/src/components/AdapterLoginChrome.test.tsx +++ b/ui/src/components/AdapterLoginChrome.test.tsx @@ -77,7 +77,7 @@ describe("the connect step's cards", () => { it.each([ ["submitted_code", "Claude", "Waiting for code…"], - ["displayed_code", "OpenAI", "Waiting for sign-in…"], + ["displayed_code", "OpenAI", "Waiting…"], ] as const)("keeps waiting and retry inside the %s card", (mode, providerName, waitingLabel) => { const open = vi.fn(); const retry = vi.fn(); diff --git a/ui/src/components/AdapterLoginChrome.tsx b/ui/src/components/AdapterLoginChrome.tsx index 290f1da0274..bcb5d57b64f 100644 --- a/ui/src/components/AdapterLoginChrome.tsx +++ b/ui/src/components/AdapterLoginChrome.tsx @@ -523,7 +523,7 @@ export function ProviderSubscriptionCard({ {waiting ? ( ) :