{"record":{"id":"b20b171c7c667790","repo":"shareAI-lab/learn-claude-code","slug":"dependency-not-found-dependency-b20b17","errorCode":null,"errorMessage":"Dependency not found: {dependency}","messagePattern":"Dependency not found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"s13_agent_teams/code.py","lineNumber":142,"sourceCode":"    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):\n            task = Task(\n                id=f\"task_{secrets.token_hex(4)}\",\n                subject=subject,\n                description=description,\n                status=\"pending\",\n                owner=None,\n                blockedBy=dependencies,\n            )\n            try:\n                with _task_path(task.id).open(\"x\", encoding=\"utf-8\") as handle:\n                    json.dump(asdict(task), handle, indent=2)\n                return task\n            except FileExistsError:\n                continue\n    raise RuntimeError(\"Could not allocate a unique task ID\")\n\n","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/shareAI-lab/learn-claude-code/blob/985456f4adea6f4df8fbad4112245dbd97444eae/s13_agent_teams/code.py#L124-L160","documentation":"create_task(blockedBy=[...]) validates every dependency ID by calling _task_path(dependency).is_file() — the dependency's JSON must already exist in .tasks/. This prevents tasks from referencing nonexistent predecessors, which would deadlock scheduling since can_start() waits on those dependencies completing.","triggerScenarios":"create_task('x', blockedBy=['task_00000000']) when no such file exists; passing an ID with a typo; passing dependency IDs created in another workspace; a race where the dependency task was created but its file write failed.","commonSituations":"Copy-pasting task graphs between workspaces; races in tests that create dependent tasks concurrently; stale hardcoded IDs from a previous run (IDs are random hex per run).","solutions":["Create dependency tasks first and use their returned Task.id values for blockedBy.","Deduplicate/validate IDs against list_tasks() before calling create_task.","In tests, build the dependency chain in order rather than in parallel threads."],"exampleFix":"// before\ncreate_task('deploy', blockedBy=['task_deadbeef'])  // may not exist\n\n// after\nbuild = create_task('build')\ndeploy = create_task('deploy', blockedBy=[build.id])","handlingStrategy":"validation","validationCode":"def deps_exist(dependency_ids: list[str]) -> bool:\n    from pathlib import Path\n    return all((TASKS_DIR / f'{d}.json').is_file() for d in dependency_ids)\n\n# before create_task:\nassert deps_exist(blockedBy or [])","typeGuard":null,"tryCatchPattern":"try:\n    task = create_task(subject, blockedBy=deps)\nexcept ValueError as exc:\n    if str(exc).startswith('Dependency not found'):\n        deps = [d for d in deps if (TASKS_DIR / f'{d}.json').is_file()]\n        task = create_task(subject, blockedBy=deps)  # or report upstream\n    else:\n        raise","preventionTips":["Create dependencies first and chain their returned .id values.","Filter blockedBy against list_tasks() when IDs come from storage or user input.","In tests, create the dependency graph sequentially."],"tags":["dependencies","create-task","validation","scheduling"],"backgroundTag":null,"analyzedSha":"985456f4adea6f4df8fbad4112245dbd97444eae","analyzedAt":"2026-08-14T22:02:26.028Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}