FoundationAgents/MetaGPT · error · ValueError
Detected source code "{filename}" from an unknown origin.
Error message
Detected source code "{filename}" from an unknown origin. What it means
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).
Source
Thrown at metagpt/roles/engineer.py:309
old_code_doc = await self.repo.srcs.get(filename)
if not old_code_doc:
old_code_doc = Document(root_path=str(self.repo.src_relative_path), filename=filename, content="")
dependencies = {Path(i) for i in await dependency.get(old_code_doc.root_relative_path)}
task_doc = None
design_doc = None
code_plan_and_change_doc = await self._get_any_code_plan_and_change() if await self._is_fixbug() else None
for i in dependencies:
if str(i.parent) == TASK_FILE_REPO:
task_doc = await self.repo.docs.task.get(i.name)
elif str(i.parent) == SYSTEM_DESIGN_FILE_REPO:
design_doc = await self.repo.docs.system_design.get(i.name)
elif str(i.parent) == CODE_PLAN_AND_CHANGE_FILE_REPO:
code_plan_and_change_doc = await self.repo.docs.code_plan_and_change.get(i.name)
if not task_doc or not design_doc:
if filename == "__init__.py": # `__init__.py` created by `init_python_folder`
return None
logger.error(f'Detected source code "{filename}" from an unknown origin.')
raise ValueError(f'Detected source code "{filename}" from an unknown origin.')
context = CodingContext(
filename=filename,
design_doc=design_doc,
task_doc=task_doc,
code_doc=old_code_doc,
code_plan_and_change_doc=code_plan_and_change_doc,
)
return context
async def _new_coding_doc(self, filename, dependency) -> Optional[Document]:
context = await self._new_coding_context(filename, dependency)
if not context:
return None # `__init__.py` created by `init_python_folder`
coding_doc = Document(
root_path=str(self.repo.src_relative_path), filename=filename, content=context.model_dump_json()
)
return coding_doc
View on GitHub (pinned to 11cdf466d0)
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
Defensive patterns
Strategy: try-catch
Validate before calling
deps = list(dependency)
parents = {str(i.parent) for i in deps}
if not ({"task"} & parents and {"system_design"} & parents):
# file will be rejected; skip or re-link dependencies before calling the Engineer
return None Try / catch
try:
doc = await engineer._new_coding_doc(filename, dependency)
except ValueError as e:
if "unknown origin" in str(e):
logger.warning("skipping %s: no task/design dependency", filename)
doc = None
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No requirement document found.
- File format not supported.
- File {path} not found.
- File path is not set.
- File {data_path} not found.
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/48011c0de744f0c2.
Report an issue: GitHub.