copilot: Fix auth db fallback#57764
Merged
Merged
Conversation
The GitHub Copilot SDK migrated its OAuth token storage from JSON files (apps.json / hosts.json) to a SQLite database (auth.db) under the same github-copilot config directory. Zed only knew about the JSON files, so users on a fresh SDK install saw an empty Copilot Chat model dropdown even though they were signed in via the LSP. Changes: * Add extract_oauth_token_from_db() which reads token_ciphertext from the oauth_tokens table via the existing sqlez dependency. The column stores the raw 'ghu_...' OAuth token as text on current SDK builds; format is validated (prefix + length + charset) so we fail closed if the SDK changes the schema. * Replace the previous fs.watch() loop on the config directory with an LSP-driven reload. The copilot crate already receives didChangeStatus notifications from the Copilot language server; we now route those through a small public CopilotChat::reload_auth() method. SQLite's WAL writes interact poorly with directory watchers (we observed both spurious early fires and missed commits on Windows), and the LSP gives us a clean, semantic, cross-platform signal that fires after the token is durable. * Sign-out clears api_endpoint and the model catalogue so a subsequent sign-in re-discovers them rather than reusing stale state. Tested on Windows 11 with the official Copilot SDK build that ships auth.db; cold sign-in now populates the model list within a couple of seconds of the LSP reporting Authorized status, with no manual restart.
tomhoule
approved these changes
May 27, 2026
cameron1024
approved these changes
May 28, 2026
Comment on lines
+1013
to
+1020
| let db = sqlez::connection::Connection::open_file(db_path.to_str()?); | ||
|
|
||
| let token_bytes: Option<Vec<u8>> = db | ||
| .select_row_bound::<&str, Vec<u8>>( | ||
| "SELECT token_ciphertext FROM oauth_tokens WHERE auth_authority = ? ORDER BY last_used_at DESC, token_id DESC LIMIT 1", | ||
| ) | ||
| .ok() | ||
| .and_then(|mut select| select(auth_authority).ok().flatten()); |
Contributor
There was a problem hiding this comment.
I think this is doing blocking IO on the foreground thread
Member
|
/cherry-pick preview |
This was referenced May 28, 2026
zed-zippy Bot
added a commit
that referenced
this pull request
May 28, 2026
Cherry-pick of #57764 to stable ---- This PR uses #57758 as a base and adds tests, cleans up the comments, and checks changes the database query used in auth.db to include oauth key. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes #ISSUE Release Notes: - Fixed GitHub Copilot Chat showing an empty model dropdown for users on newer Copilot SDK builds --------- Co-authored-by: Alexander Shlemov <eodus@users.noreply.github.com> Co-authored-by: cameron <cameron.studdstreet@gmail.com> Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Co-authored-by: Alexander Shlemov <eodus@users.noreply.github.com> Co-authored-by: cameron <cameron.studdstreet@gmail.com>
zed-zippy Bot
added a commit
that referenced
this pull request
May 28, 2026
Cherry-pick of #57764 to preview ---- This PR uses #57758 as a base and adds tests, cleans up the comments, and checks changes the database query used in auth.db to include oauth key. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes #ISSUE Release Notes: - Fixed GitHub Copilot Chat showing an empty model dropdown for users on newer Copilot SDK builds --------- Co-authored-by: Alexander Shlemov <eodus@users.noreply.github.com> Co-authored-by: cameron <cameron.studdstreet@gmail.com> Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Co-authored-by: Alexander Shlemov <eodus@users.noreply.github.com> Co-authored-by: cameron <cameron.studdstreet@gmail.com>
This was referenced May 28, 2026
TomPlanche
pushed a commit
to TomPlanche/zed
that referenced
this pull request
Jun 2, 2026
This PR uses zed-industries#57758 as a base and adds tests, cleans up the comments, and checks changes the database query used in auth.db to include oauth key. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes #ISSUE Release Notes: - Fixed GitHub Copilot Chat showing an empty model dropdown for users on newer Copilot SDK builds --------- Co-authored-by: Alexander Shlemov <eodus@users.noreply.github.com> Co-authored-by: cameron <cameron.studdstreet@gmail.com>
This was referenced Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR uses #57758 as a base and adds tests, cleans up the comments, and checks changes the database query used in auth.db to include oauth key.
Self-Review Checklist:
Closes #ISSUE
Release Notes: