{"record":{"id":"0ff0276668fd4f8f","repo":"eyaltoledano/claude-task-master","slug":"not-in-active-tdd-phase","errorCode":null,"errorMessage":"Not in active TDD phase","messagePattern":"Not in active TDD phase","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/workflow/services/workflow.service.ts","lineNumber":425,"sourceCode":"\t\t\t\t\taction: 'unknown',\n\t\t\t\t\tdescription: 'Unknown TDD phase',\n\t\t\t\t\tnextSteps: 'Use autopilot_status to check workflow state.'\n\t\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Complete current TDD phase with test results\n\t */\n\tasync completePhase(testResults: TestResult): 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) {\n\t\t\tthrow new Error('Not in active TDD phase');\n\t\t}\n\n\t\t// Transition based on current phase\n\t\tswitch (tddPhase) {\n\t\t\tcase 'RED':\n\t\t\t\tawait this.orchestrator.transition({\n\t\t\t\t\ttype: 'RED_PHASE_COMPLETE',\n\t\t\t\t\ttestResults\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase 'GREEN':\n\t\t\t\tawait this.orchestrator.transition({\n\t\t\t\t\ttype: 'GREEN_PHASE_COMPLETE',\n\t\t\t\t\ttestResults\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase 'COMMIT':\n\t\t\t\tthrow new Error(","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/workflow/services/workflow.service.ts#L407-L443","documentation":"completePhase() requires the workflow to currently be inside an active TDD phase (RED, GREEN, or COMMIT) of the SUBTASK_LOOP. getCurrentTDDPhase() returns undefined when the workflow is in PREFLIGHT, BRANCH_SETUP, FINALIZE, COMPLETE, or otherwise not mid-cycle, and the method throws 'Not in active TDD phase'. Unlike the no-orchestrator error, the workflow exists here; it is just in a phase where test results cannot be applied.","triggerScenarios":"Calling completePhase() right after startWorkflow() while still in PREFLIGHT/BRANCH_SETUP (BRANCH_CREATED transition not yet processed); calling it during FINALIZE or COMPLETE; calling it twice in a row when the first call already advanced RED->GREEN and results were stale-resubmitted for a non-loop phase.","commonSituations":"Reporting test results before the subtask loop began; resuming a workflow that was mid-finalize; automation double-firing completePhase so the second call lands in a transition window with no TDD phase.","solutions":["Check status first: only call completePhase() when status.phase === 'SUBTASK_LOOP' and status.tddPhase is RED or GREEN","Wait for startWorkflow() to fully finish (it transitions through PREFLIGHT and BRANCH_CREATED) before reporting results","Use getNextAction(); if action is 'unknown' or 'finalize_workflow', the workflow is not in a phase that accepts test results","Guard with getCurrentTDDPhase()/status.tddPhase before calling completePhase()"],"exampleFix":"// before\nawait workflowService.completePhase(results); // throws outside RED/GREEN\n// after\nconst s = workflowService.getStatus();\nif (s.phase === 'SUBTASK_LOOP' && (s.tddPhase === 'RED' || s.tddPhase === 'GREEN')) {\n  await workflowService.completePhase(results);\n}","handlingStrategy":"validation","validationCode":"const s = workflowService.getStatus();\nif (s.phase !== 'SUBTASK_LOOP' || !s.tddPhase) {\n  throw new Error(`Cannot completePhase in phase ${s.phase}`);\n}","typeGuard":"function isInActiveTddPhase(s: { phase: string; tddPhase?: string }): boolean {\n  return s.phase === 'SUBTASK_LOOP' && (s.tddPhase === 'RED' || s.tddPhase === 'GREEN' || s.tddPhase === 'COMMIT');\n}","tryCatchPattern":"try {\n  await workflowService.completePhase(results);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Not in active TDD phase') {\n    const s = workflowService.getStatus();\n    // wait for SUBTASK_LOOP or route to commit()/finalize as appropriate\n  } else throw e;\n}","preventionTips":["Wait for startWorkflow() to fully return before reporting results (PREFLIGHT/BRANCH_SETUP must finish)","Check getStatus().phase === 'SUBTASK_LOOP' before every completePhase() call","Do not double-fire completePhase for the same cycle; each call advances the state machine","Use getNextAction() to confirm the expected action before transitioning"],"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"}