Repository navigation
Retry the Studio UI shutdown re-login on transient goto timeout - #7027
Conversation
The Chat UI Playwright smoke intermittently failed at the pre-shutdown
re-login: page.goto('/login') can hit a 60s TimeoutError on a slow runner
even while the server is healthy, and the surrounding except only tolerated
ERR_ABORTED / interrupted-navigation, so a plain timeout hard-failed the job.
Wrap the re-login goto/wait/fill/submit in the same 3-attempt retry the
change-password step already uses (recover_or_replace_page between tries,
per-attempt fail screenshots, wait_for_health pre-gate). The composer wait
stays outside the loop so a retry never re-navigates after login has set
tokens (which would redirect to /chat via the guest guard); it remains the
authoritative confirmation, so a genuinely broken login still fails.
There was a problem hiding this comment.
Code Review
This pull request wraps the re-login sequence in a retry loop to handle slow CI environments and transient network issues, including page recovery and diagnostic logging. The feedback highlights two key improvements: first, waiting for the login POST response to ensure transient server errors are caught and retried within the loop; second, re-attaching event listeners to the new page instance if page recovery replaces the original page, ensuring errors continue to be tracked.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| pw_field = page.locator("#password") | ||
| pw_field.wait_for(state = "visible", timeout = 60_000) | ||
| pw_field.fill(NEW2) | ||
| page.locator('button[type="submit"]').click() |
There was a problem hiding this comment.
The click() method on the submit button does not wait for the network request to complete. If a transient network error or server-side failure (such as a 500 or 502 error) occurs during the /api/auth/login POST request, the loop will still break immediately because no exception is raised during the click itself. The failure will only be caught later by composer.wait_for outside the loop, which prevents the retry mechanism from attempting a recovery.
To ensure transient login request failures are caught and retried within the loop, we should use click_and_wait_for_response to wait for the /api/auth/login response, matching the pattern used in the change-password step.
status, _ = click_and_wait_for_response(
page,
url_substr = "/api/auth/login",
method = "POST",
do_click = lambda: page.locator('button[type="submit"]').click(),
timeout_ms = 30_000,
info = lambda m: print(f"[ui] {m}", flush = True),
)
if status is not None and status >= 400:
raise AssertionError(
f"login POST returned {status}; "
f"see console_errors={console_errors[:1]!r}"
)There was a problem hiding this comment.
Good catch, fixed in 94ceac7. The login submit now goes through click_and_wait_for_response on /api/auth/login with the same status >= 400 check the change-password step uses, so a transient 4xx/5xx is raised and retried inside the loop rather than surfacing only at the out-of-loop composer wait. This does not reintroduce the guest-guard race: waiting on the POST does not re-navigate, and a failed login leaves tokens unset so the retry re-goto to /login still shows the password field.
| page = recover_or_replace_page( | ||
| page, | ||
| ctx, | ||
| default_timeout_ms = 60_000, | ||
| info = lambda m: print(f"[ui] recovery: {m}", flush = True), | ||
| ) |
There was a problem hiding this comment.
When recover_or_replace_page replaces a closed page with a new one, the newly created page does not inherit the pageerror and console event listeners registered on the original page. As a result, any subsequent console or page errors on the recovered page will not be tracked or asserted at the end of the test.
We should check if the page was replaced and re-attach the listeners if so.
| page = recover_or_replace_page( | |
| page, | |
| ctx, | |
| default_timeout_ms = 60_000, | |
| info = lambda m: print(f"[ui] recovery: {m}", flush = True), | |
| ) | |
| old_page = page | |
| page = recover_or_replace_page( | |
| page, | |
| ctx, | |
| default_timeout_ms = 60_000, | |
| info = lambda m: print(f"[ui] recovery: {m}", flush = True), | |
| ) | |
| if page is not old_page: | |
| page.on("pageerror", lambda e: page_errors.append(str(e))) | |
| page.on("console", _on_console) |
There was a problem hiding this comment.
Fixed in 94ceac7. When recover_or_replace_page swaps in a fresh page (only when the old one is closed) the retry now re-attaches the pageerror and console listeners via an is-not identity check, so recovered-page errors stay tracked for the end-of-test assertions. The common transient-timeout path does not close the page, so it keeps the original listeners.
…n recovery Wait on the /api/auth/login POST inside the retry (via click_and_wait_for_response) so a transient 4xx/5xx is retried in-loop instead of surfacing only at the out-of-loop composer wait, matching the change-password step. When recover_or_replace_page swaps in a fresh page, re-attach the pageerror/console listeners so error tracking survives the replacement.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94ceac7f18
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| pw_field.fill(NEW2) | ||
| # Wait on the login POST so a transient 4xx/5xx is caught and retried | ||
| # here, not swallowed until the out-of-loop composer wait. | ||
| status, _ = click_and_wait_for_response( |
There was a problem hiding this comment.
Retry failed login response captures
When click_and_wait_for_response times out or the submit click/response capture fails, the helper returns (None, exc) after a best-effort fallback click; this code discards that exception and then breaks out of the retry loop because status is None. In a transient CI case such as a swallowed click, closed page, or net::ERR_NO_BUFFER_SPACE during /api/auth/login, the form may never authenticate, so the out-of-loop composer wait fails once without using the remaining re-login attempts. Capture the second return value and raise/retry when it is non-None before clearing relogin_err.
Useful? React with 👍 / 👎.
Problem
The Studio UI CI ("Chat UI Tests",
studio-ui-smoke.yml) intermittently fails at the pre-shutdown re-login intests/studio/playwright_chat_ui.py. In the "Shutdown via account menu" step, after the CLI password rotation and full session teardown, the test re-logs-in to obtain a valid/api/shutdowntoken:On a slow runner this can raise
playwright TimeoutError: Page.goto: Timeout 60000ms exceededeven though the server is healthy. The surroundingexceptonly toleratedERR_ABORTED/ "interrupted by another navigation", so a plain timeout re-raised and hard-failed the whole job (the#password/ composer waits below never got a chance to recover).Fix
Wrap the re-login goto/wait/fill/submit in the same 3-attempt retry the change-password step already uses:
recover_or_replace_page(...)between attempts and per-attempt fail screenshots, matching the existing loop.wait_for_health(BASE)diagnostic pre-gate before the loop (never raises) so a briefly-unready backend is waited out instead of sinking a full 60s navigation.try/exceptkeeps the existing tolerated-navigation handling; a plainTimeoutErrornow retries instead of failing./chat). The composer wait remains the authoritative confirmation, so a genuinely broken login still fails loudly, and an exhausted retry re-raises.Single file, single hunk; no app / CI / auth behavior changes.
Scope
Surgical fix for the one navigation that flaked. The other single navigations (
goto('/chat'),goto('/data-recipes'), and thereload()session-survival calls) run mid-test against a warm, authenticated shell and have not flaked, so they are left as-is; they can be wrapped the same way if they ever do.Notes
Independent of the embedding fix in #6939 (that PR only touched
unsloth/models/sentence_transformer.pyand two Python tests; it tripped this workflow only because the workflow triggers onunsloth/**).Verification
python -m py_compile tests/studio/playwright_chat_ui.pypasses.re-login attempt N failedlog line and18-relogin-attempt-N-failartifact showing recovery rather than a hard failure.