{"record":{"id":"594676a8a309487b","repo":"Hmbown/CodeWhale","slug":"tmux-has-session-for-session-failed-with","errorCode":null,"errorMessage":"tmux has-session for {session} failed with {}: {}","messagePattern":"tmux has-session for (.+?) failed with (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/lane/src/runtime.rs","lineNumber":588,"sourceCode":"\nfn tmux_session_state(socket: &Path, session: &str) -> Result<TmuxSessionState> {\n    let output = tmux_command(socket)\n        .args([\"has-session\", \"-t\", session])\n        .stdout(Stdio::null())\n        .stderr(Stdio::piped())\n        .output()\n        .with_context(|| format!(\"query tmux session {session}\"))?;\n    if output.status.success() {\n        return Ok(TmuxSessionState::Present);\n    }\n    let stderr = String::from_utf8_lossy(&output.stderr).to_ascii_lowercase();\n    if stderr.contains(\"can't find session:\")\n        || stderr.contains(\"no server running on\")\n        || (stderr.contains(\"error connecting to\") && stderr.contains(\"no such file or directory\"))\n    {\n        return Ok(TmuxSessionState::Absent);\n    }\n    bail!(\n        \"tmux has-session for {session} failed with {}: {}\",\n        output.status,\n        stderr.trim()\n    )\n}\n\nfn stop_tmux_session(socket: &Path, session: &str) -> Result<()> {\n    let status = tmux_command(socket)\n        .args([\"kill-session\", \"-t\", session])\n        .stdout(Stdio::null())\n        .stderr(Stdio::null())\n        .status()\n        .with_context(|| format!(\"kill tmux session {session}\"))?;\n    match tmux_session_state(socket, session).with_context(|| {\n        format!(\n            \"confirm tmux session {session} on {} stopped after kill-session ({status})\",\n            socket.display()\n        )","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/lane/src/runtime.rs#L570-L606","documentation":"tmux_session_state classifies `tmux has-session -t <session>` results: success means Present, and stderr matching known patterns ('can't find session:', 'no server running on', or 'error connecting to' plus 'no such file or directory') means Absent. Any other nonzero failure bails with this message, because the session's existence is genuinely unknown and stopping or reconciling on a guess would be unsafe.","triggerScenarios":"has-session exiting nonzero with unrecognized stderr: permission denied on the socket path, a malformed session name (colons/leading dots confuse tmux targeting), tmux server errors, or tmux.conf errors surfacing on first server start.","commonSituations":"Socket directories under paths with restrictive permissions or different uids (shared machines, sudo drops); session names generated from user input containing tmux target syntax; broken global tmux.conf; leftover sockets from a crashed server with wrong ownership.","solutions":["Reproduce manually: tmux -S <socket> has-session -t <session> and read the stderr shown in the message","Fix the reported condition: correct socket dir ownership/permissions, or sanitize the session name (alphanumeric plus dashes)","Move offending user config out of tmux.conf and retry","If the server is wedged, remove the stale socket file so a fresh server can start"],"exampleFix":"// before\nlet session = format!(\"{}:{}\", user_name, raw_title); // ':' breaks targeting\n\n// after\nlet session: String = raw_title\n    .chars()\n    .map(|c| if c.is_ascii_alphanumeric() || c == '-' { c } else { '_' })\n    .collect();\nlet session = format!(\"codewhale-{lane_id}-{session}\");","handlingStrategy":"try-catch","validationCode":"fn safe_tmux_session_name(name: &str) -> bool {\n    !name.is_empty()\n        && name\n            .chars()\n            .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')\n}","typeGuard":null,"tryCatchPattern":"match tmux_session_state(&socket, &session) {\n    Ok(state) => { /* Present/Absent handling */ }\n    Err(err) if err.to_string().contains(\"has-session\") => {\n        // Existence indeterminate: surface to the operator, do not guess.\n        log::warn!(\"tmux state unknown for {session}: {err:#}\");\n        return Ok(None);\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Sanitize session names to alphanumerics, dashes, underscores — no colons or dots","Keep socket directories owned by the running uid","Validate tmux.conf in your environment setup"],"tags":["rust","lane","tmux","session","external-process"],"backgroundTag":"external-command-failed","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}