{"record":{"id":"eac9f6d1aacd29cf","repo":"HKUDS/DeepTutor","slug":"codebuddy-cli-is-required-to-sync-account-models","errorCode":null,"errorMessage":"CodeBuddy CLI is required to sync account models.","messagePattern":"CodeBuddy CLI is required to sync account models\\.","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/llm/provider_core/codebuddy_provider.py","lineNumber":788,"sourceCode":"        return\n    async with _API_KEY_ENV_LOCK:\n        previous = os.environ.get(_CODEBUDDY_API_KEY_ENV)\n        os.environ[_CODEBUDDY_API_KEY_ENV] = api_key\n        try:\n            yield\n        finally:\n            if previous is None:\n                os.environ.pop(_CODEBUDDY_API_KEY_ENV, None)\n            else:\n                os.environ[_CODEBUDDY_API_KEY_ENV] = previous\n\n\nasync def fetch_codebuddy_models(api_key: str | None = None) -> list[str]:\n    \"\"\"Return the model catalog currently available to the logged-in account.\"\"\"\n    _load_sdk()\n    cli_path = shutil.which(\"codebuddy\") or shutil.which(\"cbc\")\n    if not cli_path:\n        raise RuntimeError(\"CodeBuddy CLI is required to sync account models.\")\n\n    cli_args = [\n        cli_path,\n        \"--print\",\n        \".\",\n        \"--model\",\n        \"__deeptutor_list_models__\",\n        \"--output-format\",\n        \"json\",\n        \"--max-turns\",\n        \"1\",\n    ]\n    process_kwargs: dict[str, Any] = {}\n    if os.name == \"nt\":\n        command = [\"cmd.exe\", \"/d\", \"/s\", \"/c\", subprocess.list2cmdline(cli_args)]\n        # Windows-only constants; the stubs omit them off-Windows, and mypy\n        # cannot narrow on os.name the way it narrows on sys.platform.\n        process_kwargs[\"creationflags\"] = (","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/llm/provider_core/codebuddy_provider.py#L770-L806","documentation":"fetch_codebuddy_models() needs the CodeBuddy CLI executable (codebuddy or cbc) on PATH to query the account's model catalog via a subprocess; shutil.which() found neither, so it raises RuntimeError. The SDK alone isn't enough — model sync shells out to the CLI.","triggerScenarios":"Calling fetch_codebuddy_models() on a machine without the CodeBuddy CLI installed, or where the binary isn't on PATH (installed via nvm-style isolated location, GUI session PATH, container image).","commonSituations":"Docker/CI images that pip-install the SDK but never install the CLI; SSH non-login shells with trimmed PATH; macOS app-launched processes missing /usr/local/bin.","solutions":["Install the CodeBuddy CLI and ensure `codebuddy` (or `cbc`) is on PATH (verify with `which codebuddy`).","In containers/CI, add the CLI install step to the image.","If PATH is the issue, launch the process with an environment that includes the CLI's install dir."],"exampleFix":"# before\n# CLI not installed\nmodels = await fetch_codebuddy_models()\n\n# after\n# Dockerfile / CI\nRUN npm install -g @codebuddy/cli\nmodels = await fetch_codebuddy_models()","handlingStrategy":"validation","validationCode":"import shutil\nif not (shutil.which(\"codebuddy\") or shutil.which(\"cbc\")):\n    print(\"CodeBuddy CLI missing — install it and ensure it is on PATH\")","typeGuard":"def codebuddy_cli_on_path() -> bool:\n    import shutil\n    return shutil.which(\"codebuddy\") is not None or shutil.which(\"cbc\") is not None","tryCatchPattern":"try:\n    models = await fetch_codebuddy_models()\nexcept RuntimeError as e:\n    if \"CLI is required\" in str(e):\n        # skip model sync, use a static fallback list\n        models = [\"fallback-model\"]\n    else:\n        raise","preventionTips":["Install the CLI in the same image/environment as the SDK.","Add a which-codebuddy check to container healthchecks.","Fall back to a cached/static model list when the CLI is absent."],"tags":["codebuddy","cli","path","missing-binary"],"backgroundTag":"cli-binary-not-found","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}