{"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":null,"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/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/lane/src/runtime.rs#L570-L606","documentation":"`tmux_session_state` runs `tmux has-session -t <session>` against a pinned socket to classify whether a lane's tmux session is Present or Absent. Known-benign stderr patterns (\"can't find session:\", \"no server running on\", \"error connecting to\" + \"no such file or directory\") are treated as Absent; any other nonzero exit means tmux failed in an unexpected way, so the runtime bails rather than guessing the session state. Callers `stop_tmux_session` and `reconcile` depend on this classification being trustworthy, which is why failure is loud.","triggerScenarios":"Calling `stop` or `reconcile` on a tmux lane when `tmux has-session` exits nonzero with stderr that matches none of the benign absence patterns — e.g. the socket path is stale/unreachable, tmux reports a protocol-version mismatch with an existing server, the socket file has wrong permissions, or tmux is corrupted.","commonSituations":"A tmux server was upgraded between runs so the on-disk socket speaks an incompatible protocol; the pinned socket path was deleted or recreated with different permissions; a stale socket directory with a dead server that tmux cannot clean up; running the runtime as a different user who cannot access the socket.","solutions":["Run `tmux -S <socket> has-session -t <session>` manually to see the full stderr and diagnose the actual tmux failure.","If the tmux server protocol is stale (version mismatch), kill the old server (`tmux -S <socket> kill-server`) or remove the stale socket file, then retry the stop/reconcile.","Check socket permissions/ownership — ensure the runtime process runs as the same user that created the session.","If the session is genuinely gone but tmux errors oddly, remove the lane record or clear its pinned tmux_socket/tmux_session metadata so reconcile treats it as absent."],"exampleFix":"// diagnose\n$ tmux -S /run/codewhale/lane.sock has-session -t lane-42\n# error connecting to /run/codewhale/lane.sock: Permission denied\n$ sudo rm /run/codewhale/lane.sock   # stale socket owned by another user","handlingStrategy":"try-catch","validationCode":"let out = std::process::Command::new(\"tmux\")\n    .args([\"-S\", socket, \"has-session\", \"-t\", session])\n    .output()\n    .map_err(|e| e.to_string())?;\nif !out.status.success() && !is_benign_absence(&String::from_utf8_lossy(&out.stderr)) {\n    return Err(String::from_utf8_lossy(&out.stderr).into());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a dedicated socket directory owned by the runtime user.","Kill stale tmux servers after tmux version upgrades.","Don't share lane sockets across user accounts."],"tags":["tmux","socket","process"],"backgroundTag":"command-execution-failed","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"}