Hmbown/CodeWhale · error

This runtime is already active in another process. Close…

Error message

This runtime is already active in another process. Close the other Codewhale session and try again, or set CODEWHALE_RUNTIME_DIR to a different directory.

What it means

The Runtime takes an exclusive OS-level file lock (Runtime process owner lock) to ensure only one Codewhale process owns a runtime directory. After a short contention deadline (~25ms) it bails with RUNTIME_PROCESS_OWNER_LOCK_HELD, telling the user another session holds the directory.

Solutions

  1. Close the other Codewhale session holding the runtime directory
  2. Set CODEWHALE_RUNTIME_DIR to a different directory for the second instance
  3. Verify no orphaned codewhale process still runs (ps/kill it) if no other session is visibly open

Example fix

// before
CODEWHALE_RUNTIME_DIR=~/.codewhale codewhale  # while another session runs
// after
CODEWHALE_RUNTIME_DIR=~/.codewhale-work codewhale
Defensive patterns

Strategy: retry

Validate before calling

// check for an existing owner process before starting
std::env::var("CODEWHALE_RUNTIME_DIR").map(|dir| format!("{dir}/owner.lock")).map(|_| ()).map_err(|_| "CODEWHALE_RUNTIME_DIR not set".to_string())

Try / catch

match start_runtime(dir) {
    Err(e) if e.to_string().contains("already active in another process") => {
        eprintln!("Another Codewhale session owns {}; use a different CODEWHALE_RUNTIME_DIR", dir);
    }
    other => other?,
}

Prevention

When it happens

Trigger: Starting a Codewhale TUI/CLI session pointed at a runtime directory whose owner lock file is still locked by another live process.

Common situations: Two terminal windows open on the same CODEWHALE_RUNTIME_DIR; a previous session crashed leaving a stale process holding the lock; shared home dir used from two machines.

Related errors


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

Appendix: source

Thrown at crates/tui/src/runtime_threads.rs:4602

            options.create(true).truncate(false).read(true).write(true);
        })?;
        #[cfg(unix)]
        {
            use std::os::unix::fs::PermissionsExt as _;
            file.set_permissions(fs::Permissions::from_mode(0o600))
                .context("Failed to protect Runtime process owner lock")?;
        }
        // Same-process drop-then-reopen can observe WouldBlock for a brief
        // window while the previous fd is still closing — the same close-
        // release race #5735 hit on the Runtime Chat scope lock. Retry only
        // that contention; a lock that stays held still belongs to its owner.
        let deadline = Instant::now() + Duration::from_millis(25);
        loop {
            match Self::try_lock_exclusive(&file) {
                Ok(()) => break,
                Err(error) if Self::is_contention(&error) => {
                    if Instant::now() >= deadline {
                        bail!("{RUNTIME_PROCESS_OWNER_LOCK_HELD}");
                    }
                    std::thread::yield_now();
                    std::thread::sleep(Duration::from_millis(1));
                }
                Err(error) => {
                    return Err(error).context("Failed to acquire Runtime process owner lock");
                }
            }
        }
        Ok(Self { _file: file })
    }

    fn is_contention(error: &std::io::Error) -> bool {
        error.kind() == std::io::ErrorKind::WouldBlock
            || matches!(error.raw_os_error(), Some(32 | 33))
    }

    fn try_lock_exclusive(file: &File) -> std::io::Result<()> {

View on GitHub (pinned to 73e0f67d83)