Skip to content

fix(e2e): close the sign-in page before the redirect loads; bound isolated sign-ins - #1198

Merged
frankbria merged 1 commit into
mainfrom
fix/signinas-ci-hang
Nov 9, 2026
Merged

frankbria merged 1 commit into
mainfrom
fix/signinas-ci-hang

Conversation

@frankbria

Copy link
Copy Markdown
Owner

Problem

Three CI runs since #1191 (42562536594, 42563372336 on main, 42568470680) hung in Playwright global setup until the 30-minute E2E job timeout cancelled them. Each stalled right after 💾 Saved auth state, in the isolated users' signInAs loop, with no error printed. Five runs between #1191's merge and the first hang passed, so it is intermittent. Runner image is identical (ubuntu-26.04 20261028.624) for hung and passing runs.

Cause (best evidence; not reproduced locally)

Every call in signInAs has a timer (20–30s) except page.close(), and a timed-out call would have printed "Authentication setup failed", which never appears. #1191 moved page.close() to after an extra /api/auth/session request, so it now runs while the post-login redirect to /upload is loading. On a CI runner that route compiles cold. Before #1191 the page closed right after the credentials callback, and that ordering has a long green record. Four local runs pinned to two cores (taskset -c 0,1) did not hang: all 15 sign-in steps finished in under a second.

Fix

Verification

🤖 Generated with Claude Code

…lated sign-ins

Since #1191 moved page.close() after an extra session request, three CI
smoke runs hung in global setup for the full 30-minute job timeout,
right after saving the default user's state. page.close() is the one
call there with no timeout, and it now ran while the post-login /upload
page was loading (compiled cold on CI). Close it straight after the
credentials callback again, as before #1191, and check the session over
the context's request API. Each isolated sign-in now fails after 60s,
naming the user, instead of holding the job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-09T06:16:56.399694Z
We couldn’t complete this review. Comment @codex review to try again.
19f8ae9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Review: small, focused e2e hardening. No blocking issues.

Bugs / correctness

  • The timeout does not cancel the sign-in (global-setup.ts). Promise.race rejects after 60s, but the losing signInAs keeps running and its browser context stays open. This is harmless if the setup error path closes the browser. If it doesn't, the process may linger. Consider a try/finally that closes the browser, or pass a timeout into signInAs so it cleans up its own context.
  • The timer is never cleared on success. unref() stops it holding the process open, so this is fine in practice, but clearing it in a finally would be tidier.
  • The 60s limit is fixed. A cold Next.js compile on a slow runner could exceed it. Consider a named constant or env override.

apiAuth.ts

  • Closing the page before the session check is sensible. The cookie is already set on the context once the callback response arrives. The comment explains the reason well.
  • If page.close() can still hang, the race covers only the isolated users, not the shared-user signInAs call. Wrapping the timeout inside signInAs would cover every caller.

Tests

  • Nothing exercises the timeout path. It would be worth confirming once, for example with a stubbed hanging signInAs, that the error names the user. This follows the CLAUDE.md rule that assertions must be able to fail.

Style

  • Matches the surrounding code, and the comments explain the why.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Claude finished @frankbria's task in 8m 51s —— View job


Third-party precision review — complete

  • Pull PR context and full diff
  • Read the changed files and every caller (global-setup.ts, apiAuth.ts, admin-guard.spec.ts, plan-limit.spec.ts, isolatedUsers.ts)
  • Cross-check existing review threads to avoid repeats
  • Confirm or discard suspected defects against real code
  • Post inline findings — none confirmed, none posted
  • Post summary review comment: ✅ no defects found

Verdict: no concrete defects in the diff. Suspects examined and cleared:

  • Close-before-session-check loses the cookie — no: the callback's Set-Cookie lands on the BrowserContext (not the page), and context.request remains valid with zero open pages; the retained identity check would turn any loss into a loud, named failure.
  • Caller regression from the moved page.close() — no: signInAs closed its page internally before returning even before this PR; all three call sites use only context.request/context.newPage() and close the context themselves.
  • Unhandled rejection from a losing/hung signInAs — no: Promise.race attaches handlers to both contenders, and the pre-existing finally { await browser.close() } in globalSetup tears down a stalled context when the 60s guard fires.
  • Unbounded wait elsewhere — no: every remaining signInAs step carries a 20s timeout, and context.request.get defaults to a 30s API timeout.

One watch item (not a finding — could not be confirmed here): setTimeout(...).unref() at e2e/global-setup.ts:132 sits under a tsconfig whose lib includes dom, where the DOM setTimeout overload returns number (no .unref). This checkout has no node_modules and CI (run 42572078248) was still in progress, so the overload resolution could not be verified either way. The PR gate's tsc --noEmit job settles it definitively; if the frontend type-check job goes red on that line, that's why.

No files modified, no commits pushed, per the review guardrails.

@frankbria

Copy link
Copy Markdown
Owner Author

Third-party review (review chain)

Review: sign-in hang fix (early page.close() + 60s watchdog)

Skill loading was denied, so this is a direct analysis of the diff.

The four checks

