{"record":{"id":"3a4a607935616efe","repo":"eyaltoledano/claude-task-master","slug":"cannot-commit-in-tddphase-phase-complete-red-a","errorCode":null,"errorMessage":"Cannot commit in ${tddPhase} phase. Complete RED and GREEN phases first.","messagePattern":"Cannot commit in (.+?) phase\\. Complete RED and GREEN phases first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/workflow/services/workflow.service.ts","lineNumber":464,"sourceCode":"\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unknown TDD phase: ${tddPhase}`);\n\t\t}\n\n\t\treturn this.getStatus();\n\t}\n\n\t/**\n\t * Commit current changes and advance workflow\n\t */\n\tasync commit(): Promise<WorkflowStatus> {\n\t\tif (!this.orchestrator) {\n\t\t\tthrow new Error('No active workflow. Start or resume a workflow first.');\n\t\t}\n\n\t\tconst tddPhase = this.orchestrator.getCurrentTDDPhase();\n\n\t\tif (tddPhase !== 'COMMIT') {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot commit in ${tddPhase} phase. Complete RED and GREEN phases first.`\n\t\t\t);\n\t\t}\n\n\t\t// Capture current subtask before transitioning\n\t\tconst currentSubtask = this.orchestrator.getCurrentSubtask();\n\t\tconst completedSubtaskId = currentSubtask?.id;\n\n\t\t// Transition COMMIT phase complete\n\t\tawait this.orchestrator.transition({\n\t\t\ttype: 'COMMIT_COMPLETE'\n\t\t});\n\n\t\t// Check if should advance to next subtask\n\t\tconst progress = this.orchestrator.getProgress();\n\t\tif (progress.current < progress.total) {\n\t\t\tawait this.orchestrator.transition({ type: 'SUBTASK_COMPLETE' });\n\t\t} else {","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/workflow/services/workflow.service.ts#L446-L482","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait workflowService.commit(); // throws in RED/GREEN\n// after\nlet s = workflowService.getStatus();\nif (s.tddPhase === 'RED' || s.tddPhase === 'GREEN') {\n  await workflowService.completePhase(results); // advance the cycle\n  s = workflowService.getStatus();\n}\nif (s.tddPhase === 'COMMIT') await workflowService.commit();","handlingStrategy":"validation","validationCode":"const s = workflowService.getStatus();\nif (s.tddPhase !== 'COMMIT') {\n  throw new Error(`Finish RED/GREEN first (current: ${s.tddPhase})`);\n}\nawait workflowService.commit();","typeGuard":"function isCommitPhaseError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('Cannot commit in');\n}","tryCatchPattern":"try {\n  await workflowService.commit();\n} catch (e) {\n  if (isCommitPhaseError(e)) {\n    // advance the cycle first\n    await workflowService.completePhase(results);\n    await workflowService.commit();\n  } else throw e;\n}","preventionTips":["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"],"tags":["workflow","tdd","state-machine"],"backgroundTag":"invalid-workflow-phase","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}