Skip to content

Commit 6a2457f

Browse files
committed
fix: improve tmux script robustness for parallel agents
- Add PID + random suffix to session names to avoid collisions - Clear .last-sent-text on session start to prevent false positive dedup - Add 50ms delay before Enter key for Gemini CLI compatibility
1 parent ac3357d commit 6a2457f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

scripts/tmux/tmux-send.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,24 @@ if [[ "$FORCE_SEND" != true ]] && [[ -f "$LAST_SENT_FILE" ]]; then
233233
fi
234234
fi
235235

236+
# Clear any existing input in the buffer before sending new text
237+
# This prevents concatenation when commands are sent in rapid succession
238+
tmux send-keys -t "$SESSION_NAME" C-u
239+
sleep 0.05
240+
236241
# Send text using bracketed paste mode
237242
# \e[200~ = start bracketed paste
238243
# \e[201~ = end bracketed paste
239244
tmux send-keys -t "$SESSION_NAME" $'\e[200~'"$TEXT"$'\e[201~'
240245

241-
# Optionally press Enter
246+
# Optionally press Enter (with small delay to let TUI apps process the paste first)
242247
if [[ "$AUTO_ENTER" == true ]]; then
248+
sleep 0.05
243249
tmux send-keys -t "$SESSION_NAME" Enter
250+
# Wait for CLI to process Enter and clear input buffer before returning
251+
# This prevents the next send from concatenating with the previous input
252+
# 200ms is needed for slower CLIs like Codex to fully process the command
253+
sleep 0.2
244254
fi
245255

246256
# Log the text send as YAML and update last-sent tracker

scripts/tmux/tmux-start.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ while [[ $# -gt 0 ]]; do
119119
done
120120

121121
# Generate session name if not provided
122+
# Use timestamp + PID + random suffix to avoid collisions when running multiple agents in parallel
122123
if [[ -z "$SESSION_NAME" ]]; then
123-
SESSION_NAME="tui-test-$(date +%s)"
124+
SESSION_NAME="tui-test-$(date +%s)-$$-$RANDOM"
124125
fi
125126

126127
# Check if tmux is available
@@ -182,6 +183,9 @@ fi
182183
SESSION_DIR="$PROJECT_ROOT/debug/tmux-sessions/$SESSION_NAME"
183184
mkdir -p "$SESSION_DIR"
184185

186+
# Clear deduplication state from any previous session with the same name
187+
rm -f "$SESSION_DIR/.last-sent-text"
188+
185189
# Save session info as YAML
186190
cat > "$SESSION_DIR/session-info.yaml" << EOF
187191
session: $SESSION_NAME

0 commit comments

Comments
 (0)