{"record":{"id":"1d6c467a44dffed0","repo":"eyaltoledano/claude-task-master","slug":"green-phase-must-have-zero-failures","errorCode":null,"errorMessage":"GREEN phase must have zero failures","messagePattern":"GREEN phase must have zero failures","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/workflow/orchestrators/workflow-orchestrator.ts","lineNumber":229,"sourceCode":"\t\t\t\tthis.context.currentTDDPhase = 'GREEN';\n\t\t\t\tthis.emit('tdd:green:started');\n\t\t\t\tbreak;\n\n\t\t\tcase 'GREEN_PHASE_COMPLETE':\n\t\t\t\tif (currentTDD !== 'GREEN') {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Invalid transition: GREEN_PHASE_COMPLETE from non-GREEN phase'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Validate test results are provided\n\t\t\t\tif (!event.testResults) {\n\t\t\t\t\tthrow new Error('Test results required for GREEN phase transition');\n\t\t\t\t}\n\n\t\t\t\t// Validate GREEN phase has no failures\n\t\t\t\tif (event.testResults.failed !== 0) {\n\t\t\t\t\tthrow new Error('GREEN phase must have zero failures');\n\t\t\t\t}\n\n\t\t\t\t// Store test results in context\n\t\t\t\tthis.context.lastTestResults = event.testResults;\n\n\t\t\t\tthis.emit('tdd:green:completed');\n\t\t\t\tthis.context.currentTDDPhase = 'COMMIT';\n\t\t\t\tthis.emit('tdd:commit:started');\n\t\t\t\tbreak;\n\n\t\t\tcase 'COMMIT_COMPLETE':\n\t\t\t\tif (currentTDD !== 'COMMIT') {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Invalid transition: COMMIT_COMPLETE from non-COMMIT phase'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.emit('tdd:commit:completed');\n\t\t\t\t// Mark current subtask as completed","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/workflow/orchestrators/workflow-orchestrator.ts#L211-L247","documentation":"GREEN in this TDD state machine means 'implement until all tests pass', so the orchestrator refuses to leave GREEN while any test is failing. This error is thrown when a GREEN_PHASE_COMPLETE event carries testResults whose failed count is not 0. Unlike RED (where failing tests are expected and drive the flow), only a fully green suite may advance the workflow to COMMIT.","triggerScenarios":"Calling transition({ type: 'GREEN_PHASE_COMPLETE', testResults }) where testResults.failed > 0; dispatching the event before the full suite has been re-run after implementation; reporting results from a partial/filtered test run that excludes still-failing tests from its counts incorrectly.","commonSituations":"Developer/agent declares the subtask done while some tests still fail; flaky tests fail intermittently when the GREEN suite runs; a test-runner integration counts errors/skipped tests as failures; stale results from a previous run are attached to the event.","solutions":["Fix the failing tests or the implementation, re-run the suite until failed === 0, then dispatch GREEN_PHASE_COMPLETE with the fresh passing results.","Re-run the full test suite immediately before the transition so the attached summary reflects current code.","Investigate flaky tests (isolate, mock external dependencies, add retries) if failures are intermittent.","If the subtask cannot be made to pass, abort or restructure the workflow instead of forcing the GREEN transition."],"exampleFix":"// before\nawait orchestrator.transition({ type: 'GREEN_PHASE_COMPLETE', testResults: currentRun });\n\n// after\nif (currentRun.failed !== 0) {\n  throw new Error(`Cannot complete GREEN: ${currentRun.failed} test(s) still failing`);\n}\nawait orchestrator.transition({ type: 'GREEN_PHASE_COMPLETE', testResults: currentRun });","handlingStrategy":"validation","validationCode":"if (testResults.failed !== 0) {\n  throw new Error(`Refusing GREEN_PHASE_COMPLETE: ${testResults.failed} test(s) failing`);\n}","typeGuard":"function isGreenPassing(r: { total: number; passed: number; failed: number }): boolean {\n  return r.failed === 0 && r.passed + r.failed === r.total;\n}","tryCatchPattern":"try {\n  await orchestrator.transition({ type: 'GREEN_PHASE_COMPLETE', testResults });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('zero failures')) {\n    // stay in GREEN: fix code/tests and re-run before retrying\n  } else {\n    throw e;\n  }\n}","preventionTips":["Gate the transition in CI code on a green suite: only dispatch when failed === 0.","Re-run the full suite right before the transition; never reuse stale summaries.","Treat intermittent failures as blockers — stabilize or quarantine flaky tests before completing GREEN."],"tags":["validation","workflow","tdd","tests","precondition-failed"],"backgroundTag":"tests-still-failing","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}