zed-industries/zed · error · anyhow::Error
Sign-out occurred during token refresh
Error message
Sign-out occurred during token refresh
What it means
A guard detected that the auth_generation counter changed between the start and end of a background token refresh, meaning the user signed out (or switched accounts) while the refresh was in flight. The freshly obtained credentials no longer belong to the active session and are discarded.
Source
Thrown at crates/openai_subscribed/src/openai_subscribed.rs:1001
.map_err(|e| LanguageModelCompletionError::Other(anyhow::anyhow!("{e}")));
}
// We are the first caller to notice expiry — spawn the refresh task.
let http_client_clone = http_client.clone();
let state_clone = state.clone();
let refresh_token_value = creds.refresh_token.clone();
// Capture the generation so we can detect sign-outs that happened during refresh.
let generation = state
.read_with(&*cx, |s, _| s.auth_generation)
.map_err(LanguageModelCompletionError::Other)?;
let shared_task = cx
.spawn(async move |cx| {
let result = refresh_token(&http_client_clone, &refresh_token_value).await;
match result {
Ok(refreshed) => {
let persist_result: Result<CodexCredentials, Arc<anyhow::Error>> = async {
// Check if auth_generation changed (sign-out during refresh).
let current_generation = state_clone
.read_with(&*cx, |s, _| s.auth_generation)
.map_err(|e| Arc::new(e))?;
if current_generation != generation {
return Err(Arc::new(anyhow!(
"Sign-out occurred during token refresh"
)));
}
let credentials_provider = state_clone
.read_with(&*cx, |s, _| s.credentials_provider.clone())
.map_err(|e| Arc::new(e))?;
let json =
serde_json::to_vec(&refreshed).map_err(|e| Arc::new(e.into()))?;
View on GitHub (pinned to 5a9b9558db)
Solutions
- No fix needed for stale credentials — they are intentionally dropped; complete the new sign-in flow instead
- If this fires spuriously without a sign-out, look for code paths that increment auth_generation unexpectedly
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/openai_subscribed/src/openai_subscribed.rs:969 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20).
Data as JSON: /api/errors/7dd5b39755a91d67.
Report an issue: GitHub.