{"record":{"id":"3b9b0d1c4b3512b9","repo":"shareAI-lab/learn-claude-code","slug":"invalid-task-id-task-id-r-3b9b0d","errorCode":null,"errorMessage":"Invalid task ID: {task_id!r}","messagePattern":"Invalid task ID: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"s15_integrated_harness/code.py","lineNumber":200,"sourceCode":"        finally:\n            if team is not None:\n                team.release()\n\n\n@dataclass\nclass Task:\n    id: str\n    subject: str\n    description: str\n    status: str\n    owner: str | None\n    blockedBy: list[str]\n    worktree: str | None = None\n\n\ndef _task_path(task_id: str) -> Path:\n    if not isinstance(task_id, str) or not TASK_ID_PATTERN.fullmatch(task_id):\n        raise ValueError(f\"Invalid task ID: {task_id!r}\")\n    path = (TASKS_DIR / f\"{task_id}.json\").resolve()\n    if (not TASKS_ROOT.is_relative_to(WORKDIR.resolve())\n            or not path.is_relative_to(TASKS_ROOT)):\n        raise ValueError(f\"Invalid task ID: {task_id!r}\")\n    return path\n\n\ndef create_task(subject: str, description: str = \"\",\n                blockedBy: list[str] | None = None) -> Task:\n    subject = subject.strip()\n    if not subject:\n        raise ValueError(\"Task subject cannot be empty\")\n    dependencies = list(dict.fromkeys(blockedBy or []))\n    with task_store_lock():\n        for dependency in dependencies:\n            if not _task_path(dependency).is_file():\n                raise ValueError(f\"Dependency not found: {dependency}\")\n        for _ in range(100):","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/shareAI-lab/learn-claude-code/blob/985456f4adea6f4df8fbad4112245dbd97444eae/s15_integrated_harness/code.py#L182-L218","documentation":"_task_path() validates a task ID before mapping it to a file under the tasks directory. This first raise fires when task_id is not a str or fails TASK_ID_PATTERN.fullmatch — i.e. the ID is malformed (wrong shape, bad characters) before any filesystem resolution happens. All task APIs (create/load/save/get_task_json/can_start) funnel through this guard.","triggerScenarios":"Calling load_task/save_task/create_task dependencies with values like None, an int, 'task_abc' not matching the pattern, IDs containing slashes or '../', or empty strings. Also model-generated tool calls passing unvalidated IDs from conversation text.","commonSituations":"An LLM tool call hallucinating a task ID format; passing a file stem with whitespace; passing a Path object instead of str; IDs from an older format after the pattern was tightened.","solutions":["Generate IDs only via create_task() (format task_ + 8 hex chars, e.g. task_1a2b3c4d) and pass those verbatim.","Sanitize caller input against the same pattern (regex like r'task_[0-9a-f]{8}') before invoking task APIs.","If you changed TASK_ID_PATTERN, regenerate/rewrite existing task JSON filenames to match."],"exampleFix":"// before\nload_task(user_supplied_id)  // raises ValueError: Invalid task ID\n\n// after\nimport re\nTASK_ID_RE = re.compile(r\"task_[0-9a-f]{8}\")\nif not isinstance(user_supplied_id, str) or not TASK_ID_RE.fullmatch(user_supplied_id):\n    return f\"Error: malformed task ID {user_supplied_id!r}\"\ntask = load_task(user_supplied_id)","handlingStrategy":"validation","validationCode":"import re\n\nTASK_ID_RE = re.compile(r\"task_[0-9a-f]{8}\")\n\ndef is_valid_task_id(task_id) -> bool:\n    return isinstance(task_id, str) and bool(TASK_ID_RE.fullmatch(task_id))","typeGuard":"def is_task_id(value) -> bool:\n    return isinstance(value, str) and bool(__import__('re').fullmatch(r'task_[0-9a-f]{8}', value))","tryCatchPattern":"try:\n    task = load_task(task_id)\nexcept ValueError as e:\n    if \"Invalid task ID\" in str(e):\n        return f\"Error: {e}\"  # surface to model/user, do not retry\n    raise","preventionTips":["Only use IDs returned by create_task().","Validate IDs against task_[0-9a-f]{8} before calling task APIs.","Never accept task IDs verbatim from freeform model text without a regex check."],"tags":["validation","task-id","filesystem","input-validation"],"backgroundTag":null,"analyzedSha":"985456f4adea6f4df8fbad4112245dbd97444eae","analyzedAt":"2026-08-14T22:02:26.028Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}