Maestro-orchestrate execution
Phase execution methodology for orchestration workflows with error handling and completion protocols
git clone https://github.com/josstei/maestro-orchestrate
T=$(mktemp -d) && git clone --depth=1 https://github.com/josstei/maestro-orchestrate "$T" && mkdir -p ~/.claude/skills && cp -r "$T/claude/src/skills/shared/execution" ~/.claude/skills/josstei-maestro-orchestrate-execution-0a6f2e && rm -rf "$T"
claude/src/skills/shared/execution/SKILL.mdExecution Skill
Activate this skill during Phase 3 (Execution) of Maestro orchestration. This skill defines how Maestro executes implementation phases through native subagent delegation.
Execution Mode Gate
Step 0 — Express bypass (early return)
If
workflow_mode is express in the current session, STOP HERE. Do not proceed
to the execution mode gate. Do not prompt the user. Do not resolve execution mode.
Express always dispatches sequentially. Return to the Express Workflow and continue
from the delegation step.
<HARD-GATE>
This gate MUST resolve before ANY delegation proceeds. Do not skip it. Do not defer it. Do not begin delegating to subagents until execution_mode is recorded in session state. If you reach a delegation step and execution_mode is not set, STOP and return here.
</HARD-GATE>
Step 1 — Read the configured mode
Read
MAESTRO_EXECUTION_MODE (default: ask).
- If
: callparallel
withupdate_session
to record in session state. Skip to delegation.{ execution_mode: 'parallel', execution_backend: 'native' } - If
: callsequential
withupdate_session
to record in session state. Skip to delegation.{ execution_mode: 'sequential', execution_backend: 'native' } - If
: proceed to Step 2.ask
Step 2 — Analyze the implementation plan
Before prompting the user, analyze the approved plan to generate a recommendation:
-
Count total phases in the plan
-
Count phases marked
(parallelizable phases)parallel: true -
Count distinct parallel batches (groups of parallelizable phases at the same dependency depth)
-
Count sequential-only phases (phases with
dependencies that prevent parallelization)blocked_by -
Cross-check file ownership across all phases. If any two phases share a file in their
arrays, those phases CANNOT be parallel-eligible — subtract them from the parallelizable count. Report each overlap as an Overlapping-file Warning in the prompt.files -
If
was called during planning and returned avalidate_plan
, use itsparallelization_profile
andparallel_eligible
counts as the authoritative source for items 1-5 above. These are computed from actual dependency depths and override any manual flag-based counts. Ifeffective_batches
is not available, use the counts from items 1-5 as-is.parallelization_profile
Record these counts — they feed into the prompt.
Step 3 — Determine the recommendation
- If parallelizable phases ≤ 1 → auto-select sequential. Call
withupdate_session
. Inform the user: "All phases are sequential — no parallel batches available." Skip to delegation. Do NOT prompt with a choice. Do NOT call{ execution_mode: 'sequential', execution_backend: 'native' }
. Do NOT present options. (Parallelism requires at least 2 phases at the same dependency depth; a single parallel-eligible phase has nothing to batch with.)ask_user
When parallelizable phases ≤ 1, there is NO choice to make. Auto-select sequential and skip directly to delegation. Do not show a picker. </ANTI-PATTERN>
- If parallelizable phases > 50% of total phases → recommend parallel
- If parallelizable phases ≤ 50% but > 1 → recommend sequential (limited benefit)
- The recommended option appears first in the
options list with "(Recommended)" appended to its label. The non-recommended option MUST NOT include "(Recommended)" in its label.ask_user
Step 4 — Prompt the user
Call
ask_user with type: 'choice' using exactly one of these option sets:
When recommending parallel: options: - label: "Parallel (Recommended)" description: "Spawn child agents for each ready batch where file ownership does not overlap." - label: "Sequential (High Precision)" description: "Spawn one child agent at a time in dependency order."
When recommending sequential: options: - label: "Sequential (Recommended)" description: "Spawn one child agent at a time in dependency order." - label: "Parallel" description: "Spawn child agents for each ready batch where file ownership does not overlap."
<ANTI-PATTERN> WRONG — Both options labeled "(Recommended)": options: - label: "Parallel (Recommended)" - label: "Sequential (High Precision) (Recommended)"Only ONE option receives the "(Recommended)" suffix. Never both. </ANTI-PATTERN>
Prompt the user for a choice using the user-prompt tool from runtime context. Replace
[N], [M], and [B] with actual counts from Step 2. The prompt should convey the execution mode analysis and offer two options as described above.
Step 5 — Record and proceed
- Call
with the selectedupdate_session
andexecution_modeexecution_backend: native - The tool atomically persists both fields
- Use the selected mode for the remainder of the session unless the user changes it
Mode-specific behavior
- If
is selected and a ready batch has only one phase, execute it sequentiallyparallel - If
is selected, preserve plan order even when phases are parallel-safesequential
Safety fallback
If
execution_mode is not present in session state at the point where delegation is about to begin, STOP. Do not default to sequential. Return to this gate and resolve it. This catches any edge case where the gate was skipped.
State File Access
When MCP state tools (
get_session_status, update_session, transition_phase) are available, prefer them for state operations. They provide structured I/O and atomic transitions.
When MCP tools are not available, state lives inside
<MAESTRO_STATE_DIR> and is accessible through read_file and write_file.
Helper scripts remain available for shell-injected command prompts:
node <runtime-script-root>/read-state.js <relative-path> node <runtime-script-root>/read-active-session.js
Hook Lifecycle During Execution
Hooks fire automatically at agent boundaries. The orchestrator does not invoke them directly.
The hooks system tracks which agent is currently executing. Before each agent dispatch, a hook resolves the active agent identity from the required
Agent: header first, then falls back to legacy env/regex detection, and injects compact session context. After completion, a hook validates that the response contains both Task Report and Downstream Context; it requests one retry on the first malformed response.
The hook state directory under
/tmp/maestro-hooks/<session-id>/ is transient and separate from orchestration state.
Sequential Execution Protocol
For a sequential phase:
- Verify all
dependencies are completedblocked_by - Mark the phase
in_progress - Update
current_phase - Set
current_batch: null - Update the progress-tracking tool (use the tool names from
) before delegationget_runtime_context - Delegate to the assigned agent with the required header and full context
- Parse the returned handoff
- Update session state
- Mark the phase
orcompletedfailed - Update the progress-tracking tool after the state update
Native Parallel Execution Protocol
Use native parallel execution only for sibling phases at the same dependency depth with non-overlapping file ownership.
Batch Rules
- Verify all blocking phases for every phase in the batch are completed
- Slice the ready batch into the current dispatch chunk using
MAESTRO_MAX_CONCURRENT - Mark only the current chunk phases
in_progress - Set
in session state for that chunkcurrent_batch - Write one in-progress todo item for the chunk
- In the next turn, emit only agent tool calls for that chunk
- Do not mix shell commands, validation commands, file writes, or narration between those agent calls
means emit the entire ready batch in one turnMAESTRO_MAX_CONCURRENT=0
Native Constraints
- The runtime only parallelizes contiguous agent calls in one turn
- Native subagents currently run without user approval gates
remains available; a batch may pause while waiting for user inputask_user- If execution is interrupted, restart unfinished
phases on resume instead of attempting to restore in-flight subagent interactionsin_progress
Progress Context
Include the following in every delegation query body:
Progress: Phase [N] of [M]: [Phase Name] Session: [session_id]
For native parallel batches, also include the batch identifier in the required header:
Agent: <agent_name> Phase: <id>/<total> Batch: <batch_id> Session: <session_id>
Error Handling Protocol
Record all errors in session state with:
agenttimestamptypemessageresolution
Retry Logic
- Maximum retries per phase:
(defaultMAESTRO_MAX_RETRIES
)2 - First failure: analyze, adjust context/scope, retry automatically
- Subsequent failures up to the limit: continue retrying with clearer constraints
- Limit exceeded: mark the phase
and escalate to the userfailed
Increment
retry_count on each retry.
Recovery Protocol
When a subagent terminates early, times out, returns malformed output, or when
delegation.constraints.result_surface is deferred and the agent's text cannot be retrieved:
- Poll: For deferred-result runtimes (Codex), call the runtime's wait tool (
equivalent) with a bounded timeout. For synchronous runtimes, the initial dispatch return IS the result.wait_agent - Detect drift: Call
. If the returnedscan_phase_changes(session_id, phase_id)
orcandidates.created
arrays are non-empty, the agent produced filesystem output without a handoff.candidates.modified - Ask the user to confirm: Using the runtime's user-prompt tool, present the scan candidates and ask the user to confirm which files belong to this phase. For a parallel batch, include the
from each phase's session state to assist attribution. If the scan surfaces files beyond any phase'splanned_files
, raise a blocker and surface the ambiguity to the user rather than silently attributing.planned_files - Reconcile: Call
with the user-confirmed manifest. This clearsreconcile_phase(session_id, phase_id, files_created, files_modified, files_deleted, downstream_context, reason)
.requires_reconciliation - Retry or advance: If the user chose to retry the agent, re-delegate with the original scope plus the scan results as context. If the user accepted the work as delivered, advance to the next phase.
Record all recovery events in session state with
{agent, timestamp, type: 'recovery', resolution: 'retry'|'reconciled'|'aborted'}.
File Conflict Handling
When a subagent reports a file conflict:
- Stop execution immediately
- Record the conflicting files and phases
- Do not attempt automatic merge resolution
- Ask the user how to proceed
Subagent Output Processing
Native subagent results are wrapped. Do not assume the handoff begins at byte 0.
Parsing Rules
- Locate
(or## Task Report
) inside the returned text# Task Report - Locate
(or## Downstream Context
) inside the returned text# Downstream Context - Parse:
- status
- files created / modified / deleted
- downstream context fields
- validation result
- reported errors
- Persist the full raw output plus the parsed fields into session state
State Update Sequence
After processing each handoff:
- Update the phase file manifests
- Update
downstream_context - Append any errors
- Aggregate token usage
- If validation passed, mark the phase
completed - If validation failed, trigger retry logic
- Update
updated - Advance or clear
as each chunk finishescurrent_batch
Completion Protocol
When all phases are completed:
- Verify there are no
orfailed
phasespending - Confirm plan deliverables are accounted for
- Run the final code-review gate for non-documentation changes
- Archive the session through
session-management - Present a final summary with deliverables, files changed, token usage, deviations, and review status