hotfix: use NUL-delimited IPC for dispatch command builder#654
hotfix: use NUL-delimited IPC for dispatch command builder#654marcusquinn merged 2 commits intomainfrom
Conversation
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.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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)
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. Comment |
Summary of ChangesHello @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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Sun Feb 8 19:50:17 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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
- 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)
| 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") |
There was a problem hiding this comment.
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.
| 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
- Using
mapfileorreadarrayis a modern bash best practice for reading command output or file content directly into an array, replacing more verbosewhile readloops.



Summary
Root Cause (deeper than #653)
PR #653 fixed the
bash -cquoting issue but missed the upstream problem:build_dispatch_cmd()outputs arguments viaecho(newline-delimited), andcmd_dispatch()reads them withwhile IFS= read -r. When the prompt contains newlines (from worker restrictions, memory context),read -rsplits the single prompt argument into multiple array elements.Example: a prompt like:
Was being split into 4 separate arguments instead of 1, causing
opencode runto misparse the command.Fix
build_dispatch_cmd(): Replaceechowithprintf '%s\0'(NUL-delimited output)cmd_dispatch(): Replaceread -rwithread -r -d ''(NUL-delimited input)NUL bytes cannot appear in shell strings, making them the only safe delimiter for arbitrary content including newlines.
Verification
$'...\n...'quoted argumentImpact
This unblocks the entire
self-improvement-02batch (t175-t178, t166) which has been failing since the t173 worker restrictions were added.