Skip to content

hotfix: use NUL-delimited IPC for dispatch command builder#654

Merged
marcusquinn merged 2 commits intomainfrom
hotfix/dispatch-null-delim
Feb 8, 2026
Merged

hotfix: use NUL-delimited IPC for dispatch command builder#654
marcusquinn merged 2 commits intomainfrom
hotfix/dispatch-null-delim

Conversation

@marcusquinn
Copy link
Owner

Summary

Root Cause (deeper than #653)

PR #653 fixed the bash -c quoting issue but missed the upstream problem: build_dispatch_cmd() outputs arguments via echo (newline-delimited), and cmd_dispatch() reads them with while IFS= read -r. When the prompt contains newlines (from worker restrictions, memory context), read -r splits the single prompt argument into multiple array elements.

Example: a prompt like:

/full-loop t175 --headless -- Fix bug

## MANDATORY Worker Restrictions
- Do NOT edit TODO.md

Was being split into 4 separate arguments instead of 1, causing opencode run to misparse the command.

Fix

  • build_dispatch_cmd(): Replace echo with printf '%s\0' (NUL-delimited output)
  • cmd_dispatch(): Replace read -r with read -r -d '' (NUL-delimited input)

NUL bytes cannot appear in shell strings, making them the only safe delimiter for arbitrary content including newlines.

Verification

  • Simulated dispatch with multi-line prompt: 7 parts (correct), prompt is single argument with 4 lines
  • Generated dispatch script: valid bash syntax, prompt is single $'...\n...' quoted argument
  • ShellCheck: zero violations
  • All 78 supervisor state machine tests pass

Impact

This unblocks the entire self-improvement-02 batch (t175-t178, t166) which has been failing since the t173 worker restrictions were added.

build_dispatch_cmd() used echo (newline-delimited) to pass arguments
back to cmd_dispatch(), but multi-line prompts (worker restrictions,
memory context) caused read -r to split a single prompt argument into
multiple array elements. Workers received the prompt as many separate
positional args instead of one, causing opencode to misparse and exit
with help text.

Fix: use printf '%s\0' (NUL-delimited) output and read -r -d '' to
preserve multi-line strings as single arguments through the IPC
boundary.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hotfix/dispatch-null-delim

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a crucial hotfix to address a systemic issue preventing AI workers from executing commands correctly. The core problem stemmed from how multi-line prompts were being interpreted, leading to command parsing errors and worker failures. By refining the internal communication protocol to robustly handle complex prompt structures, this change restores the stability of the supervisor dispatch system and enables the progression of several blocked development initiatives.

Highlights

  • Critical Bug Fix: Resolves the root cause of supervisor-dispatched workers failing due to multi-line prompts being incorrectly parsed as multiple arguments.
  • IPC Mechanism Update: Switches from newline-delimited echo and read -r to NUL-delimited printf '%s\0' and read -r -d '' for inter-process communication (IPC) in command dispatch.
  • Prompt Handling: Ensures that multi-line prompts are correctly treated as a single argument, preventing malformed commands and worker failures.
  • Unblocks Development: Unblocks the entire self-improvement-02 batch (t175-t178, t166) which was previously failing due to this issue.
Changelog
  • .agents/scripts/supervisor-helper.sh
    • Replaced echo with printf '%s\0' in build_dispatch_cmd to output NUL-delimited arguments.
    • Replaced read -r with read -r -d '' in cmd_dispatch to correctly read NUL-delimited arguments.
    • Added comments to clarify the NUL-delimited IPC implementation.
  • TODO.md
    • Updated the note for task t175 to indicate it was blocked by the 'Re-prompt dispatch failed: ambiguous_skipped_ai' issue.
Activity
  • This pull request is a hotfix addressing a critical bug that caused supervisor-dispatched workers to fail.
  • It identifies and resolves a deeper root cause than a previous attempt (PR hotfix: fix dispatch command breaking on multi-line prompts #653) by focusing on IPC delimitation.
  • The author has provided detailed verification, including simulated dispatch, generated script validation, ShellCheck, and confirmation that all 78 supervisor state machine tests pass.
  • The successful implementation of this fix unblocks significant progress on the self-improvement-02 batch of tasks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 37 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Feb 8 19:50:14 UTC 2026: Code review monitoring started
Sun Feb 8 19:50:15 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 37

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 37
  • VULNERABILITIES: 0

Generated on: Sun Feb 8 19:50:17 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 8, 2026

@marcusquinn marcusquinn merged commit 1442764 into main Feb 8, 2026
11 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a critical bug where multi-line prompts were being split into multiple arguments. The switch to NUL-delimited IPC between build_dispatch_cmd and cmd_dispatch is a robust solution. I've provided a couple of suggestions to refactor the new code for improved clarity, maintainability, and conciseness by using more idiomatic bash constructs.

Comment on lines 2599 to 2622
if [[ "$ai_cli" == "opencode" ]]; then
echo "opencode"
echo "run"
echo "--format"
echo "json"
printf '%s\0' "opencode"
printf '%s\0' "run"
printf '%s\0' "--format"
printf '%s\0' "json"
if [[ -n "$model" ]]; then
echo "-m"
echo "$model"
printf '%s\0' "-m"
printf '%s\0' "$model"
fi
echo "--title"
echo "$task_id"
echo "$prompt"
printf '%s\0' "--title"
printf '%s\0' "$task_id"
printf '%s\0' "$prompt"
else
# claude CLI
echo "claude"
echo "-p"
echo "$prompt"
printf '%s\0' "claude"
printf '%s\0' "-p"
printf '%s\0' "$prompt"
if [[ -n "$model" ]]; then
echo "--model"
echo "$model"
printf '%s\0' "--model"
printf '%s\0' "$model"
fi
echo "--output-format"
echo "json"
printf '%s\0' "--output-format"
printf '%s\0' "json"
fi

Choose a reason for hiding this comment

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

medium

This block contains a number of repetitive printf calls. To improve readability and maintainability, you can build an array of command parts first and then print all elements at once with a single printf call. This approach reduces code duplication.

Suggested change
if [[ "$ai_cli" == "opencode" ]]; then
echo "opencode"
echo "run"
echo "--format"
echo "json"
printf '%s\0' "opencode"
printf '%s\0' "run"
printf '%s\0' "--format"
printf '%s\0' "json"
if [[ -n "$model" ]]; then
echo "-m"
echo "$model"
printf '%s\0' "-m"
printf '%s\0' "$model"
fi
echo "--title"
echo "$task_id"
echo "$prompt"
printf '%s\0' "--title"
printf '%s\0' "$task_id"
printf '%s\0' "$prompt"
else
# claude CLI
echo "claude"
echo "-p"
echo "$prompt"
printf '%s\0' "claude"
printf '%s\0' "-p"
printf '%s\0' "$prompt"
if [[ -n "$model" ]]; then
echo "--model"
echo "$model"
printf '%s\0' "--model"
printf '%s\0' "$model"
fi
echo "--output-format"
echo "json"
printf '%s\0' "--output-format"
printf '%s\0' "json"
fi
local -a cmd_parts=()
if [[ "$ai_cli" == "opencode" ]]; then
cmd_parts+=("opencode" "run" "--format" "json")
if [[ -n "$model" ]]; then
cmd_parts+=("-m" "$model")
fi
cmd_parts+=("--title" "$task_id" "$prompt")
else
# claude CLI
cmd_parts+=("claude" "-p" "$prompt")
if [[ -n "$model" ]]; then
cmd_parts+=("--model" "$model")
fi
cmd_parts+=("--output-format" "json")
fi
printf '%s\0' "${cmd_parts[@]}"
References
  1. The style guide recommends using bash arrays for dynamic command construction. While the original rule is to avoid eval, applying the same principle of using arrays here improves code clarity and maintainability. (link)

Comment on lines 3106 to 3109
local -a cmd_parts=()
while IFS= read -r part; do
while IFS= read -r -d '' part; do
cmd_parts+=("$part")
done < <(build_dispatch_cmd "$task_id" "$worktree_path" "$log_file" "$ai_cli" "$memory_context" "$tmodel" "$tdesc")

Choose a reason for hiding this comment

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

medium

The while read loop for populating the cmd_parts array is functional, but a more concise and idiomatic approach in modern bash is to use mapfile (also known as readarray). It's designed for this exact purpose of reading stream data into an array, making the code shorter and more efficient.

Suggested change
local -a cmd_parts=()
while IFS= read -r part; do
while IFS= read -r -d '' part; do
cmd_parts+=("$part")
done < <(build_dispatch_cmd "$task_id" "$worktree_path" "$log_file" "$ai_cli" "$memory_context" "$tmodel" "$tdesc")
local -a cmd_parts
mapfile -d '' -t cmd_parts < <(build_dispatch_cmd "$task_id" "$worktree_path" "$log_file" "$ai_cli" "$memory_context" "$tmodel" "$tdesc")
References
  1. Using mapfile or readarray is a modern bash best practice for reading command output or file content directly into an array, replacing more verbose while read loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant