{"record":{"id":"f447a5295fdc8f4d","repo":"eyaltoledano/claude-task-master","slug":"config-error-f447a5","errorCode":"CONFIG_ERROR","errorMessage":"'Failed to save runtime state'","messagePattern":"'Failed to save runtime state'","errorType":"exception","errorClass":"TaskMasterError","httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/config/services/runtime-state-manager.service.ts","lineNumber":107,"sourceCode":"\t */\n\tasync saveState(): Promise<void> {\n\t\tconst stateDir = path.dirname(this.stateFilePath);\n\n\t\ttry {\n\t\t\tawait fs.mkdir(stateDir, { recursive: true });\n\n\t\t\tconst stateToSave = {\n\t\t\t\t...this.currentState,\n\t\t\t\tlastUpdated: new Date().toISOString()\n\t\t\t};\n\n\t\t\tawait fs.writeFile(\n\t\t\t\tthis.stateFilePath,\n\t\t\t\tJSON.stringify(stateToSave, null, 2),\n\t\t\t\t'utf-8'\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new TaskMasterError(\n\t\t\t\t'Failed to save runtime state',\n\t\t\t\tERROR_CODES.CONFIG_ERROR,\n\t\t\t\t{ statePath: this.stateFilePath },\n\t\t\t\terror as Error\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get the currently active tag\n\t */\n\tgetCurrentTag(): string {\n\t\treturn this.currentState.currentTag;\n\t}\n\n\t/**\n\t * Set the current tag\n\t */","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/config/services/runtime-state-manager.service.ts#L89-L125","documentation":"TaskMasterError thrown by RuntimeStateManager.saveState when JSON.stringify + fs.writeFile of the runtime state file fails. It is surfaced through setCurrentTag and updateMetadata, so any tag switch or metadata update that cannot persist the state file fails with this error. The state file path is attached in details.statePath and the fs error as cause.","triggerScenarios":"setCurrentTag(tag) or updateMetadata(patch) triggering saveState when the state file's parent directory does not exist, the file/dir is read-only or owned by another user, the disk is full, or stateFilePath points to an invalid location.","commonSituations":"First run in a fresh project where the .taskmaster directory was gitignored and never created; running the CLI in a Docker container with a read-only volume; permission mismatch after running once with sudo; EACCES on shared CI machines; circular references in metadata causing JSON.stringify to throw.","solutions":["Check error.details.statePath and error.cause to identify the exact fs failure","Create the state file's parent directory (mkdir -p) and ensure write permission for the current user","If metadata update caused it, verify the metadata object is JSON-serializable (no circular refs, no BigInt)","Check available disk space (df -h) if the error is ENOSPC","Avoid running with sudo which can leave root-owned state files; chown them back"],"exampleFix":"// before\nawait stateManager.setCurrentTag('feature-x'); // throws if dir missing\n// after\nimport { mkdirSync } from 'fs';\nmkdirSync(path.dirname(statePath), { recursive: true });\nawait stateManager.setCurrentTag('feature-x');","handlingStrategy":"validation","validationCode":"import { accessSync, constants } from 'fs';\nconst dir = path.dirname(statePath);\ntry {\n  accessSync(dir, constants.W_OK);\n} catch {\n  mkdirSync(dir, { recursive: true });\n}","typeGuard":"function isSerializable(v: unknown): boolean {\n  try { JSON.stringify(v); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  await stateManager.setCurrentTag(tag);\n} catch (e) {\n  if (e instanceof TaskMasterError && e.details?.statePath) {\n    console.error(`Cannot write ${e.details.statePath}:`, (e.cause as Error)?.message);\n  }\n  // proceed in-memory or abort the tag switch\n}","preventionTips":["Create the state directory (mkdir -p) at app startup","Ensure metadata passed to updateMetadata is plain JSON-serializable data","Run as a user owning the project directory; avoid sudo-created root-owned files","Check disk space before large state writes","Add the state directory to permissions checks in container/CI setups"],"tags":["config","filesystem","state","persistence"],"backgroundTag":"config-file-write-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}