{"record":{"id":"c6e17c5c9d076a6b","repo":"semaphoreui/semaphore","slug":"task-not-found","errorCode":null,"errorMessage":"task not found","messagePattern":"task not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/tasks/RemoteJob.go","lineNumber":142,"sourceCode":"\t\tif !r.IsOnline(now, offlineTimeout) {\n\t\t\tcontinue\n\t\t}\n\t\tif n := busyTasks(r.ID); n < r.MaxParallelTasks || r.MaxParallelTasks == 0 {\n\t\t\treturn r\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (t *RemoteJob) Run(username string, incomingVersion *string, alias string) (err error) {\n\ttsk, err := t.taskPool.GetTask(t.Task.ID)\n\n\tif err != nil {\n\t\treturn\n\t}\n\n\tif tsk == nil {\n\t\treturn fmt.Errorf(\"task not found\")\n\t}\n\n\ttsk.IncomingVersion = incomingVersion\n\ttsk.Username = username\n\ttsk.Alias = alias\n\tt.taskPool.state.UpdateRuntimeFields(tsk)\n\n\tvar runners []db.Runner\n\ttagFilterMode := db.RunnerFilterTagCompleteMatch\n\tif t.RunnerTag == nil {\n\t\ttagFilterMode = db.RunnerFilterIsDefault\n\t}\n\n\tvar projectRunners []db.Runner\n\tprojectRunners, err = t.taskPool.store.GetRunners(t.Task.ProjectID, true, tagFilterMode, t.RunnerTag)\n\tif err != nil {\n\t\treturn\n\t}","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/tasks/RemoteJob.go#L124-L160","documentation":"RemoteJob.Run looks up the task by ID before executing it remotely; if the database lookup succeeds but returns no task, Run fails with 'task not found'. This protects against running jobs for tasks that were deleted or belong to another project while the job was queued.","triggerScenarios":"Calling Run for a task ID that no longer exists in the database — the task was deleted between scheduling and execution, the ID is wrong, or the DB connection points to a different/rolled-back database.","commonSituations":"Task canceled/deleted while a remote job was still pending; stale job records replayed after a database restore; server replicas pointing at different databases; passing an incorrect task ID to the internal job runner.","solutions":["Check the task still exists (GET /project/{project_id}/tasks/{task_id}) before/while the job runs","Do not delete tasks while their jobs are queued; cancel the job first","Verify all server replicas connect to the same primary database","Confirm the task ID used by the job scheduler matches a real task"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"tsk, err := dbStore.GetTask(projectID, taskID)\nif err != nil || tsk == nil { /* do not schedule the job */ }","typeGuard":null,"tryCatchPattern":"if err := job.Run(...); err != nil {\n    if strings.Contains(err.Error(), \"task not found\") {\n        log.Printf(\"task %d vanished before run; skipping\", taskID)\n        return nil // treat as benign\n    }\n    return err\n}","preventionTips":["Do not delete tasks while their remote jobs are queued","Use cascading deletes so job records die with their tasks","Verify all replicas point at the same database"],"tags":["go","tasks","not-found"],"backgroundTag":"record-not-found","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}