{"record":{"id":"2470361dec39e3a8","repo":"OpenBMB/ChatDev","slug":"python-workspace-root-missing-from-context","errorCode":null,"errorMessage":"python_workspace_root missing from _context","messagePattern":"python_workspace_root missing from _context","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"functions/function_calling/uv_related.py","lineNumber":50,"sourceCode":"    preview = _trim_output_preview(stdout, stderr)\n    if preview:\n        return f\"{message}. Last output: {preview}\"\n    return message\n\n\nclass WorkspaceCommandContext:\n    \"\"\"Resolve the workspace root from the injected runtime context.\"\"\"\n\n    def __init__(self, ctx: Dict[str, Any] | None):\n        if ctx is None:\n            raise ValueError(\"_context is required for uv tools\")\n        self.workspace_root = self._require_workspace(ctx.get(\"python_workspace_root\"))\n        self._raw_ctx = ctx\n\n    @staticmethod\n    def _require_workspace(raw_path: Any) -> Path:\n        if raw_path is None:\n            raise ValueError(\"python_workspace_root missing from _context\")\n        path = Path(raw_path).expanduser().resolve()\n        path.mkdir(parents=True, exist_ok=True)\n        return path\n\n    def resolve_under_workspace(self, relative_path: str | Path) -> Path:\n        candidate = Path(relative_path)\n        absolute = candidate if candidate.is_absolute() else self.workspace_root / candidate\n        absolute = absolute.expanduser().resolve()\n        if self.workspace_root not in absolute.parents and absolute != self.workspace_root:\n            raise ValueError(\"script path is outside workspace root\")\n        return absolute\n\n\ndef _validate_packages(packages: Sequence[str]) -> List[str]:\n    normalized: List[str] = []\n    for pkg in packages:\n        if not isinstance(pkg, str):\n            raise ValueError(\"package entries must be strings\")","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/functions/function_calling/uv_related.py#L32-L68","documentation":"The injected _context dict must contain a python_workspace_root entry; _require_workspace raises when it is None. The workspace root anchors all path resolution and script execution for uv tools, and it is created (mkdir -p) if the directory does not yet exist, so only a missing key fails — not a missing directory.","triggerScenarios":"Calling uv_run/install_python_packages with a _context dict lacking python_workspace_root; misnamed key (e.g. workspace_root, python_workspace_dir); context built from a config where the root setting was never populated.","commonSituations":"Framework/runtime version mismatch where the context key was renamed or not yet set; custom tool hosts that build the context dict manually; environments where workspace initialization was skipped.","solutions":["Add python_workspace_root to the _context dict, set to an absolute path under which scripts/packages should run","Check for key-name typos against the documented context schema","Upgrade or align the calling runtime version so it injects the expected key"],"exampleFix":"# before\nctx = {\"workspace_root\": \"/tmp/ws\"}\n# after\nctx = {\"python_workspace_root\": \"/tmp/ws\"}","handlingStrategy":"validation","validationCode":"if \"python_workspace_root\" not in (_context or {}):\n    _context = {**(_context or {}), \"python_workspace_root\": \"/abs/path/ws\"}\nuv_run(script=\"run.py\", _context=_context)","typeGuard":"def context_has_workspace_root(ctx) -> bool:\n    return isinstance(ctx, dict) and ctx.get(\"python_workspace_root\") is not None","tryCatchPattern":"try:\n    uv_run(script=\"run.py\", _context=_context)\nexcept ValueError as e:\n    if \"python_workspace_root missing\" in str(e):\n        _context[\"python_workspace_root\"] = str(Path.cwd())\n        uv_run(script=\"run.py\", _context=_context)\n    else:\n        raise","preventionTips":["Verify the exact context key name against the library docs","Set python_workspace_root during workspace initialization","Align caller/runtime versions so the key is injected"],"tags":["configuration","context","uv","missing-key"],"backgroundTag":"missing-context-injection","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}