{"record":{"id":"ee9140025887bbe6","repo":"bytedance/deer-flow","slug":"unsupported-context-mode","errorCode":null,"errorMessage":"Unsupported context_mode","messagePattern":"Unsupported context_mode","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"warning","filePath":"backend/app/gateway/routers/scheduled_tasks.py","lineNumber":78,"sourceCode":"async def list_scheduled_tasks(request: Request):\n    repo = get_scheduled_task_repo(request)\n    user = await get_optional_user_from_request(request)\n    if user is None:\n        return []\n    return await repo.list_by_user(str(user.id))\n\n\n@router.post(\"/scheduled-tasks\")\n@require_permission(\"threads\", \"write\")\nasync def create_scheduled_task(request: Request, body: ScheduledTaskCreateRequest):\n    config = get_config()\n    repo = get_scheduled_task_repo(request)\n    thread_store = get_thread_store(request)\n    user = await get_optional_user_from_request(request)\n    if user is None:\n        raise HTTPException(status_code=401, detail=\"Authentication required\")\n    if body.context_mode not in {\"fresh_thread_per_run\", \"reuse_thread\"}:\n        raise HTTPException(status_code=422, detail=\"Unsupported context_mode\")\n    if body.context_mode == \"reuse_thread\":\n        if not body.thread_id:\n            raise HTTPException(status_code=422, detail=\"reuse_thread requires thread_id\")\n        if not await thread_store.check_access(body.thread_id, str(user.id), require_existing=True):\n            raise HTTPException(status_code=404, detail=\"Thread not found\")\n    if body.schedule_type not in {\"once\", \"cron\"}:\n        raise HTTPException(status_code=422, detail=\"Unsupported schedule_type\")\n\n    schedule_spec = dict(body.schedule_spec)\n    try:\n        validate_timezone(body.timezone)\n        if body.schedule_type == \"cron\":\n            raw_cron = schedule_spec.get(\"cron\")\n            if not isinstance(raw_cron, str):\n                raise HTTPException(status_code=422, detail=\"cron schedule requires schedule_spec.cron\")\n            schedule_spec[\"cron\"] = normalize_cron_expression(raw_cron)\n        next_run_at = compute_next_run_at(\n            body.schedule_type,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/gateway/routers/scheduled_tasks.py#L60-L96","documentation":"Raised as HTTP 422 by POST /api/scheduled-tasks when body.context_mode is not one of the two supported values: 'fresh_thread_per_run' or 'reuse_thread'. It is a free-form string field validated in the handler, not by the Pydantic model, so bad values reach this check.","triggerScenarios":"Creating a task with context_mode omitted-but-overridden, misspelled ('fresh-thread-per-run'), or an unsupported value like 'shared'.","commonSituations":"Client written against older/newer API docs; hand-crafted JSON payloads; enum drift between frontend and backend versions.","solutions":["Set context_mode to exactly 'fresh_thread_per_run' or 'reuse_thread'.","If reusing a thread, also supply thread_id (see the separate 422).","Pin the client against the backend's supported values — check the ScheduledTaskCreateRequest schema via /docs (OpenAPI)."],"exampleFix":"// before\n{ \"context_mode\": \"fresh-thread-per-run\", ... }\n// after\n{ \"context_mode\": \"fresh_thread_per_run\", ... }","handlingStrategy":"validation","validationCode":"VALID_CONTEXT_MODES = {\"fresh_thread_per_run\", \"reuse_thread\"}\nassert body[\"context_mode\"] in VALID_CONTEXT_MODES, f\"use one of {VALID_CONTEXT_MODES}\"","typeGuard":"type ContextMode = \"fresh_thread_per_run\" | \"reuse_thread\";\nconst isContextMode = (v: unknown): v is ContextMode =>\n  v === \"fresh_thread_per_run\" || v === \"reuse_thread\";","tryCatchPattern":null,"preventionTips":["Define the two allowed values as a shared constant/enum in the client.","Reject form submission client-side before hitting the API.","Regenerate the client from the OpenAPI schema after backend upgrades."],"tags":["scheduled-tasks","validation","http-422"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}