Skip to content

profiles: enforce name uniqueness atomically in the user stores #343

Open

Description

@RXWatcher

Follow-up to #342, which enforces per-account profile name uniqueness at the API layer (handler compares against a ListProfiles snapshot before writing).

Gap

The check is read-then-write, so two concurrent creates/renames on the same account with the same trimmed, case-folded name can both pass the snapshot and both commit — neither the SQLite per-user store (internal/userdb) nor the Postgres store (internal/userstore/pgstore) constrains normalized names, only the profile-ID primary key. Raised by Codex review on #342 (P2).

Practical exposure is small (same household firing matching-name writes in the same instant), and the failure mode is the pre-#342 behavior: a duplicate name slips in. But the name_conflict contract should be a guarantee, not best-effort.

Proposed fix

Enforce in the store layer, both backends:

  • either a unique index on the normalized name (lower(trim(name)), per account in Postgres), or a check-then-insert inside the write transaction (SQLite: BEGIN IMMEDIATE);
  • a typed userstore.ErrProfileNameConflict the handler maps to the existing 409 name_conflict;
  • migration note: accounts holding pre-existing duplicates (created before fix(profiles): enforce per-account profile name uniqueness #342) will fail unique-index creation — needs a dedupe/rename migration first, or the transactional-check approach which grandfathers them.

AI-use disclosure

Drafted with Claude Code (Claude Fable 5).

Activity

  1. darthShadow commented on Jul 8, 2026

    @darthShadow
    Contributor

    I really like Django does this with it's slugify function. Eventually, I would like to replace the IDs in the URLs with slugs, where possible. For now, would it make sense to have it just for the uniqueness checks and a DB field? The actual plumbing into URLs can come later.

    References:

  2. added
    bug
    triaged
    and removed
    triaged
    on Sep 20, 2026
  3. added theissue type on Sep 20, 2026
  4. removed
    bug
    on Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions