Repository navigation
Description
Problem
The Phase type is defined independently in three locations with divergent values, creating a type safety gap:
| File | Values | Missing |
|---|---|---|
src/lib/workflow/types.ts:8-15 |
spec, security-review, testgen, exec, test, qa, loop | verify, merger |
src/lib/workflow/state-schema.ts:69-79 |
spec, security-review, exec, testgen, test, verify, qa, loop, merger | — (superset) |
src/lib/workflow/run-log-schema.ts:25-33 |
spec, security-review, testgen, exec, test, qa, loop | verify, merger |
Impact: 10+ modules import Phase from the incomplete types.ts (including ci/types.ts, content-analyzer.ts, phase-executor.ts, batch-executor.ts, worktree-manager.ts). Code handling verify or merger phases through these import paths has no compile-time safety. batch-executor.ts already imports both Phase from types.ts AND Phase as StatePhase from state-schema.ts (lines 15-16) — a clear signal of the divergence.
Adding a new phase requires updating 3 files manually, with no test or lint catching omissions.
Acceptance Criteria
- Single
Phasedefinition exists (Zod schema + inferred TS type) that all modules import -
state-schema.tsandrun-log-schema.tsboth reference the canonical definition (not their own copies) - All existing imports compile and tests pass after the migration
- The
Phase as StatePhasealiased import inbatch-executor.ts:15is eliminated - String-union verdict types in
merge-check/types.ts("PASS" | "WARN" | "FAIL","READY" | "NEEDS_ATTENTION" | "BLOCKED") useas constwith a Zod schema for runtime validation - Integration test or static check ensures all Phase consumers agree on the same set of values
Files in Scope
Primary:
src/lib/workflow/types.ts— current canonical Phase (incomplete)src/lib/workflow/state-schema.ts— Zod PhaseSchema (superset)src/lib/workflow/run-log-schema.ts— Zod PhaseSchema (incomplete)
Secondary (import consumers, verify compilation):
src/lib/ci/types.ts,src/lib/ci/triggers.ts,src/lib/ci/config.ts,src/lib/ci/inputs.tssrc/lib/content-analyzer.ts,src/lib/phase-signal.ts,src/lib/solve-comment-parser.tssrc/lib/workflow/phase-executor.ts,src/lib/workflow/batch-executor.tssrc/lib/workflow/worktree-manager.ts,src/lib/workflow/phase-mapper.tssrc/lib/workflow/state-hook.ts,src/lib/workflow/worktree-discovery.tssrc/lib/merge-check/types.ts(verdict types)
Also fix in this PR
The topological sort comment in batch-executor.ts:220-222 is backwards:
// Note: inDegree counts how many issues depend on each issue
// We want to process issues that nothing depends on last
// So we sort by: issues nothing depends on first, then dependent issuesLine 2 says "last" but the algorithm correctly processes them first. The comment should say "We want to process issues that have no dependencies first, so dependent issues come after their prerequisites." This is a 1-line fix but important — someone reading the comment and "correcting" the code to match it would break the algorithm.
Design Notes
Recommended approach: keep the Zod schema as the single source in a new src/lib/workflow/phase-types.ts (or consolidate into types.ts), export both PhaseSchema and type Phase = z.infer<typeof PhaseSchema>. State-schema and run-log-schema import and re-use it.
Activity
fix(#401): unify Phase type definitions into single source of truth
admarble commentedon Mar 25, 2026
Exec Phase: Implementation Complete
AC Coverage
Phase as StatePhasealias eliminatedas const+ ZodKey Files Changed
src/lib/workflow/types.ts— canonicalPhaseSchema+Phasetype (was manual string union)src/lib/workflow/state-schema.ts— imports + re-exports from types.tssrc/lib/workflow/run-log-schema.ts— imports + re-exports from types.tssrc/lib/workflow/batch-executor.ts— removedStatePhasealias, fixed topo-sort commentsrc/lib/workflow/phase-executor.ts— addedverify+mergertoRecord<Phase, string>mapssrc/lib/merge-check/types.ts— added Zod schemas for verdict typessrc/lib/workflow/phase-types.test.ts— new test (10 cases) ensuring schema identityQuality Gates
npm run buildnpm run lintnpm testPR
#426
admarble commentedon Mar 25, 2026
QA Review for Issue #401
AC Coverage
PhaseSchemaintypes.tswithz.enum(...)+type Phase = z.infer<>state-schema.tsandrun-log-schema.tsreference canonical definitionPhaseSchemafromtypes.tsand re-export; no independent definitionsPhase as StatePhasealiased import eliminatedbatch-executor.ts; usesPhasefromtypes.tsdirectlyas const+ Zod schemaCHECK_VERDICTS/BATCH_VERDICTSas const +z.enum()+ inferred typesphase-types.test.ts: identity checks (toBe) verify schemas are same objectCoverage: 6/6 AC items fully met
CI Status
build (20.x)build (22.x)typecheckvalidate-skillsvalidate-pluginCI Summary: 5 passed, 0 pending, 0 failed
Quality Metrics
any)Stale Branch Check
Test Coverage Analysis
src/lib/workflow/types.tsphase-types.test.ts(covers schema identity)src/lib/workflow/state-schema.tsphase-types.test.ts(verifies re-export)src/lib/workflow/run-log-schema.tsphase-types.test.ts+run-log-schema.test.tssrc/lib/workflow/batch-executor.tssrc/lib/workflow/phase-executor.tssrc/lib/merge-check/types.tsphase-types.test.ts(verdict schema tests)src/lib/workflow/phase-types.test.tsCHANGELOG.mdCoverage: 5/6 changed source files have test coverage
Critical paths without tests: None (phase-executor changes are type-checked by
Record<Phase, string>)Code Review
Strengths:
PhaseSchemadefined once, re-exported fromstate-schema.tsandrun-log-schema.tstoBe) verify schemas are the same object, not just structurally equal — catches any future divergenceWORKFLOW_PHASES = PhaseSchema.optionselegantly derives the array from the schemaCHECK_VERDICTS,BATCH_VERDICTS) follow same pattern withas const+ ZodIssues: None found
Suggestions: None — implementation is minimal and focused
Anti-Pattern Detection
Code Patterns
No anti-patterns detected in changed files:
0.0.0.0bindingsBuild Verification
N/A — Build passed
CHANGELOG Verification
Result: CHANGELOG requirements met
Call-Site Review
N/A — No new exported functions
Execution Evidence
N/A — No executable script changes (type/schema refactor only)
Skill Command Verification
N/A — No skill files changed
CLI Registration Verification
N/A — No option interface changes
Smoke Test
Not Required — No workflow-affecting changes (type definitions only)
Self-Evaluation
toBe) catch any divergence;Record<Phase, string>maps catch missing phases at compile timetypes.ts— prevented by the single-source pattern and testsVerdict: READY_FOR_MERGE
All 6 acceptance criteria are met. The implementation cleanly consolidates three divergent Phase definitions into a single Zod schema source of truth. Tests verify schema identity (not just structural equality), ensuring future phases need only be added in one place. CI is fully green.
Documentation
Next Steps
/docs 401if documentation is desiredadmarble commentedon Mar 25, 2026
QA Review for Issue #401
AC Coverage
PhaseSchema = z.enum([...])intypes.ts:14,type Phase = z.infer<>at line 29state-schema.tsandrun-log-schema.tsreference canonical definitionPhaseSchemafromtypes.tsand re-export; no independentz.enumdefinitions remainPhase as StatePhasealiased import eliminatedbatch-executor.ts:15;phase as Phaseused at lines 671, 755as const+ Zod schemaCHECK_VERDICTS/BATCH_VERDICTSas const +z.enum()+ inferred types inmerge-check/types.ts:30-39phase-types.test.ts: identity checks (toBe) verifyStatePhaseSchema === PhaseSchema,RunLogPhaseSchema === PhaseSchema,WORKFLOW_PHASES === PhaseSchema.optionsCoverage: 6/6 AC items fully met
Quality Plan Verification
N/A — No quality plan found in issue comments
CI Status
build (20.x)build (22.x)typecheckvalidate-skillsvalidate-pluginCI Summary: 5 passed, 0 pending, 0 failed
Stale Branch Check
Quality Metrics
any)Cache Status
N/A — Fresh run
Build Verification
N/A — Build passed
Test Coverage Analysis
src/lib/workflow/types.tsphase-types.test.ts(schema identity)src/lib/workflow/state-schema.tsphase-types.test.ts(re-export identity)src/lib/workflow/run-log-schema.tsphase-types.test.ts(re-export identity)src/lib/workflow/batch-executor.tssrc/lib/workflow/phase-executor.tsRecord<Phase, string>maps — enforced by TypeScriptsrc/lib/merge-check/types.tsphase-types.test.ts(verdict schema tests)src/lib/workflow/phase-types.test.tsCHANGELOG.mdCoverage: 5/6 changed source files have test coverage
Critical paths without tests: None
Code Review
Strengths:
PhaseSchemadefined once intypes.ts, re-exported fromstate-schema.tsandrun-log-schema.tstoBe) catch future divergence — stronger than structural equalityWORKFLOW_PHASES = PhaseSchema.optionselegantly derives the array from the schematypes.ts→run-log-schema.tsimport is type-only (erased at runtime)phase-executor.tscorrectly addsverify/mergerentries toRecord<Phase, string>maps (required by unified type)Issues: None
Suggestions: None — implementation is minimal and focused
Test Quality Review
Anti-Pattern Detection
Code Patterns
No anti-patterns detected:
Dependency Audit
N/A — No dependency changes
Call-Site Review
N/A — No new exported functions
Execution Evidence
N/A — No executable script changes (type/schema refactor only)
Skill Command Verification
N/A — No skill files changed
CLI Registration Verification
N/A — No option interface changes
Smoke Test
Not Required — No workflow-affecting changes
CHANGELOG Verification
Result: CHANGELOG requirements met
Self-Evaluation
toBe) catch any divergence;Record<Phase, string>maps catch missing phases at compile timetypes.ts— prevented by the single-source pattern + identity testsVerdict: READY_FOR_MERGE
All 6 acceptance criteria are met. The implementation cleanly consolidates three divergent Phase definitions into a single Zod schema source of truth in
types.ts. Identity-based tests ensurestate-schema.tsandrun-log-schema.tsre-export the exact same object. The topological sort comment fix is correct. CI is fully green (5/5).Documentation
Next Steps
fix(#401): import Phase from canonical types.ts in worktree-discovery
admarble commentedon Mar 25, 2026
Documentation Generated
File:
docs/features/phase-type-definitions.mdSections Included:
Next Steps:
Ready to merge!
docs(#401): add phase type definitions developer reference
fix(#401): unify Phase type definitions into single source of truth (#…