vxcontrol/pentagi · error · stateGuard
task %q (ID: %d) is currently running; patching is not allow
Error message
task %q (ID: %d) is currently running; patching is not allowed while a task is executing. Call %s first, then retry %s
What it means
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.
Source
Thrown at backend/pkg/tools/flow_manager.go:855
func (t *patchFlowSubtasksTool) Handle(ctx context.Context, name string, args json.RawMessage) (string, error) {
var action PatchFlowSubtasksAction
if err := json.Unmarshal(args, &action); err != nil {
return "", fmt.Errorf("failed to parse patch_flow_subtasks args: %w", err)
}
if action.TaskID <= 0 {
return "", fmt.Errorf("task_id must be a positive integer")
}
// Validate flow is not running
tasks, err := t.db.GetFlowTasks(ctx, t.flowID)
if err != nil {
return "", fmt.Errorf("failed to check flow status: %w", err)
}
for _, task := range tasks {
if task.Status == database.TaskStatusRunning {
return "", stateGuard(fmt.Errorf(
"task %q (ID: %d) is currently running; "+
"patching is not allowed while a task is executing. "+
"Call %s first, then retry %s",
task.Title, task.ID, StopFlowToolName, PatchFlowSubtasksToolName))
}
}
taskBelongsToFlow := false
for _, task := range tasks {
if task.ID == action.TaskID {
taskBelongsToFlow = true
break
}
}
if !taskBelongsToFlow {
return "", stateGuard(fmt.Errorf(
"task ID %d was not found in this flow; "+
"obtain a valid task ID from %s with detail='tasks'",View on GitHub (pinned to ea665308ba)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Only patch when no task is running
tasks := getFlowTasks(ctx)
for _, t := range tasks {
if t.Status == "running" {
stopFlow(ctx, "prepare for patch")
waitUntilWaiting(ctx)
break
}
} Type guard
func flowIsIdle(tasks []Task) bool {
for _, t := range tasks {
if t.Status == "running" { return false }
}
return len(tasks) > 0
} Try / catch
_, err := tool.Handle(ctx, "patch_flow_subtasks", args)
if err != nil && strings.Contains(err.Error(), "currently running") {
stopFlow(ctx, "clear state before patch")
waitUntilWaiting(ctx)
_, err = tool.Handle(ctx, "patch_flow_subtasks", args)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- task ID %d was not found in this flow; obtain a valid task I
- task %d has a subtask (ID: %d, %q) currently running. Call %
- failed to finish assistant %d: %w
- flow %d stopped: %w
- failed to add assistant to flow: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/901505fd90806de8.
Report an issue: GitHub.