| name | phase-gate-sequence |
| description | Encodes the mandatory 6-step inter-phase checkpoint sequence that executive-tier agents run after every domain phase and before delegating the next. Includes the context window alert trigger conditions and session handoff prompt template.
USE FOR: running the post-phase prune → checkpoint → commit → grep sweep → review → compact sequence; triggering the context-window alert and generating a handoff prompt; ensuring no domain phase is skipped or batched without a gate record.
DO NOT USE FOR: deciding which agent to delegate to (use delegation-routing); session start/close lifecycle (use session-management); individual script command syntax (see docs/toolchain/).
|
| argument-hint | current phase number and name (e.g. 'Phase 3 — Synthesis') |
| tier | Foundation |
| type | automation |
| effort | m |
| applies-to | ["Executive Orchestrator","Executive Researcher","Executive Fleet","Executive Docs"] |
| status | active |
Phase Gate Sequence
This skill enacts the Algorithms-Before-Tokens axiom from MANIFESTO.md: the 6-step gate is a deterministic algorithm encoded once and shared across all executive agents, eliminating parallel re-derivation and enforcing consistent phase discipline fleet-wide.
Beliefs & Context
- Governing axiom: Axiom 2 — Algorithms Before Tokens — deterministic procedure over repeated instruction
- GitHub issue: #79 — Skills as Decision Codifiers
- Formal FSM spec:
data/phase-gate-fsm.yml — machine-readable state specification for this gate loop (states: INIT, PHASE_RUNNING, GATE_CHECK, COMPACT_CHECK, COMMIT, CLOSED)
- Agents that use this skill: Executive Orchestrator, Executive Researcher, Executive Fleet, Executive Docs
- Foundation docs:
AGENTS.md — compaction-aware writing, commit discipline, Programmatic-First
executive-orchestrator.agent.md — canonical per-phase sequence (lines 169–196) and context window alert protocol (lines 198–242)
Workflow
Run this sequence after every ## Phase N Output write, before delegating the next domain phase.
Step 0: Loop Audit (Pre-Phase)
Before any complex phase execution, run the orchestration loop detector:
uv run python scripts/detect_orchestration_loop.py \
--task "<current-phase-name>" \
--scratchpad ".tmp/$(git branch --show-current | tr '/' '-')/$(date +%Y-%m-%d).md"
- If
loop_detected: false → proceed to Step 1
- If
loop_detected: true → do not execute. Write to scratchpad: ## Loop Detected — [task] — iteration [N]; awaiting user direction. Surface to user: "I detected that I attempted this task [N] iterations ago. What should I do differently?"
Encoding point: Governed by AGENTS.md § Guardrails. Script: scripts/detect_orchestration_loop.py. Research basis: docs/research/orchestrator-autopilot-failure.md § Recommendation 4.
Step 1 — Prune
If the scratchpad exceeds 2000 lines:
uv run python scripts/prune_scratchpad.py
Step 1.5 — Pre-Delegation Rate-Limit Gate (Sprint 18+)
Before delegating the next phase, check the rate-limit budget gate (see rate-limit-resilience SKILL, issue #325):
CURRENT_BUDGET=75000
OPERATION='delegation'
PROVIDER='claude'
GATE_RESULT=$(uv run python scripts/rate_limit_gate.py "$CURRENT_BUDGET" "$OPERATION" --provider "$PROVIDER" --audit-log)
if echo "$GATE_RESULT" | grep -q '"safe": true'; then
echo "Gate APPROVED: safe to proceed"
else
SLEEP_SEC=$(echo "$GATE_RESULT" | grep -o '"recommended_sleep_sec": [0-9]*' | cut -d: -f2)
echo "Gate BLOCKED: Rate-limited. Recommended sleep: ${SLEEP_SEC}s"
echo "Defer this delegation to next session or sleep and retry"
fi
Integration: This check prevents cascading rate-limit failures mid-phase. If blocked:
- Log the gate decision to scratchpad under
## Rate-Limit Gate Output
- Defer the delegation to the next session, OR
- Sleep for recommended duration and monitor for consecutive failures (circuit-breaker)
Note: This is new infrastructure from Phase 0 (Sprint 18, issue #325). Phase 1 research (docs/research/ai-cognitive-load.md, issue #315) validates this gate: token-heavy workflows with >4 handoffs exceed working memory capacity; rate-limit gates reduce decision surface and human error. Integration point: AGENTS.md § Rate-Limit Resilience Throughout MANIFESTO Axioms shows how this gate operationalizes Algorithms-Before-Tokens (#319 trendslop research), Local-Compute-First (#317 vendor lock-in), and Endogenous-First (#315 cognitive load) axioms.
All orchestrators must check before high-cost delegations (e.g., research scout with 3+ parallel scouts).
Step 2 — Write Pre-Compact Checkpoint
Append ## Pre-Compact Checkpoint to the scratchpad with:
- What is complete (include commit SHAs)
- What is next
- Any open questions or blockers
Step 3 — Commit In-Progress Changes (Orchestrator)
Orchestrator commits in-progress changes via terminal:
git add -A && git commit -m "chore: pre-compact checkpoint — Phase N complete"
Step 4 — Pre-Review Grep Sweep
Scans the entire .github/ directory (all agent and skill files) for known heading-contract violations and erroneous patterns — not scoped to changed files only, since stale patterns can exist anywhere.
if grep -r "Phase N Review Output\|Fetch-before-check" .github/; then
echo "ERROR: known pattern violations found — fix before requesting review"
elif [ $? -eq 1 ]; then
echo "grep sweep clean"
else
echo "ERROR: grep failed during sweep — investigate before requesting review"
fi
Fix any matches before invoking Review.
Step 5 — Review Gate
Invoke the Review agent with the changed file list and scratchpad location. Append verdict to the scratchpad under ## Review Output. Do not advance to the next phase until APPROVED.
Step 6 — Compact Recommendation
If the completed phase was a long research, synthesis, or multi-file editing delegation, recommend /compact before the next delegation. After any compaction event: re-read the scratchpad and workplan from disk before continuing.
Context Window Alert — Trigger Conditions
Pause all delegation immediately when any of the following is true:
- Compaction has occurred in this session, OR
- The user signals compaction is becoming frequent, OR
- You detect you are reconstructing already-explored context (re-reading the same file, re-running the same search)
When triggered:
- Write
## Context Window Checkpoint to the scratchpad: active phase + status, committed vs. in-progress deliverables (with SHAs), last agent delegated + ≤100-token return summary, single next concrete step, open blockers.
- Commit and push all in-progress changes.
- Present the session handoff prompt template from
executive-orchestrator.agent.md lines 215–236 — fill in bracketed fields from the scratchpad.
- Do not proceed until the user resumes via the handoff prompt.
Completion Criteria
The phase gate is correctly applied for a given phase when:
Exit condition: The loop terminates when ## Session Summary has been written and uv run python scripts/prune_scratchpad.py --force has run — see the session-management skill for the full session close sequence.