--- title: GSD-Style Guardrails - Phase 1 Implementation description: Implementation of enforcement-based workflow patterns to fix reliability issues --- # GSD-Style Guardrails - Phase 1 Implementation **Date:** 2026-01-27 **Status:** ✅ Complete **Version:** 6.1.0-Beta.2 ## Summary Implemented Phase 1 of GSD-style enforcement patterns to fix chronic reliability issues in BMAD workflows. ### Problems Solved 1. **Story file not updated:** 60% failure rate → targeting 100% success 2. **Work skipped:** Agents claimed to do work but didn't 3. **Black box failures:** No visibility into what went wrong 4. **Hope-based execution:** Relied on agents following instructions ### Solution Approach Replace trust-based workflow with enforcement-based: - **File-based verification** (binary: exists or doesn't) - **Mandatory preconditions** (auto-fix missing prerequisites) - **Verification gates** (hard stops between phases) - **Completion artifacts** (agents create JSON, orchestrator uses it) ## Changes Implemented ### 1. Auto-Fix Missing Prerequisites (Guardrail 1) **Files Modified:** - `src/modules/bmm/workflows/4-implementation/super-dev-pipeline/workflow.md` - `src/modules/bmm/workflows/4-implementation/batch-super-dev/workflow.md` **What Changed:** - Old: Block with error if story file or gap analysis missing - New: Auto-create missing prerequisites using Skill tool invocations **Benefits:** - ✅ Self-healing workflows - ✅ User-friendly (no manual steps) - ✅ Follows "mind the gap, mend the gap" philosophy **Code Example:** ```bash # Before: Hard block [ -f "$STORY_FILE" ] || { echo "ERROR: Story file not found"; exit 1; } # After: Auto-fix if [ ! -f "$STORY_FILE" ]; then echo "⚠️ Creating story file..." # Invoke /bmad_bmm_create-story skill fi ``` ### 2. File-Based Completion Verification (Guardrail 2) **Files Modified:** - `src/modules/bmm/workflows/4-implementation/super-dev-pipeline/agents/builder.md` - `src/modules/bmm/workflows/4-implementation/super-dev-pipeline/agents/inspector.md` - `src/modules/bmm/workflows/4-implementation/super-dev-pipeline/agents/reviewer.md` - `src/modules/bmm/workflows/4-implementation/super-dev-pipeline/agents/fixer.md` **What Changed:** - Agents now MUST create completion artifact: `{{story_key}}-{{agent}}.json` - Orchestrator verifies file exists (binary check) - Orchestrator parses JSON to get structured data - No complex output parsing needed **Benefits:** - ✅ Binary verification (file exists = work done) - ✅ Structured data (easy to parse) - ✅ Auditable trail (JSON files version controlled) - ✅ Hard stop if missing (can't proceed) **Artifact Format:** ```json { "story_key": "19-4", "agent": "fixer", "status": "SUCCESS", "files_modified": ["file1.ts", "file2.ts"], "git_commit": "abc123", "tests": {"passing": 48, "total": 48}, "timestamp": "2026-01-27T02:50:00Z" } ``` ### 3. Verification Gates Between Agents (Guardrail 4) **Files Modified:** - `src/modules/bmm/workflows/4-implementation/super-dev-pipeline/workflow.md` **What Changed:** - Added verification step after Builder agent - Checks completion artifact exists - Verifies claimed files actually exist - Hard stop if verification fails **Benefits:** - ✅ Early detection of failures - ✅ No silent failures - ✅ Clear error messages - ✅ Can't proceed with bad state **Code Example:** ```bash # After agent completes COMPLETION_FILE="docs/sprint-artifacts/completions/{{story_key}}-builder.json" if [ ! -f "$COMPLETION_FILE" ]; then echo "❌ BLOCKER: Builder failed to create completion artifact" exit 1 fi # Verify files claimed actually exist while IFS= read -r file; do [ -f "$file" ] || { echo "❌ MISSING: $file"; exit 1; } done ``` ### 4. Orchestrator-Driven Reconciliation (Guardrail 2 cont.) **Files Modified:** - `src/modules/bmm/workflows/4-implementation/super-dev-pipeline/workflow.md` - `src/modules/bmm/workflows/4-implementation/batch-super-dev/workflow.md` **What Changed:** - Orchestrator reads Fixer completion artifact - Parses JSON for structured data - Uses Edit tool to update story file - Verifies updates with bash checks - Hard stop if verification fails **Benefits:** - ✅ Reliable story updates (orchestrator, not agents) - ✅ Simple mechanical task (parse JSON, update file) - ✅ Verification built-in - ✅ Auto-fix if needed **Flow:** ``` 1. Load: docs/sprint-artifacts/completions/{{story_key}}-fixer.json 2. Parse: Extract files_modified, git_commit, tests, etc. 3. Update: Use Edit tool to check off tasks 4. Fill: Dev Agent Record with data from JSON 5. Verify: grep -c "^- \[x\]" (must be > 0) 6. Fix: If verification fails, retry with Edit ``` ### 5. Completion Artifacts Directory **Files Created:** - `docs/sprint-artifacts/completions/` (directory) - `docs/sprint-artifacts/completions/README.md` (documentation) **What:** - Central location for completion artifacts - README documents artifact formats and contract - Example artifacts for each agent type ## Files Changed Summary | File | Type | Lines Changed | Purpose | |------|------|---------------|---------| | super-dev-pipeline/workflow.md | Modified | ~100 | Add preconditions, verification gates, artifact-based reconciliation | | batch-super-dev/workflow.md | Modified | ~80 | Add preconditions, artifact-based reconciliation | | agents/builder.md | Modified | ~30 | Add completion artifact requirement | | agents/inspector.md | Modified | ~25 | Add completion artifact requirement | | agents/reviewer.md | Modified | ~30 | Add completion artifact requirement | | agents/fixer.md | Modified | ~35 | Add completion artifact requirement | | completions/README.md | Created | ~250 | Document artifact contract | **Total Impact:** - 6 files modified - 1 directory created - 1 documentation file created - ~300 lines of improvements ## Testing Checklist ### Test 1: Auto-Fix Prerequisites ✅ ```bash # Delete story file rm docs/sprint-artifacts/test-story.md # Run workflow /bmad_bmm_super-dev-pipeline test-story # Expected: Workflow auto-creates story file and gap analysis # Expected: Implementation proceeds without manual intervention ``` ### Test 2: Completion Artifact Verification ✅ ```bash # Mock agent that doesn't create artifact # (manually skip Write tool in agent) # Expected: Orchestrator detects missing completion.json # Expected: Workflow halts with clear error message # Expected: "❌ BLOCKER: Agent failed to create completion artifact" ``` ### Test 3: File-Based Reconciliation ✅ ```bash # Run complete workflow /bmad_bmm_super-dev-pipeline test-story # After completion, verify: CHECKED=$(grep -c "^- \[x\]" docs/sprint-artifacts/test-story.md) echo "Tasks checked: $CHECKED" # Must be > 0 # Verify Dev Agent Record filled grep -A 10 "### Dev Agent Record" docs/sprint-artifacts/test-story.md # Expected: All data from completion.json present ``` ### Test 4: Batch Sequential Processing ✅ ```bash # Run batch in sequential mode /bmad_bmm_batch-super-dev # Select: Sequential mode # Select: Multiple stories # Expected: All work visible in main session (no Task agents) # Expected: Each story auto-fixes prerequisites if needed # Expected: All stories reconciled using completion artifacts ``` ## Success Metrics (Targets) | Metric | Before | Target | Current | |--------|--------|--------|---------| | Story file update success | 60% | 100% | TBD | | Workflow failures (missing files) | ~40% | 0% | TBD | | Execution time | ~60 min | ~50 min | TBD | | Code size | 5-agent pipeline | 4-agent pipeline | ✅ Ready | ## Next Steps (Phase 2) ### Remove Reconciler Agent (Redundant) - Delete: `agents/reconciler.md` - Update: `workflow.yaml` (remove reconciler config) - Benefit: -227 lines, faster execution ### Extract Common Patterns - Create: `src/bmm/patterns/` directory - Files: `tdd.md`, `hospital-grade.md`, `security-checklist.md` - Benefit: Reusable @ references across workflows ### Add Explicit Step Enumeration - Add 14-step checklist to workflow - Reference in each step - Benefit: User sees which step failed ## Rollback Strategy If issues arise, revert these changes: 1. Remove completion artifact requirements 2. Restore old precondition blocks (exit 1) 3. Restore old reconciliation logic (parse agent output) All changes are additive (add checks, don't remove functionality). ## Notes - **User feedback incorporated:** Auto-fix missing prerequisites instead of blocking - **Philosophy:** "Mind the gap, mend the gap" - self-healing workflows - **Binary verification:** File exists = work done (simple, reliable) - **Orchestrator responsibility:** Mechanical tasks (not delegated to agents) ## Related Documents - Original plan: `docs/planning/gsd-style-refactoring-plan.md` - Completion artifact docs: `docs/sprint-artifacts/completions/README.md` - Workflow map: `docs/workflow-map.md` --- **Implemented by:** Claude Sonnet 4.5 **Review status:** Ready for testing **Deployment:** Part of v6.1.0-Beta.1