1. Does closing the page before the redirect lose the session cookie?
No. In this NextAuth-style flow, the session cookie is delivered as Set-Cookie on the callback response (the 302 from /api/auth/callback/...). The browser's network stack commits it when that response arrives — i.e., by the time waitForResponse resolves. The post-login redirect consumes the cookie; it doesn't establish it. Cookies live on the BrowserContext, not the page, so page.close() can't drop them, and both storageState() and context.request read the same jar. Two extra safety nets: this exact ordering is what ran green before the regression, and the relocated session check converts a wrong assumption into a loud, deterministic signed in as nobody instead error — never a silent failure.

2. Can context.request.get run after page.close()?
Yes. context.request (APIRequestContext) is owned by the BrowserContext and shares its cookie jar; it's independent of pages and stays usable until context.close(). Here the context outlives the page and is closed by the caller after storageState().

3. Does the race timer leak or keep the process alive?
No. .unref() means a pending timer never holds the Node event loop (relevant if the run finishes within 60s of the last sign-in — exit isn't delayed). Each timer fires within 60s and becomes GC-eligible; N isolated users ⇒ at most N short-lived timers. Requires Node typings for NodeJS.Timeout.unref() — standard for Playwright e2e, but confirm the e2e tsconfig includes @types/node.

4. Is the unhandled losing promise a problem?
No. Promise.race attaches reactions to both promises, so the losing timer's late rejection is delivered into an already-settled race promise and discarded — unhandledRejection never fires. Symmetrically, the abandoned signInAs (when the timer wins) also has a race reaction attached, so its eventual settlement is handled, just silently swallowed.

Findings

CRITICAL — none.

MAJOR

  1. Watchdog coverage gap — apps/frontend/e2e/global-setup.ts: the race guards only the ISOLATED_USERS loop, but the hunk's own comment ("must not share the user above") indicates an earlier signInAs for the shared user in the same setup, unguarded (same for any spec-side callers). The new comment promises "a stalled sign-in must fail the run naming the user" — the code delivers that only for some call sites. If a stall has any cause other than the close-during-redirect interaction, the 30-minute silent hang is still reachable. Extract the race into a helper (e.g., signInWithDeadline(user, ms)) and wrap every sign-in in global setup. Cheap, and directly serves the stated goal.

MINOR
2. Failure-path cleanup: when the timer wins (or the session check throws), the abandoned page/context and the setup-launched browser are never closed. Playwright usually reaps them when the runner exits, but a try/finally { await browser.close().catch(() => {}) } in global setup — and closing the context in signInAs's error path — would make teardown deterministic.
3. Lost diagnostics: the abandoned signInAs may eventually settle with the real cause (e.g., a Playwright timeout error), which is silently discarded per check 4. Consider stashing the promise and logging if it settles after the deadline.
4. Nits: inline magic 60_000 (named constant reads better); if the file literally contains \" inside the template literal, that's a useless escape (likely a paste artifact — it also appears in unchanged context lines).

Verdict

The core reordering is correct, self-verifying (the session check is exactly the right guard for check 1), and restores known-good behavior; the watchdog mechanics are right. Blocking only on finding 1 — bounding the hazard this diff exists to kill should cover all sign-ins in the file, not a subset.

REQUEST_CHANGES

Dispositions. MAJOR 1: not taken. The default user doesn't sign in through signInAs; it runs its own retry loop, where every call is time-bounded, and all three hung runs show it finishing ("Saved auth state") before the stall. The only path that hung is the one now guarded. MINOR 2: global setup already closes the browser in a finally. MINOR 3/4: not taken; the timer's error names the user, which is what the guard is for.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Third Party Review — glm-5.2

✅ Third Party Review: no defects found.

Concrete-defect scope only, diff at 19f8ae9 (e2e/global-setup.ts, e2e/helpers/apiAuth.ts). Suspects examined against the surrounding code and all callers, and cleared:

  • Close-before-session-check loses the cookie — no: the callback Set-Cookie lands on the BrowserContext, not the page, and context.request stays valid with zero open pages (cookie lifetime is context-scoped). The retained identity check (signInAs(…): signed in as nobody instead) makes any cookie loss a loud, named failure rather than silent corruption.
  • Caller regression from the moved page.close() — no: signInAs closed its page internally before returning even before this PR, so no caller ever saw an open page; all three call sites use only context.request / context.newPage() and close the context themselves.
  • Unhandled rejection from a losing/hung signInAs — no: Promise.race attaches handlers to both contenders, so a late-settling loser cannot raise unhandledRejection; and the pre-existing finally { await browser.close() } in globalSetup tears down a stalled context when the 60s guard fires.
  • Unbounded wait elsewhere — no: every remaining signInAs step carries a 20s waitForResponse timeout, and context.request.get defaults to a 30s API timeout.

Model: glm-5.2

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Reviewer failover

  • Codex: ⚠️ failed (failure) for a reason other than quota — investigate the job run
  • Kimi: quota exhausted, failed over
  • glm-5.2: reviewed

@frankbria
frankbria merged commit 8af9127 into main Nov 9, 2026
17 checks passed
@frankbria
frankbria deleted the fix/signinas-ci-hang branch November 9, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant