{"record":{"id":"7dd5b39755a91d67","repo":"zed-industries/zed","slug":"sign-out-occurred-during-token-refresh","errorCode":null,"errorMessage":"Sign-out occurred during token refresh","messagePattern":"Sign-out occurred during token refresh","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/openai_subscribed/src/openai_subscribed.rs","lineNumber":1001,"sourceCode":"            .map_err(|e| LanguageModelCompletionError::Other(anyhow::anyhow!(\"{e}\")));\n    }\n\n    // We are the first caller to notice expiry — spawn the refresh task.\n    let http_client_clone = http_client.clone();\n    let state_clone = state.clone();\n    let refresh_token_value = creds.refresh_token.clone();\n\n    // Capture the generation so we can detect sign-outs that happened during refresh.\n    let generation = state\n        .read_with(&*cx, |s, _| s.auth_generation)\n        .map_err(LanguageModelCompletionError::Other)?;\n\n    let shared_task = cx\n        .spawn(async move |cx| {\n            let result = refresh_token(&http_client_clone, &refresh_token_value).await;\n\n            match result {\n                Ok(refreshed) => {\n                    let persist_result: Result<CodexCredentials, Arc<anyhow::Error>> = async {\n                        // Check if auth_generation changed (sign-out during refresh).\n                        let current_generation = state_clone\n                            .read_with(&*cx, |s, _| s.auth_generation)\n                            .map_err(|e| Arc::new(e))?;\n                        if current_generation != generation {\n                            return Err(Arc::new(anyhow!(\n                                \"Sign-out occurred during token refresh\"\n                            )));\n                        }\n\n                        let credentials_provider = state_clone\n                            .read_with(&*cx, |s, _| s.credentials_provider.clone())\n                            .map_err(|e| Arc::new(e))?;\n\n                        let json =\n                            serde_json::to_vec(&refreshed).map_err(|e| Arc::new(e.into()))?;\n","sourceCodeStart":983,"sourceCodeEnd":1019,"githubUrl":"https://github.com/zed-industries/zed/blob/5a9b9558db01a6b906cec2fb70a797affdc58cdd/crates/openai_subscribed/src/openai_subscribed.rs#L983-L1019","documentation":"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.","triggerScenarios":"Thrown at crates/openai_subscribed/src/openai_subscribed.rs:969 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5a9b9558db01a6b906cec2fb70a797affdc58cdd","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}