{"record":{"id":"1b81b675cf34342f","repo":"Hmbown/CodeWhale","slug":"the-signed-in-account-changed-refresh-and-try-again","errorCode":null,"errorMessage":"The signed-in account changed. Refresh and try again.","messagePattern":"The signed-in account changed\\. Refresh and try again\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/cloud.rs","lineNumber":431,"sourceCode":"            .save(bundle)\n            .context(\"failed to save the Codewhale account session in the local secret store\")\n    }\n\n    fn me(&self) -> Result<CloudUser> {\n        let (response, snapshot) =\n            self.execute_authenticated_snapshot(HttpMethod::Get, \"/api/me\", None)?;\n        let me: MeResponse = expect_json(response, &[200])?;\n        if me.user.id.trim().is_empty() {\n            bail!(\"The Codewhale service returned an account without an ID\");\n        }\n        if let Some(mut stored) = snapshot.load()? {\n            if stored\n                .bundle\n                .user\n                .as_ref()\n                .is_some_and(|user| !user.id.is_empty() && user.id != me.user.id)\n            {\n                bail!(\"The signed-in account changed. Refresh and try again.\");\n            }\n            stored.bundle.user = Some(me.user.clone());\n            if self\n                .account_store\n                .save_if_unchanged(&snapshot, stored.bundle)?\n                .is_none()\n            {\n                bail!(\"The signed-in account changed. Refresh and try again.\");\n            }\n        }\n        Ok(me.user)\n    }\n\n    fn set_key(&self, provider: &str, key: &str, label: &str) -> Result<()> {\n        let path = format!(\"/api/model-keys/{provider}\");\n        let response = self.execute_authenticated(\n            HttpMethod::Put,\n            &path,","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/cloud.rs#L413-L449","documentation":"While refreshing the user via /api/me, the client compares the service's account id against the id stored in the local account bundle. If a different non-empty id is already stored, it refuses to overwrite and throws this optimistic-concurrency error.","triggerScenarios":"Running `codewhale me` (or any command via execute_authenticated) when the locally stored signed-in account belongs to a different user than the service returns — typically after switching accounts or tokens in another session/process.","commonSituations":"Two terminal sessions signed in as different accounts; a shared machine where another user re-logged-in; stale token refreshed against a different account.","solutions":["Log out (`codewhale logout`) and log in again as the intended account.","Check other open sessions/terminals that may have switched accounts concurrently.","Re-run the command once you are signed in as the account you expect."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust\nmatch cloud.me() {\n    Err(e) if e.to_string().contains(\"signed-in account changed\") => {\n        // re-authenticate: logout, login, then retry\n    }\n    other => other,\n}","preventionTips":["Avoid signing into different accounts from multiple concurrent sessions on one machine.","After switching accounts, re-run the command instead of reusing stale state."],"tags":["auth","concurrency","cloud","state-conflict"],"backgroundTag":"invalid-state-transition","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}