{"record":{"id":"556ee321f752797f","repo":"eyaltoledano/claude-task-master","slug":"failed-to-load-workflow-state-error-message","errorCode":null,"errorMessage":"Failed to load workflow state: ${error.message}","messagePattern":"Failed to load workflow state: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/workflow/managers/workflow-state-manager.ts","lineNumber":123,"sourceCode":"\t\t\tawait fs.access(this.statePath);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Load workflow state from disk\n\t */\n\tasync load(): Promise<WorkflowState> {\n\t\ttry {\n\t\t\tconst content = await fs.readFile(this.statePath, 'utf-8');\n\t\t\treturn JSON.parse(content) as WorkflowState;\n\t\t} catch (error: any) {\n\t\t\tif (error.code === 'ENOENT') {\n\t\t\t\tthrow new Error(`Workflow state file not found at ${this.statePath}`);\n\t\t\t}\n\t\t\tthrow new Error(`Failed to load workflow state: ${error.message}`);\n\t\t}\n\t}\n\n\t/**\n\t * Save workflow state to disk\n\t * Uses steno for atomic writes and automatic queueing of concurrent saves\n\t */\n\tasync save(state: WorkflowState): Promise<void> {\n\t\ttry {\n\t\t\t// Ensure writer is initialized (creates directory if needed)\n\t\t\tawait this.ensureWriter();\n\n\t\t\t// Serialize and validate JSON\n\t\t\tconst jsonContent = JSON.stringify(state, null, 2);\n\n\t\t\t// Validate that the JSON is well-formed by parsing it back\n\t\t\ttry {\n\t\t\t\tJSON.parse(jsonContent);","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/workflow/managers/workflow-state-manager.ts#L105-L141","documentation":"WorkflowStateManager.load() wraps any non-ENOENT failure (permission denied, invalid JSON from JSON.parse, EACCES, EISDIR) as a plain Error `Failed to load workflow state: <message>`. It distinguishes real load/parse problems from the benign 'file not found' case.","triggerScenarios":"State file exists but contains invalid JSON (truncated by a crash, hand-edited); read permission denied; statePath is a directory; disk I/O error during fs.readFile.","commonSituations":"Killed process leaving a half-written state file; user manually editing the JSON and introducing a syntax error; restrictive permissions after copying the project as root or via a container volume mount.","solutions":["Read the embedded original message to decide: JSON SyntaxError → repair/validate the file; EACCES → fix permissions","Validate the JSON with `JSON.parse(fs.readFileSync(statePath,'utf8'))` manually and fix syntax errors","Restore the state file from backup or delete it and let the workflow recreate it via save()","Check ownership/permissions (chmod/chown) and that statePath is a file, not a directory"],"exampleFix":"// before\nconst state = await stateManager.load(); // opaque: Failed to load workflow state: Unexpected token\n// after\ntry {\n  const state = await stateManager.load();\n} catch (e) {\n  if (e instanceof SyntaxError || String(e.message).includes('Unexpected token')) {\n    await stateManager.save(DEFAULT_WORKFLOW_STATE); // reset corrupt state\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"import { readFileSync } from 'fs';\ntry { JSON.parse(readFileSync(statePath, 'utf8')); }\ncatch (e) { /* corrupt or unreadable — reset or repair before load() */ }","typeGuard":"const isLoadFailure = (e: unknown) =>\n  e instanceof Error && e.message.startsWith('Failed to load workflow state:');","tryCatchPattern":"try {\n  state = await stateManager.load();\n} catch (e) {\n  if (isLoadFailure(e)) {\n    await stateManager.save(DEFAULT_WORKFLOW_STATE); // reset corrupt state\n    state = DEFAULT_WORKFLOW_STATE;\n  } else throw e;\n}","preventionTips":["Use atomic writes for state (the manager's save uses steno) — never truncate via direct fs writes","Validate state JSON after manual edits before running the workflow","Check file permissions/ownership after copying projects between users/containers","Back up the state file; on parse failure, reset rather than retrying a doomed load"],"tags":["workflow","filesystem","json-parsing"],"backgroundTag":"json-parse-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}