vxcontrol/pentagi · error
failed to get task %d subtasks: %w
Error message
failed to get task %d subtasks: %w
What it means
RefineSubtasks first reloads the task's subtasks from the database via GetTaskSubtasks before asking the LLM provider for a refined plan. This error wraps any failure of that read, binding the task ID to the underlying store error. It is a pre-condition failure: refinement never starts because the current subtask state could not be loaded.
Source
Thrown at backend/pkg/controller/subtasks.go:100
for _, info := range plan {
_, err := stc.taskCtx.DB.CreateSubtask(ctx, database.CreateSubtaskParams{
Status: database.SubtaskStatusCreated,
TaskID: stc.taskCtx.TaskID,
Title: info.Title,
Description: info.Description,
})
if err != nil {
return fmt.Errorf("failed to create subtask for task %d: %w", stc.taskCtx.TaskID, err)
}
}
return nil
}
func (stc *subtaskController) RefineSubtasks(ctx context.Context) error {
subtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, stc.taskCtx.TaskID)
if err != nil {
return fmt.Errorf("failed to get task %d subtasks: %w", stc.taskCtx.TaskID, err)
}
plan, err := stc.taskCtx.Provider.RefineSubtasks(ctx, stc.taskCtx.TaskID)
if err != nil {
return fmt.Errorf("failed to refine subtasks for task %d: %w", stc.taskCtx.TaskID, err)
}
if len(plan) == 0 {
return nil // no subtasks refined
}
subtaskIDs := make([]int64, 0, len(subtasks))
for _, subtask := range subtasks {
if subtask.Status == database.SubtaskStatusCreated {
subtaskIDs = append(subtaskIDs, subtask.ID)
}
}
View on GitHub (pinned to ea665308ba)
Solutions
- Check backend logs for the wrapped cause (%w) — usually a pq/GORM connection error
- Verify PostgreSQL is reachable and the DB pool is not exhausted
- Confirm migrations ran (goose up) so the subtasks table matches SQLC queries
- Retry RefineSubtasks once the DB connection is restored; the operation is safe to re-run
Example fix
// before
subtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, stc.taskCtx.TaskID)
if err != nil {
return fmt.Errorf("failed to get task %d subtasks: %w", stc.taskCtx.TaskID, err)
}
// after
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
subtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, stc.taskCtx.TaskID)
if err != nil {
return fmt.Errorf("failed to get task %d subtasks: %w", stc.taskCtx.TaskID, err)
} Defensive patterns
Strategy: retry
Validate before calling
if stc.taskCtx.TaskID <= 0 { return fmt.Errorf("invalid task id") }
if err := db.PingContext(ctx); err != nil { return fmt.Errorf("db unavailable: %w", err) } Try / catch
subtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, taskID)
if err != nil {
if errors.Is(err, context.Canceled) { return err }
return fmt.Errorf("failed to get task %d subtasks: %w", taskID, err)
} Prevention
- Run goose migrations on deploy so SQLC queries match schema
- Monitor DB connection pool saturation
- Always pass a live, non-cancelled context to DB calls
When it happens
Trigger: Calling RefineSubtasks when the database connection is down, the subtasks table is missing/corrupted, the query context is cancelled (e.g. client disconnect or timeout), or GetTaskSubtasks returns a row-scan error.
Common situations: Postgres restarted mid-flow; context deadline exceeded because the flow context was cancelled while the agent was running; migration drift after upgrading so SQLC query no longer matches schema.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- token not found in database
- flow not found
- flow not found
- failed to create flow in DB: %w
- failed to get user %d: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/62197141d166979d.
Report an issue: GitHub.