{"record":{"id":"b6ed72efe26c850f","repo":"vxcontrol/pentagi","slug":"failed-to-put-input-for-task-d-w","errorCode":null,"errorMessage":"failed to put input for task %d: %w","messagePattern":"failed to put input for task (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/task.go","lineNumber":93,"sourceCode":"\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,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to put input for task %d: %w\", taskCtx.TaskID, err)\n\t}\n\n\terr = stc.GenerateSubtasks(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to generate subtasks: %w\", err)\n\t}\n\n\tsubtasks, err := flowCtx.DB.GetTaskSubtasks(ctx, task.ID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get subtasks for task %d: %w\", task.ID, err)\n\t}\n\n\tflowCtx.Publisher.TaskUpdated(ctx, task, subtasks)\n\n\treturn &taskWorker{\n\t\tmx:        &sync.RWMutex{},\n\t\tstc:       stc,\n\t\ttaskCtx:   taskCtx,","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/task.go#L75-L111","documentation":"After creating the task row, NewTaskWorker records the original user input into the message chain via PutMsglog (type input). This error wraps that logging failure. The task exists in the DB at this point, so failing here can leave a task created without its input message recorded, and CreateTask returns an error anyway.","triggerScenarios":"PutMsglog fails on DB connection loss, context cancellation, msgchain/msglog FK or constraint issues (e.g. msgchain row not committed yet), or oversized input payload.","commonSituations":"Very large inputs exceeding column limits; Postgres connectivity blips right after the CreateTask insert; transaction visibility issues if msgchain insert happens in a separate transaction.","solutions":["Inspect the wrapped cause from PutMsglog","Verify the msglog/msgchain schema matches the SQLC queries after migrations","Consider making task creation + input logging transactional so both succeed or fail together","Retry CreateTask; note the orphaned task row from the first attempt may need cleanup"],"exampleFix":"// before\nif err != nil {\n    return nil, fmt.Errorf(\"failed to put input for task %d: %w\", taskCtx.TaskID, err)\n}\n// after\nif err != nil {\n    log.Error(\"input logging failed for created task\", \"task_id\", taskCtx.TaskID, \"err\", err)\n    return nil, fmt.Errorf(\"failed to put input for task %d: %w\", taskCtx.TaskID, err)\n}","handlingStrategy":"validation","validationCode":"if input == \"\" { return fmt.Errorf(\"empty input\") }\nif len(input) > msglogMaxLen { input = truncate(input, msglogMaxLen) }","typeGuard":null,"tryCatchPattern":"if err := publisher.PutMsglog(ctx, ..., input); err != nil {\n    log.Error(\"orphan task without input log\", \"task_id\", taskCtx.TaskID, \"err\", err)\n    return nil, fmt.Errorf(\"failed to put input for task %d: %w\", taskCtx.TaskID, err)\n}","preventionTips":["Truncate/validate input length before logging","Make task insert and input logging one transaction","Alert on tasks that exist without an input msglog row"],"tags":["database","logging","msgchain"],"backgroundTag":"database-write-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}