Tencent/WeKnora · error

find conflicting memory: %w

Error message

find conflicting memory: %w

What it means

Wraps a failure from repo.FindActiveByKey, which looks up an existing live memory item with the same normalized topic+content key before writing. The service needs to know whether the statement already exists to deduplicate or supersede it; if the storage lookup itself fails, the write is aborted with this message.

Source

Thrown at internal/application/service/memory/service.go:352

			ctx, scope, item.SourceMessageID, rejectedMessageWindow,
		)
		if err != nil {
			return nil, fmt.Errorf("check forgotten source: %w", err)
		}
	}
	if forgotten {
		logger.Infof(ctx, "memory: skipped a statement the user previously deleted")
		return nil, ErrPreviouslyForgotten
	}
	if _, err := s.repo.EnsureSubject(ctx, scope); err != nil {
		return nil, fmt.Errorf("ensure memory subject: %w", err)
	}

	topic := types.SanitizeMemoryTopic(item.Topic)
	normalizedKey := types.MemoryItemKey(topic, content)
	existing, err := s.repo.FindActiveByKey(ctx, scope, normalizedKey)
	if err != nil {
		return nil, fmt.Errorf("find conflicting memory: %w", err)
	}
	if existing != nil && types.SanitizeMemoryContent(existing.Content) == content {
		// Same statement about the same topic: nothing changed, so keep the
		// original timestamps instead of churning the row on every turn.
		return existing, nil
	}
	if existing == nil {
		// The same fact often arrives twice: once because the user said
		// "remember ..." and again from the background distillation, phrased
		// slightly differently ("我们的生产库是 X" vs "生产库是 X"). They get
		// different topic keys, so key matching alone lets both through and
		// the user sees their memory duplicated.
		duplicate, longer, err := s.findContainedDuplicate(ctx, scope, item.Kind, content)
		if err != nil {
			return nil, err
		}
		if duplicate != nil && !longer {
			return duplicate, nil

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check the wrapped cause (%w) for the actual repo/DB error and fix that layer first (connectivity, migration, constraint).
  2. Verify the memory repository backend is reachable and the schema/migrations for memory items are applied.
  3. Increase the context timeout or run memory extraction outside the request path if deadline exceeded.
  4. Retry the memory write; the operation is idempotent because existing items with identical content are returned as-is.

Example fix

// before
existing, err := s.repo.FindActiveByKey(ctx, scope, normalizedKey)
if err != nil {
    return nil, fmt.Errorf("find conflicting memory: %w", err)
}
// after
existing, err := s.repo.FindActiveByKey(ctx, scope, normalizedKey)
if err != nil {
    logger.Warnf(ctx, "memory: find conflicting item failed: %v", err)
    return nil, fmt.Errorf("find conflicting memory: %w", err) // keep wrap, but ensure caller retries
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check connectivity
if err := s.repo.Ping(ctx); err != nil { return fmt.Errorf("memory repo unavailable: %w", err) }

Try / catch

existing, err := svc.Remember(ctx, scope, item)
if err != nil {
    if errors.Is(err, context.DeadlineExceeded) { /* retry with longer timeout */ }
    var dbErr *storage.DBError
    if errors.As(err, &dbErr) { /* alert on repo health */ }
    return fmt.Errorf("memory write skipped: %w", err)
}

Prevention

When it happens

Trigger: Calling Remember, PromoteTopic, CreateItem, mergeRedundant, applyDecisions or observeTopics when the underlying memory repository (DB) errors on FindActiveByKey — e.g. DB connection failure, timeout, table missing, or context canceled mid-query.

Common situations: Database outage or connection pool exhaustion during a chat turn that extracts memories; context deadline exceeded when the memory write happens inside a request with a short timeout; schema drift after migration where the memory_items index/key lookup fails.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/97e45942a18fd338. Report an issue: GitHub.