{"record":{"id":"6d1af5f13a77ea40","repo":"shareAI-lab/learn-claude-code","slug":"task-task-id-not-found-6d1af5","errorCode":null,"errorMessage":"Task {task_id} not found","messagePattern":"Task (.+?) not found","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agents/s12_worktree_task_isolation.py","lineNumber":143,"sourceCode":"        self.dir.mkdir(parents=True, exist_ok=True)\n        self._next_id = self._max_id() + 1\n\n    def _max_id(self) -> int:\n        ids = []\n        for f in self.dir.glob(\"task_*.json\"):\n            try:\n                ids.append(int(f.stem.split(\"_\")[1]))\n            except Exception:\n                pass\n        return max(ids) if ids else 0\n\n    def _path(self, task_id: int) -> Path:\n        return self.dir / f\"task_{task_id}.json\"\n\n    def _load(self, task_id: int) -> dict:\n        path = self._path(task_id)\n        if not path.exists():\n            raise ValueError(f\"Task {task_id} not found\")\n        return json.loads(path.read_text())\n\n    def _save(self, task: dict):\n        self._path(task[\"id\"]).write_text(json.dumps(task, indent=2))\n\n    def create(self, subject: str, description: str = \"\") -> str:\n        task = {\n            \"id\": self._next_id,\n            \"subject\": subject,\n            \"description\": description,\n            \"status\": \"pending\",\n            \"owner\": \"\",\n            \"worktree\": \"\",\n            \"blockedBy\": [],\n            \"created_at\": time.time(),\n            \"updated_at\": time.time(),\n        }\n        self._save(task)","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/shareAI-lab/learn-claude-code/blob/985456f4adea6f4df8fbad4112245dbd97444eae/agents/s12_worktree_task_isolation.py#L125-L161","documentation":"Raised by the worktree task manager's _load() in agents/s12_worktree_task_isolation.py:143 when task_<id>.json is absent from the tasks dir. Unlike the s07 variant, this file's id-scan _max_id() wraps int() in try/except, so corrupt task filenames degrade gracefully — this error strictly means the requested id has no backing file.","triggerScenarios":"get/update/bind_worktree with a nonexistent, stale, or externally deleted id; ids from a previous run against a freshly initialized tasks dir; or a race where another process removed the file between list and load.","commonSituations":"Worktree task files deleted by a cleanup script or `git clean` while ids persist in conversation or memory. Resuming an old session against a reset tasks dir. Model inventing ids instead of listing tasks first.","solutions":["Always enumerate tasks (list) first and use returned ids; this manager also exposes exists(task_id) — check it before load","If the tasks dir was reset, re-create tasks and re-bind worktrees; stale ids are unrecoverable","Guard external cleanup (git clean / rm) so it skips the tasks dir"],"exampleFix":"# before\ntasks.update(task_id=12, status=\"in_progress\")\n# ValueError: Task 12 not found\n\n# after\nif tasks.exists(12):\n    tasks.update(task_id=12, status=\"in_progress\")\nelse:\n    created = json.loads(tasks.create(\"redo the work\"))\n    tasks.update(task_id=created[\"id\"], status=\"in_progress\")","handlingStrategy":"validation","validationCode":"# the manager exposes exists(); use it before any id-based call\nif not TASKS.exists(task_id):\n    created = json.loads(TASKS.create(subject=\"recreated task\"))\n    task_id = created[\"id\"]\nresult = TASKS.update(task_id, status=\"in_progress\")","typeGuard":"def is_loadable_task_id(task_id: object, manager) -> bool:\n    return isinstance(task_id, int) and not isinstance(task_id, bool) and task_id >= 1 and manager.exists(task_id)","tryCatchPattern":"try:\n    task = TASKS._load(task_id)  # or the public get/update/bind_worktree\nexcept ValueError as e:\n    if \"not found\" in str(e):\n        return f\"Task {task_id} missing (tasks dir reset or cleaned). List tasks and use a current id.\"\n    raise","preventionTips":["Check manager.exists(task_id) before id-based operations","Enumerate with list() and use returned ids; never reuse ids from earlier sessions after a dir reset","Exclude the tasks dir from git clean / cleanup scripts"],"tags":["validation","task-system","worktree","persistence","python"],"backgroundTag":null,"analyzedSha":"985456f4adea6f4df8fbad4112245dbd97444eae","analyzedAt":"2026-08-14T22:02:26.028Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}