vxcontrol/pentagi · warning

failed to create search log: %w

Error message

failed to create search log: %w

What it means

PutLog persists a search-log record (query, engine result, flow/task/subtask IDs) via the database insert CreateSearchLog; on failure it returns "failed to create search log: %w". The SearchLogAdded event is published only after a successful insert, so this error means the search was not recorded. The frontend treats engine as an opaque string, but a lost insert means the log is invisible in the UI.

Source

Thrown at backend/pkg/controller/slog.go:67

	result string,
	taskID *int64,
	subtaskID *int64,
) (int64, error) {
	slw.mx.Lock()
	defer slw.mx.Unlock()

	slLog, err := slw.db.CreateSearchLog(ctx, database.CreateSearchLogParams{
		Initiator: initiator,
		Executor:  executor,
		Engine:    engine,
		Query:     query,
		Result:    result,
		FlowID:    slw.flowID,
		TaskID:    database.Int64ToNullInt64(taskID),
		SubtaskID: database.Int64ToNullInt64(subtaskID),
	})
	if err != nil {
		return 0, fmt.Errorf("failed to create search log: %w", err)
	}

	slw.pub.SearchLogAdded(ctx, slLog)

	return slLog.ID, nil
}

func (slw *flowSearchLogWorker) GetLog(ctx context.Context, msgID int64) (database.Searchlog, error) {
	msg, err := slw.db.GetFlowSearchLog(ctx, database.GetFlowSearchLogParams{
		ID:     msgID,
		FlowID: slw.flowID,
	})
	if err != nil {
		return database.Searchlog{}, fmt.Errorf("failed to get search log: %w", err)
	}

	return msg, nil
}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Unwrap the error to identify the driver/constraint cause.
  2. Check the result payload size against the DB column type/limits.
  3. Verify DB health and that the referenced flow/task rows still exist.
  4. Retry the insert after transient failures; search-log writes are idempotent-safe to reissue for a new record.

Example fix

null
Defensive patterns

Strategy: fallback

Validate before calling

// bound the stored result size before the insert
if len(result) > maxSearchLogResultLen {
    result = result[:maxSearchLogResultLen]
}

Type guard

null

Try / catch

id, err := slw.PutLog(ctx, taskID, subtaskID, engine, query, result)
if err != nil {
    // search logs are observability data — never fail the search itself
    logger.WithError(err).Warn("search log not persisted")
    return 0, nil
}

Prevention

When it happens

Trigger: The web_search orchestrator records a search while the INSERT fails: DB unreachable, constraint violation (e.g. invalid engine or flow_id FK), oversized result payload, or context cancellation during the write.

Common situations: Large search results exceeding column limits; database restart or failover during an active pentest run; FK failure when the flow/task was deleted while a search was in flight; connection pool exhaustion under heavy tool activity.

Related errors


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