vxcontrol/pentagi · error

knowledge: list all: %w

Error message

knowledge: list all: %w

What it means

The same ListDocuments flow, but for the branch where no FlowID filter is set: it wraps failures of ListAllKnowledgeDocuments — listing every knowledge document across all flows — as "knowledge: list all: %w". Root causes are database-level: connectivity, timeout, or extension/SQL errors on the full-table scan.

Source

Thrown at backend/pkg/database/knowledge/knowledge.go:267

}

// ---- ListDocuments (admin) --------------------------------------------------

func (ks *knowledgeStore) ListDocuments(ctx context.Context, filter *model.KnowledgeFilter, withContent bool) ([]*model.KnowledgeDocument, error) {
	var docs []*model.KnowledgeDocument

	if filter != nil && filter.FlowID != nil {
		rows, err := ks.db.ListFlowKnowledgeDocuments(ctx, nsOf(strconv.FormatInt(*filter.FlowID, 10)))
		if err != nil {
			return nil, fmt.Errorf("knowledge: list by flow: %w", err)
		}
		for _, r := range rows {
			docs = append(docs, rowToModel(r.ID, r.Document, nullStr(r.Cmetadata), withContent))
		}
	} else {
		rows, err := ks.db.ListAllKnowledgeDocuments(ctx)
		if err != nil {
			return nil, fmt.Errorf("knowledge: list all: %w", err)
		}
		for _, r := range rows {
			docs = append(docs, rowToModel(r.ID, r.Document, nullStr(r.Cmetadata), withContent))
		}
	}

	return applyGoFilters(docs, filter), nil
}

// ---- ListUserDocuments (user-scoped) ----------------------------------------

func (ks *knowledgeStore) ListUserDocuments(ctx context.Context, userID int64, filter *model.KnowledgeFilter, withContent bool) ([]*model.KnowledgeDocument, error) {
	userIDStr := strconv.FormatInt(userID, 10)
	var docs []*model.KnowledgeDocument

	if filter != nil && filter.FlowID != nil {
		// Flow-scoped listing; user_id check applied in Go for safety.
		rows, err := ks.db.ListFlowKnowledgeDocuments(ctx, nsOf(strconv.FormatInt(*filter.FlowID, 10)))

View on GitHub (pinned to ea665308ba)

Solutions

  1. Unwrap the driver error and check PostgreSQL server logs.
  2. Prefer flow-scoped listing (set filter.FlowID) to avoid the unbounded full scan.
  3. Add pagination/LIMIT to ListAllKnowledgeDocuments for large tables.
  4. Verify DB connectivity and the pgvector extension state.
  5. Increase statement timeout or optimize indexes if the scan legitimately needs to run.

Example fix

// before
docs, err := kStore.ListDocuments(ctx, nil, true)
// after
filter := &model.KnowledgeFilter{FlowID: &flowID} // scope instead of listing all
docs, err := kStore.ListDocuments(ctx, filter, true)
if err != nil { return fmt.Errorf("list docs: %w", err) }
Defensive patterns

Strategy: validation

Validate before calling

// avoid unbounded listing when possible
if filter == nil || filter.FlowID == nil {
    if !allowFullKnowledgeScan {
        return fmt.Errorf("refusing unbounded knowledge listing; set FlowID filter")
    }
}
if err := ctx.Err(); err != nil {
    return nil, err
}

Type guard

func isQueryTimeout(err error) bool {
    var pgErr *pgconn.PgError
    return errors.As(err, &pgErr) && pgErr.Code == "57014"
}

Try / catch

docs, err := kStore.ListDocuments(ctx, nil, withContent)
if err != nil {
    if isQueryTimeout(err) {
        return listAllInBatches(ctx, kStore, withContent) // chunked fallback
    }
    return nil, fmt.Errorf("knowledge list all: %w", err)
}

Prevention

When it happens

Trigger: Calling ListDocuments(ctx, nil filter or filter without FlowID, withContent) when PostgreSQL is unreachable, the full listing times out under a large table, or the pgvector/JSONB metadata columns error during scan.

Common situations: Admin UI listing all knowledge documents on a large deployment; database under heavy load; metadata column schema drift after a manual migration; connection pool exhaustion.

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


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