{"record":{"id":"e621fb8b90271ea5","repo":"vxcontrol/pentagi","slug":"task-d-has-a-subtask-id-d-q-currently-runni","errorCode":null,"errorMessage":"task %d has a subtask (ID: %d, %q) currently running. Call %s first, then retry","messagePattern":"task (.+?) has a subtask \\(ID: (.+?), %q\\) currently running\\. Call (.+?) first, then retry","errorType":"validation","errorClass":"stateGuard","httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/flow_manager.go","lineNumber":900,"sourceCode":"\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}\n\n\tpatch := SubtaskPatch{\n\t\tOperations: action.Operations,\n\t\tMessage:    action.Message,\n\t}\n","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/flow_manager.go#L882-L918","documentation":"A stateGuard error raised by the create/patch-subtasks tool when the task has a subtask currently in SubtaskStatusRunning. Patching the plan while a subtask is executing is disallowed because it would race with live execution; the agent must first stop the flow via the stop_flow tool, then retry. This is an intentional concurrency guard, not a system failure.","triggerScenarios":"Calling patch-subtasks (or create-subtasks with operations) for a task that has a subtask whose status is 'running'.","commonSituations":"The agent tries to revise a plan while a long-running subtask (e.g. an nmap scan) is still executing; a stale or crashed run left a subtask stuck in 'running' status; two agents operate on the same flow concurrently.","solutions":["Call stop_flow to stop the running subtask, then retry the patch operation","Wait until the running subtask completes, then patch the task's plan","If a subtask is stuck in 'running' after a crash, restart the flow/worker so its status is reconciled, then retry"],"exampleFix":"// before\n// patch-subtasks(task_id=42, operations=[...]) -> error: subtask 17 running\n// after\n// 1) stop_flow(subtask_id=17)\n// 2) patch-subtasks(task_id=42, operations=[...])","handlingStrategy":"validation","validationCode":"// before patching, verify no subtask of the task is running\nfor _, st := range subtasks {\n\tif st.TaskID == taskID && st.Status == database.SubtaskStatusRunning {\n\t\treturn fmt.Errorf(\"subtask %d is running; call stop_flow first\", st.ID)\n\t}\n}","typeGuard":null,"tryCatchPattern":"out, err := mgr.Handle(ctx, action)\nif err != nil {\n\tif strings.Contains(err.Error(), \"currently running\") {\n\t\t// call stop_flow for the running subtask, then retry the patch\n\t}\n\treturn err\n}","preventionTips":["Poll flow status and wait for subtasks to finish before restructuring a task's plan","Stop running subtasks explicitly before patching","Reconcile subtasks stuck in 'running' after crashes before further edits","Serialize plan mutations: one agent owns the flow at a time"],"tags":["flow-manager","state-guard","agent-tools","concurrency"],"backgroundTag":"subtask-currently-running","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}