{"record":{"id":"f6eb6a2782f0c047","repo":"vxcontrol/pentagi","slug":"task-id-d-was-not-found-in-this-flow-obtain-a-va","errorCode":null,"errorMessage":"task ID %d was not found in this flow; obtain a valid task ID from %s with detail='tasks'","messagePattern":"task ID (.+?) was not found in this flow; obtain a valid task ID from (.+?) with detail='tasks'","errorType":"validation","errorClass":"stateGuard","httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/flow_manager.go","lineNumber":871,"sourceCode":"\tfor _, task := range tasks {\n\t\tif task.Status == database.TaskStatusRunning {\n\t\t\treturn \"\", stateGuard(fmt.Errorf(\n\t\t\t\t\"task %q (ID: %d) is currently running; \"+\n\t\t\t\t\t\"patching is not allowed while a task is executing. \"+\n\t\t\t\t\t\"Call %s first, then retry %s\",\n\t\t\t\ttask.Title, task.ID, StopFlowToolName, PatchFlowSubtasksToolName))\n\t\t}\n\t}\n\n\ttaskBelongsToFlow := false\n\tfor _, task := range tasks {\n\t\tif task.ID == action.TaskID {\n\t\t\ttaskBelongsToFlow = true\n\t\t\tbreak\n\t\t}\n\t}\n\tif !taskBelongsToFlow {\n\t\treturn \"\", stateGuard(fmt.Errorf(\n\t\t\t\"task ID %d was not found in this flow; \"+\n\t\t\t\t\"obtain a valid task ID from %s with detail='tasks'\",\n\t\t\taction.TaskID, GetFlowStatusToolName))\n\t}\n\n\tplanned, err := t.db.GetTaskPlannedSubtasks(ctx, action.TaskID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get planned subtasks for task %d: %w\", action.TaskID, err)\n\t}\n\n\tif len(planned) == 0 && len(action.Operations) > 0 {\n\t\tsubtasks, err := t.db.GetFlowSubtasks(ctx, t.flowID)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to check subtask state for task %d: %w\", action.TaskID, err)\n\t\t}\n\n\t\tfor _, st := range subtasks {\n\t\t\tif st.TaskID != action.TaskID {","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/flow_manager.go#L853-L889","documentation":"The task_id passed to patch_flow_subtasks parses and is positive, but no task with that ID exists in this flow — GetFlowTasks found no matching ID, so the patch is rejected with a state guard. This prevents cross-flow or stale ID patching.","triggerScenarios":"Calling patch_flow_subtasks with a task ID from a different flow, an ID fabricated/hallucinated by the LLM, or an ID from a task that was deleted when the flow was restarted.","commonSituations":"LLM inventing plausible-looking IDs instead of calling get_flow_status; caching task IDs across flow restarts; copy-pasting IDs between flows or sessions.","solutions":["Call get_flow_status with detail='tasks' to list the actual task IDs in this flow.","Resend patch_flow_subtasks using a valid ID from that list.","If the flow was restarted, re-fetch IDs — old ones are no longer valid.","Verify you are operating on the intended flow, not a different one."],"exampleFix":"// before: guessing an ID\n{\"task_id\": 999, \"operations\": [...]}\n// after: use get_flow_status detail='tasks' to find the real ID, then\n{\"task_id\": 3, \"operations\": [...]}","handlingStrategy":"validation","validationCode":"// Ensure the task ID belongs to the current flow\nvalidIDs := map[int64]bool{}\nfor _, t := range getFlowStatusTasks(ctx) { validIDs[t.ID] = true }\nif !validIDs[taskID] {\n    return fmt.Errorf(\"task %d is not in this flow; refetch IDs via get_flow_status\", taskID)\n}","typeGuard":"func taskBelongsToFlow(taskID int64, tasks []Task) bool {\n    for _, t := range tasks {\n        if t.ID == taskID { return true }\n    }\n    return false\n}","tryCatchPattern":"_, err := tool.Handle(ctx, \"patch_flow_subtasks\", args)\nif err != nil && strings.Contains(err.Error(), \"was not found in this flow\") {\n    ids := fetchTaskIDs(ctx) // get_flow_status detail='tasks'\n    args = rebuildArgsWithValidID(ids)\n    _, _ = tool.Handle(ctx, \"patch_flow_subtasks\", args)\n}","preventionTips":["Always source task IDs from get_flow_status detail='tasks', never from LLM guesses.","Invalidate cached task IDs after any flow stop/restart.","Scope IDs per flow — never reuse across flows or sessions.","Log the ID list alongside patch attempts for auditability."],"tags":["state-guard","validation","flow-control"],"backgroundTag":"entity-not-found","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}