{"record":{"id":"bcdf7d404215ef57","repo":"Hmbown/CodeWhale","slug":"ambiguous-prefix-matches-sessions","errorCode":null,"errorMessage":"Ambiguous prefix '{}' matches {} sessions","messagePattern":"Ambiguous prefix '(.+?)' matches (.+?) sessions","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/session_manager.rs","lineNumber":2499,"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":2481,"sourceCodeEnd":2517,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/session_manager.rs#L2481-L2517","documentation":"Prefix resolution also rejects a prefix matching more than one session, returning an InvalidInput io::Error listing the match count. The library throws this because it cannot choose between multiple candidates and refuses to pick arbitrarily.","triggerScenarios":"Calling the prefix-resolution API with a prefix shared by two or more session ids (e.g. a single common character or a shared timestamp prefix).","commonSituations":"Short prefixes in scripts or shell history where many sessions share the leading characters.","solutions":["Lengthen the prefix until it uniquely identifies one session (copy more characters from the full id).","Use the full session id to be unambiguous.","Enumerate sessions first and disambiguate in your own tooling before resolving."],"exampleFix":"// before\nlet id = manager.resolve_session_prefix(\"2026\")?; // ambiguous\n// after\nlet id = manager.resolve_session_prefix(\"20260921-a1b2\")?; // longer, unique","handlingStrategy":"validation","validationCode":"fn prefix_is_unique(prefix: &str, sessions: &[SessionInfo]) -> bool {\n    sessions.iter().filter(|s| s.id.starts_with(prefix)).count() == 1\n}","typeGuard":null,"tryCatchPattern":"match resolve_session_prefix(prefix) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => {\n        eprintln!(\"prefix '{prefix}' is ambiguous; use a longer prefix\");\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Use prefixes long enough to be unique (avoid common shared heads like timestamps alone).","Enumerate candidates yourself when building interactive pickers.","Prefer full ids in scripts."],"tags":["session-id","prefix-lookup","ambiguity","invalid-input"],"backgroundTag":"invalid-argument-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}