{"record":{"id":"901505fd90806de8","repo":"vxcontrol/pentagi","slug":"task-q-id-d-is-currently-running-patching-is","errorCode":null,"errorMessage":"task %q (ID: %d) is currently running; patching is not allowed while a task is executing. Call %s first, then retry %s","messagePattern":"task %q \\(ID: (.+?)\\) is currently running; patching is not allowed while a task is executing\\. Call (.+?) first, then retry (.+?)","errorType":"validation","errorClass":"stateGuard","httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/flow_manager.go","lineNumber":855,"sourceCode":"func (t *patchFlowSubtasksTool) Handle(ctx context.Context, name string, args json.RawMessage) (string, error) {\n\tvar action PatchFlowSubtasksAction\n\tif err := json.Unmarshal(args, &action); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse patch_flow_subtasks args: %w\", err)\n\t}\n\n\tif action.TaskID <= 0 {\n\t\treturn \"\", fmt.Errorf(\"task_id must be a positive integer\")\n\t}\n\n\t// Validate flow is not running\n\ttasks, err := t.db.GetFlowTasks(ctx, t.flowID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to check flow status: %w\", err)\n\t}\n\n\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'\",","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/flow_manager.go#L837-L873","documentation":"patch_flow_subtasks refuses to modify the subtask plan while any task in the flow has status 'running' — the plan is being executed and patching would race with the executor. This is an intentional state guard (stateGuard), not an internal failure, and tells the caller to stop the flow first.","triggerScenarios":"Calling patch_flow_subtasks while a task in the flow is in TaskStatusRunning — e.g. attempting to re-plan mid-execution instead of after stop_flow.","commonSituations":"LLM trying to fix a bad subtask without stopping execution first; concurrent automation (another agent/session) keeping the task running while a user attempts a patch.","solutions":["Call stop_flow with a reason to halt the running task.","Confirm via get_flow_status that no task is running and the flow is 'waiting'.","Retry patch_flow_subtasks once the flow is idle.","If the task appears stuck running, investigate the worker/agent before force-stopping."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Only patch when no task is running\ntasks := getFlowTasks(ctx)\nfor _, t := range tasks {\n    if t.Status == \"running\" {\n        stopFlow(ctx, \"prepare for patch\")\n        waitUntilWaiting(ctx)\n        break\n    }\n}","typeGuard":"func flowIsIdle(tasks []Task) bool {\n    for _, t := range tasks {\n        if t.Status == \"running\" { return false }\n    }\n    return len(tasks) > 0\n}","tryCatchPattern":"_, err := tool.Handle(ctx, \"patch_flow_subtasks\", args)\nif err != nil && strings.Contains(err.Error(), \"currently running\") {\n    stopFlow(ctx, \"clear state before patch\")\n    waitUntilWaiting(ctx)\n    _, err = tool.Handle(ctx, \"patch_flow_subtasks\", args)\n}","preventionTips":["Establish a stop → confirm waiting → patch sequence as standard practice.","Never attempt to re-plan while execution is in flight.","Check for other sessions/agents driving the flow before stopping.","Use get_flow_status after stop_flow to confirm the idle state."],"tags":["state-guard","concurrency","flow-control"],"backgroundTag":"resource-is-locked","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}