Skip to content

Enforce user_embeddings provenance ownership consistency #162

Description

@AnthonyRonning

Summary

Follow-up hardening from PR #161.

user_embeddings currently validates provenance shape (user_message_id vs assistant_message_id, conversation_id presence, etc.), but it does not enforce at the database layer that the referenced message rows belong to the same user_id / conversation_id as the embedding row.

Why this is worth tracking

  • Current write paths appear safe, so this did not block the schema-sync PR.
  • A bad future write path could still create cross-user or cross-conversation provenance links.
  • This is the kind of invariant that is easy to assume in code and hard to notice once violated.

Affected migration

  • migrations/2026-02-10-020612_user_embeddings

Follow-up direction

  • Add DB-level ownership validation for user_message_id / assistant_message_id / conversation_id.
  • Composite FKs may work if the referenced tables expose the needed uniqueness; otherwise use a trigger-based validation approach.
  • Preserve the existing Feb/Mar migration lineage by addressing this in a new forward migration rather than editing the historical migration files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions