Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/changed-15330.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- chore(crux): move tmux session accessors out of manager.go (#15330)
38 changes: 0 additions & 38 deletions src/crux/agent/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1637,44 +1637,6 @@ func (m *Manager) GetOutput(name string, lines int) ([]string, error) {
return nil, nil
}

// SessionMissing reports whether an agent the manager believes is RUNNING has
// no live tmux session β€” the zombie case, where in-memory state and reality
// have diverged.
//
// It is deliberately false for any agent that is not StateRunning: a paused,
// stopped or never-started agent legitimately has no session, and reporting
// those as missing would turn every deliberate pause into a fault.
//
// The session check must go through the agent's OWN tmux socket. Each agent
// runs under its own UID on its own socket (e.g. /tmp/tmux-2007/hive-scanner),
// so a query against the default socket answers "no server running" even when
// every session is alive β€” the exact false reading that has sent live
// diagnosis down the wrong path.
func (m *Manager) SessionMissing(name string) bool {
m.mu.RLock()
agent, ok := m.agents[name]
if !ok || agent.State != StateRunning || agent.Paused {
m.mu.RUnlock()
return false
}
m.mu.RUnlock()
// The exec runs outside the lock: it shells out to tmux, and holding a
// manager lock across a subprocess is how the startup path has deadlocked
// before.
return !m.tmuxSessionExistsForAgent(agent)
}

func (m *Manager) TmuxSession(name string) string {
m.mu.RLock()
defer m.mu.RUnlock()

agent, ok := m.agents[name]
if !ok {
return ""
}
return agent.tmuxSession
}

func (m *Manager) bobPreflightUnlocked(agent *AgentProcess) {
if agent == nil {
return
Expand Down
38 changes: 38 additions & 0 deletions src/crux/agent/manager_tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,3 +666,41 @@ const attachedClientIdleGrace = 30 * time.Minute
func (t tmuxTerminal) SleepDuringPromptDismiss(d time.Duration) {
time.Sleep(d)
}

// SessionMissing reports whether an agent the manager believes is RUNNING has
// no live tmux session β€” the zombie case, where in-memory state and reality
// have diverged.
//
// It is deliberately false for any agent that is not StateRunning: a paused,
// stopped or never-started agent legitimately has no session, and reporting
// those as missing would turn every deliberate pause into a fault.
//
// The session check must go through the agent's OWN tmux socket. Each agent
// runs under its own UID on its own socket (e.g. /tmp/tmux-2007/hive-scanner),
// so a query against the default socket answers "no server running" even when
// every session is alive β€” the exact false reading that has sent live
// diagnosis down the wrong path.
func (m *Manager) SessionMissing(name string) bool {
m.mu.RLock()
agent, ok := m.agents[name]
if !ok || agent.State != StateRunning || agent.Paused {
m.mu.RUnlock()
return false
}
m.mu.RUnlock()
// The exec runs outside the lock: it shells out to tmux, and holding a
// manager lock across a subprocess is how the startup path has deadlocked
// before.
return !m.tmuxSessionExistsForAgent(agent)
}

func (m *Manager) TmuxSession(name string) string {
m.mu.RLock()
defer m.mu.RUnlock()

agent, ok := m.agents[name]
if !ok {
return ""
}
return agent.tmuxSession
}
Loading