{"record":{"id":"31034056305e216b","repo":"Hmbown/CodeWhale","slug":"ambiguous-prefix-prefix-matches-matches-len-sessions","errorCode":null,"errorMessage":"Ambiguous prefix '{prefix}' matches {matches.len()} sessions","messagePattern":"Ambiguous prefix '(.+?)' matches (.+?) sessions","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/session_manager.rs","lineNumber":2355,"sourceCode":"        self.load_session(&self.resolve_session_id_prefix(prefix)?)\n    }\n\n    /// Resolve a unique ID without applying resume-time repair to its record.\n    pub(crate) fn resolve_session_id_prefix(&self, prefix: &str) -> std::io::Result<String> {\n        let sessions = self.list_sessions()?;\n\n        let matches: Vec<_> = sessions\n            .into_iter()\n            .filter(|s| s.id.starts_with(prefix))\n            .collect();\n\n        match matches.len() {\n            0 => Err(std::io::Error::new(\n                std::io::ErrorKind::NotFound,\n                format!(\"No session found with prefix: {prefix}\"),\n            )),\n            1 => Ok(matches[0].id.clone()),\n            _ => Err(std::io::Error::new(\n                std::io::ErrorKind::InvalidInput,\n                format!(\n                    \"Ambiguous prefix '{}' matches {} sessions\",\n                    prefix,\n                    matches.len()\n                ),\n            )),\n        }\n    }\n\n    /// List all saved sessions, sorted by most recently updated\n    pub fn list_sessions(&self) -> std::io::Result<Vec<SessionMetadata>> {\n        let mut sessions = Vec::new();\n\n        for entry in fs::read_dir(&self.sessions_dir)? {\n            let entry = entry?;\n            let path = entry.path();\n","sourceCodeStart":2337,"sourceCodeEnd":2373,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/session_manager.rs#L2337-L2373","documentation":"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.","triggerScenarios":"Calling the prefix-resolution API with a prefix shorter than needed to uniquely identify one session among the saved sessions.","commonSituations":"Short prefixes like a single hex character colliding across many sessions; large session history where ids share leading characters.","solutions":["Supply a longer prefix until it matches exactly one session.","Use the full session id from the session list output.","Delete or archive old duplicate-prefix sessions if unambiguous naming matters."],"exampleFix":"// before\nmanager.resolve_session_id(\"9f\")?; // matches 3 sessions\n// after\nmanager.resolve_session_id(\"9f2e1a3c\")?;","handlingStrategy":"validation","validationCode":"let n = manager.list_sessions()?.iter().filter(|s| s.id.starts_with(prefix)).count();\nif n > 1 { eprintln!(\"prefix {prefix} is ambiguous ({n} matches)\"); return; }","typeGuard":null,"tryCatchPattern":"match manager.resolve_session_id(prefix) {\n    Err(e) if e.kind() == io::ErrorKind::InvalidInput && e.to_string().contains(\"Ambiguous prefix\") => prompt_user_to_disambiguate(),\n    r => r?,\n}","preventionTips":["Always use long/full session ids in scripts","Periodically prune old sessions to reduce id collisions","Surface the ambiguity error to the user with the match count"],"tags":["session","ambiguous-identifier","lookup"],"backgroundTag":"ambiguous-identifier","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T21:17:16.096Z"}