Skip to content

Commit 1e7958b

Browse files
committed
fix: avoid interrupting busy agent during watcher escalation
1 parent 205c1af commit 1e7958b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

scripts/inbox_watcher.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,11 @@ agent_has_self_watch() {
387387
# Returns 0 (true) if agent is busy, 1 if idle.
388388
agent_is_busy() {
389389
local pane_content
390-
pane_content=$(timeout 2 tmux capture-pane -t "$PANE_TARGET" -p 2>/dev/null | tail -15)
390+
# NOTE: Capture more lines to reduce false-idle detection (status line can scroll).
391+
pane_content=$(timeout 2 tmux capture-pane -t "$PANE_TARGET" -p 2>/dev/null | tail -60)
391392
# Codex CLI: "Working", "Thinking", "Planning", "Sending"
392393
# Claude CLI: thinking spinner, tool execution
393-
if echo "$pane_content" | grep -qiE '(Working|Thinking|Planning|Sending|esc to interrupt)'; then
394+
if echo "$pane_content" | grep -qiE '(Working|Thinking|Planning|Sending|task is in progress|esc to interrupt|Compacting conversation|思考中|考え中|計画中|送信中|処理中|実行中)'; then
394395
return 0 # busy
395396
fi
396397
return 1 # idle
@@ -556,6 +557,15 @@ for s in data.get('specials', []):
556557
local now
557558
now=$(date +%s)
558559

560+
# When the agent is busy/thinking, do NOT escalate. Interrupting with Escape or /clear
561+
# can terminate the current thought. Also pause the escalation timer while busy so we
562+
# don't immediately jump to Phase 2/3 once it becomes idle.
563+
if agent_is_busy; then
564+
FIRST_UNREAD_SEEN=$now
565+
echo "[$(date)] $normal_count unread for $AGENT_ID but agent is busy — pausing escalation timer" >&2
566+
return 0
567+
fi
568+
559569
# Track when we first saw unread messages
560570
if [ "$FIRST_UNREAD_SEEN" -eq 0 ]; then
561571
FIRST_UNREAD_SEEN=$now

0 commit comments

Comments
 (0)