Honor device sign-in expiry during onboarding (#23270)

## 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
This commit is contained in:
Tonio authored and GitHub committed 2026-11-30 08:34:29 +00:00
1 parent 111973c5e3
commit 429a004da5
5 files changed
+42 -5

No files matched your search

@@ -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") {
@@ -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 {
+3 -2
View File
@@ -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
@@ -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();
+1 -1
View File
@@ -523,7 +523,7 @@ export function ProviderSubscriptionCard({
{waiting ? (
<Button type="button" disabled className="rounded-full px-5">
<Loader2 className="size-4 motion-safe:animate-spin" />
{mode === "submitted_code" ? "Waiting for code…" : "Waiting for sign-in…"}
{mode === "submitted_code" ? "Waiting for code…" : "Waiting…"}
</Button>
) : <Button asChild className="gap-1 rounded-full py-0 pl-3 pr-6">
<a href={authorizationUrl} target="_blank" rel="noopener noreferrer" onClick={event => {