Hmbown/CodeWhale · error
xAI OAuth lifecycle lock was poisoned
Error message
xAI OAuth lifecycle lock was poisoned
What it means
This error is thrown by with_xai_oauth_lifecycle_lock when the process-wide std::sync::Mutex guarding all xAI/chatgpt OAuth credential mutations is poisoned — i.e. another thread panicked while holding the lock. Once poisoned, every subsequent lock() returns Err and this library surfaces it as an anyhow error instead of proceeding with a possibly inconsistent credential store.
Solutions
- Restart the process — a poisoned std mutex cannot be recovered in-process.
- Find and fix the panic that originally poisoned the lock (check logs for the first panic during an OAuth credential operation).
- If you own the calling code, avoid panics inside credential operations (return Result instead of unwrap/expect).
- As a workaround within the library, the lock could be re-acquired via poison recovery (into_inner), but prefer fixing the root cause over patching the library.
Example fix
// before
let creds = store.clear_all_xai_oauth_credentials()?; // fails after a poisoning panic
// after
// restart the process first; then guard the operation
match store.clear_all_xai_oauth_credentials() {
Ok(()) => info!("credentials cleared"),
Err(e) => error!("oauth lock poisoned or op failed: {e:#}"),
} Defensive patterns
Strategy: try-catch
Try / catch
match store.clear_all_xai_oauth_credentials() {
Err(e) if e.to_string().contains("lock was poisoned") => {
eprintln!("OAuth lifecycle lock poisoned; restart the process and investigate the earlier panic");
}
other => other?,
} Prevention
- Avoid panics (unwrap/expect) in code paths that run under the OAuth lifecycle lock
- Log and investigate the first panic in any OAuth credential operation — later failures are secondary
- Restart the process once the lock is poisoned; it cannot recover in-process
- Keep credential-mutating operations small so a panic window is minimal
When it happens
Trigger: Calling with_xai_oauth_lifecycle_lock (directly or via with_xai_oauth_revocation_transaction, remove_xai_oauth_generation, clear_all_xai_oauth_credentials, clear_all_chatgpt_oauth_credentials, remove_chatgpt_oauth_generation) after some thread panicked while holding the PROCESS_LOCK mutex.
Common situations: An earlier OAuth operation panicked mid-mutation (disk error unwrapping, a bug in the credential store) leaving the mutex poisoned; a long-running process where one bad request poisons the lock and all later credential operations fail.
Related errors
- catalog cache unavailable
- Frame lock failed
- installing a new xAI OAuth generation without replacement
- refusing to replace xAI OAuth generation
- shell manager lock poisoned
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/d2e0fad1dc51f5e8.
Report an issue: GitHub.
Appendix: source
Thrown at crates/config/src/xai_credentials.rs:167
}
pub fn legacy_chatgpt_oauth_path() -> Result<PathBuf> {
Ok(xai_oauth_credentials_dir()?.join(LEGACY_CHATGPT_OAUTH_FILE_NAME))
}
/// Serialize every Codewhale-owned xAI OAuth lifecycle mutation across threads
/// and processes while pinning the lexical credentials directory.
///
/// Lock order is always xAI lifecycle first, then config document. Callers must
/// not invoke this function recursively.
pub fn with_xai_oauth_lifecycle_lock<T>(
operation: impl FnOnce(&XaiOAuthCredentialStore) -> Result<T>,
) -> Result<T> {
static PROCESS_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
let _process_guard = PROCESS_LOCK
.get_or_init(|| Mutex::new(()))
.lock()
.map_err(|_| anyhow::anyhow!("xAI OAuth lifecycle lock was poisoned"))?;
let store = XaiOAuthCredentialStore::open()?;
let lock_file = store.open_lock_file()?;
let mut lock = fd_lock::RwLock::new(lock_file);
let _guard = lock.write().with_context(|| {
format!(
"failed to acquire xAI OAuth lifecycle lock in {}",
crate::quote_os_path(store.directory())
)
})?;
operation(&store)
}
/// Run an authority mode switch while the prior owned OAuth epoch is hidden
/// from concurrent Codewhale readers. A failed authority mutation restores the
/// old files; a successful mutation permanently removes them.
pub fn with_xai_oauth_revocation_transaction<T>(
operation: impl FnOnce() -> Result<T>,
) -> Result<T> {View on GitHub (pinned to 73e0f67d83)