t274: Fix decomposition worker dispatch to use standard CLI and process patterns#1066
t274: Fix decomposition worker dispatch to use standard CLI and process patterns#1066marcusquinn merged 1 commit intomainfrom
Conversation
…tion worker (t274) - Replace hardcoded "Claude" CLI with resolve_ai_cli() for opencode/claude support - Add PID-based throttle to prevent duplicate decomposition workers per pulse - Use nohup/setsid dispatch + wrapper scripts matching cmd_dispatch() pattern - Fix metadata concatenation to handle empty metadata (avoids leading comma) - Improve subtask detection regex to include cancelled [-] checkbox state - Add explicit PLANS.md edit restriction to decomposition worker prompt
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
WalkthroughThe change introduces a robust, throttled decomposition worker dispatch system in the supervisor helper script. It adds PID-based throttling to prevent concurrent workers, dynamic AI CLI resolution with fallback logic, script-based dispatch pattern replacement, and enhanced process lifecycle tracking with improved logging and monitoring across decomposition workflows. Changes
Sequence DiagramsequenceDiagram
participant Supervisor as Supervisor<br/>Helper
participant PIDMgr as PID File<br/>Manager
participant CLIRes as AI CLI<br/>Resolver
participant Dispatcher as Dispatch<br/>Script Gen
participant Wrapper as Wrapper<br/>Script Gen
participant Launcher as Process<br/>Launcher
participant DB as Task<br/>Database
Supervisor->>PIDMgr: Check for existing {task_id}-decompose.pid
alt PID exists & valid
PIDMgr-->>Supervisor: PID is alive, log already running
Supervisor->>Supervisor: Skip decomposition (throttled)
else PID stale/missing
PIDMgr-->>Supervisor: Ready to dispatch
Supervisor->>CLIRes: resolve_ai_cli() — pick opencode or claude
CLIRes-->>Supervisor: Return selected AI CLI
Supervisor->>Dispatcher: Create dispatch script<br/>with selected CLI + formatted prompt
Dispatcher-->>Supervisor: Dispatch script created at pids/{task_id}-decompose-dispatch.sh
Supervisor->>Wrapper: Create wrapper script<br/>to manage child, log exit codes, cleanup
Wrapper-->>Supervisor: Wrapper script created at pids/{task_id}-decompose-wrapper.sh
Supervisor->>Launcher: Launch wrapper via nohup + setsid<br/>with disown + background tracking
Launcher-->>Supervisor: Worker PID obtained
Supervisor->>PIDMgr: Store worker PID in {task_id}-decompose.pid
PIDMgr-->>Supervisor: PID file updated
Supervisor->>DB: Update task metadata with decomposition worker PID
DB-->>Supervisor: Metadata committed
Supervisor->>Supervisor: Log dispatch details & monitor
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
🔍 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: Wed Feb 11 03:02:54 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @.agents/scripts/supervisor-helper.sh:
- Around line 12713-12716: The script is passing a --metadata flag to cmd_add
(and updating tasks.metadata) which fails because cmd_add rejects unknown flags
and the metadata column may not exist; remove the --metadata usage on cmd_add
and instead persist the plan_anchor/decomposition_worker_pid via a separate DB
update after cmd_add returns (use the existing db function and sql_escape with
the task id and worker PID), or if you prefer to keep metadata semantics add a
DB migration to create the metadata column and add --metadata handling in
cmd_add; update the code paths referencing decomposition_worker_pid (the db
"UPDATE tasks SET metadata = ..." block and any cmd_add invocations) to follow
the chosen approach.
- Around line 12546-12551: The code reads the PID file using cat which triggers
ShellCheck SC2002; instead, read the PID into existing_pid without using cat by
using shell builtins (e.g., read or filename expansion) where the variable
pid_file and the existing_pid assignment occur; update the block that creates
pid_file and checks kill -0 "$existing_pid" to populate existing_pid via read or
$(<"$pid_file") so ShellCheck no longer flags a useless cat.
🧹 Nitpick comments (1)
.agents/scripts/supervisor-helper.sh (1)
12677-12696: Consider recursive cleanup to avoid orphaned grandchildren.The wrapper only terminates direct children; opencode/CLI stacks can spawn nested processes. Mirroring the recursive cleanup used in
cmd_dispatchwould tighten reliability and keep the process tree clean.
| # Check for already-running decomposition worker (throttle) | ||
| local pid_file="$SUPERVISOR_DIR/pids/${task_id}-decompose.pid" | ||
| if [[ -f "$pid_file" ]]; then | ||
| local existing_pid | ||
| existing_pid=$(cat "$pid_file" 2>/dev/null || true) | ||
| if [[ -n "$existing_pid" ]] && kill -0 "$existing_pid" 2>/dev/null; then |
There was a problem hiding this comment.
Avoid SC2002 by reading the PID file without cat.
This line will trip ShellCheck’s “useless cat” warning. Keep the A‑grade by using read or $(<file) instead.
As per coding guidelines: Run ShellCheck with zero violations on all scripts in .agents/scripts/.
🧹 ShellCheck‑clean PID read
- existing_pid=$(cat "$pid_file" 2>/dev/null || true)
+ if ! read -r existing_pid < "$pid_file"; then
+ existing_pid=""
+ fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Check for already-running decomposition worker (throttle) | |
| local pid_file="$SUPERVISOR_DIR/pids/${task_id}-decompose.pid" | |
| if [[ -f "$pid_file" ]]; then | |
| local existing_pid | |
| existing_pid=$(cat "$pid_file" 2>/dev/null || true) | |
| if [[ -n "$existing_pid" ]] && kill -0 "$existing_pid" 2>/dev/null; then | |
| # Check for already-running decomposition worker (throttle) | |
| local pid_file="$SUPERVISOR_DIR/pids/${task_id}-decompose.pid" | |
| if [[ -f "$pid_file" ]]; then | |
| local existing_pid | |
| if ! read -r existing_pid < "$pid_file"; then | |
| existing_pid="" | |
| fi | |
| if [[ -n "$existing_pid" ]] && kill -0 "$existing_pid" 2>/dev/null; then |
🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 12546 - 12551, The code
reads the PID file using cat which triggers ShellCheck SC2002; instead, read the
PID into existing_pid without using cat by using shell builtins (e.g., read or
filename expansion) where the variable pid_file and the existing_pid assignment
occur; update the block that creates pid_file and checks kill -0 "$existing_pid"
to populate existing_pid via read or $(<"$pid_file") so ShellCheck no longer
flags a useless cat.
| # Update task metadata with worker PID | ||
| local escaped_id | ||
| escaped_id=$(sql_escape "$task_id") | ||
| db "$SUPERVISOR_DB" "UPDATE tasks SET metadata = CASE WHEN metadata IS NULL OR metadata = '' THEN 'decomposition_worker_pid=$worker_pid' ELSE metadata || ',decomposition_worker_pid=$worker_pid' END WHERE id = '$escaped_id';" 2>/dev/null || true |
There was a problem hiding this comment.
Auto‑pickup will fail: cmd_add doesn’t accept --metadata (and tasks.metadata isn’t in schema).
cmd_add’s option parser rejects unknown flags, so the #plan auto‑pickup path exits early and never dispatches the decomposition worker. Also, UPDATE tasks SET metadata=... will fail silently if the column doesn’t exist.
Fix by either:
- Adding
--metadatasupport + ametadatacolumn/migration, or - Removing the flag and persisting plan_anchor via an existing field or a dedicated update after
cmd_add.
Also applies to: 12895-12903
🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 12713 - 12716, The script
is passing a --metadata flag to cmd_add (and updating tasks.metadata) which
fails because cmd_add rejects unknown flags and the metadata column may not
exist; remove the --metadata usage on cmd_add and instead persist the
plan_anchor/decomposition_worker_pid via a separate DB update after cmd_add
returns (use the existing db function and sql_escape with the task id and worker
PID), or if you prefer to keep metadata semantics add a DB migration to create
the metadata column and add --metadata handling in cmd_add; update the code
paths referencing decomposition_worker_pid (the db "UPDATE tasks SET metadata =
..." block and any cmd_add invocations) to follow the chosen approach.



Summary
Fixes the decomposition worker dispatch (t274) to use the standard CLI resolution and process management patterns, addressing issues found in the initial implementation merged via PR #1060.
Changes
dispatch_decomposition_worker() improvements:
Claude(capital C) withresolve_ai_cli()— supportsopencode(primary) andclaude(deprecated fallback)nohup/setsidmatchingcmd_dispatch()pattern for proper background process managementCASE WHENSQL to handle empty metadata (avoids leading comma frommetadata || ',')PLANS.mdedit restriction and#### Phasessection hintStrategy 3 subtask detection:
[-]checkbox state in subtask detection (was only matching[ ],[x],[X])Testing
bash -n): PASSbuild_dispatch_cmd()output formatRelated
cmd_dispatch()(line 5099)resolve_ai_cli()(line 3436) for CLI detectionSummary by CodeRabbit
Bug Fixes
New Features