Skip to content

copilot: Fix auth db fallback#57764

Merged
cameron1024 merged 4 commits into
mainfrom
fix/copilot-auth-db-fallback
May 28, 2026
Merged

copilot: Fix auth db fallback#57764
cameron1024 merged 4 commits into
mainfrom
fix/copilot-auth-db-fallback

Conversation

@Anthony-Eid

Copy link
Copy Markdown
Contributor

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:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • 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

eodus and others added 3 commits May 26, 2026 21:48
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.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 26, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label May 26, 2026
@maxdeviant maxdeviant changed the title copilot: Fix/copilot auth db fallback copilot: Fix auth db fallback May 26, 2026

@cameron1024 cameron1024 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.

Other the blocking issue, looks good. Have validated that it fixes the bug

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());

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.

I think this is doing blocking IO on the foreground thread

@bennetbo

Copy link
Copy Markdown
Member

/cherry-pick preview
/cherry-pick stable

@cameron1024 cameron1024 enabled auto-merge May 28, 2026 14:48
@cameron1024 cameron1024 added this pull request to the merge queue May 28, 2026
Merged via the queue into main with commit bc64e1f May 28, 2026
32 checks passed
@cameron1024 cameron1024 deleted the fix/copilot-auth-db-fallback branch May 28, 2026 15:04
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants