{"record":{"id":"67b98f8edc8a6b52","repo":"langchain-ai/deepagents","slug":"invalid-sort-order-sort-order-r-expected-updat","errorCode":null,"errorMessage":"Invalid sort_order {sort_order!r}; expected 'updated_at' or 'created_at'","messagePattern":"Invalid sort_order (.+?); expected 'updated_at' or 'created_at'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/model_config.py","lineNumber":6337,"sourceCode":"\ndef save_thread_sort_order(sort_order: str, config_path: Path | None = None) -> bool:\n    \"\"\"Save the sort order preference for the thread selector.\n\n    Args:\n        sort_order: `\"updated_at\"` or `\"created_at\"`.\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 `sort_order` is not a recognised value.\n    \"\"\"\n    if sort_order not in {\"updated_at\", \"created_at\"}:\n        msg = (\n            f\"Invalid sort_order {sort_order!r}; expected 'updated_at' or 'created_at'\"\n        )\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\"][\"sort_order\"] = sort_order\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":6319,"sourceCodeEnd":6355,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/model_config.py#L6319-L6355","documentation":"save_thread_sort_order persists the thread-selector sort preference and only accepts 'updated_at' or 'created_at'. Any other value raises ValueError(\"Invalid sort_order {sort_order!r}; expected 'updated_at' or 'created_at'\"). The library validates up front so the TOML config never holds an unusable sort key.","triggerScenarios":"Calling save_thread_sort_order(\"name\"), save_thread_sort_order(\"updatedAt\"), or any string outside {'updated_at','created_at'} (case-sensitive), with an optional config_path.","commonSituations":"Binding a UI toggle to a different label set ('name', 'asc') without mapping; camelCase vs snake_case mixups; older persisted values from a previous schema being re-saved.","solutions":["Pass exactly 'updated_at' or 'created_at'; map UI labels to these canonical values before saving.","Normalize with sort_order.lower() and validate against {'updated_at','created_at'} before the call.","Migrate/ignore legacy persisted sort values instead of re-saving them."],"exampleFix":"// before\nsave_thread_sort_order(ui_label)  # e.g. \"name\"\n// after\nif ui_label not in {\"updated_at\", \"created_at\"}:\n    ui_label = \"updated_at\"\nsave_thread_sort_order(ui_label)","handlingStrategy":"validation","validationCode":"VALID_SORT_ORDERS = {\"updated_at\", \"created_at\"}\nif sort_order not in VALID_SORT_ORDERS:\n    sort_order = \"updated_at\"  # safe default before saving","typeGuard":null,"tryCatchPattern":"try:\n    save_thread_sort_order(sort_order)\nexcept ValueError as exc:\n    logging.warning(\"%s; using default\", exc)\n    save_thread_sort_order(\"updated_at\")","preventionTips":["Define a single SortOrder Literal/enum in your app and derive UI options from it.","Map UI labels to canonical snake_case values at the boundary.","Migrate legacy persisted values once at load time."],"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"}