← Back to Pull requests

OSAC-6871: discover billing accounts and assign tenants (epic) #2160

Closed
unknown closed this pull request without merging on Dec 02, 2026 14:04 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 01:04 UTC
Author

Prerequisite

  • osac-project/osac#2686: generic filter translation and rollback fixes. Merge it first. This branch is rebased on it.
  • Why

    Billing accounts discovery and tenant assignment for the billing integration (design OSAC-3784, epic OSAC-6871). The previous branch mixed billing changes with generic changes and sat on an old base. This rebuild keeps billing changes only; generic fixes are in #2686.

    What this PR does

  • Private billing API only. BillingAccounts, BillingProviderStatuses and TenantBillingAssignments are private services. There is no public billing API.

  • Accounts. BillingAccounts.List reads the billing provider on request only. There is no background poller. Each call refreshes observed fields and stores one row per provider account.

  • Attribution token. Discovery fills an empty local attribution token from the provider's externalId. It never overwrites or clears a non-empty token and never generates one.

  • Assignments. TenantBillingAssignments create, update, list and get. Each assignment interval is append-only history. A tenant has at most one active account and an account at most one active tenant (unique indexes on the assignment table).

  • Correlation. Assignment resolves the attribution value from both sides: it generates, adopts, or reports a conflict. Then the provider must show exactly one account carrying the value; otherwise the assignment stays pending. Providers that cannot write the value report the assignment as pending with remediation.

  • Deletion. Deleting a tenant closes its assignment as a read-only tombstone and releases the account. Accounts referenced by assignment history cannot be deleted (database trigger).

  • Authorization. Billing methods are reachable only by platform admins, through the existing admin rule.

  • Scaffolds. BillingAccounts Get, Create, Update and Delete and TenantBillingAssignments Delete are defined so generic CLI commands work. They return Unimplemented.

  • Docs. Billing behaviour is documented in fulfillment-service/internal/billing/README.md.
  • Decided differences from the design

    1. Private API only; the design lists public billing methods.
    2. No per-method OPA allow-list for billing (design §4.5). Admins reach billing methods through the admin rule.
    3. No database unique index on the attribution token. The provider does not enforce uniqueness, and the account table mirrors the provider. Uniqueness is checked at assignment.
    4. No tenant self-read of assignments. The design (§4.7) is admin-only, and the epic acceptance criterion was updated to match.
    5. Assignment tenant is metadata.tenant; spec.tenant is removed.
    6. The assignment history has no foreign key to the tenant, so history survives tenant deletion.

    Out of scope (follow-ups)

  • Immediate revocation of tenant access on deletion: OSAC-8145.

  • CLI list completeness beyond 100 entries: OSAC-8148.

  • Correlation on usage events (metering): OSAC-6888.

  • Provider currency fallback: OSAC-6890.
  • Testing

  • Kind deployment with the M360 test stub, run on an earlier commit of this branch (before the discovery-time copy and the removed index): install, rollout, provider availability, assignment lifecycle, non-admin rejection, reference-protection trigger.

  • Focused billing specs on the discovery change: pass.

  • Full unit and servers suite on the rebased head: running; result to be added.

  • Not run: the deployed it/ suite and tests/e2e.
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Affected areas

  • API surface: Adds private BillingAccounts and TenantBillingAssignments services and REST routes. Removes the public BillingProviderStatuses service, its proto files, and its REST route.

  • Auth: Billing access is limited to deployment-wide administrators and cloud-provider-admin. Public billing routes return 404.

  • Database: Adds migrations 160–164 for billing accounts, tenant billing assignments, released finalized tenant domains, retained deleted tenant identities, and tenant lifecycle triggers. Updates migrations.sha256.

  • Servers and CLI: Adds private billing servers and a billing-availability interceptor. Changes billing-provider-status CLI aliases and output. Adds billing support to generic get, edit, delete, and completion.

  • Billing adapter: Adds M360 status mapping, correlation resolution, and bounded paging. Removes correlation-write methods from the adapter.

  • CI and tests: Adds billing-stub setup to the integration job and new unit, database, migration, and integration tests.
  • Backward compatibility

  • Removes the public billing-provider-status API and CLI alias.

  • Deleted tenant names cannot be reused. Recreation returns FailedPrecondition with TENANT_IDENTITY_RETAINED.

  • Tenant deletion now closes active billing intervals.

  • Tenant domain reservations persist until finalizers complete.

  • Migration 162 fails with 55P03 while a tenant writer holds a lock. Operators must drain writers before it runs.
  • Risk classification

    Not available. The repository search for risk:ship, risk:show, and risk:ask returned no labeling criteria. Its only matches were unrelated text in vendored and documentation files. The second search's output was not returned, so it is not established. No label is applied. The labeling criteria were not supplied, so no nearest classification can be established.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: amito Review duration: 42539m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.75) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #2160"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%