{"record":{"id":"48011c0de744f0c2","repo":"FoundationAgents/MetaGPT","slug":"detected-source-code-filename-from-an-unknown","errorCode":null,"errorMessage":"Detected source code \"{filename}\" from an unknown origin.","messagePattern":"Detected source code \"(.+?)\" from an unknown origin\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/roles/engineer.py","lineNumber":309,"sourceCode":"        old_code_doc = await self.repo.srcs.get(filename)\n        if not old_code_doc:\n            old_code_doc = Document(root_path=str(self.repo.src_relative_path), filename=filename, content=\"\")\n        dependencies = {Path(i) for i in await dependency.get(old_code_doc.root_relative_path)}\n        task_doc = None\n        design_doc = None\n        code_plan_and_change_doc = await self._get_any_code_plan_and_change() if await self._is_fixbug() else None\n        for i in dependencies:\n            if str(i.parent) == TASK_FILE_REPO:\n                task_doc = await self.repo.docs.task.get(i.name)\n            elif str(i.parent) == SYSTEM_DESIGN_FILE_REPO:\n                design_doc = await self.repo.docs.system_design.get(i.name)\n            elif str(i.parent) == CODE_PLAN_AND_CHANGE_FILE_REPO:\n                code_plan_and_change_doc = await self.repo.docs.code_plan_and_change.get(i.name)\n        if not task_doc or not design_doc:\n            if filename == \"__init__.py\":  # `__init__.py` created by `init_python_folder`\n                return None\n            logger.error(f'Detected source code \"{filename}\" from an unknown origin.')\n            raise ValueError(f'Detected source code \"{filename}\" from an unknown origin.')\n        context = CodingContext(\n            filename=filename,\n            design_doc=design_doc,\n            task_doc=task_doc,\n            code_doc=old_code_doc,\n            code_plan_and_change_doc=code_plan_and_change_doc,\n        )\n        return context\n\n    async def _new_coding_doc(self, filename, dependency) -> Optional[Document]:\n        context = await self._new_coding_context(filename, dependency)\n        if not context:\n            return None  # `__init__.py` created by `init_python_folder`\n        coding_doc = Document(\n            root_path=str(self.repo.src_relative_path), filename=filename, content=context.model_dump_json()\n        )\n        return coding_doc\n","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/roles/engineer.py#L291-L327","documentation":"Engineer._new_coding_context builds a CodingContext only when the file's dependencies trace back to a task doc and a system design doc in the repo. If neither dependency chain yields both task_doc and design_doc (and the file is not the special __init__.py scaffold), the role refuses to write code for a file of unknown provenance by raising this ValueError (also logged as an error).","triggerScenarios":"The Engineer role receives a filename whose dependencies do not include a parent of TASK_FILE_REPO and SYSTEM_DESIGN_FILE_REPO — e.g. files added outside the standard PRD->design->task pipeline, or a stale workspace with renamed task/design documents.","commonSituations":"Resuming/recovering a project whose docs directory drifted from the code dependencies; manually injecting extra files into the repo; document renames breaking dependency parent links.","solutions":["Ensure the project was produced through the standard pipeline (WritePRD -> WriteDesign -> WriteTasks) so each code file depends on a task and design doc","If recovering, pass the correct --recover-path matching the workspace that generated the code","For scaffold-only files, name them __init__.py, which the method explicitly allows"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"deps = list(dependency)\nparents = {str(i.parent) for i in deps}\nif not ({\"task\"} & parents and {\"system_design\"} & parents):\n    # file will be rejected; skip or re-link dependencies before calling the Engineer\n    return None","typeGuard":null,"tryCatchPattern":"try:\n    doc = await engineer._new_coding_doc(filename, dependency)\nexcept ValueError as e:\n    if \"unknown origin\" in str(e):\n        logger.warning(\"skipping %s: no task/design dependency\", filename)\n        doc = None\n    else:\n        raise","preventionTips":["Generate projects through the standard PRD/design/task pipeline so dependencies link correctly","Keep task and design doc filenames stable between rounds; renames break dependency parents","When recovering workspaces, use the matching --recover-path"],"tags":["engineer-agent","workflow","dependencies","document"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}