feat(grokbuild): persist official auth.json for multi-account switching - #6792
feat(grokbuild): persist official auth.json for multi-account switching#6792652036 wants to merge 6 commits into
Conversation
Official Grok login previously left ~/.grok/auth.json live-only, so only one account could be used. Snapshot auth.json onto each official provider like Codex, restore it on switch, and drop the live session when moving to a third-party relay so api_key actually wins.
Do not delete ~/.grok/auth.json on a third-party write unless the live session was copied onto an official card. When saving or syncing the current official card, merge live tokens (including a newer grok login) instead of writing the stale DB snapshot.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f842a0243
ℹ️ 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".
| if crate::grok_config::merge_live_grok_oauth_into_settings( | ||
| &mut official.settings_config, | ||
| &live, | ||
| false, | ||
| ) { |
There was a problem hiding this comment.
Treat an already-saved OAuth snapshot as preserved
When switching from the seeded grokbuild-official card to a relay, switch_normal first backfills the live auth onto that same row, so its stored auth is now identical to live. merge_live_grok_oauth_into_settings returns false for this equality case, and because every matching row is then treated as an unsuccessful preservation, preserve_live_grok_oauth_in_db returns false; write_grok_live_with_db consequently skips stripping OAuth. The live official session therefore continues to override the relay's api_key, breaking the normal seeded-official-to-relay switch. Distinguish an already-identical snapshot from an identity conflict and return the safe-to-strip result for the former.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. After switch_normal backfills the live session onto grokbuild-official, stored already equals live, so merge was returning false and we skipped the strip. I now treat that identical snapshot as already preserved, so official → relay still drops OAuth.
cargo test after pointing TEMP at a WSL UNC path re-links and mt.exe fails (LNK1327). Compile with native TEMP, then execute the test binary with WSL TEMP so the ignored UNC contract still sees wsl.localhost.
|
Windows + WSL2 CI failed on the last run — not because of the Grok auth.json change (the other backend jobs were green). That job sets I pushed a CI-only fix: compile the tests with a normal Windows temp dir, then run the already-built test binary with the WSL The new run is waiting for a workflow approval ( |
switch_normal can backfill live auth onto grokbuild-official first, so stored==live is success, not a conflict. Preserve that case so a relay switch still strips OAuth and api_key wins.
Summary / 概述
Grok Official previously wrote an empty
~/.grok/config.tomland never snapshotted~/.grok/auth.json, so only one official Grok CLI login could exist.This change stores
auth.jsonon each official Grok provider (same{ auth, config }shape as Codex), restores it on switch, backfills the live session when leaving a card, and strips OAuth scopes when switching to a third-party relay so the official session cannot overrideapi_key.Adding Grok Official now creates a new card instead of only ensuring the seed, so multiple official accounts can be saved and switched like Codex / Claude.
Follow-ups already included:
GrokBuildProviderForm.tsx.Related Issue / 关联 Issue
Fixes #
Screenshots / 截图
Official Grok cards now include an
auth.jsoneditor. Selecting Grok Official again adds another account card instead of reusinggrokbuild-official.Checklist / 检查清单
pnpm typecheckpasses / 通过 TypeScript 类型检查pnpm format:checkpasses (changed frontend files) / 已检查改动的前端文件格式cargo clippypasses (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)