Tasks bound to fake document ids cannot be tenant-scoped on cancellation
Follow-up from the review discussion on #19359.
The task-cancellation authorization in #19359 deliberately skips tasks bound to fake document ids (canvas debug CANVAS_DEBUG_DOC_ID, graph/raptor GRAPH_RAPTOR_FAKE_DOC_ID) because they carry no resolvable document to scope the check against. Those flows are authorized elsewhere, but the underlying gap remains: Task (api/db/db_models.py, ~L1428-1451) has no tenant_id or kb_id column, and canvas debug task ids come from get_uuid() (api/apps/restful_apis/agent_api.py, ~L1300), so any authenticated caller who learns such a task id can cancel it through POST /tasks/<task_id>/cancel or PATCH /tasks/<task_id> with action=stop.
Expected: tasks bound to fake doc ids can be authorized on cancellation like document-bound tasks.
Proposal: add tenant scoping to the Task model (a tenant_id or kb_id column, populated at task creation and backfilled where resolvable) so the cancel path can authorize these tasks as well. Flagged by @xugangqiang in the #19359 review as needing this schema change.
Source: infiniflow/ragflow