vxcontrol/pentagi · error · stateGuard

task %d has a subtask (ID: %d, %q) waiting for user input. O

Error message

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

What it means

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.

Source

Thrown at backend/pkg/tools/flow_manager.go:894

	planned, err := t.db.GetTaskPlannedSubtasks(ctx, action.TaskID)
	if err != nil {
		return "", fmt.Errorf("failed to get planned subtasks for task %d: %w", action.TaskID, err)
	}

	if len(planned) == 0 && len(action.Operations) > 0 {
		subtasks, err := t.db.GetFlowSubtasks(ctx, t.flowID)
		if err != nil {
			return "", fmt.Errorf("failed to check subtask state for task %d: %w", action.TaskID, err)
		}

		for _, st := range subtasks {
			if st.TaskID != action.TaskID {
				continue
			}
			switch st.Status {
			case database.SubtaskStatusWaiting:
				return "", stateGuard(fmt.Errorf(
					"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",
					action.TaskID, st.ID, st.Title, SubmitFlowInputToolName))
			case database.SubtaskStatusRunning:
				return "", stateGuard(fmt.Errorf(
					"task %d has a subtask (ID: %d, %q) currently running. "+
						"Call %s first, then retry",
					action.TaskID, st.ID, st.Title, StopFlowToolName))
			}
		}

		return "", stateGuard(fmt.Errorf(
			"no 'created' subtasks found for task %d; "+
				"all subtasks have been executed or the task has no plan yet. "+
				"Use %s to create a new task instead",
			action.TaskID, SubmitFlowInputToolName))
	}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Call submit_flow_input with the waiting subtask's ID to answer the pending question first, then retry the patch
  2. Include the waiting subtask's ID in the patch operations to modify or remove it
  3. Pick a different task without waiting subtasks, or finish the waiting subtask before restructuring the plan

Example fix

// before
// patch-subtasks(task_id=42, operations=[...]) -> error: subtask waiting
// after
// 1) submit_flow_input(subtask_id=17, answer="yes, proceed with nmap scan")
// 2) patch-subtasks(task_id=42, operations=[...])
// or: patch-subtasks(task_id=42, operations=[{op: "remove", id: 17}, ...])
Defensive patterns

Strategy: validation

Validate before calling

// before patching, verify no subtask of the task is in 'waiting' state
for _, st := range subtasks {
	if st.TaskID == taskID && st.Status == database.SubtaskStatusWaiting {
		return fmt.Errorf("subtask %d is waiting for user input; call submit_flow_input first", st.ID)
	}
}

Try / catch

out, err := mgr.Handle(ctx, action)
if err != nil {
	if strings.Contains(err.Error(), "waiting for user input") {
		// answer via submit_flow_input, or add a remove/modify op for the waiting subtask, then retry
	}
	return err
}

Prevention

When it happens

Trigger: Calling the patch-subtasks (or create-subtasks with operations) tool action for a task that has at least one subtask with status 'waiting'.

Common situations: 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.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/077a11b974869c8c. Report an issue: GitHub.