{"record":{"id":"3aa968cafc60f15c","repo":"Hmbown/CodeWhale","slug":"tmux-new-session-failed-with-status","errorCode":null,"errorMessage":"tmux new-session failed with {status}","messagePattern":"tmux new-session failed with (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/lane/src/runtime.rs","lineNumber":783,"sourceCode":"        );\n\n        let mut cmd = tmux_command(&socket);\n        cmd.args([\"new-session\", \"-d\", \"-s\", &session]);\n        if let Some(cwd) = cwd.as_ref() {\n            cmd.arg(\"-c\").arg(cwd);\n        }\n        cmd.arg(shell_cmd);\n        let proposed_record = record.clone();\n        let spawned = std::cell::Cell::new(false);\n        let rolled_back = std::cell::Cell::new(false);\n        match registry.mark_running_if_pending_with(\n            record,\n            || {\n                let status = cmd\n                    .status()\n                    .with_context(|| format!(\"spawn tmux session {session}\"))?;\n                if !status.success() {\n                    bail!(\"tmux new-session failed with {status}\");\n                }\n                spawned.set(true);\n                Ok(())\n            },\n            || {\n                stop_tmux_session(&socket, &session)?;\n                rolled_back.set(true);\n                Ok(())\n            },\n        ) {\n            Ok(true) => {}\n            Ok(false) => {\n                if let Some(path) = environment_path.as_deref() {\n                    remove_file_if_present(path)?;\n                }\n                let mut stopped_record = proposed_record;\n                stopped_record.stopped_at = record.stopped_at.clone();\n                self.cleanup_worktree(&stopped_record)?;","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/lane/src/runtime.rs#L765-L801","documentation":"Inside the registry's mark_running_if_pending_with start closure, TmuxRuntime runs the assembled `tmux new-session ...` synchronously; a nonzero exit bails with the status. The registry's rollback closure then kills the session (if one materialized), so the lane does not linger in a half-spawned state, and the outer error path marks the record Failed and cleans the worktree.","triggerScenarios":"tmux new-session exiting nonzero: session name already exists on that socket, socket directory missing or unwritable, an invalid command string passed through the shell wrapper, or tmux server startup failures.","commonSituations":"Reusing a session name from a previous lane that was not reaped; socket parent directory removed by tmp cleaners; commands with unbalanced quotes built via string concatenation; permissions after a uid change (sudo, container user mismatch).","solutions":["Run the printed-equivalent manually: tmux -S <socket> new-session -d -s <session> '<command>' and read the stderr","Ensure session names are unique per lane (or kill the stale session first)","Verify the socket's parent directory exists and is writable by the current user","Check the command string for quoting/escaping bugs when it was assembled from parts"],"exampleFix":"# before\n# session name reused across runs\nlet session = format!(\"codewhale\");\n\n# after\nlet session = format!(\"codewhale-{lane_id}\");\n# and ensure the socket parent exists\nfs::create_dir_all(socket.parent().unwrap())?;","handlingStrategy":"retry","validationCode":"fn tmux_launch_preconditions_met(socket: &Path, session: &str) -> bool {\n    socket\n        .parent()\n        .map(|p| p.exists())\n        .unwrap_or(false)\n        && !session.is_empty()\n        && session.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')\n}","typeGuard":null,"tryCatchPattern":"match start_result {\n    Err(err) if err.to_string().contains(\"new-session failed\") => {\n        // Inspect manually: tmux -S <socket> new-session -d -s <session> '<cmd>'\n        // Retry once after clearing a stale same-name session if that was the cause.\n    }\n    other => other?,\n}","preventionTips":["Derive session names from lane ids so they cannot collide","Create the socket parent directory before start and keep it writable","Assemble commands as argv vectors, not quoted strings, where possible"],"tags":["rust","lane","tmux","spawn","external-process"],"backgroundTag":"process-spawn-failed","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}