eyaltoledano/claude-task-master · error
Cannot commit in ${tddPhase} phase. Complete RED and GREEN p
Error message
Cannot commit in ${tddPhase} phase. Complete RED and GREEN phases first. What it means
commit() is only valid during the COMMIT TDD phase, reached after RED and GREEN complete successfully. If getCurrentTDDPhase() returns anything else (RED, GREEN, or undefined outside the subtask loop), the method throws this message telling you to finish RED and GREEN first. The workflow is active; it is simply not far enough through the cycle.
Source
Thrown at packages/tm-core/src/modules/workflow/services/workflow.service.ts:464
default:
throw new Error(`Unknown TDD phase: ${tddPhase}`);
}
return this.getStatus();
}
/**
* Commit current changes and advance workflow
*/
async commit(): Promise<WorkflowStatus> {
if (!this.orchestrator) {
throw new Error('No active workflow. Start or resume a workflow first.');
}
const tddPhase = this.orchestrator.getCurrentTDDPhase();
if (tddPhase !== 'COMMIT') {
throw new Error(
`Cannot commit in ${tddPhase} phase. Complete RED and GREEN phases first.`
);
}
// Capture current subtask before transitioning
const currentSubtask = this.orchestrator.getCurrentSubtask();
const completedSubtaskId = currentSubtask?.id;
// Transition COMMIT phase complete
await this.orchestrator.transition({
type: 'COMMIT_COMPLETE'
});
// Check if should advance to next subtask
const progress = this.orchestrator.getProgress();
if (progress.current < progress.total) {
await this.orchestrator.transition({ type: 'SUBTASK_COMPLETE' });
} else {View on GitHub (pinned to c0c98d367c)
Solutions
- Complete RED first: run tests expecting failure, then completePhase(results) to move to GREEN
- Complete GREEN: implement until tests pass, then completePhase(results) to move to COMMIT
- Only call commit() when getStatus().tddPhase === 'COMMIT' (or getNextAction().action === 'commit_changes')
- After resuming mid-RED/GREEN, re-run the phase work before attempting commit
Example fix
// before
await workflowService.commit(); // throws in RED/GREEN
// after
let s = workflowService.getStatus();
if (s.tddPhase === 'RED' || s.tddPhase === 'GREEN') {
await workflowService.completePhase(results); // advance the cycle
s = workflowService.getStatus();
}
if (s.tddPhase === 'COMMIT') await workflowService.commit(); Defensive patterns
Strategy: validation
Validate before calling
const s = workflowService.getStatus();
if (s.tddPhase !== 'COMMIT') {
throw new Error(`Finish RED/GREEN first (current: ${s.tddPhase})`);
}
await workflowService.commit(); Type guard
function isCommitPhaseError(e: unknown): e is Error {
return e instanceof Error && e.message.startsWith('Cannot commit in');
} Try / catch
try {
await workflowService.commit();
} catch (e) {
if (isCommitPhaseError(e)) {
// advance the cycle first
await workflowService.completePhase(results);
await workflowService.commit();
} else throw e;
} Prevention
- Always run completePhase() for RED and GREEN before attempting commit
- Gate commit on getStatus().tddPhase === 'COMMIT'
- If tests fail in RED, fix/iterate before any commit attempt
- After resuming mid-cycle, redo the pending RED/GREEN work before committing
When it happens
Trigger: Calling commit() during RED (tests not yet written/failed) or GREEN (code not passing); calling commit() while phase is PREFLIGHT/BRANCH_SETUP/FINALIZE where tddPhase is undefined; skipping completePhase() after writing tests and jumping straight to commit.
Common situations: An agent trying to commit immediately after startWorkflow(); automation that maps 'commit' to every step; test failures kept the workflow in RED but the script proceeded to commit; resuming mid-cycle before the RED/GREEN phases were redone after a crash.
Related errors
- Invalid transition: RED_PHASE_COMPLETE from non-RED phase
- Invalid transition: GREEN_PHASE_COMPLETE from non-GREEN phas
- Invalid transition: COMMIT_COMPLETE from non-COMMIT phase
- Not in active TDD phase
- Workflow has been aborted
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/3a4a607935616efe.
Report an issue: GitHub.