Skip to content

design: scope provider name uniqueness to (owner, name) #1996

Closed

Description

@pdettori

Context

With per-user provider ownership (#1995, OpenShell PR #19), users can create and manage their own providers. However, provider names remain globally unique — two users cannot both create a provider named "openai".

Problem

The current DB schema enforces UNIQUE(object_type, name):

CREATE UNIQUE INDEX objects_name_uq
    ON objects (object_type, name)
    WHERE name IS NOT NULL;

This means user A creating a provider "openai" prevents user B from creating their own "openai" provider, even though they're completely isolated by ownership labels.

Desired behavior

Provider name uniqueness should be scoped to (owner, name):

  • Alice can have "openai", Bob can also have "openai"
  • Shared providers (no owner) remain globally unique within the shared namespace
  • Internal lookups (inference routing, credential refresh, sandbox resolution) continue to work

Complexity analysis

~20+ call sites resolve providers by name via get_message_by_name::<Provider>(name):

  • grpc/provider.rs — CRUD handlers
  • grpc/sandbox.rs — providers_for_sandbox(), attach/detach
  • inference.rs — route resolution
  • provider_refresh.rs — credential refresh worker

Sandboxes store provider references as plain name strings in spec.providers. Internal systems resolve those names without user context.

Options considered

Approach Pros Cons
A: DB migration — add owner column, composite unique index Clean separation, no name encoding Changes store API for all entity types, requires migration for sqlite + postgres
B: Name prefixing — store {owner}/{name} as DB key No schema change, no store API change Two-pass resolution (try owned, then shared), all 20+ call sites need updating
C: Scope column — repurpose existing scope column for owner No new column scope already used for refresh states; semantic overloading
D: Accept global uniqueness — document as known limitation Zero work Users on shared gateways collide on common names

Recommendation

Option B (name prefixing) with the following design:

  1. On create: store DB name as {sanitized_owner}/{name} for owned, raw {name} for shared
  2. Proto metadata.name stores the user-visible name (not the DB key)
  3. Add a resolver: try {owner}/{name} first, fall back to {name} (shared)
  4. Sandbox spec.providers stores the DB key (scoped name) — internal lookups work unchanged
  5. List/get responses strip the owner prefix for display

This avoids a DB migration while keeping internal resolution paths simple.

Depends on

Activity

  1. pdettori commented on Jun 17, 2026

    @pdettori
    MemberAuthor

    Implementation Analysis

    Confirmed Option B (name prefixing) is viable with zero DB migration — the existing objects_name_uq index on (object_type, name) already accommodates scoped names because the stored name changes:

    Before: name = "openai"         (globally unique)
    After:  name = "alice-uuid/openai"  (unique per owner)
            name = "openai"             (shared, no owner)
    

    Store Layer Design

    graph LR
        subgraph "DB objects table"
            A["alice-uuid/openai<br/>(owned by alice)"]
            B["bob-uuid/openai<br/>(owned by bob)"]
            C["openai<br/>(shared, no owner)"]
        end
        
        subgraph "Proto response (metadata.name)"
            D["openai"]
            E["openai"]
            F["openai"]
        end
        
        A --> D
        B --> E
        C --> F
    
    Loading

    Resolution order (when a user looks up "openai"):

    1. Try {sanitized_owner}/{name} → user's own provider
    2. Fall back to {name} → shared provider (no owner label)
    3. Not found → error

    Key design points

    1. scoped_name(owner, name) -> String — constructs "{owner}/{name}" for storage
    2. resolve_provider_by_name(store, name, principal) — two-pass lookup (owned → shared)
    3. Sandbox spec.providers stores the DB key (scoped name) — so internal resolution is single-pass
    4. List/Get strip the prefix for display: metadata.name always shows the user-visible name
    5. Admin resolution — admins can specify {owner}/{name} explicitly to target another user's provider
    6. No DB migration needed — existing partial unique index handles this as-is

    Call sites to update (~20)

    File Change
    grpc/provider.rs Create stamps scoped name; Get/Update/Delete use resolver
    grpc/sandbox.rs providers_for_sandbox() uses resolver; stores DB key in spec
    inference.rs Route resolution uses resolver
    provider_refresh.rs Refresh worker resolves by DB key (already scoped in spec)

    Test plan

    • Unit: scoped_name construction, sanitize_subject edge cases
    • Integration: Two users create "openai" → both succeed; sandbox references owned provider; shared fallback; admin cross-user access

    Branch

    Will base on kagenti/mvp-v2 where PR #19 (per-user provider ownership) is merged.


    Starting implementation.

  2. pdettori commented on Jun 23, 2026

    @pdettori
    MemberAuthor

    this is implemented now in the kagenti/openshell branch

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

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions