vxcontrol/pentagi · warning
context cancelled while waiting for task to start. Call %s t
Error message
context cancelled while waiting for task to start. Call %s to check whether a task was created
What it means
After submit_flow_input successfully delivered input that triggers task creation, waitForTaskReady polls the DB for a running/waiting task. If the caller's context is cancelled during that polling window, the tool aborts with this message. The input was likely delivered, but the tool cannot confirm the generator produced a task — the caller must check flow status.
Source
Thrown at backend/pkg/tools/flow_manager.go:808
tasks, err := t.db.GetFlowTasks(ctx, t.flowID)
if err == nil {
for _, task := range tasks {
if task.Status == database.TaskStatusRunning || task.Status == database.TaskStatusWaiting {
return fmt.Sprintf(
"Input accepted. Task %q (ID: %d) is now running — the generator has produced its subtask plan. "+
"Call %s with detail='running' to see what the agent is doing.",
task.Title, task.ID, GetFlowStatusToolName), nil
}
}
}
if time.Now().After(deadline) {
break
}
select {
case <-ctx.Done():
return "", fmt.Errorf(
"context cancelled while waiting for task to start. "+
"Call %s to check whether a task was created",
GetFlowStatusToolName)
case <-ticker.C:
}
}
return fmt.Sprintf(
"Input accepted but no running task appeared within %s. "+
"The generator may still be working. Call %s to check the current state.",
t.pollTimeout, GetFlowStatusToolName), nil
}
// patchFlowSubtasksTool implements patch_flow_subtasks.
type patchFlowSubtasksTool struct {
flowID int64
db database.Querier
handler func(ctx context.Context, taskID int64, patch SubtaskPatch) errorView on GitHub (pinned to ea665308ba)
Solutions
- Call get_flow_status to see whether a task was actually created before retrying anything.
- If a task exists, do not resubmit input — proceed with the normal flow.
- If no task was created and the flow is waiting, resubmit the input with a longer-lived context.
- Ensure the caller's context deadline comfortably exceeds pollTimeout (taskReadyPollTimeout) so cancellation does not interrupt the confirmation loop.
Example fix
// before: short-lived request context kills the confirmation poll reqCtx := r.Context() result, _ := tool.Handle(reqCtx, "submit_flow_input", args) // after: decouple from request lifetime ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() result, _ := tool.Handle(ctx, "submit_flow_input", args)
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the caller's deadline comfortably exceeds the poll window
if deadline, ok := ctx.Deadline(); ok && time.Until(deadline) < taskReadyPollTimeout+5*time.Second {
ctx, _ = context.WithTimeout(context.Background(), taskReadyPollTimeout+time.Minute)
} Try / catch
_, err := tool.Handle(ctx, "submit_flow_input", args)
if err != nil && strings.Contains(err.Error(), "context cancelled while waiting") {
// input was likely delivered; confirm via status instead of resubmitting
_ = getFlowStatus(ctx)
} Prevention
- Use a context independent of short-lived HTTP requests for flow tools.
- Size the caller deadline larger than taskReadyPollTimeout.
- Handle SIGTERM shutdowns by letting in-flight submits finish or persisting state.
- Never resubmit input after this error until status confirms no task was created.
When it happens
Trigger: The parent context (agent run deadline, HTTP request, operator cancel) is cancelled while waitForTaskReady is between poll ticks — e.g. long generator latency exceeding the caller's remaining budget.
Common situations: Generator/LLM taking longer than the surrounding request timeout; shutting down the agent mid-poll; a gateway cancelling the request; pollTimeout configured larger than the caller's context deadline.
Related errors
- flow %d stopped: %w
- wait for flow completion failed: %w
- submit timed out after %s — the flow may not have received t
- the waiting subtask's execution context is no longer availab
- failed to submit flow input: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/0f46582190def216.
Report an issue: GitHub.