-
Notifications
You must be signed in to change notification settings - Fork 8
hotfix: fix dispatch command breaking on multi-line prompts #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
|
|
||||||
| local worker_pid=$! | ||||||
|
|
@@ -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 & | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The temporary
Suggested change
References
|
||||||
| local worker_pid=$! | ||||||
| disown "$worker_pid" 2>/dev/null || true | ||||||
|
|
||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newly created
dispatch_scriptis not removed after execution. This will lead to an accumulation of script files in thepidsdirectory 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.References
trapcleanup. 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)