Skip to content

Fix #162: add source semantics and effective routing endpoint#166

Merged
charlesrhoward merged 3 commits intomainfrom
codex/issue-162-tenant-routing-source-effective
Feb 16, 2026
Merged

Fix #162: add source semantics and effective routing endpoint#166
charlesrhoward merged 3 commits intomainfrom
codex/issue-162-tenant-routing-source-effective

Conversation

@charlesrhoward
Copy link
Contributor

@charlesrhoward charlesrhoward commented Feb 16, 2026

Summary

  • add deterministic tenant mapping source semantics via mapping_source (auto / override) with migration/backfill in sdk_tenant_databases
  • persist source on writes:
    • runtime auto-provision writes mapping_source = auto
    • management/legacy tenant override writes mapping_source = override
  • expose source in tenant listing responses and surface source badges in the dashboard tenant mapping list
  • add GET /api/sdk/v1/management/tenant-routing/effective?tenantId=... to return effective routing diagnostics:
    • resolved target
    • mapping status + source
    • owner scope context
    • decision/fallback reason and auto-provision eligibility details
  • add shared source normalization helper for compatibility with legacy rows (metadata.provisionedBy fallback)

Verification

  • cd packages/web && pnpm vitest run src/app/api/mcp/tenants/__tests__/route.test.ts src/app/api/sdk/v1/management/tenant-overrides/__tests__/route.test.ts src/app/api/sdk/v1/management/tenant-routing/effective/__tests__/route.test.ts src/lib/memory-service/scope.test.ts
  • cd packages/core && pnpm vitest run src/__tests__/client.test.ts
  • cd packages/web && pnpm typecheck
  • cd packages/core && pnpm typecheck

Note

Medium Risk
Adds a new persistent column with backfill plus new/updated management endpoints that influence tenant routing decisions; mistakes could misclassify mappings or affect provisioning/disable flows, but changes are scoped and covered by tests.

Overview
Adds deterministic tenant mapping source semantics by introducing mapping_source (auto vs override) on sdk_tenant_databases, including a Supabase migration that backfills existing rows (using metadata.provisionedBy) and enforces defaults/constraints.

Updates runtime auto-provisioning and both legacy (/api/mcp/tenants) and SDK management (/api/sdk/v1/management/tenant-overrides) APIs to persist and return source, plus a shared normalizeTenantMappingSource helper for legacy compatibility and dashboard UI badges/disable gating (only override mappings can be disabled).

Adds GET /api/sdk/v1/management/tenant-routing/effective?tenantId=... to return routing diagnostics (resolved target, mapping readiness/source/credentials, owner-scope context, and auto-provision eligibility/blocked reasons), and refactors management auth/rate-limit handling into a reusable resolveManagementIdentity utility.

Written by Cursor Bugbot for commit ddf402e. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Feb 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
memories Ready Ready Preview, Comment, Open in v0 Feb 16, 2026 11:29pm

Request Review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2e16a87c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +232 to +234
if (params.autoProvisionEnabled && params.hasPlatformToken && params.billingEligible === true) {
return {
code: "AUTO_PROVISION_ELIGIBLE",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict AUTO_PROVISION_ELIGIBLE to real fallback states

This branch marks every existing non-ready mapping as AUTO_PROVISION_ELIGIBLE when billing passes, but runtime auto-provisioning in resolveTenantTurso only runs for missing mappings, disabled/error mappings, or missing credentials. In the valid status="provisioning" + credentials case, this endpoint claims runtime will replace the mapping even though requests actually fail as not-ready, so the new effective-routing diagnostics can direct operators toward the wrong remediation path.

Useful? React with 👍 / 👎.

@cursor

This comment has been minimized.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is ON. A Cloud Agent has been kicked off to fix the reported issue.

@cursor
Copy link

cursor bot commented Feb 16, 2026

Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.

  • ✅ Fixed: Required source field breaks SDK backward compatibility
    • I made managementTenantSchema.source default to "override" so older server responses without source now parse successfully instead of throwing.

@charlesrhoward charlesrhoward merged commit 53d5b06 into main Feb 16, 2026
14 checks passed
@charlesrhoward charlesrhoward deleted the codex/issue-162-tenant-routing-source-effective branch February 18, 2026 19:35
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.

2 participants