{"record":{"id":"37683df307aef3e6","repo":"Hmbown/CodeWhale","slug":"state-dir-resolution-error","errorCode":null,"errorMessage":"<state dir resolution error>","messagePattern":"<state dir resolution error>","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/session_manager.rs","lineNumber":3062,"sourceCode":"    let lhs_canonical = fs::canonicalize(lhs).ok();\n    let rhs_canonical = fs::canonicalize(rhs).ok();\n    match (lhs_canonical, rhs_canonical) {\n        (Some(lhs), Some(rhs)) => lhs == rhs,\n        _ => lhs == rhs,\n    }\n}\n\n/// Resolve the default session directory path.\n///\n/// v0.8.44: prefers `~/.codewhale/sessions`, falls back to\n/// `~/.deepseek/sessions` for existing installs. Uses the write-path resolver\n/// so the first access relocates any legacy `~/.deepseek/sessions` into\n/// `~/.codewhale/sessions` when the primary directory is missing (#3240).\n/// If an older build already created an empty primary sessions directory, copy\n/// missing legacy entries into it without overwriting newer CodeWhale data.\npub fn default_sessions_dir() -> std::io::Result<PathBuf> {\n    let dir = codewhale_config::ensure_state_dir(\"sessions\")\n        .map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, e.to_string()))?;\n    match merge_missing_legacy_session_entries(&dir) {\n        Ok(0) => {}\n        Ok(count) => {\n            tracing::info!(\n                target: \"session::migration\",\n                \"Copied {count} missing legacy session entries into {}\",\n                dir.display()\n            );\n        }\n        Err(err) => {\n            tracing::warn!(\n                target: \"session::migration\",\n                \"Could not copy legacy sessions into {}: {err}\",\n                dir.display()\n            );\n        }\n    }\n    Ok(dir)","sourceCodeStart":3044,"sourceCodeEnd":3080,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/session_manager.rs#L3044-L3080","documentation":"`default_sessions_dir` (crates/tui/src/session_manager.rs) resolves the sessions directory via `codewhale_config::ensure_state_dir(\"sessions\")`. If that fails (state dir cannot be created or resolved), the underlying error is converted into an io::Error with kind NotFound whose message is the state-dir resolver's error text. This is a wrapped environment error, not a library bug — the state root (~/.codewhale or CODEWHALE_HOME) is unusable.","triggerScenarios":"Calling SessionManager::new / default_sessions_dir when the state directory cannot be created or resolved: unwritable home, CODEWHALE_HOME pointing somewhere invalid, or disk/permission failure inside ensure_state_dir.","commonSituations":"Read-only or full home directory; CODEWHALE_HOME set to a path with wrong permissions; running in a sandbox/container where $HOME is not writable; NFS mount issues.","solutions":["Read the wrapped message for the underlying cause (permission denied, path missing, etc.) and fix that filesystem condition.","Check CODEWHALE_HOME points to a writable location, or unset it to fall back to the default home.","Verify $HOME exists and is writable, then retry session listing."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before listing sessions\nlet home = std::env::var(\"HOME\")?;\nlet writable = std::fs::metadata(&home).is_ok();","typeGuard":null,"tryCatchPattern":"match default_sessions_dir() {\n    Err(e) if e.kind() == io::ErrorKind::NotFound => {\n        eprintln!(\"state dir unavailable: {e}\"); // inspect wrapped cause\n    }\n    Err(e) => return Err(e),\n    Ok(dir) => use_dir(dir),\n}","preventionTips":["Ensure $HOME (or CODEWHALE_HOME) exists and is writable before launch.","Avoid read-only home mounts in containers/sandboxes.","Monitor disk space on the state volume."],"tags":["filesystem","state-directory","environment"],"backgroundTag":"directory-not-found","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}