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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ the in-app updater downloads the `agent-desk_<version>_<os>_<arch>.tar.gz` asset

## [Unreleased]

### Fixed

- The tmux open-file-limit banner no longer says "Close an extra agent-desk window" to a server on the old 256 default. Closing a window only frees descriptors for a moment on a server that stays capped, and assumes you have a second window to close; a server agent-desk started before v1.0.28 (or a plain `tmux` from a shell) keeps 256 until it exits. The banner now says that only a tmux server restart lifts the limit, **and that the restart ends every session** (`R` resumes Claude ones), so the choice stays yours. A roomier server that is merely full still points you to close a window.
- The "tmux server is full" banner knows which kind of server it is. A full server cannot be probed, so the banner used to lose the limit at the moment it mattered; it now uses the last reading that succeeded.

## [1.0.28] - 2026-11-11

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions internal/tmux/pipemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type PipeManager struct {
// probe is cached and debited per pipe, so a batch of connects costs one.
roomMu sync.Mutex
room ServerFiles
lastRoom ServerFiles // the last reading a probe returned without error
roomAt time.Time
roomErr error
skipped map[string]bool // sessions left without a pipe for lack of room
Expand Down Expand Up @@ -444,6 +445,7 @@ func (pm *PipeManager) takeRoom(sessionName string) error {
f, err := pm.probeRoom()
pm.room, pm.roomErr, pm.roomAt = f, err, time.Now()
if err == nil {
pm.lastRoom = f
pipeLog.Debug("tmux_server_files", slog.Int("limit", f.Limit), slog.Int("in_use", f.InUse), slog.Int("pipe_budget", f.PipeBudget()))
}
}
Expand Down Expand Up @@ -484,6 +486,17 @@ func (pm *PipeManager) Room() (ServerFiles, int) {
return pm.room, len(pm.skipped)
}

// LastRoom is the last reading a probe returned without error. A server that
// refuses clients cannot be probed, so Room goes blank exactly when the
// banner most needs to know which class of server it is talking about; the
// limit does not change while a server lives, so the last good one stands.
// Zero when no probe has succeeded yet.
func (pm *PipeManager) LastRoom() ServerFiles {
pm.roomMu.Lock()
defer pm.roomMu.Unlock()
return pm.lastRoom
}

// tmuxSessionExists checks if a tmux session exists (lightweight subprocess).
func tmuxSessionExists(name string) bool {
cmd := exec.Command("tmux", "has-session", "-t", name)
Expand Down
14 changes: 14 additions & 0 deletions internal/tmux/serverfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ func (f ServerFiles) Headroom() int { return f.Limit - f.InUse }
// the ones a few agent-desk windows can fill.
func (f ServerFiles) Low() bool { return f.Limit > 0 && f.Limit < 1024 }

// Relief is the shortest instruction that gives the server room again. A
// server on the old default class (Low) stays capped however many windows
// close, so closing one only buys time; the real fix is to restart it so a
// fresh server inherits agent-desk's raised limit. That restart ends every
// session in the server, so the instruction says so: the banner must not
// send someone to the destructive fix without its cost. A roomier server
// that is merely full answers again the moment a window closes.
func (f ServerFiles) Relief() string {
if f.Low() {
return "Only a tmux server restart lifts its limit, and that ends every session (R resumes Claude ones). Troubleshooting: tmux file limit"
}
return "Close an extra agent-desk window (Troubleshooting: tmux file limit)"
}

// ProbeServerFiles reads the default tmux server's limit (through a shell it
// spawns, which inherits it) and counts its descriptors with lsof.
func ProbeServerFiles() (ServerFiles, error) {
Expand Down
43 changes: 43 additions & 0 deletions internal/tmux/serverfiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,49 @@ func TestPipeBudget(t *testing.T) {
assert.False(t, ServerFiles{Limit: 16384}.Low())
}

// A low-limit (legacy) server is capped no matter how many windows close, so
// its relief is to restart, and the instruction carries what that costs; a
// roomier server that is merely full frees up when a window closes.
func TestRelief(t *testing.T) {
low := ServerFiles{Limit: 256, InUse: 200}.Relief()
assert.Contains(t, low, "tmux server restart")
assert.Contains(t, low, "ends every session")
roomy := ServerFiles{Limit: 16384, InUse: 16000}.Relief()
assert.Contains(t, roomy, "Close an extra agent-desk window")
assert.NotContains(t, roomy, "restart")
assert.Contains(t, ServerFiles{}.Relief(), "Close an extra agent-desk window", "unknown limit: the safe instruction")
}

// A server that refuses clients cannot be probed, and the failed probe blanks
// Room. LastRoom keeps the last good reading so the full-server banner still
// knows it is talking about a low-limit server.
func TestLastRoomSurvivesFailedProbe(t *testing.T) {
pm := NewPipeManager(t.Context(), nil)
defer pm.Close()
fail := false
pm.probeRoom = func() (ServerFiles, error) {
if fail {
return ServerFiles{}, errors.New("server exited unexpectedly")
}
return ServerFiles{PID: 1, Limit: 256, InUse: 100}, nil
}

assert.Equal(t, 0, pm.LastRoom().Limit, "nothing known before a probe")
_ = pm.takeRoom("agentdesk_nope_a")
assert.Equal(t, 256, pm.LastRoom().Limit)

fail = true
pm.roomMu.Lock()
pm.roomAt = time.Time{} // the reading has gone stale
pm.roomMu.Unlock()
_ = pm.takeRoom("agentdesk_nope_b")

room, _ := pm.Room()
assert.Equal(t, 0, room.Limit, "the failed probe blanked the current reading")
assert.True(t, pm.LastRoom().Low(), "the last good reading stands")
assert.Contains(t, pm.LastRoom().Relief(), "tmux server restart")
}

// A server without room for another pipe gets none: Connect refuses before
// spawning a client, and the session is counted as going without.
func TestConnectRefusedWithoutServerRoom(t *testing.T) {
Expand Down
24 changes: 16 additions & 8 deletions internal/ui/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,22 +1321,30 @@ func (h *Home) bannerMsg() string {
// unexpectedly" while the agents keep running (issues #3, #4). Reads only
// cached state, so it is cheap per tick.
func tmuxServerWarning() string {
pm := tmux.GetPipeManager()
var room, known tmux.ServerFiles
skipped := 0
if pm != nil {
room, skipped = pm.Room()
known = pm.LastRoom()
}

// A full server cannot be probed, so room is blank here; the last good
// reading says which class of server it is.
if since, full := tmux.ServerUnreachable(); full {
return fmt.Sprintf("tmux server is full (open-file limit) since %s: agents still running. Close an extra agent-desk window to free it",
since.Format("3:04pm"))
return fmt.Sprintf("tmux server is full (open-file limit) since %s: agents still running. %s",
since.Format("3:04pm"), known.Relief())
}
pm := tmux.GetPipeManager()
if pm == nil {
return ""
}
room, skipped := pm.Room()
if skipped > 0 {
return fmt.Sprintf("tmux server near its open-file limit (%d of %d): %d session(s) without live status. Close an extra agent-desk window (Troubleshooting: tmux file limit)",
room.InUse, room.Limit, skipped)
return fmt.Sprintf("tmux server near its open-file limit (%d of %d): %d session(s) without live status. %s",
room.InUse, room.Limit, skipped, room.Relief())
}
if room.Low() && room.PipeBudget() < pm.ConnectedCount() {
return fmt.Sprintf("tmux server allows only %d open files (%d in use): another agent-desk window won't fit (Troubleshooting: tmux file limit)",
room.Limit, room.InUse)
return fmt.Sprintf("tmux server allows only %d open files (%d in use): another agent-desk window won't fit. %s",
room.Limit, room.InUse, room.Relief())
}
return ""
}
Expand Down