Skip to content

Studio: reset-password rotates the credential in place instead of deleting auth.db - #7573

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
NilayYadav:fix-reset-password-live-server
Jul 29, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
NilayYadav:fix-reset-password-live-server

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

reset-password deleted auth.db and left the next server start to recreate it. On Linux/macOS unlink() succeeds on a file a running process holds open, so with Studio running the delete silently "worked" and nothing re-seeded the admin row (ensure_default_admin() only runs at startup). The server stayed healthy but unusable: /api/auth/status returned initialized: false, every login failed including with the correct password and only a restart recovered it.

It now rotates in place. One transaction rehashes the password, rotates the JWT secret, and reokes refresh tokens, API keys, and the desktop secret. Auth reads open their own connection, so a running server accepts the new password on its next request. must_change_password stays 0 on purpose: at 1 a running server injects its startup-cached (now wrong) password into the login page. The new passphrase is printed to the terminal instead of .bootstrap_password.

Also:

  • CI used reset-password for a pristine auth state, then read .bootstrap_password. A rotation writes no such file, so 10 workflows and run-studio-permission-browser.sh wipe auth/ instead.
  • reset-password caught only sqlite3.Error; an unwritable ~/.unsloth now exits 1 instead of tracebacking.
  • run.py's --password error pointed at reset-password "first", which no longer unblocks it.

@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: 9a8687a325

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread unsloth_cli/commands/studio.py Resolved
Comment thread unsloth_cli/commands/studio.py Resolved

@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: ae2731256e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread unsloth_cli/commands/studio.py Resolved

@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: 3fdcf23405

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/auth/storage.py Resolved
Comment thread unsloth_cli/commands/studio.py Resolved
Comment thread studio/backend/auth/authentication.py Resolved
Comment thread unsloth_cli/commands/studio.py Resolved

@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: 34c30f9fe9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/routes/auth.py Resolved
Comment thread studio/backend/auth/storage.py Resolved

@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: 2ccaf2c7ae

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/auth/authentication.py Resolved
Comment thread studio/backend/auth/storage.py Resolved

@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: 6a51dfe277

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: ef1b52e19a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Drop the now-unused validate_api_key import from studio/backend/auth/authentication.py.
Every call site moved to validate_api_key_with_credential, so the Source lint job's
import-hoist gate flagged it as a blocker. The wrapper itself stays in storage.py;
test_api_key_expiry.py still exercises it.

Make test_run_reexec_forwards_resolved_frontend_on_public_launch compare against
str(Path(...)) instead of a POSIX literal. _find_frontend_dist returns a Path, so on
Windows the forwarded value is \fake\studio\frontend\dist and the assertion could
never pass there. Pre-existing, surfaced by running unsloth_cli/tests on Windows.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed a small commit to this branch (d3204d5) with two fixes:

  1. studio/backend/auth/authentication.py: dropped the now-unused validate_api_key import. Every call site moved to validate_api_key_with_credential, so the import-hoist safety net in Source lint was flagging it as a blocker. That was the only PR-caused red check. The validate_api_key wrapper stays in storage.py since test_api_key_expiry.py still exercises it.

  2. unsloth_cli/tests/test_studio_password_prompt.py: test_run_reexec_forwards_resolved_frontend_on_public_launch compared the forwarded --frontend value against the literal "/fake/studio/frontend/dist". _find_frontend_dist returns a Path, so on Windows that renders as \fake\studio\frontend\dist and the assertion can never pass. Now compares against str(Path(...)). This one is pre-existing, not from this PR, but it shows up as soon as these tests run on Windows.

Validation

I reproduced the bug on main against a live server, which behaves exactly as described: unlink() succeeds on the open file, the admin row is never re-seeded, /api/auth/status flips to initialized: false, and login fails with the correct password while /api/health still returns 200. On this branch the same sequence gives a working password on the next request with no restart, and the pre-reset access token, refresh token and API key all return 401.

Beyond that:

  • Concurrency. Drove all six windows between "credential verified" and "credential minted" with a real second process committing the reset at a barrier, rather than simulating the interleaving in one connection. Login, refresh, desktop login, change-password, API-key creation and data-recipe job start all hold. Also covered a reader holding an open WAL snapshot, a writer holding the lock past busy_timeout (exits 1 cleanly, prints no password, leaves nothing half-rotated), and three simultaneous resets.
  • Old installs. All five historical auth schema generations, from the original Studio PR through current main, migrate on first open, keep existing sessions alive, and reset cleanly. Downgrading also works: pre-PR code opens a database carrying secret_gen and issues, consumes and validates tokens against it without complaint.
  • Mixed versions. A Studio built from origin/main serving live, with this branch's CLI rotating its database underneath it, picks up the new password with no restart and rejects every pre-reset credential. That is the realistic upgrade path and it works in both directions.
  • Cross-platform. Ran the auth suites plus the concurrency and compatibility harnesses on ubuntu-latest, ubuntu-22.04, ubuntu-24.04-arm, macos-14, macos-15, macos-15-intel, windows-latest, windows-2022 and windows-11-arm, spanning SQLite 3.37.2 to 3.50.4 and Python 3.10 to 3.13. All green. Worth noting the OS split is the whole reason this bug exists: unlink() on an open SQLite file raises PermissionError on Windows and silently succeeds on POSIX.
  • Storage engines. The rotation stays complete and atomic under journal_mode of DELETE, TRUNCATE, PERSIST and MEMORY, not just WAL, which matters because get_connection() swallows a failed PRAGMA journal_mode=WAL and WAL is unavailable on network mounts.
  • Browsers. Chromium (Chrome and Edge), Firefox and WebKit (Safari) all render the login page after a reset with no stale bootstrap password injected, reject the old password and accept the new one.

Two things left, neither blocking

  • Core and Repo tests (CPU) are red for an unrelated reason (the bitsandbytes has no attribute 'functional' collection error). Tests: import bitsandbytes before the GPU-free harness spoofs CUDA #7582 fixed that on main, so merging main in should clear them.
  • .github/workflows/local-agent-guides-ci.yml still calls unsloth studio reset-password at four sites. Under the new semantics that prints the generated passphrase unmasked into the job log and no longer produces a pristine auth state. Swapping those for rm -rf ~/.unsloth/studio/auth like the other files would be more honest about what the step does.

Separately, and not something for this PR to fix: nothing in CI currently collects unsloth_cli/tests/. The two pytest invocations are rooted at studio/backend/tests/ and the top-level tests/, and testpaths is pinned to tests/security, so the 68 tests in test_studio_password_prompt.py never run on any platform. I will open something separate for that.

Nice fix, the transactional generation binding is the right shape.

@danielhanchen
danielhanchen merged commit 52609fb into unslothai:main Jul 29, 2026
45 of 50 checks passed
danielhanchen added a commit that referenced this pull request Jul 29, 2026
Since #7573 reset-password rotates the credential in place and prints the new
passphrase to stdout, so these four steps were writing it unmasked into the job
log and no longer produced the clean auth state their name implies. They never
read .bootstrap_password (serve-unsloth-run.sh only parses the sk-unsloth key
off the banner), so the wipe the other ten studio-* workflows already use is the
right shape here too.
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.

2 participants