Repository navigation
Studio: keep every tab signed in when a refresh answer is lost - #18353
Conversation
A refresh token is single-use, so when the answer to a successful rotation never reached the browser (tab closed or reloaded mid-refresh, proxy timeout, phone suspending the page) the browser kept the spent token, its next refresh got a 401 and every open tab was signed out. A just-rotated token now rotates again for 60 seconds; logout, password changes and account revokes still end it at once. The window lives in its own table, so an older build never sees a spent token. Plain-HTTP tabs racing on one token now both get a 200; a tab whose own answer lands after a peer stored a pair reuses the peer's pair, as the 401 path did.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsFinding details are still loading. Check the individual review comments. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…oids An unstamped legacy refresh token skips the credential generation check, so a CLI password reset (which rotates the secret with its own SQL) could not void its reuse row. Only stamped tokens get the window now. [skip ci]
Each replay inside the reuse window inserted another refresh token without consuming anything. Cap replays per spent token at REFRESH_REUSE_MAX (8): enough for a lost answer and a burst of racing tabs, whose extra 401s the client already answers from the peer's stored pair. [skip ci]
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ng, MLX batch sizes, QAT CUDA skip) (#18471) ## Summary Four tests fail on `main` in the "Repo tests (CPU, studio)" shard, so every PR that runs it is red (seen on the staging runs of #18353 and others). Reproduced on `main` at `415cdcf1be`: ``` FAILED tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe FAILED tests/studio/test_model_picker_contracts.py::test_batch_sizes_setting_wired_end_to_end FAILED tests/studio/test_model_picker_contracts.py::test_batch_sizes_reach_an_api_load_through_the_server_mirror FAILED tests/studio/test_chat_ui_picker_collapsed_row.py::test_a_loaded_model_still_opens_the_picker_collapsed ``` Each was attributed to the PR that changed the code it reads, and each was checked for whether the PR or the test is wrong. ## Root causes and changes ### Picker collapsed after a load (#18445): test was wrong #18445 added the "Show full model list" setting, so the load effect now calls `setExpanded(useChatRuntimeStore.getState().pickerExpandLoaded)` instead of a literal `?? false`. The setting defaults to off, so a fresh browser (every CI driver) still opens the picker collapsed, which is what this test protects: the drivers' expand click is still needed. `test_a_loaded_model_still_opens_the_picker_collapsed` now accepts either form, and when the setting drives it, also asserts the store default is `loadBool(PICKER_EXPAND_LOADED_KEY, false)`. Flipping that default to `true` fails the test, which the old literal check could not see. ### Batch sizes sent on a load (#18426): test was wrong #18426 brought MLX up to GGUF parity, so `n_batch` / `n_ubatch` are now sent for `(target.isGguf || mlx)` and copied for MLX overrides too. GGUF behaviour is unchanged; the tests pinned the old GGUF-only literal. - `test_batch_sizes_setting_wired_end_to_end`: matches the gate with a regex that allows widening to MLX but still requires `target.isGguf` and "only when set". Dropping the gate (sending the fields to every engine) fails it. - `test_batch_sizes_reach_an_api_load_through_the_server_mirror`: replaces the source-text check on the GGUF block with a behavioural check through `_override_load_kwargs`, which the test already imports. Dropping `n_ubatch` from the copied keys fails it. ### QAT stream test skip guard (#18434): PR was wrong `tests/test_qat_weight_memo_guards.py` gated `test_cached_weight_not_served_to_another_stream` on `torch.cuda.is_available()`, which `tests/_zoo_aggressive_cuda_spoof.py` patches to `True` process-wide, so on a CPU runner the test un-skips and calls `.cuda()` when it shares a session with the spoofing suites. The existing guard caught this. The skip now gates on `has_real_cuda()` first, as the other CUDA-only tests do. ## Testing - The four tests plus their files: `241 passed, 1 skipped` on this branch; the same four fail on `main`. - Sabotage, each against this branch: - store default `pickerExpandLoaded` set to `true`: the picker test fails; - `n_batch` sent without the GGUF/MLX gate: the end-to-end batch test fails; - `n_ubatch` dropped from the backend override copy: the server-mirror test fails; - QAT skip guard reverted: the skip-guard test fails.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Every open Unsloth Studio tab could still sign out at once when the answer to a successful session refresh never reached the browser. With this change the session survives that.
What was wrong
Refresh tokens are single-use. When
/api/auth/refreshrotates a token, the server deletes the old one and returns a new pair. If that answer is lost on the way back, the browser keeps the old token, which is already gone on the server:The next refresh sends the spent token, gets a 401, and the client clears the tokens in shared storage. That signs out every tab on that browser.
#16468 (Web Locks) and #16755 (plain-HTTP peer wait) fixed the two-tab race reported on Discord. This lost-answer case is the one path that still ends the session.
The fix
A token rotated by
/api/auth/refreshstays exchangeable for 60 seconds (REFRESH_REUSE_GRACE_SECONDS). Presenting it again in that window rotates once more and returns a fresh pair instead of a 401. This makes a retried refresh idempotent, the same idea as Supabase's refresh token reuse interval and Okta's grace period._delete_refresh_rows. A password change is also caught by the existing credential generation check.refresh_token_reusetable, and the spent token is still deleted fromrefresh_tokens. An older build never reads the new table, so it cannot revive a spent token.REFRESH_REUSE_MAX(8) pairs inside the window; later replays get a 401, which the client already answers from a peer's stored pair.consume_refresh_tokenstays strictly single-use, and expired rows and rows older than the window are purged on every rotation.peerRotatedcheck, as the 401 path already did, instead of handing its caller the original 401.No new UI: the only visible change is that the tabs stay signed in. Desktop, which runs on a secure origin with Web Locks, follows the same path as before.
Tests
401 Invalid or expired refresh token200, new pair workstests/test_refresh_reuse_grace.py(11)tests/auth-refresh-transient.test.tsnode --test(16,708 tests)test_health_response_reports_desktop_capability_fields, already fails on main.test_auth_db_lock_contention.pythat pinned "immediate reuse is a 401" now assert the 401 after the window instead.test_logout_inside_the_window_still_ends_the_session; recording unstamped tokens failstest_a_legacy_unstamped_token_gets_no_window.Before and after in Studio
Two isolated Studio installs (merge base
daf25ce59vs this branch). Two tabs are signed in; page JS posts the stored refresh token to/api/auth/refreshand drops the 200, so the server has rotated the token while the browser still holds the spent one. The access token is then invalidated and both tabs reload. Before, the spent token gets a 401 and both tabs land on the login page; after, both tabs stay signed in on the chat page.