{"record":{"id":"c066a0de9f6538cd","repo":"bytedance/deer-flow","slug":"failed-to-set-thread-goal","errorCode":null,"errorMessage":"Failed to set thread goal","messagePattern":"Failed to set thread goal","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"backend/app/gateway/routers/threads.py","lineNumber":1110,"sourceCode":"\n    ``/chats/new`` pages already hold a generated UUID before the first run, so\n    this endpoint creates the missing thread checkpoint on demand.\n    \"\"\"\n    checkpointer = get_checkpointer(request)\n    try:\n        goal = build_goal_state(body.objective, max_continuations=body.max_continuations)\n        async with reserve_checkpoint_write(request, thread_id, user_id=get_effective_user_id()):\n            await _ensure_thread_for_goal(thread_id, request)\n            await write_thread_goal(checkpointer, thread_id, goal, as_node=\"goal\", create_if_missing=True)\n    except ValueError as exc:\n        raise HTTPException(status_code=422, detail=str(exc)) from exc\n    except ConflictError:\n        raise HTTPException(status_code=409, detail=\"Thread has a run in flight. Set the goal after the run finishes.\") from None\n    except HTTPException:\n        raise\n    except Exception:\n        logger.exception(\"Failed to set goal for thread %s\", sanitize_log_param(thread_id))\n        raise HTTPException(status_code=500, detail=\"Failed to set thread goal\") from None\n    return ThreadGoalResponse(goal=goal)\n\n\n@router.delete(\"/{thread_id}/goal\", response_model=ThreadGoalResponse)\n@require_permission(\"threads\", \"write\", owner_check=True)\nasync def clear_thread_goal(thread_id: ThreadId, request: Request) -> ThreadGoalResponse:\n    \"\"\"Clear the active goal for a thread.\"\"\"\n    checkpointer = get_checkpointer(request)\n    try:\n        async with reserve_checkpoint_write(request, thread_id, user_id=get_effective_user_id()):\n            await write_thread_goal(checkpointer, thread_id, None, as_node=\"goal\")\n    except ConflictError:\n        raise HTTPException(status_code=409, detail=\"Thread has a run in flight. Clear the goal after the run finishes.\") from None\n    except LookupError:\n        return ThreadGoalResponse(goal=None)\n    except Exception:\n        logger.exception(\"Failed to clear goal for thread %s\", sanitize_log_param(thread_id))\n        raise HTTPException(status_code=500, detail=\"Failed to clear thread goal\") from None","sourceCodeStart":1092,"sourceCodeEnd":1128,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/gateway/routers/threads.py#L1092-L1128","documentation":"Error \"Failed to set thread goal\" thrown in bytedance/deer-flow.","triggerScenarios":"Thrown at backend/app/gateway/routers/threads.py:1110 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the Gateway logs for the underlying goal-write failure.","Verify the thread exists and no run is in flight, then retry."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}