Feature Request: Playbook Exit Condition Detection for Auto Run
Summary
When using Auto Run mode, playbooks have no mechanism to signal completion to Maestro. Even when all work is done and the playbook sets a completion marker, Auto Run continues cycling indefinitely (Loop 16, 17, 18...) until manually stopped or Max Loops is reached.
Current Behavior
- Auto Run only exits on: Max Loops reached OR Manual Stop
- Playbooks cannot signal "I'm done, stop running"
- Agents correctly detect completion states but cannot affect Maestro's control flow
- Results in wasted compute as agents cycle through documents finding nothing to do
Evidence
Running SpecFlow_Development playbook with 16 features:
- Both agents completed all features after ~6 hours
.maestro/CURRENT_FEATURE.mdupdated withALL_FEATURES_COMPLETE- Auto Run continued for 6+ more hours (Loop 16-17+) before manual stop
- Agents marked all tasks complete each loop but couldn't exit
Proposed Solutions
Option 1: Exit File Detection (Recommended)
Check for a sentinel file before starting each loop:
.maestro/PLAYBOOK_COMPLETE
If file exists and contains EXIT, stop Auto Run gracefully.
Implementation:
- Simple file check between loop iterations
- Playbooks write this file when complete
- Clear and documented contract between playbook and Maestro
Option 2: Document Exit Directive
Allow documents to embed an exit signal:
<!-- MAESTRO:EXIT -->
Maestro parses this after processing each document and stops if found.
Option 3: Exit Task Type
Special task checkbox that triggers exit when checked:
- [x] **MAESTRO:EXIT** - All work complete, exit Auto Run
Benefits
- Resource efficiency - No wasted compute on completed playbooks
- Better UX - Users don't need to monitor loop counters
- Graceful completion - Clean exit with proper state
- Playbook autonomy - Playbooks can define their own completion criteria
Related
- Issue #201 - Observability during Auto Run (related need for visibility)
- Issue #227 - Request to stop Auto Run immediately (manual stop improvement)
Environment
- Maestro Version: 0.14.4
- Platform: macOS
- Playbook: SpecFlow_Development (16 features, 7 documents)
Yeah this is a great idea. I think the current method of exit conditions being predicated on no work remaining is overly complex. Having an exit condition would be valuable. Let me put some thought into how best to implement this.
Side note, love your issues. Thank you for taking the time to share this valuable feedback.
Thanks! I'd encourage looking deeper into the SpecFlow integration - it's been surprisingly powerful for structured development.
Here's how the components orchestrate together:
The Stack
┌─────────────────────────────────────────────────────────────┐
│ MAESTRO │ Playbook execution, loop control │
│ (Orchestrator) │ Loads documents from playbook repo │
├─────────────────────────────────────────────────────────────┤
│ PAI │ Agent infrastructure, skills, hooks │
│ (Agent Harness) │ Lives IN the target repo │
├─────────────────────────────────────────────────────────────┤
│ specflow CLI │ Feature/task tracking, TDD gates │
│ (specflow-bundle) │ External CLI from jcfischer │
└─────────────────────────────────────────────────────────────┘
State in Target Repo
All state accumulates in the TARGET project (the git worktree being developed):
target-repo/
├── .maestro/ # Playbook working state
│ ├── CURRENT_FEATURE.md # "F-017, phase: tasks"
│ └── outputs/
│ ├── LOOP_PROGRESS.md # "11/17 tasks complete"
│ └── COMPLETED_FEATURES/ # Archived feature contexts
├── .specflow/features.db # SQLite: all features, phases, tasks
└── .specify/specs/f-017/ # Spec documents (spec.md, plan.md, tasks.md)
How They Interact
Loop 11 of F-017 (real example from my session):
-
Maestro runs
4_IMPLEMENT.mdfrom playbook repo, in context of/worktrees/signal-agent-2/ -
PAI agent (Claude Code with PAI infrastructure) executes document tasks
-
Document calls
specflow implement F-017:specflow CLI reads: .specflow/features.db Returns: "T-4.1: Instrument ToolUseInstrumentation.hook.ts" -
Agent implements using TDD (642 tests passing)
-
Maestro runs
5_VERIFY.md- phase guard checks SpecFlow state:INCOMPLETE=$(specflow status F-017 --json | jq '...') # Returns: 6 tasks remaining → "return to IMPLEMENT" -
When complete,
6_COMPLETE.mdwrites marker to target repo:echo "ALL_FEATURES_COMPLETE" > .maestro/CURRENT_FEATURE.md
The Gap
SpecFlow knows "ALL_FEATURES_COMPLETE" - it wrote the marker to the target repo. But Maestro doesn't read it, so it keeps cycling.
Playbook: SpecFlow_Development
SpecFlow bundle: jcfischer/specflow-bundle
PAI: danielmiessler/Personal_AI_Infrastructure
Hey @pedramamini, I just wanted to congratulate you on creating something quite powerful here and thank you very much for sharing your work with us.
Worth flagging: Auto Run already supports a graceful playbook-signaled exit via the <!-- maestro:halt --> HTML-comment marker, which I think covers this request without needing a separate .maestro/PLAYBOOK_COMPLETE sentinel file.
How it works (see src/cli/services/batch-processor.ts:41):
<!-- maestro:halt -->
<!-- maestro:halt: All features complete -->
When the agent writes either form into the current Auto Run document, the next iteration of the loop reads the doc, detects the marker, emits a halt event with the optional reason, writes a final history entry, and breaks out of the entire playbook — skipping all remaining tasks in the current document and all subsequent documents.
It's wired up at three levels:
- Pre-execution scan (
batch-processor.ts~127–183): refuses to start if a stale halt marker from a previous run is still in the doc, so an exited playbook stays exited. - Mid-execution detection after each agent spawn (
batch-processor.ts~497, 587–619): same loop iteration that read the doc for task counting also checks for the marker. - Renderer parity in
useDocumentProcessor/useBatchRunner.
It has tests for the bare marker, the marker-with-reason variant, case-insensitive matching, and false-positive avoidance (see batch-processor.test.ts).
This is more ergonomic than a sentinel file because the playbook author can put the marker directly in the doc the agent is editing (no extra .maestro/ directory contract, no extra file I/O), and the optional reason becomes a first-class field in the history entry.
If the rest of the feedback in this issue (resource efficiency, better UX, graceful completion) is still missing once you know the marker exists, happy to keep this open and dig into the gap. Otherwise this can probably be closed.
Thanks for the thorough write-up, @mellanon, the loop counters and the SpecFlow evidence made this easy to pin down.
Good news: the contract you're asking for already half-exists. Auto Run supports a halt marker an agent can write into the current document to early-exit a whole playbook:
<!-- maestro:halt: all features complete -->
The catch, and the reason you saw Loop 16/17/18 keep going: detection was only ever wired into the CLI batch runner. The desktop app advertised the marker (it's in the Auto Run help modal and the default Auto Run prompt) but the desktop run loop never actually checked for it, so the marker was silently ignored. That lines up exactly with your "agents detect completion but can't affect control flow" observation.
We think we have a fix in #1149. It wires halt detection into the desktop Auto Run loop so that when an agent writes the marker the run stops immediately (no more tasks, no more documents, no more loops), records a Halted by agent: <reason> entry in history, and pops a toast telling you why it stopped. This is essentially your Option 2 (a document-embedded exit directive), using the marker Maestro already documents.
For your SpecFlow playbook, the move would be: have the agent write <!-- maestro:halt: ALL_FEATURES_COMPLETE --> into the active document once it detects the completion state, instead of (or alongside) the .maestro/CURRENT_FEATURE.md sentinel.
Would that cover your use case? Curious whether the existing halt marker is enough, or whether you'd still want a dedicated sentinel file (your Option 1) as a separate signal. Feedback welcome on the PR.