Skip to content

Retry the Studio UI shutdown re-login on transient goto timeout - #7027

Merged
danielhanchen merged 2 commits into
mainfrom
fix-studio-ui-relogin-retry
Jul 9, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix-studio-ui-relogin-retry

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

The Studio UI CI ("Chat UI Tests", studio-ui-smoke.yml) intermittently fails at the pre-shutdown re-login in tests/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/shutdown token:

page.goto(f"{BASE}/login", wait_until = "domcontentloaded", timeout = 60_000)

On a slow runner this can raise playwright TimeoutError: Page.goto: Timeout 60000ms exceeded even though the server is healthy. The surrounding except only tolerated ERR_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.
  • A 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.
  • The inner try/except keeps the existing tolerated-navigation handling; a plain TimeoutError now retries instead of failing.
  • The composer wait stays outside the loop: the loop breaks right after submit, so a retry never re-navigates once login has set tokens (which would hit the guest guard and redirect to /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 the reload() 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.py and two Python tests; it tripped this workflow only because the workflow triggers on unsloth/**).

Verification

  • python -m py_compile tests/studio/playwright_chat_ui.py passes.
  • The retry mirrors the proven change-password loop line-for-line.
  • End-to-end coverage is the Studio UI CI job itself (real Studio server + Chromium + GGUF); the flake is timing-dependent, so the signal is a green job plus, if any attempt ever times out, a re-login attempt N failed log line and 18-relogin-attempt-N-fail artifact showing recovery rather than a hard failure.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/studio/playwright_chat_ui.py Outdated
pw_field = page.locator("#password")
pw_field.wait_for(state = "visible", timeout = 60_000)
pw_field.fill(NEW2)
page.locator('button[type="submit"]').click()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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}"
                )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1354 to +1359
page = recover_or_replace_page(
page,
ctx,
default_timeout_ms = 60_000,
info = lambda m: print(f"[ui] recovery: {m}", flush = True),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@danielhanchen
danielhanchen merged commit 8205d4c into main Jul 9, 2026
21 checks passed
@danielhanchen
danielhanchen deleted the fix-studio-ui-relogin-retry branch July 9, 2026 08:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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