{"record":{"id":"077a11b974869c8c","repo":"vxcontrol/pentagi","slug":"task-d-has-a-subtask-id-d-q-waiting-for-use","errorCode":null,"errorMessage":"task %d has a subtask (ID: %d, %q) waiting for user input. Only 'created' subtasks can be patched, but you can include the waiting subtask's ID in your operations to modify or remove it. Alternatively, answer it via %s first","messagePattern":"task (.+?) has a subtask \\(ID: (.+?), %q\\) waiting for user input\\. Only 'created' subtasks can be patched, but you can include the waiting subtask's ID in your operations to modify or remove it\\. Alternatively, answer it via (.+?) first","errorType":"validation","errorClass":"stateGuard","httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/flow_manager.go","lineNumber":894,"sourceCode":"\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 {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tswitch st.Status {\n\t\t\tcase database.SubtaskStatusWaiting:\n\t\t\t\treturn \"\", stateGuard(fmt.Errorf(\n\t\t\t\t\t\"task %d has a subtask (ID: %d, %q) waiting for user input. \"+\n\t\t\t\t\t\t\"Only 'created' subtasks can be patched, but you can include the waiting subtask's ID in your operations to modify or remove it. \"+\n\t\t\t\t\t\t\"Alternatively, answer it via %s first\",\n\t\t\t\t\taction.TaskID, st.ID, st.Title, SubmitFlowInputToolName))\n\t\t\tcase database.SubtaskStatusRunning:\n\t\t\t\treturn \"\", stateGuard(fmt.Errorf(\n\t\t\t\t\t\"task %d has a subtask (ID: %d, %q) currently running. \"+\n\t\t\t\t\t\t\"Call %s first, then retry\",\n\t\t\t\t\taction.TaskID, st.ID, st.Title, StopFlowToolName))\n\t\t\t}\n\t\t}\n\n\t\treturn \"\", stateGuard(fmt.Errorf(\n\t\t\t\"no 'created' subtasks found for task %d; \"+\n\t\t\t\t\"all subtasks have been executed or the task has no plan yet. \"+\n\t\t\t\t\"Use %s to create a new task instead\",\n\t\t\taction.TaskID, SubmitFlowInputToolName))\n\t}","sourceCodeStart":876,"sourceCodeEnd":912,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/flow_manager.go#L876-L912","documentation":"A stateGuard error raised by the create/patch-subtasks tool when, among the task's existing subtasks, one is in SubtaskStatusWaiting — i.e. it is paused waiting for the user to answer a question via the submit_flow_input tool. Only 'created' (not yet executed) subtasks may be patched; the message tells the agent to answer the waiting subtask first or include its ID in operations to modify/remove it. This is an intentional guard, not a system fault.","triggerScenarios":"Calling the patch-subtasks (or create-subtasks with operations) tool action for a task that has at least one subtask with status 'waiting'.","commonSituations":"An agent tries to rewrite a task's plan while one of its subtasks asked the user a question and is blocked on input; the agent forgot it previously created a waiting subtask; concurrent agents editing the same flow.","solutions":["Call submit_flow_input with the waiting subtask's ID to answer the pending question first, then retry the patch","Include the waiting subtask's ID in the patch operations to modify or remove it","Pick a different task without waiting subtasks, or finish the waiting subtask before restructuring the plan"],"exampleFix":"// before\n// patch-subtasks(task_id=42, operations=[...]) -> error: subtask waiting\n// after\n// 1) submit_flow_input(subtask_id=17, answer=\"yes, proceed with nmap scan\")\n// 2) patch-subtasks(task_id=42, operations=[...])\n// or: patch-subtasks(task_id=42, operations=[{op: \"remove\", id: 17}, ...])","handlingStrategy":"validation","validationCode":"// before patching, verify no subtask of the task is in 'waiting' state\nfor _, st := range subtasks {\n\tif st.TaskID == taskID && st.Status == database.SubtaskStatusWaiting {\n\t\treturn fmt.Errorf(\"subtask %d is waiting for user input; call submit_flow_input first\", st.ID)\n\t}\n}","typeGuard":null,"tryCatchPattern":"out, err := mgr.Handle(ctx, action)\nif err != nil {\n\tif strings.Contains(err.Error(), \"waiting for user input\") {\n\t\t// answer via submit_flow_input, or add a remove/modify op for the waiting subtask, then retry\n\t}\n\treturn err\n}","preventionTips":["Always check flow status (detail='tasks') for waiting subtasks before patching a task's plan","Answer pending subtask questions promptly instead of leaving them open","Include waiting subtask IDs in patch operations if you intend to change or remove them","Avoid concurrent agents editing the same flow"],"tags":["flow-manager","state-guard","agent-tools","subtask-status"],"backgroundTag":"subtask-waiting-user-input","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}