{"record":{"id":"0d5dfac8d635dfef","repo":"eyaltoledano/claude-task-master","slug":"cannot-finalize-workflow-in-phase-phase-comple","errorCode":null,"errorMessage":"Cannot finalize workflow in ${phase} phase. Complete all subtasks first.","messagePattern":"Cannot finalize workflow in (.+?) phase\\. Complete all subtasks first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/workflow/services/workflow.service.ts","lineNumber":508,"sourceCode":"\t\t\tawait this.updateTaskStatus(completedSubtaskId, 'done', context.tag);\n\t\t}\n\n\t\treturn this.getStatus();\n\t}\n\n\t/**\n\t * Finalize and complete the workflow\n\t * Validates working tree is clean before marking complete\n\t * Cleans up workflow state file after successful completion\n\t */\n\tasync finalizeWorkflow(): 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 phase = this.orchestrator.getCurrentPhase();\n\t\tif (phase !== 'FINALIZE') {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot finalize workflow in ${phase} phase. Complete all subtasks first.`\n\t\t\t);\n\t\t}\n\n\t\t// Check working tree is clean\n\t\tconst gitAdapter = new GitAdapter(this.projectRoot);\n\t\tconst statusSummary = await gitAdapter.getStatusSummary();\n\n\t\tif (!statusSummary.isClean) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot finalize workflow: working tree has uncommitted changes.\\n` +\n\t\t\t\t\t`Staged: ${statusSummary.staged}, Modified: ${statusSummary.modified}, ` +\n\t\t\t\t\t`Deleted: ${statusSummary.deleted}, Untracked: ${statusSummary.untracked}\\n` +\n\t\t\t\t\t`Please commit all changes before finalizing the workflow.`\n\t\t\t);\n\t\t}\n\n\t\t// Capture task ID before transitioning","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/workflow/services/workflow.service.ts#L490-L526","documentation":"Thrown by WorkflowService.finalizeWorkflow() when the workflow orchestrator's current phase is not FINALIZE. Finalization (which commits and wraps up the workflow) is only permitted once all implementation subtasks are complete and the orchestrator has advanced to the FINALIZE phase. Throwing early prevents committing or archiving a half-finished workflow.","triggerScenarios":"Calling workflowService.finalizeWorkflow() while the orchestrator's getCurrentPhase() returns IMPLEMENT, REVIEW, or any phase other than 'FINALIZE' — typically because some subtasks are still pending/in-progress.","commonSituations":"Developers invoking finalize right after starting a workflow, after completing only some subtasks, or resuming a workflow that still has open subtasks. Also occurs when the phase-transition logic hasn't run yet (e.g. subtasks completed but phase not advanced).","solutions":["Complete all remaining subtasks of the workflow so the orchestrator advances to the FINALIZE phase, then call finalizeWorkflow() again.","Check the current phase first with workflowService.orchestrator.getCurrentPhase() (or an equivalent getter) and only finalize when it equals 'FINALIZE'.","If all subtasks are actually done but the phase is stale, restart or resume the workflow so phase computation re-runs.","If you don't intend to finalize the whole workflow, remove the finalizeWorkflow() call."],"exampleFix":"// before\nawait workflowService.finalizeWorkflow(); // throws in IMPLEMENT phase\n// after\nconst phase = workflowService.getPhase?.() ?? 'IMPLEMENT';\nif (phase === 'FINALIZE') {\n  await workflowService.finalizeWorkflow();\n} else {\n  await workflowService.continueWorkflow(); // finish remaining subtasks first\n}","handlingStrategy":"validation","validationCode":"// check phase before finalizing\nconst phase = workflowService.getPhase?.() ?? 'IMPLEMENT';\nif (phase !== 'FINALIZE') throw new Error(`Workflow not ready to finalize (phase: ${phase}); complete all subtasks first.`);","typeGuard":null,"tryCatchPattern":"try {\n  await workflowService.finalizeWorkflow();\n} catch (e) {\n  if (/Cannot finalize workflow in .* phase/.test(e.message)) {\n    // resume/continue workflow until FINALIZE phase\n  } else throw e;\n}","preventionTips":["Only call finalizeWorkflow after confirming all subtasks are complete.","Expose/check the orchestrator phase in your tooling before finalize.","Drive finalization from the workflow's own completion event rather than manual calls."],"tags":["workflow","state-machine","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}