vxcontrol/pentagi · error

failed to put input for task %d: %w

Error message

failed to put input for task %d: %w

What it means

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.

Source

Thrown at backend/pkg/controller/task.go:93

	flowCtx.Publisher.TaskCreated(ctx, task, []database.Subtask{})

	taskCtx := &TaskContext{
		FlowContext: *flowCtx,
		TaskID:      task.ID,
		TaskTitle:   title,
		TaskInput:   input,
	}
	stc := NewSubtaskController(taskCtx)

	_, err = taskCtx.MsgLog.PutTaskMsg(
		ctx,
		database.MsglogTypeInput,
		taskCtx.TaskID,
		"", // thinking is empty because this is input
		input,
	)
	if err != nil {
		return nil, fmt.Errorf("failed to put input for task %d: %w", taskCtx.TaskID, err)
	}

	err = stc.GenerateSubtasks(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to generate subtasks: %w", err)
	}

	subtasks, err := flowCtx.DB.GetTaskSubtasks(ctx, task.ID)
	if err != nil {
		return nil, fmt.Errorf("failed to get subtasks for task %d: %w", task.ID, err)
	}

	flowCtx.Publisher.TaskUpdated(ctx, task, subtasks)

	return &taskWorker{
		mx:        &sync.RWMutex{},
		stc:       stc,
		taskCtx:   taskCtx,

View on GitHub (pinned to ea665308ba)

Solutions

  1. Inspect the wrapped cause from PutMsglog
  2. Verify the msglog/msgchain schema matches the SQLC queries after migrations
  3. Consider making task creation + input logging transactional so both succeed or fail together
  4. Retry CreateTask; note the orphaned task row from the first attempt may need cleanup

Example fix

// before
if err != nil {
    return nil, fmt.Errorf("failed to put input for task %d: %w", taskCtx.TaskID, err)
}
// after
if err != nil {
    log.Error("input logging failed for created task", "task_id", taskCtx.TaskID, "err", err)
    return nil, fmt.Errorf("failed to put input for task %d: %w", taskCtx.TaskID, err)
}
Defensive patterns

Strategy: validation

Validate before calling

if input == "" { return fmt.Errorf("empty input") }
if len(input) > msglogMaxLen { input = truncate(input, msglogMaxLen) }

Try / catch

if err := publisher.PutMsglog(ctx, ..., input); err != nil {
    log.Error("orphan task without input log", "task_id", taskCtx.TaskID, "err", err)
    return nil, fmt.Errorf("failed to put input for task %d: %w", taskCtx.TaskID, err)
}

Prevention

When it happens

Trigger: 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.

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

Related errors


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