codex_quota_sponsorship

Generation-bound Codex quota sponsorship state.

Sponsorship grants access to an owner’s capacity as a routing fallback. It does not transfer ownership of the account generation, its credential home, or any account-management capability to the beneficiary.

class codex_quota_sponsorship.CodexSponsorGrant(owner_subject, beneficiary_subject, account_id, owner_connected_at, granted_at)

Bases: object

An internal, generation-pinned fallback candidate.

Parameters:
  • owner_subject (str)

  • beneficiary_subject (str)

  • account_id (str)

  • owner_connected_at (str)

  • granted_at (str)

owner_subject: str
beneficiary_subject: str
account_id: str
owner_connected_at: str
granted_at: str
exception codex_quota_sponsorship.CodexSponsorshipIdentityChanged

Bases: CodexSponsorshipStoreUnavailable

The beneficiary’s canonical identity changed during a grant.

exception codex_quota_sponsorship.CodexSponsorshipOwnerChanged

Bases: CodexSponsorshipStoreUnavailable

The owner’s linked account generation changed during a grant.

exception codex_quota_sponsorship.CodexSponsorshipStoreUnavailable

Bases: RuntimeError

Sponsorship state could not be verified or changed safely.

class codex_quota_sponsorship.ResolvedCodexBeneficiary(user_id, target_alias, subject, unified_id)

Bases: object

One server-resolved Discord target without any credential material.

Parameters:
  • user_id (str)

  • target_alias (str)

  • subject (str)

  • unified_id (str)

user_id: str
target_alias: str
subject: str
unified_id: str
codex_quota_sponsorship.beneficiary_grants_redis_key(beneficiary_subject)
Return type:

str

Parameters:

beneficiary_subject (str)

codex_quota_sponsorship.discord_identity_alias_key(user_id)
Return type:

str

Parameters:

user_id (str)

async codex_quota_sponsorship.get_valid_codex_sponsors(redis, beneficiary_subject)

Return validated fallback candidates, pruning stale generations atomically.

Tuple order is deterministic for testing and transport, not a donor-draining priority. The inference layer must apply per-turn fair ordering and must fall back only after an effect-free self-account quota refusal.

Return type:

tuple[CodexSponsorGrant, ...]

Parameters:
  • redis (Any)

  • beneficiary_subject (str)

async codex_quota_sponsorship.get_valid_codex_beneficiaries(redis, *, owner_subject, owner_account_id, owner_connected_at)

List raw Discord IDs currently authorized by one account generation.

The lookup verifies both sponsorship indexes atomically and prunes dangling records. Only owner-visible target IDs leave this boundary; account IDs, canonical beneficiary subjects, and provider identity never do.

Return type:

tuple[str, ...]

Parameters:
  • redis (Any)

  • owner_subject (str)

  • owner_account_id (str)

  • owner_connected_at (str)

async codex_quota_sponsorship.grant_codex_sponsorship(redis, *, owner_subject, owner_account_id, owner_connected_at, beneficiary, granted_at=None)

Atomically add or refresh one generation-bound owner grant.

False means the exact grant already existed. The beneficiary’s own linked account remains primary; callers may use returned grants only as fallback candidates after self capacity is absent or exhausted.

Return type:

bool

Parameters:
codex_quota_sponsorship.is_explicit_discord_user_id(value)

Accept only a raw Discord snowflake, never a mention or subject token.

Return type:

bool

Parameters:

value (str)

codex_quota_sponsorship.owner_grants_redis_key(owner_subject)
Return type:

str

Parameters:

owner_subject (str)

async codex_quota_sponsorship.resolve_discord_beneficiary(redis, user_id)

Resolve a raw Discord ID to the same canonical subject used at ingress.

Return type:

ResolvedCodexBeneficiary

Parameters:
async codex_quota_sponsorship.revoke_codex_sponsorship(redis, *, owner_subject, beneficiary_user_id)

Atomically remove only the caller-owned edge for one Discord ID.

Return type:

bool

Parameters:
  • redis (Any)

  • owner_subject (str)

  • beneficiary_user_id (str)