openai/codex · error · anyhow::Error
failed to write OAuth tokens to keyring
Error message
failed to write OAuth tokens to keyring: {} What it means
Raised by save_oauth_tokens_to_direct_keyring when the OS keyring backend rejected the write of the serialized OAuth tokens for an MCP server; the message carries the backend's own error text. The tokens remain unsaved, so a subsequent login may be required again.
Solutions
- Retry the keyring write, some backends fail transiently
- Verify the OS keyring service is running and unlocked (e.g. gnome-keyring)
- Switch to the File credential store mode if the keyring is unavailable
- Check keyring access permissions for the current user/session
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at codex-rs/rmcp-client/src/oauth.rs:485 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of openai/codex@339751715c (2026-08-25).
Data as JSON: /api/errors/8c7e96a19f74b622.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/rmcp-client/src/oauth.rs:485
}
fn save_oauth_tokens_to_direct_keyring<K: KeyringStore>(
keyring_store: &K,
server_name: &str,
tokens: &StoredOAuthTokens,
) -> Result<()> {
let serialized = serde_json::to_string(tokens).context("failed to serialize OAuth tokens")?;
let key = compute_store_key(server_name, &tokens.url)?;
match keyring_store.save(KEYRING_SERVICE, &key, &serialized) {
Ok(()) => Ok(()),
Err(error) => {
let message = format!(
"failed to write OAuth tokens to keyring: {}",
error.message()
);
warn!("{message}");
Err(Error::new(error.into_error()).context(message))
}
}
}
/// Saves one credential while holding the Secrets aggregate-store lock across the mutation.
fn save_oauth_tokens_to_secrets_keyring<K: KeyringStore + Clone + 'static>(
keyring_store: &K,
server_name: &str,
tokens: &StoredOAuthTokens,
) -> Result<()> {
let serialized = serde_json::to_string(tokens).context("failed to serialize OAuth tokens")?;
let _store_lock = OAuthStoreLock::acquire_for_write(OAuthStore::Secrets)?;
save_oauth_tokens_to_secrets_keyring_with_lock_held(
keyring_store,
server_name,
tokens,
&serialized,
)View on GitHub (pinned to 339751715c)