Skip to content

Commit fd63a6f

Browse files
Baudbotbenvinegar
authored andcommitted
refactor: use baudbot- prefix for scalable tmux cleanup
Replace per-session cleanup with prefix-based pattern. Now adding new tmux sessions requires zero cleanup code. ## Changes 1. Rename session: slack-bridge → baudbot-slack-bridge 2. Kill all 'baudbot-*' sessions instead of individual session names ## Scalability Before (not scalable): • Add new tmux session → add new kill-session command • O(n) cleanup code per session After (scalable): • Add new tmux session with baudbot- prefix • Zero additional cleanup code needed • O(1) regardless of number of sessions ## Pattern All agent tmux sessions use 'baudbot-' prefix: - baudbot-slack-bridge (Slack integration) - baudbot-metrics (future: metrics collection) - baudbot-health-monitor (future: health checks) - etc. One command kills them all: tmux list-sessions -F '#{session_name}' | grep '^baudbot-' | xargs tmux kill-session -t ## Hybrid Approach - Most services: killed via PGID (automatic, zero code) - Tmux sessions: killed via prefix pattern (scalable, minimal code) This combines the best of both: automatic cleanup for regular processes, convention-based cleanup for tmux (which escapes PGID due to setsid).
1 parent b366a29 commit fd63a6f

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

pi/skills/control-agent/startup-pi.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ fi
8686
BRIDGE_LOG_DIR="$HOME/.pi/agent/logs"
8787
BRIDGE_LOG_FILE="$BRIDGE_LOG_DIR/slack-bridge.log"
8888
BRIDGE_DIR="/opt/baudbot/current/slack-bridge"
89-
BRIDGE_TMUX_SESSION="slack-bridge"
89+
BRIDGE_TMUX_SESSION="baudbot-slack-bridge"
9090

9191
mkdir -p "$BRIDGE_LOG_DIR"
9292

93-
9493
# --- Detect bridge mode ---
9594
BRIDGE_SCRIPT=""
9695
if [ -f "$BRIDGE_DIR/broker-bridge.mjs" ] && varlock run --path "$HOME/.config/" -- sh -c '
@@ -127,10 +126,14 @@ fi
127126
# termination. We need to explicitly kill old sessions before creating new ones.
128127
MAX_CONSECUTIVE_FAILURES=10
129128

130-
# Kill old tmux session if it exists (tmux sessions have their own PGID)
131-
if tmux has-session -t "$BRIDGE_TMUX_SESSION" 2>/dev/null; then
132-
echo "Killing old tmux session: $BRIDGE_TMUX_SESSION"
133-
tmux kill-session -t "$BRIDGE_TMUX_SESSION" 2>/dev/null || true
129+
# Kill all agent tmux sessions (prefix: baudbot-*)
130+
# Tmux sessions create their own PGID, so they survive process group cleanup.
131+
# Using a naming convention allows us to kill all agent sessions without
132+
# tracking individual session names.
133+
AGENT_SESSIONS=$(tmux list-sessions -F '#{session_name}' 2>/dev/null | grep '^baudbot-' || true)
134+
if [ -n "$AGENT_SESSIONS" ]; then
135+
echo "Killing agent tmux sessions: $AGENT_SESSIONS"
136+
echo "$AGENT_SESSIONS" | xargs -r -I{} tmux kill-session -t {} 2>/dev/null || true
134137
sleep 1
135138
fi
136139

0 commit comments

Comments
 (0)