shareAI-lab/learn-claude-code · error · ValueError
Task {task_id} not found
Error message
Task {task_id} not found What it means
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.
Source
Thrown at agents/s12_worktree_task_isolation.py:143
self.dir.mkdir(parents=True, exist_ok=True)
self._next_id = self._max_id() + 1
def _max_id(self) -> int:
ids = []
for f in self.dir.glob("task_*.json"):
try:
ids.append(int(f.stem.split("_")[1]))
except Exception:
pass
return max(ids) if ids else 0
def _path(self, task_id: int) -> Path:
return self.dir / f"task_{task_id}.json"
def _load(self, task_id: int) -> dict:
path = self._path(task_id)
if not path.exists():
raise ValueError(f"Task {task_id} not found")
return json.loads(path.read_text())
def _save(self, task: dict):
self._path(task["id"]).write_text(json.dumps(task, indent=2))
def create(self, subject: str, description: str = "") -> str:
task = {
"id": self._next_id,
"subject": subject,
"description": description,
"status": "pending",
"owner": "",
"worktree": "",
"blockedBy": [],
"created_at": time.time(),
"updated_at": time.time(),
}
self._save(task)View on GitHub (pinned to 985456f4ad)
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
Example fix
# before
tasks.update(task_id=12, status="in_progress")
# ValueError: Task 12 not found
# after
if tasks.exists(12):
tasks.update(task_id=12, status="in_progress")
else:
created = json.loads(tasks.create("redo the work"))
tasks.update(task_id=created["id"], status="in_progress") Defensive patterns
Strategy: validation
Validate before calling
# the manager exposes exists(); use it before any id-based call
if not TASKS.exists(task_id):
created = json.loads(TASKS.create(subject="recreated task"))
task_id = created["id"]
result = TASKS.update(task_id, status="in_progress") Type guard
def is_loadable_task_id(task_id: object, manager) -> bool:
return isinstance(task_id, int) and not isinstance(task_id, bool) and task_id >= 1 and manager.exists(task_id) Try / catch
try:
task = TASKS._load(task_id) # or the public get/update/bind_worktree
except ValueError as e:
if "not found" in str(e):
return f"Task {task_id} missing (tasks dir reset or cleaned). List tasks and use a current id."
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Task {task_id} not found
- Invalid status: {status}
- Invalid status: {status}
- Max 20 todos allowed
- Item {item_id}: text required
AI-assisted analysis of shareAI-lab/learn-claude-code@985456f4ad (2026-08-14).
Data as JSON: /api/errors/6d1af5f13a77ea40.
Report an issue: GitHub.