Skip to content

feat(proxy): self-provision catch-all tenant when no default configured (Option B, no hardcoded id)#342

Merged
epappas merged 1 commit into
mainfrom
feat/proxy-catchall-tenant-fallback
May 30, 2026
Merged

feat(proxy): self-provision catch-all tenant when no default configured (Option B, no hardcoded id)#342
epappas merged 1 commit into
mainfrom
feat/proxy-catchall-tenant-fallback

Conversation

@epappas

@epappas epappas commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Proxy side of the catch-all design. Pairs with the lifecycle PR (#341, Option A primary).

Change

build_app_state resolves an effective catch-all tenant via resolve_catch_all_tenant_id:

  • Option A: if LLMTRACE_DEFAULT_TENANT_ID is set (lifecycle-supplied), use it verbatim.
  • Option B (fallback): if unset, generate a fresh TenantId(Uuid::new_v4()) at runtime (never hardcoded), log it, and use it.
    Then ensure_tenant_exists(catch_all_id, "catch-all") (idempotent) so the catch-all is a real tenant row in both cases. Tenant-less /v1 traffic is attributed to the catch-all; the 401 path remains only as a defensive guard.

No hardcoded id

Option B is purely Uuid::new_v4(); a test asserts the id is never nil / never the anonymous sentinel, and that two builds produce distinct ids (proving runtime generation). proxy.rs change is doc-comment only.

Tests (7, all pass)

config.rs: configured-id-used, generated-when-unset, distinct-across-builds, never-nil/sentinel. main.rs: full build_app_state for configured + self-provisioned + distinct-across-builds (catch-all row present, name "catch-all").

Verification

cargo fmt --all 0; cargo clippy --workspace -- -D warnings 0; cargo test -p llmtrace -p llmtrace-core -p llmtrace-storage 0; cargo build --workspace 0.

…when no default configured (no hardcoded id)

Tenant-less /v1 traffic (no X-LLMTrace-Tenant-ID and no derivable API key)
is now attributed to a catch-all tenant rather than rejected with 401.

At startup build_app_state resolves an effective catch-all tenant id via
config::resolve_catch_all_tenant_id:

- Option A: when LLMTRACE_DEFAULT_TENANT_ID is set (lifecycle-supplied),
  that id is used verbatim.
- Option B (fallback): when unset, a fresh TenantId(Uuid::new_v4()) is
  GENERATED at runtime (never a hardcoded literal), stamped onto
  config.default_tenant_id, and logged.

The resolved id is materialised as a real tenant row via the idempotent
ensure_tenant_exists for BOTH cases so the catch-all surfaces in
queries/dashboard. The request path reads config.default_tenant_id to
stamp tenant-less traffic, so the 401 branch becomes a defensive guard.
@epappas epappas merged commit 88a2783 into main May 30, 2026
15 checks passed
@epappas epappas deleted the feat/proxy-catchall-tenant-fallback branch May 30, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant