{"record":{"id":"ba8fdb9d234f2e5e","repo":"vxcontrol/pentagi","slug":"failed-to-create-task-in-db-w","errorCode":null,"errorMessage":"failed to create task in DB: %w","messagePattern":"failed to create task in DB: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/task.go","lineNumber":72,"sourceCode":") (TaskWorker, error) {\n\tctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, \"controller.NewTaskWorker\")\n\tdefer span.End()\n\n\tctx = tools.PutAgentContext(ctx, database.MsgchainTypePrimaryAgent)\n\n\ttitle, err := flowCtx.Provider.GetTaskTitle(ctx, input)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get task title: %w\", err)\n\t}\n\n\ttask, err := flowCtx.DB.CreateTask(ctx, database.CreateTaskParams{\n\t\tStatus: database.TaskStatusCreated,\n\t\tTitle:  title,\n\t\tInput:  input,\n\t\tFlowID: flowCtx.FlowID,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create task in DB: %w\", err)\n\t}\n\n\tflowCtx.Publisher.TaskCreated(ctx, task, []database.Subtask{})\n\n\ttaskCtx := &TaskContext{\n\t\tFlowContext: *flowCtx,\n\t\tTaskID:      task.ID,\n\t\tTaskTitle:   title,\n\t\tTaskInput:   input,\n\t}\n\tstc := NewSubtaskController(taskCtx)\n\n\t_, err = taskCtx.MsgLog.PutTaskMsg(\n\t\tctx,\n\t\tdatabase.MsglogTypeInput,\n\t\ttaskCtx.TaskID,\n\t\t\"\", // thinking is empty because this is input\n\t\tinput,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/task.go#L54-L90","documentation":"After generating a title, NewTaskWorker persists the task via CreateTask (DB insert). This error wraps that insert failure. The title was already generated (LLM cost incurred) but nothing is committed; the caller sees the task creation fail.","triggerScenarios":"DB connection loss, context cancellation between the LLM call and insert, FlowID referencing a missing flow (FK violation), or column constraint failures on title/input.","commonSituations":"Flow deleted concurrently while its task was being created (FK violation); Postgres pool exhaustion; oversized input exceeding the input column limit.","solutions":["Inspect the wrapped DB error — FK violation vs connection vs constraint","Verify the flow exists before creating tasks against it","Ensure input length fits the DB column definition","Retry CreateTask once the DB issue is resolved"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if flowCtx.FlowID <= 0 { return fmt.Errorf(\"invalid flow id\") }\nif len(input) > maxInputLen { return fmt.Errorf(\"input too large\") }","typeGuard":null,"tryCatchPattern":"task, err := flowCtx.DB.CreateTask(ctx, params)\nif err != nil {\n    var pqErr *pq.Error\n    if errors.As(err, &pqErr) && pqErr.Code == \"23503\" {\n        return nil, fmt.Errorf(\"flow %d no longer exists\", flowCtx.FlowID)\n    }\n    return nil, fmt.Errorf(\"failed to create task in DB: %w\", err)\n}","preventionTips":["Check flow existence before creating its tasks","Enforce input length limits at the API boundary","Monitor DB pool and connection errors"],"tags":["database","insert","task-creation"],"backgroundTag":"database-write-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}