Skip to content
Merged
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
33 changes: 29 additions & 4 deletions .agents/scripts/supervisor-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3113,20 +3113,34 @@ cmd_dispatch() {
# This ensures headless mode even if the AI doesn't parse --headless from the prompt
local headless_env="FULL_LOOP_HEADLESS=true"

# Write dispatch script to a temp file to avoid bash -c quoting issues
# with multi-line prompts (newlines in printf '%q' break bash -c strings)
local dispatch_script="${SUPERVISOR_DIR}/pids/${task_id}-dispatch.sh"
{
echo '#!/usr/bin/env bash'
echo "cd '${worktree_path}' || exit 1"
echo "export ${headless_env}"
# Write each cmd_part as a properly quoted array element
printf 'exec '
printf '%q ' "${cmd_parts[@]}"
printf '\n'
} > "$dispatch_script"
chmod +x "$dispatch_script"

if [[ "$dispatch_mode" == "tabby" ]]; then
# Tabby: attempt to open in a new tab via OSC 1337 escape sequence
log_info "Opening Tabby tab for $task_id..."
local tab_cmd
tab_cmd="cd '${worktree_path}' && ${headless_env} ${cmd_parts[*]} > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'"
tab_cmd="'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'"
printf '\e]1337;NewTab=%s\a' "$tab_cmd" 2>/dev/null || true
# Also start background process as fallback (Tabby may not support OSC 1337)
# Use nohup + disown to survive parent (cron) exit
nohup bash -c "cd '${worktree_path}' && export ${headless_env} && $(printf '%q ' "${cmd_parts[@]}") > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
nohup bash -c "'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
else
# Headless: background process
# Use nohup + disown to survive parent (cron) exit — without this,
# workers die after ~2 minutes when the cron pulse script exits
nohup bash -c "cd '${worktree_path}' && export ${headless_env} && $(printf '%q ' "${cmd_parts[@]}") > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
nohup bash -c "'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
fi
Comment on lines 3130 to 3144

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The newly created dispatch_script is not removed after execution. This will lead to an accumulation of script files in the pids directory over time. The repository style guide requires that temporary files are cleaned up.

To address this, I suggest appending a cleanup command (rm -f '${dispatch_script}') to the commands that execute the script.

Suggested change
if [[ "$dispatch_mode" == "tabby" ]]; then
# Tabby: attempt to open in a new tab via OSC 1337 escape sequence
log_info "Opening Tabby tab for $task_id..."
local tab_cmd
tab_cmd="cd '${worktree_path}' && ${headless_env} ${cmd_parts[*]} > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'"
tab_cmd="'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'"
printf '\e]1337;NewTab=%s\a' "$tab_cmd" 2>/dev/null || true
# Also start background process as fallback (Tabby may not support OSC 1337)
# Use nohup + disown to survive parent (cron) exit
nohup bash -c "cd '${worktree_path}' && export ${headless_env} && $(printf '%q ' "${cmd_parts[@]}") > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
nohup bash -c "'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
else
# Headless: background process
# Use nohup + disown to survive parent (cron) exit — without this,
# workers die after ~2 minutes when the cron pulse script exits
nohup bash -c "cd '${worktree_path}' && export ${headless_env} && $(printf '%q ' "${cmd_parts[@]}") > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
nohup bash -c "'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'" &>/dev/null &
fi
if [[ "$dispatch_mode" == "tabby" ]]; then
# Tabby: attempt to open in a new tab via OSC 1337 escape sequence
log_info "Opening Tabby tab for $task_id..."
local tab_cmd
tab_cmd="'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'; rm -f '${dispatch_script}'"
printf '\e]1337;NewTab=%s\a' "$tab_cmd" 2>/dev/null || true
# Also start background process as fallback (Tabby may not support OSC 1337)
# Use nohup + disown to survive parent (cron) exit
nohup bash -c "'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'; rm -f '${dispatch_script}'" &>/dev/null &
else
# Headless: background process
# Use nohup + disown to survive parent (cron) exit — without this,
# workers die after ~2 minutes when the cron pulse script exits
nohup bash -c "'${dispatch_script}' > '${log_file}' 2>&1; echo \"EXIT:\$?\" >> '${log_file}'; rm -f '${dispatch_script}'" &>/dev/null &
fi
References
  1. Rule feat: add /session-review and /full-loop commands for comprehensive AI workflow #33 states that temporary files must have a trap cleanup. While a trap is not directly applicable here due to the background process, the principle of cleaning up temporary files still applies. The generated dispatch scripts are temporary and should be removed after use. (link)


local worker_pid=$!
Expand Down Expand Up @@ -3787,8 +3801,19 @@ Task description: ${tdesc:-$task_id}"
# Ensure PID directory exists
mkdir -p "$SUPERVISOR_DIR/pids"

# Write dispatch script to avoid bash -c quoting issues with multi-line prompts
local dispatch_script="${SUPERVISOR_DIR}/pids/${task_id}-reprompt.sh"
{
echo '#!/usr/bin/env bash'
echo "cd '${work_dir}' || exit 1"
printf 'exec '
printf '%q ' "${cmd_parts[@]}"
printf '\n'
} > "$dispatch_script"
chmod +x "$dispatch_script"

# Use nohup + disown to survive parent (cron) exit
nohup bash -c "cd '${work_dir}' && $(printf '%q ' "${cmd_parts[@]}") > '${new_log_file}' 2>&1; echo \"EXIT:\$?\" >> '${new_log_file}'" &>/dev/null &
nohup bash -c "'${dispatch_script}' > '${new_log_file}' 2>&1; echo \"EXIT:\$?\" >> '${new_log_file}'" &>/dev/null &

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The temporary dispatch_script created for reprompting is not cleaned up after execution, which violates the style guide rule for temporary files. This will cause script files to accumulate in the pids directory.

Suggested change
nohup bash -c "'${dispatch_script}' > '${new_log_file}' 2>&1; echo \"EXIT:\$?\" >> '${new_log_file}'" &>/dev/null &
nohup bash -c "'${dispatch_script}' > '${new_log_file}' 2>&1; echo \"EXIT:\$?\" >> '${new_log_file}'; rm -f '${dispatch_script}'" &>/dev/null &
References
  1. Rule feat: add /session-review and /full-loop commands for comprehensive AI workflow #33 states that temporary files must have a trap cleanup. The principle of cleaning up temporary files applies here. The generated dispatch scripts are temporary and should be removed after use. (link)

local worker_pid=$!
disown "$worker_pid" 2>/dev/null || true

Expand Down
Loading