{"record":{"id":"336e22b934fead92","repo":"Tencent/WeKnora","slug":"task-s-in-queue-s-cannot-run-now","errorCode":null,"errorMessage":"task %s in queue %s cannot run now","messagePattern":"task (.+?) in queue (.+?) cannot run now","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/router/task_inspector.go","lineNumber":659,"sourceCode":"\tinfo, err := projectRuntimeTask(task, workers[task.Queue+\"\\x00\"+task.ID])\n\tif err != nil {\n\t\treturn nil, true, err\n\t}\n\treturn &info, true, nil\n}\n\n// RunRuntimeTask moves a scheduled, retry, or archived task to pending. Asynq\n// deliberately preserves the retry counter.\nfunc (a *asynqTaskInspector) RunRuntimeTask(ctx context.Context, queue, taskID string) (bool, error) {\n\tif a == nil || a.inspector == nil {\n\t\treturn false, nil\n\t}\n\ttask, _, err := a.GetRuntimeTask(ctx, queue, taskID)\n\tif err != nil {\n\t\treturn true, err\n\t}\n\tif task == nil || !task.Allows(types.RuntimeTaskActionRunNow) {\n\t\treturn true, fmt.Errorf(\"task %s in queue %s cannot run now\", taskID, queue)\n\t}\n\treturn true, a.inspector.RunTask(queue, taskID)\n}\n\nfunc (a *asynqTaskInspector) DeleteRuntimeTask(ctx context.Context, queue, taskID string) (bool, error) {\n\tif a == nil || a.inspector == nil {\n\t\treturn false, nil\n\t}\n\ttask, _, err := a.GetRuntimeTask(ctx, queue, taskID)\n\tif err != nil {\n\t\treturn true, err\n\t}\n\tif task == nil || !task.Allows(types.RuntimeTaskActionDelete) {\n\t\treturn true, fmt.Errorf(\"task %s in queue %s cannot be deleted\", taskID, queue)\n\t}\n\treturn true, a.inspector.DeleteTask(queue, taskID)\n}\n","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/router/task_inspector.go#L641-L677","documentation":"RunRuntimeTask wraps asynq's inspector RunTask with a permission check. Before running a task it fetches the RuntimeTask via GetRuntimeTask and verifies its state allows RuntimeTaskActionRunNow. If the task does not exist (nil) or its current state (e.g. active, archived, completed) does not permit 'run now', this error is returned instead of forwarding to asynq.","triggerScenarios":"Calling RunRuntimeTask(ctx, queue, taskID) for a taskID that does not exist in the queue, or whose task state denies the RunNow action — e.g. the task is currently active/being processed, is in a completed/archived state, or belongs to a queue other than the one passed.","commonSituations":"A UI 'Run now' button fires after the task already started or was consumed; the task ID was copied from a different queue; the task was picked up by a worker between listing and clicking run; retrying an already-succeeded task.","solutions":["Re-fetch the queue's task list and confirm the task still exists and is in a state that permits RunNow (e.g. pending/scheduled/retry) before calling again","Verify the taskID and queue name are correct and paired (task IDs are per-queue)","If the task is active, wait for it to finish or cancel it instead of forcing a run","If the intent is to remove a stuck task, use the force-delete path rather than run-now"],"exampleFix":"// before\ntasks, _ := inspector.ListRuntimeTasks(ctx, \"emails\")\ninspector.RunRuntimeTask(ctx, \"emails\", tasks[0].ID) // may already be active\n// after\ntask, _, _ := inspector.GetRuntimeTask(ctx, \"emails\", taskID)\nif task != nil && task.Allows(types.RuntimeTaskActionRunNow) {\n    inspector.RunRuntimeTask(ctx, \"emails\", taskID)\n}","handlingStrategy":"validation","validationCode":"task, _, err := inspector.GetRuntimeTask(ctx, queue, taskID)\nif err != nil { return err }\nif task == nil || !task.Allows(types.RuntimeTaskActionRunNow) {\n    return fmt.Errorf(\"skip: task %s in queue %s not runnable now\", taskID, queue)\n}","typeGuard":"func canRunNow(t types.RuntimeTask) bool { return t != nil && t.Allows(types.RuntimeTaskActionRunNow) }","tryCatchPattern":"var stateErr *interface{ Error() string }\nif err := inspector.RunRuntimeTask(ctx, queue, taskID); err != nil {\n    if strings.Contains(err.Error(), \"cannot run now\") { /* treat as no-op / refresh UI */ }\n    return err\n}","preventionTips":["Always GetRuntimeTask and check Allows(RuntimeTaskActionRunNow) before invoking run-now","Revalidate immediately before the call — task state changes concurrently as workers pick tasks up","Use idempotent UI handling: a 'cannot run now' response should refresh the task list, not retry blindly"],"tags":["asynq","task-queue","permissions","task-state"],"backgroundTag":"task-not-runnable-state","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}