{"record":{"id":"5bb99fa0bf274b0b","repo":"langchain-ai/deepagents","slug":"invalid-scope-scope-r-expected-cwd-or-all","errorCode":null,"errorMessage":"Invalid scope {scope!r}; expected 'cwd' or 'all'","messagePattern":"Invalid scope (.+?); expected 'cwd' or 'all'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/model_config.py","lineNumber":6383,"sourceCode":"    return True\n\n\ndef save_thread_scope(scope: str, config_path: Path | None = None) -> bool:\n    \"\"\"Save the directory-scope preference for the thread selector.\n\n    Args:\n        scope: `\"cwd\"` (current working directory) or `\"all\"` (all directories).\n        config_path: Path to config file.\n\n    Returns:\n        True if save succeeded, False on I/O error.\n\n    Raises:\n        ValueError: If `scope` is not a recognised value.\n    \"\"\"\n    if scope not in {\"cwd\", \"all\"}:\n        msg = f\"Invalid scope {scope!r}; expected 'cwd' or 'all'\"\n        raise ValueError(msg)\n    if config_path is None:\n        config_path = DEFAULT_CONFIG_PATH\n    try:\n        with _config_write_lock:\n            config_path.parent.mkdir(parents=True, exist_ok=True)\n            if config_path.exists():\n                with config_path.open(\"rb\") as f:\n                    data = tomllib.load(f)\n            else:\n                data = {}\n            if \"threads\" not in data:\n                data[\"threads\"] = {}\n            data[\"threads\"][\"scope\"] = scope\n            fd, tmp_path = tempfile.mkstemp(dir=config_path.parent, suffix=\".tmp\")\n            try:\n                with os.fdopen(fd, \"wb\") as f:\n                    tomli_w.dump(data, f)\n                Path(tmp_path).replace(config_path)","sourceCodeStart":6365,"sourceCodeEnd":6401,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/model_config.py#L6365-L6401","documentation":"The thread-scope preference saver only accepts 'cwd' (current working directory) or 'all'. Any other scope raises ValueError(\"Invalid scope {scope!r}; expected 'cwd' or 'all'\"). Validating before the TOML write keeps the stored scope a recognized value for the thread list filter.","triggerScenarios":"Calling the scope-saving function with \"global\", \"project\", \"\", or any value outside {'cwd','all'} (case-sensitive), with an optional config_path.","commonSituations":"Mapping a UI dropdown with different labels ('this project' / 'everywhere') without translation; passing a boolean or enum member instead of the string; re-saving a legacy stored value.","solutions":["Pass exactly 'cwd' or 'all'; translate UI labels to these canonical strings first.","Normalize and validate: scope.lower() in {'cwd','all'} before calling.","Discard or migrate legacy scope values rather than re-saving them."],"exampleFix":"// before\nsave_thread_scope(scope_label)  # e.g. \"global\"\n// after\nscope = \"all\" if scope_label == \"global\" else \"cwd\"\nsave_thread_scope(scope)","handlingStrategy":"validation","validationCode":"VALID_SCOPES = {\"cwd\", \"all\"}\nif scope not in VALID_SCOPES:\n    scope = \"cwd\"  # safe default before saving","typeGuard":null,"tryCatchPattern":"try:\n    save_thread_scope(scope)\nexcept ValueError as exc:\n    logging.warning(\"%s; using default\", exc)\n    save_thread_scope(\"cwd\")","preventionTips":["Use a Literal[\"cwd\", \"all\"] type for scope in your calling code.","Translate UI dropdown labels to canonical scope strings at the boundary.","Discard unrecognized legacy stored scopes instead of re-saving them."],"tags":["python","validation","config","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}