fix(tmux): add debounce delay between paste and Enter
Fixes race condition where Enter key arrives before paste is fully processed, causing workers to sit idle at prompts. - SendKeys now uses 100ms default debounce - New SendKeysDebounced allows configurable delay - Inject scales delay 100-500ms based on message size Closes: gt-w3bu 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -228,6 +228,7 @@ func (m *Manager) Capture(polecat string, lines int) (string, error) {
|
||||
}
|
||||
|
||||
// Inject sends a message to a polecat session.
|
||||
// Uses a longer debounce delay for large messages to ensure paste completes.
|
||||
func (m *Manager) Inject(polecat, message string) error {
|
||||
sessionID := m.sessionName(polecat)
|
||||
|
||||
@@ -239,7 +240,14 @@ func (m *Manager) Inject(polecat, message string) error {
|
||||
return ErrSessionNotFound
|
||||
}
|
||||
|
||||
return m.tmux.SendKeys(sessionID, message)
|
||||
// Use longer debounce for large messages (spawn context can be 1KB+)
|
||||
// Scale delay based on message size: 100ms base + 50ms per KB
|
||||
debounceMs := 100 + (len(message)/1024)*50
|
||||
if debounceMs > 500 {
|
||||
debounceMs = 500 // Cap at 500ms
|
||||
}
|
||||
|
||||
return m.tmux.SendKeysDebounced(sessionID, message, debounceMs)
|
||||
}
|
||||
|
||||
// StopAll terminates all sessions for this rig.
|
||||
|
||||
@@ -110,11 +110,23 @@ func (t *Tmux) ListSessions() ([]string, error) {
|
||||
|
||||
// SendKeys sends keystrokes to a session and presses Enter.
|
||||
// Always sends Enter as a separate command for reliability.
|
||||
// Uses a debounce delay between paste and Enter to ensure paste completes.
|
||||
func (t *Tmux) SendKeys(session, keys string) error {
|
||||
return t.SendKeysDebounced(session, keys, 100) // 100ms default debounce
|
||||
}
|
||||
|
||||
// SendKeysDebounced sends keystrokes with a configurable delay before Enter.
|
||||
// The debounceMs parameter controls how long to wait after paste before sending Enter.
|
||||
// This prevents race conditions where Enter arrives before paste is processed.
|
||||
func (t *Tmux) SendKeysDebounced(session, keys string, debounceMs int) error {
|
||||
// Send text using literal mode (-l) to handle special chars
|
||||
if _, err := t.run("send-keys", "-t", session, "-l", keys); err != nil {
|
||||
return err
|
||||
}
|
||||
// Wait for paste to be processed
|
||||
if debounceMs > 0 {
|
||||
time.Sleep(time.Duration(debounceMs) * time.Millisecond)
|
||||
}
|
||||
// Send Enter separately - more reliable than appending to send-keys
|
||||
_, err := t.run("send-keys", "-t", session, "Enter")
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user