Hmbown/CodeWhale · error

xAI OAuth lifecycle lock changed repeatedly while opening

Error message

xAI OAuth lifecycle lock changed repeatedly while opening

What it means

open_internal_file acquires/creates the xAI OAuth lifecycle lock and retries when the lock file's identity keeps changing under it (concurrent openers racing to create/remove it). If the lock changes repeatedly through all retry attempts, it gives up with this error rather than proceeding on an unstable store.

Solutions

  1. Ensure only one Codewhale process performs login/logout at a time; retry after the other finishes
  2. Delete a stale lifecycle lock file in the credentials directory and retry the operation
  3. Investigate what is repeatedly creating/removing the lock (crash loop, watcher, sync tool like Dropbox)

Example fix

null
Defensive patterns

Strategy: retry

Validate before calling

let lock_path = creds_dir.join("lifecycle.lock");
if lock_path.exists() {
    let id1 = std::fs::metadata(&lock_path)?.inode_or_id();
    std::thread::sleep(std::time::Duration::from_millis(100));
    let id2 = std::fs::metadata(&lock_path)?.inode_or_id();
    if id1 != id2 { return Err("lifecycle lock is churning; another process is racing"); }
}

Try / catch

match Store::open(dir) {
    Err(e) if e.to_string().contains("changed repeatedly") => {
        // wait out the racing process, then retry with backoff
        std::thread::sleep(Duration::from_secs(1));
        Store::open(dir)
    }
    other => other,
}

Prevention

When it happens

Trigger: Multiple processes/threads calling Store::open (or login/logout) concurrently on the same credentials directory so the lifecycle lock file keeps being created and deleted; a stuck or rapidly churned lock.

Common situations: Two Codewhale instances starting at once; a leftover monitoring agent touching the lock file; a container restart loop with concurrent login attempts.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/b9ba6fde49f00ef9. Report an issue: GitHub.

Appendix: source

Thrown at crates/config/src/xai_credentials.rs:1085

            let secured = (|| -> Result<()> {
                validate_windows_file_shape(&file, &path)?;
                secure_windows_owner_only_handle(&file, false)
                    .context("securing a new xAI OAuth lifecycle lock")?;
                validate_owned_file_handle(&file, &path)?;
                Ok(())
            })();
            if let Err(error) = secured {
                let cleanup = mark_windows_file_handle_for_deletion(&file);
                return match cleanup {
                    Ok(()) => Err(error),
                    Err(cleanup) => Err(error).context(format!(
                        "also failed to delete the empty lifecycle lock: {cleanup:#}"
                    )),
                };
            }
            return Ok(file);
        }
        bail!("xAI OAuth lifecycle lock changed repeatedly while opening")
    }

    fn write_owned_file(&self, name: &str, bytes: &[u8], allow_replace: bool) -> Result<()> {
        let path = self.directory.join(name);
        if let Some(existing) = self.open_owned_file_for_read(name)? {
            anyhow::ensure!(
                allow_replace,
                "refusing to replace an existing xAI OAuth generation"
            );
            drop(existing);
        }
        let mut temporary = tempfile::NamedTempFile::new_in(&self.directory)
            .context("creating private xAI OAuth temporary file")?;
        let temporary_path = temporary.path().to_path_buf();
        let security_handle =
            reopen_windows_file_for_owner_security(temporary.as_file(), &temporary_path)?;
        secure_windows_owner_only_handle(&security_handle, false)
            .context("securing a new xAI OAuth temporary file before writing credentials")?;

View on GitHub (pinned to 73e0f67d83)