mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-03 05:59:43 +02:00
fix: detect stale tmux sessions on startInteractive/startShell
When Claude exits inside a tmux session, tmux destroys the session (remain-on-exit is off), but the _muxSession reference persists. On restart, startInteractive() treats it as a "restored session" and tries to attach to the dead tmux — causing instant exit code 1. Now checks tmux has-session before attaching. If the session is gone, clears the stale reference and creates a fresh tmux session. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -155,4 +155,7 @@ export interface TerminalMultiplexer extends EventEmitter {
|
||||
|
||||
/** Check if the multiplexer binary is available on the system */
|
||||
isAvailable(): boolean;
|
||||
|
||||
/** Check if a multiplexer session actually exists (process-level check, not just tracked) */
|
||||
muxSessionExists(muxName: string): boolean;
|
||||
}
|
||||
|
||||
@@ -849,6 +849,12 @@ export class Session extends EventEmitter {
|
||||
// If mux wrapping is enabled, create or attach to a mux session
|
||||
if (this._useMux && this._mux) {
|
||||
try {
|
||||
// Verify stale mux session — tmux destroys session when command exits
|
||||
// (remain-on-exit is off), but _muxSession reference persists
|
||||
if (this._muxSession && !this._mux.muxSessionExists(this._muxSession.muxName)) {
|
||||
console.log('[Session] Stale mux session detected (tmux gone):', this._muxSession.muxName);
|
||||
this._muxSession = null;
|
||||
}
|
||||
// Check if we already have a mux session (restored session)
|
||||
const isRestoredSession = this._muxSession !== null;
|
||||
if (isRestoredSession) {
|
||||
@@ -1128,6 +1134,11 @@ export class Session extends EventEmitter {
|
||||
// If mux wrapping is enabled, create or attach to a mux session
|
||||
if (this._useMux && this._mux) {
|
||||
try {
|
||||
// Verify stale mux session — tmux destroys session when command exits
|
||||
if (this._muxSession && !this._mux.muxSessionExists(this._muxSession.muxName)) {
|
||||
console.log('[Session] Stale mux session detected (tmux gone):', this._muxSession.muxName);
|
||||
this._muxSession = null;
|
||||
}
|
||||
// Check if we already have a mux session (restored session)
|
||||
const isRestoredSession = this._muxSession !== null;
|
||||
if (isRestoredSession) {
|
||||
|
||||
@@ -348,6 +348,10 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
|
||||
/**
|
||||
* Check if a tmux session exists.
|
||||
*/
|
||||
muxSessionExists(muxName: string): boolean {
|
||||
return this.sessionExists(muxName);
|
||||
}
|
||||
|
||||
private sessionExists(muxName: string): boolean {
|
||||
if (IS_TEST_MODE) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user