Hmbown/CodeWhale · error

Runtime store file must not be a symlink

Error message

Runtime store file must not be a symlink: {}

What it means

Before using an existing runtime store file, reject_symlinked_store_file checks its symlink_metadata; a symlink would let the store read/write outside the intended location, so it is rejected. Missing files pass (the store creates them).

Solutions

  1. Replace the symlink with a real file (copy the target content to the path)
  2. Point the store root at the real directory instead of symlinking individual files
  3. Verify with `ls -l` / symlink_metadata that no store file is a link before starting

Example fix

// before
$ ln -s /mnt/big/store.jsonl ~/.codewhale/runtime/store.jsonl
// after
$ rm ~/.codewhale/runtime/store.jsonl && cp /mnt/big/store.jsonl ~/.codewhale/runtime/store.jsonl
Defensive patterns

Strategy: validation

Validate before calling

fn is_symlink(p: &Path) -> bool {
    std::fs::symlink_metadata(p).map(|m| m.file_type().is_symlink()).unwrap_or(false)
}

Type guard

fn real_file(p: &Path) -> Option<()> {
    let m = std::fs::symlink_metadata(p).ok()?;
    (!m.file_type().is_symlink()).then_some(())
}

Try / catch

if is_symlink(&store_file) {
    std::fs::copy(store_file.read_link()?, &store_file)?; // materialize
}

Prevention

When it happens

Trigger: The store file path already exists and is a symlink when the runtime store opens or writes that file.

Common situations: Users symlinking store files to another disk/home to save space; backup-restore tooling replacing files with symlinks; dotfile managers linking config/store files.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


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

Appendix: source

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

            Component::ParentDir => {
                normalized.pop();
            }
            Component::Normal(part) => normalized.push(part),
        }
    }
    if normalized.as_os_str().is_empty() {
        PathBuf::from(".")
    } else {
        normalized
    }
}

fn reject_symlinked_store_file(path: &Path) -> Result<()> {
    let Ok(metadata) = fs::symlink_metadata(path) else {
        return Ok(());
    };
    if metadata.file_type().is_symlink() {
        bail!(
            "Runtime store file must not be a symlink: {}",
            path.display()
        );
    }
    Ok(())
}

fn open_runtime_store_file(
    path: &Path,
    purpose: &str,
    configure: impl FnOnce(&mut OpenOptions),
) -> Result<File> {
    reject_symlinked_store_file(path)?;
    let mut options = OpenOptions::new();
    configure(&mut options);
    #[cfg(unix)]
    {
        use std::os::unix::fs::OpenOptionsExt as _;

View on GitHub (pinned to 73e0f67d83)