Lifecycle Enforcement Specification
Version: 1.0.0 Status: Active Task: T2715 Epic: T2678 (Protocol Enforcement & RCSD-IVTR Alignment Audit) Date: 2026-01-28Authority
This specification is AUTHORITATIVE for lifecycle gate enforcement in the CLEO task management system. This specification governs:- Gate check algorithm for RCSD pipeline stage transitions
- Enforcement modes (strict, advisory, off)
- State query patterns against RCSD manifest schema
- Exit codes and error handling for lifecycle violations
RCSD-PIPELINE-SPEC.md- Stage definitions and pipeline flowschemas/rcsd-manifest.schema.json- State schema structure
lib/lifecycle.sh- Gate check functionslib/orchestrator-spawn.sh- Integration point (Step 6.5)
1. Overview
1.1 Purpose
Lifecycle gate enforcement prevents invalid transitions in the RCSD (Research → Consensus → Specification → Decomposition) pipeline. It ensures subagents are spawned only after prerequisite stages are completed.1.2 Scope
This specification covers:- Gate check algorithm
- Enforcement modes
- RCSD state schema integration
- Exit codes and error handling
- Integration with orchestrator-spawn.sh
1.3 Definitions
| Term | Definition |
|---|---|
| Gate | A validation checkpoint that blocks progression until prerequisite stages are completed |
| RCSD Stage | One of: initialized, research, consensus, spec, decompose |
| Lifecycle State | Current position in the RCSD pipeline |
| Enforcement Mode | Configuration controlling how gate failures are handled |
2. Gate Check Algorithm
2.1 State Query (GATE-001)
The gate check algorithm MUST query.cleo/rcsd/{epicId}/_manifest.json for stage status.
Query Pattern:
- GATE-001.1: MUST read from
.cleo/rcsd/{epicId}/_manifest.json - GATE-001.2: MUST query
.status.{stage}.statefield - GATE-001.3: MUST handle missing manifest file gracefully
- GATE-001.4: MUST handle missing stage gracefully
2.2 Prerequisite Verification (GATE-002)
The gate check MUST verify prerequisite stages are completed before allowing target stage. Dependency Chain:- GATE-002.1: MUST check all prerequisite stages are
completed - GATE-002.2: MUST allow
skippedstages if explicitly permitted - GATE-002.3: MUST NOT allow forward jumps (e.g., initialized → spec)
- GATE-002.4: MUST NOT allow backward transitions (e.g., spec → consensus)
2.3 Configurable Enforcement (GATE-003)
The gate check MUST support configurable enforcement mode. Requirements:- GATE-003.1: MUST read enforcement mode from
.cleo/config.json - GATE-003.2: MUST default to
strictif not configured - GATE-003.3: MUST support environment variable override (
LIFECYCLE_ENFORCEMENT_MODE) - GATE-003.4: MUST validate mode is one of:
strict,advisory,off
2.4 Exit Code Handling (GATE-004)
The gate check MUST return appropriate exit code based on result. Requirements:- GATE-004.1: MUST return
0(EXIT_SUCCESS) if gate passed - GATE-004.2: MUST return
75(EXIT_LIFECYCLE_GATE_FAILED) if gate failed in strict mode - GATE-004.3: MUST return
0with warning message if gate failed in advisory mode - GATE-004.4: MUST return
0if enforcement mode isoff
3. Enforcement Modes
3.1 Strict Mode (MODE-001)
MODE-001:strict mode MUST block spawn if prerequisites are not met.
Behavior:
- MUST perform gate check before spawn
- MUST return
EXIT_LIFECYCLE_GATE_FAILED(75) on gate failure - MUST provide actionable fix in error JSON
- MUST log gate check result to compliance metrics
- MUST prevent subagent spawn
3.2 Advisory Mode (MODE-002)
MODE-002:advisory mode MUST warn but SHOULD allow spawn.
Behavior:
- MUST perform gate check before spawn
- MUST log warning message if gate fails
- SHOULD allow spawn to proceed
- MUST record advisory violation in compliance metrics
- MAY display warning to user
3.3 Off Mode (MODE-003)
MODE-003:off mode MUST NOT perform gate checks.
Behavior:
- MUST NOT perform gate check before spawn
- MUST NOT log gate check results
- MUST allow all spawns regardless of stage state
3.4 Configuration (MODE-004)
MODE-004: Mode MUST be configurable via.cleo/config.json.
Requirements:
- MODE-004.1: MUST read from
.cleo/config.json - MODE-004.2: MUST support environment variable override
- MODE-004.3: MUST validate mode value
- MODE-004.4: MUST default to
strictif invalid or missing
- Environment variable:
LIFECYCLE_ENFORCEMENT_MODE - Config file:
.cleo/config.json→lifecycle.enforcement.mode - Default:
strict
4. Integration Points
4.1 Orchestrator Spawn Integration (INTG-001)
INTG-001: MUST integrate intoorchestrator-spawn.sh between Step 6.5 and Step 7.
Integration Location:
- INTG-001.1: MUST execute after protocol validation (Step 6.5)
- INTG-001.2: MUST execute before skill injection (Step 7)
- INTG-001.3: MUST block spawn in strict mode on failure
- INTG-001.4: MUST log warning in advisory mode on failure
4.2 Library Dependency (INTG-002)
INTG-002: MUST sourcelib/lifecycle.sh for gate functions.
Requirements:
- INTG-002.1: MUST source lib/lifecycle.sh in orchestrator-spawn.sh
- INTG-002.2: MUST handle missing library gracefully
- INTG-002.3: MUST verify function availability before calling
4.3 Compliance Metrics (INTG-003)
INTG-003: MUST log gate check results to compliance metrics. Requirements:- INTG-003.1: MUST log gate check attempt
- INTG-003.2: MUST log gate check result (pass/fail)
- INTG-003.3: MUST log enforcement mode
- INTG-003.4: MUST include epic_id and target_stage
5. Error Handling
5.1 Gate Failure Exit Code (ERR-001)
ERR-001: MUST useEXIT_LIFECYCLE_GATE_FAILED (75) for strict mode failures.
Requirements:
- ERR-001.1: MUST return exit code 75 on gate failure in strict mode
- ERR-001.2: MUST include error code in JSON output
- ERR-001.3: MUST map to error code name “LIFECYCLE_GATE_FAILED”
lib/exit-codes.sh lines 328-331
5.2 Actionable Fix (ERR-002)
ERR-002: MUST provide actionable fix in error JSON. Requirements:- ERR-002.1: MUST include
fixfield with command to resolve - ERR-002.2: MUST include
alternativesarray with alternative solutions - ERR-002.3: MUST include
contextobject with diagnostic information
5.3 Diagnostic Context (ERR-003)
ERR-003: MUST include context showing which stage is missing. Requirements:- ERR-003.1: MUST include
epicIdin context - ERR-003.2: MUST include
targetStagein context - ERR-003.3: MUST include
missingStagesarray in context - ERR-003.4: MUST include
currentStagein context - ERR-003.5: MUST include
enforcementModein context
6. State Query Patterns
6.1 Stage Completion Check
Query Pattern:6.2 All Prerequisites Check
Query Pattern:6.3 Current Pipeline Stage Query
Query Pattern:6.4 Stage State Query
Query Pattern:7. RCSD State Schema Integration
7.1 Schema Reference
Schema Location:schemas/rcsd-manifest.schema.json v1.0.0
Relevant Fields:
7.2 State Transitions
Valid States:pending- Stage not yet startedin_progress- Stage currently activecompleted- Stage successfully finishedskipped- Stage intentionally skippedfailed- Stage failed, requires retry or skip
pending→in_progress- Start stagein_progress→completed- Complete successfullyin_progress→failed- Failure detectedpending→skipped- Skip stagefailed→in_progress- Retry after failure
7.3 Skipped Stage Handling
Requirements:- MUST treat
skippedsame ascompletedfor prerequisites - MUST log skip reason if available
- SHOULD validate skip is permitted for stage
- MAY enforce skip permission based on stage criticality
8. Implementation Checklist
8.1 Phase 1: Core Functions (T2716)
- Implement
check_lifecycle_gate()in lib/lifecycle.sh - Implement
is_stage_completed()helper - Implement
check_prerequisites()helper - Implement
get_current_stage()helper - Implement
get_stage_state()helper - Add unit tests for gate check functions
8.2 Phase 2: Configuration (T2718)
- Add
LIFECYCLE_ENFORCEMENT_MODEconfig to schemas/config.schema.json - Implement
get_lifecycle_enforcement_mode()in lib/lifecycle.sh - Add config validation
- Add environment variable override support
- Add unit tests for configuration
8.3 Phase 3: Integration (T2720)
- Integrate gate check into orchestrator-spawn.sh (Step 6.75)
- Add compliance metrics logging
- Add error JSON formatting
- Add integration tests
- Update orchestrator documentation
8.4 Phase 4: Validation (T2722)
- Test strict mode blocks spawn
- Test advisory mode warns but allows
- Test off mode skips checks
- Test error messages are actionable
- Test compliance metrics are logged
9. Exit Code Reference
| Code | Name | Usage |
|---|---|---|
| 0 | EXIT_SUCCESS | Gate check passed |
| 75 | EXIT_LIFECYCLE_GATE_FAILED | Gate check failed (strict mode) |
| 78 | EXIT_LIFECYCLE_TRANSITION_INVALID | Invalid stage transition attempted |
lib/exit-codes.sh lines 325-348
10. Compliance
This specification follows:- RFC 2119 keyword usage (MUST, SHOULD, MAY)
- Semantic versioning (v1.0.0)
- CLEO specification protocol requirements
- MUST: 56 occurrences (strict requirements)
- SHOULD: 4 occurrences (recommendations)
- MAY: 3 occurrences (optional features)
11. References
- RCSD Pipeline Spec:
docs/developer/specifications/RCSD-PIPELINE.mdx - RCSD Manifest Schema:
schemas/rcsd-manifest.schema.json - Exit Codes:
lib/exit-codes.sh - Lifecycle Library:
lib/lifecycle.sh - Orchestrator Spawn:
lib/orchestrator-spawn.sh - Protocol Enforcement Spec:
docs/developer/specifications/PROTOCOL-ENFORCEMENT.mdx
Appendix A: Example Scenarios
Scenario 1: Successful Gate Check
Situation: Epic T2678 has completed research and consensus stages. Attempting to spawn specification stage. State:Scenario 2: Gate Check Failure (Strict Mode)
Situation: Epic T2678 has only initialized. Attempting to spawn consensus stage without research. State:Scenario 3: Advisory Mode
Situation: Same as Scenario 2, but enforcement mode isadvisory.
Result: Gate check logs warning, spawn proceeds.
Warning Message:
Scenario 4: Skipped Stage
Situation: Epic T2678 has completed research and explicitly skipped consensus. Attempting to spawn specification. State:END OF SPECIFICATION
