{"record":{"id":"7f01f0ed8fe43a54","repo":"Hmbown/CodeWhale","slug":"failed-to-enter-acp-session-cwd-err","errorCode":null,"errorMessage":"failed to enter ACP session cwd {}: {err}","messagePattern":"failed to enter ACP session cwd (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/acp_server.rs","lineNumber":2408,"sourceCode":"            \"sessionId\": session_id,\n            \"update\": update\n        }\n    });\n    write_json_line(writer, notification).await\n}\n\nstruct ScopedCurrentDir {\n    prior: PathBuf,\n}\n\nimpl ScopedCurrentDir {\n    fn new(cwd: &PathBuf) -> Result<Self> {\n        let prior = std::env::current_dir()?;\n        if cwd.as_os_str().is_empty() {\n            return Ok(Self { prior });\n        }\n        std::env::set_current_dir(cwd)\n            .map_err(|err| anyhow!(\"failed to enter ACP session cwd {}: {err}\", cwd.display()))?;\n        Ok(Self { prior })\n    }\n}\n\nimpl Drop for ScopedCurrentDir {\n    fn drop(&mut self) {\n        let _ = std::env::set_current_dir(&self.prior);\n    }\n}\n\nimpl AcpError {\n    fn invalid_params(message: impl Into<String>) -> Self {\n        Self {\n            code: -32602,\n            message: message.into(),\n        }\n    }\n","sourceCodeStart":2390,"sourceCodeEnd":2426,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/acp_server.rs#L2390-L2426","documentation":"ScopedCurrentDir::new switches the process working directory to the ACP session's cwd and returns this error if std::env::set_current_dir fails (e.g. the directory does not exist or is not accessible). The guard restores the prior directory on Drop.","triggerScenarios":"Starting or resuming an ACP session whose cwd PathBuf points to a deleted, renamed, permission-restricted, or non-directory path (empty cwd is allowed and skips the change).","commonSituations":"Client sends a session/new or load request with a cwd that was deleted since registration, a typo'd path, or a path on an unmounted volume; running in a container where the host path was never mounted.","solutions":["Verify the session cwd path exists and is a directory before sending session/new","Create the directory or correct the cwd value sent by the ACP client","Check filesystem permissions on the target directory","Re-mount the volume if the path lives on an unmounted mount point"],"exampleFix":"// before: ACP client sends stale cwd\n{\"cwd\": \"/home/user/removed-project\"}\n// after: ensure it exists client-side\nif !Path::new(&cwd).is_dir() { fs::create_dir_all(&cwd)?; }","handlingStrategy":"validation","validationCode":"fn ensure_session_cwd(cwd: &Path) -> std::io::Result<()> {\n    if cwd.as_os_str().is_empty() { return Ok(()); }\n    let meta = std::fs::metadata(cwd)?;\n    if !meta.is_dir() {\n        return Err(std::io::Error::new(std::io::ErrorKind::NotADirectory, \"not a directory\"));\n    }\n    std::env::set_current_dir(cwd) // probe accessibility\n}","typeGuard":"fn cwd_is_usable(p: &PathBuf) -> bool {\n    !p.as_os_str().is_empty() && p.is_dir()\n}","tryCatchPattern":"match ScopedCurrentDir::new(&cwd) {\n    Ok(guard) => { /* run session work */ }\n    Err(e) => eprintln!(\"cannot enter session cwd: {e:#}; check the path exists and is accessible\"),\n}","preventionTips":["Validate session cwd on session creation and persist an existing path","Re-check the path before session resume (it may have been deleted)","Mount all client-referenced paths into containers","Avoid sending relative or empty paths except intentionally"],"tags":["filesystem","acp","cwd","directory"],"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-23T08:17:48.524Z"}