Hmbown/CodeWhale · error · std::io::Error

Ambiguous prefix ' ' matches sessions

Error message

Ambiguous prefix '{prefix}' matches {matches.len()} sessions

What it means

When resolving a session by ID prefix, more than one saved session starts with that prefix, so the manager refuses to guess. It returns io::ErrorKind::InvalidInput listing the prefix and the number of matching sessions.

Solutions

  1. Supply a longer prefix until it matches exactly one session.
  2. Use the full session id from the session list output.
  3. Delete or archive old duplicate-prefix sessions if unambiguous naming matters.

Example fix

// before
manager.resolve_session_id("9f")?; // matches 3 sessions
// after
manager.resolve_session_id("9f2e1a3c")?;
Defensive patterns

Strategy: validation

Validate before calling

let n = manager.list_sessions()?.iter().filter(|s| s.id.starts_with(prefix)).count();
if n > 1 { eprintln!("prefix {prefix} is ambiguous ({n} matches)"); return; }

Try / catch

match manager.resolve_session_id(prefix) {
    Err(e) if e.kind() == io::ErrorKind::InvalidInput && e.to_string().contains("Ambiguous prefix") => prompt_user_to_disambiguate(),
    r => r?,
}

Prevention

When it happens

Trigger: Calling the prefix-resolution API with a prefix shorter than needed to uniquely identify one session among the saved sessions.

Common situations: Short prefixes like a single hex character colliding across many sessions; large session history where ids share leading characters.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/31034056305e216b. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/session_manager.rs:2355

        self.load_session(&self.resolve_session_id_prefix(prefix)?)
    }

    /// Resolve a unique ID without applying resume-time repair to its record.
    pub(crate) fn resolve_session_id_prefix(&self, prefix: &str) -> std::io::Result<String> {
        let sessions = self.list_sessions()?;

        let matches: Vec<_> = sessions
            .into_iter()
            .filter(|s| s.id.starts_with(prefix))
            .collect();

        match matches.len() {
            0 => Err(std::io::Error::new(
                std::io::ErrorKind::NotFound,
                format!("No session found with prefix: {prefix}"),
            )),
            1 => Ok(matches[0].id.clone()),
            _ => Err(std::io::Error::new(
                std::io::ErrorKind::InvalidInput,
                format!(
                    "Ambiguous prefix '{}' matches {} sessions",
                    prefix,
                    matches.len()
                ),
            )),
        }
    }

    /// List all saved sessions, sorted by most recently updated
    pub fn list_sessions(&self) -> std::io::Result<Vec<SessionMetadata>> {
        let mut sessions = Vec::new();

        for entry in fs::read_dir(&self.sessions_dir)? {
            let entry = entry?;
            let path = entry.path();

View on GitHub (pinned to 433685b202)