{"record":{"id":"4cd802515ddbfab8","repo":"bytedance/deer-flow","slug":"reuse-thread-requires-thread-id","errorCode":null,"errorMessage":"reuse_thread requires thread_id","messagePattern":"reuse_thread requires thread_id","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"warning","filePath":"backend/app/gateway/routers/scheduled_tasks.py","lineNumber":81,"sourceCode":"    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,\n            schedule_spec,\n            body.timezone,\n            now=datetime.now(UTC),","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/gateway/routers/scheduled_tasks.py#L63-L99","documentation":"Raised as HTTP 422 by POST /api/scheduled-tasks when context_mode is 'reuse_thread' but the optional thread_id field is null/omitted. Reusing a thread requires identifying which thread to continue.","triggerScenarios":"Creating a task with {\"context_mode\": \"reuse_thread\"} and no thread_id in the body.","commonSituations":"Client defaults thread_id to null and switches context_mode at runtime; copying a payload template without filling thread_id.","solutions":["Include the target thread's id: {\"context_mode\": \"reuse_thread\", \"thread_id\": \"...\"}.","Or use \"fresh_thread_per_run\" if continuing an existing thread is not intended.","Get a valid thread id from the threads listing endpoint if unsure."],"exampleFix":"// before\n{ \"context_mode\": \"reuse_thread\" }\n// after\n{ \"context_mode\": \"reuse_thread\", \"thread_id\": \"thr-abc123\" }","handlingStrategy":"validation","validationCode":"if body[\"context_mode\"] == \"reuse_thread\":\n    assert body.get(\"thread_id\"), \"reuse_thread requires a non-empty thread_id\"","typeGuard":"const isReusableThreadRequest = (b: CreateTaskBody): b is CreateTaskBody & { thread_id: string } =>\n  b.context_mode === \"reuse_thread\" && typeof b.thread_id === \"string\" && b.thread_id.length > 0;","tryCatchPattern":null,"preventionTips":["Make thread_id required in the UI whenever reuse_thread is selected.","Validate the pairing in a shared schema (zod/pydantic mirror) before send."],"tags":["scheduled-tasks","validation","http-422","threads"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}