Workflow Invariants
Model workflow behavior as explicit states and allowed transitions, then enforce it in code and tests.
Do This First
- Identify the canonical state object and transition points.
- Enumerate valid transitions and reject everything else.
- Identify cross-workflow gates that must block downstream commands.
Use this template:
state: awaiting_review
allowed: approve -> awaiting_resume
blocked: social, prep, publish
error: "Draft is awaiting final_output approval."
recovery: "Run draft approve + draft resume."Implementation Pattern
- Put transition logic in one place.
- Return structured failure payloads for invalid transitions.
- Carry recovery instructions in all blocked-path errors.
- Remove stale artifacts when moving into blocked states.
- Emit an event on every transition for traceability.
Test Pattern
- Add one positive-path test per transition.
- Add one negative-path test per blocked transition.
- Add regression tests for known stale-selection bugs.
- Assert both behavior and operator-facing message text.
Invariant Checklist
- A failed run never becomes the active run.
- A run from another week never drives current guidance.
- Downstream flows are blocked for
quality_blockedandawaiting_final_output_review. - Final artifacts do not exist before approval+resume completes.
- Help text and guidance reference the same transition names.
Output Format
When reporting work, include:
- Transition table added/updated
- Guards added
- Tests added
- Residual risk