Skip to content

Commit 32d9eaa

Browse files
barkainclaude
andcommitted
fix: break delegate→plan-mode→approve infinite loop
The Stop hook's continuation injection used `reason: "continue"` which the model interpreted as a fresh work request. Combined with orchestrator_stub's "all work MUST go via /workflow-orchestrator:delegate" rule and delegate.md's unconditional EnterPlanMode at Stage 0, this caused an infinite ExitPlanMode → Stop hook → continue → delegate → EnterPlanMode → ExitPlanMode loop after every plan approval. Three-layer fix: - Stop hook continuation message is now explicit anti-redelegation (hooks/stop/python_stop_hook.py). - Orchestrator stub adds an "Exception — continuation after plan approval" clause that overrides the routing rule during in-flight delegation (system-prompts/orchestrator_stub.md). - delegate.md gets a "RE-INVOCATION GUARD" section as the first content after frontmatter, telling the skill to skip Stage 0 if it just exited plan mode (commands/delegate.md). Layered guards because the loop is driven by model interpretation, not deterministic state — any one layer alone could be missed by prompt cache effects or session resumes; together they harden the path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b65f6a8 commit 32d9eaa

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

commands/delegate.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ argument-hint: [task description]
44
allowed-tools: Agent, Task, EnterPlanMode, ExitPlanMode, AskUserQuestion, TaskCreate, TaskUpdate, TaskGet, TaskList, ToolSearch, TeamCreate, SendMessage
55
---
66

7+
## RE-INVOCATION GUARD (READ FIRST)
8+
9+
Before doing ANYTHING else: if your most recent tool call in this conversation was `ExitPlanMode`, OR if you arrived here via a "PLAN ALREADY APPROVED" / "continuing to STAGE 1" continuation message, the plan is already approved. **Do NOT call `EnterPlanMode`. Do NOT re-enter Stage 0.** Skip directly to **STAGE 1: EXECUTION** — render the dependency graph from the approved plan in context and begin spawning Wave 0 agents. Re-entering plan mode here causes an infinite delegate→plan→approve loop.
10+
711
# Workflow Orchestrator System Prompt
812

913
## Purpose

hooks/stop/python_stop_hook.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,13 @@ def check_workflow_continuation() -> bool:
173173
# This mimics ralph-wiggum's loop mechanism
174174
output = {
175175
"decision": "block",
176-
"reason": "continue",
177-
"systemMessage": "⚡ Workflow continuation: Proceeding to STAGE 1 execution.",
176+
"reason": (
177+
"PLAN ALREADY APPROVED. Execute Stage 1 NOW directly from the existing "
178+
"approved plan in context. DO NOT call /workflow-orchestrator:delegate. "
179+
"DO NOT call EnterPlanMode. DO NOT re-enter plan mode. "
180+
"Render the dependency graph and start spawning Wave 0 agents."
181+
),
182+
"systemMessage": "⚡ Continuing to STAGE 1 execution (plan already approved).",
178183
}
179184
print(json.dumps(output)) # noqa: T201
180185
logger.debug("Output block decision with 'continue' reason")

system-prompts/orchestrator_stub.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Any user request that requires work — writing code, running tools, multi-step
1010

1111
The main agent does not execute work tools directly. Use only: Tasks API, AskUserQuestion, and `/workflow-orchestrator:delegate`. The delegate command loads the full orchestrator (planning, agent assignment, execution waves) on demand.
1212

13+
## Exception — continuation after plan approval
14+
15+
If your most recent tool call was `ExitPlanMode`, OR you received a "PLAN ALREADY APPROVED" / "continuing to STAGE 1" continuation message, **do NOT re-invoke `/workflow-orchestrator:delegate`** and **do NOT call `EnterPlanMode`** again. The orchestrator is already loaded and the plan is already approved — proceed directly to Stage 1 execution by rendering the dependency graph and spawning Wave 0 agents. The "all work → delegate" rule above does NOT apply during in-flight delegation.
16+
1317
## Team Mode
1418

1519
If `TeamCreate` is in your available tools, agent teams are enabled. When you run `/workflow-orchestrator:delegate`, default to team mode (`TeamCreate` + `Agent(team_name=...)`) for multi-agent work. If `TeamCreate` is not available, the delegate flow falls back to parallel subagents automatically.

0 commit comments

Comments
 (0)