Skip to content

Enforce explicit TimedTransitionProperty FSMs - #3303

Open
CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:timed-transition-fsm
Open

CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:timed-transition-fsm

Conversation

@CydeWeys

@CydeWeys CydeWeys commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

TLD launch phases and allocation token promotion lifecycles previously relied on ad-hoc ordering checks and unvalidated deserialization paths that permitted illegal state regressions, bypassed promo-token checks during YAML sync, resurrected terminal tokens, and suffered a TOCTOU race when ending bulk-pricing packages. This change replaces implicit enum-ordinal ordering with explicit transition graphs enforced across builders, YAML sync, CLI updates, and a bytecode CI guardrail.

Key Changes

  • Tld, EntityYamlUtils & ConfigureTldCommand:
    • Replace Ordering.natural() on Tld.tldStateTransitions with an explicit VALID_TLD_STATE_TRANSITIONS graph and non-QUIET_PERIOD progression check (forbidding regressions such as GENERAL_AVAILABILITY -> PDT, both directly and via QUIET_PERIOD).
    • Route EntityYamlUtils.TimedTransitionPropertyTldStateDeserializer and Tld.Builder.setTldStateTransitions through Tld.createTldStateTransitions, and re-validate in Tld.validateState.
    • Extract Tld.validateDefaultPromoTokens (batching DB loads via loadByKeysIfPresent and honoring empty allowedTlds as all-TLD tokens) and invoke it from both Tld.Builder.setDefaultPromoTokens and ConfigureTldCommand so YAML sync cannot persist missing, wrong-type, or wrong-TLD promo tokens.
  • TimedTransitionProperty:
    • Remove the unused forEmptyMap() method, which unconditionally threw IllegalArgumentException.
    • Add a 3-argument make() overload enforcing allowed transitions without constraining the initial state, and reject empty maps with IllegalArgumentException instead of NoSuchElementException.
  • AllocationToken, GenerateAllocationTokensCommand & UpdateAllocationTokensCommand:
    • Fix BULK_PRICING renewalPrice zero check to use Money.isZero() instead of getAmount().intValue() == 0, which truncated $0.99 to 0.
    • Add null-checked AllocationToken.isTerminalStatus (reused in both UpdateAllocationTokensCommand and GenerateAllocationTokensCommand).
    • Reject tokenStatusTransitions updates that resurrect terminal tokens (ENDED or CANCELLED), regress a live status backward (e.g., VALID -> NOT_STARTED), or shrink UNLIMITED_USE/DEFAULT_PROMO transitions to a single NOT_STARTED entry.
    • Store only token VKeys between init() and execute(), reload, re-validate, and skip already-identical tokens inside each saveBatch() transaction to close TOCTOU windows, and print updated batch token names only after transaction commit.
  • CI Guardrail & Tests:
    • Add TimedTransitionPropertyUsageTest using ClassGraph and JDK ClassFile inspection (covering both InvokeInstruction and InvokeDynamicInstruction method references) to enforce an explicit method-level allowlist of stateless production callers of raw TimedTransitionProperty.fromValueMap(), preventing stateful TldState and TokenStatus paths from bypassing transition-graph validation.
    • Add empirical regression tests covering every fix, Tld.validateState(), and edge cases.

Operational Justification & Blast Radius

  • Zero database schema or Flyway migrations; zero Protostuff entity field changes; TimedTransitionProperty does not implement Map.
  • Scoped to TLD configuration sync (configure_tld), allocation token generation/updates, and model validation.

BUG= http://b/591075479


This change is Reviewable

@CydeWeys
CydeWeys force-pushed the timed-transition-fsm branch from 22ce33f to 98ce8a0 Compare November 27, 2026 19:00
TLD launch phases and allocation token promotion lifecycles previously
relied on ad-hoc ordering checks and unvalidated deserialization paths
that permitted illegal state regressions, bypassed promo-token checks
during YAML sync, resurrected terminal tokens, and suffered a TOCTOU
race when ending bulk-pricing packages. This change replaces implicit
enum-ordinal ordering with explicit transition graphs enforced across
builders, YAML sync, CLI updates, and a bytecode CI guardrail.

Key changes:
- Tld, EntityYamlUtils & ConfigureTldCommand:
  - Replace Ordering.natural() on Tld.tldStateTransitions with an
    explicit VALID_TLD_STATE_TRANSITIONS graph and non-QUIET_PERIOD
    progression check (forbidding regressions such as
    GENERAL_AVAILABILITY -> PDT, both directly and via QUIET_PERIOD).
  - Route EntityYamlUtils.TimedTransitionPropertyTldStateDeserializer
    and Tld.Builder.setTldStateTransitions through
    Tld.createTldStateTransitions, and re-validate in Tld.validateState.
  - Extract Tld.validateDefaultPromoTokens (using batched DB loads and
    honoring empty allowedTlds as all-TLD tokens) and invoke it from
    both Tld.Builder.setDefaultPromoTokens and ConfigureTldCommand so
    YAML sync cannot persist missing, wrong-type, or wrong-TLD promo
    tokens.
- TimedTransitionProperty:
  - Remove the unused forEmptyMap() method, which unconditionally threw
    IllegalArgumentException.
  - Add a 3-argument make() overload enforcing allowed transitions
    without constraining the initial state, and reject empty maps with
    IllegalArgumentException instead of NoSuchElementException.
- AllocationToken, GenerateAllocationTokensCommand &
  UpdateAllocationTokensCommand:
  - Fix BULK_PRICING renewalPrice zero check to use Money.isZero()
    instead of getAmount().intValue() == 0, which truncated $0.99 to 0.
  - Add null-checked AllocationToken.isTerminalStatus (reused in both
    UpdateAllocationTokensCommand and GenerateAllocationTokensCommand).
  - Reject tokenStatusTransitions updates that resurrect terminal tokens
    (ENDED or CANCELLED), regress a live status backward (e.g.,
    VALID -> NOT_STARTED), or shrink UNLIMITED_USE/DEFAULT_PROMO
    transitions to a single NOT_STARTED entry.
  - Store only token VKeys between init() and execute(), reload,
    re-validate, and skip already-identical tokens inside each
    saveBatch() transaction to close TOCTOU windows, and print updated
    batch token names only after transaction commit.
- CI Guardrail & Tests:
  - Add TimedTransitionPropertyUsageTest using ClassGraph and JDK
    ClassFile inspection (covering both InvokeInstruction and
    InvokeDynamicInstruction method references) to enforce an explicit
    method-level allowlist of stateless production callers of raw
    TimedTransitionProperty.fromValueMap().
  - Add regression tests covering every fix, validateState(), and edge
    case.

Operational justification & blast radius:
- Zero database schema or Flyway migrations; zero Protostuff entity
  field changes; TimedTransitionProperty does not implement Map.
- Scoped to TLD configuration sync (configure_tld), allocation token
  generation/updates, and model validation.

BUG= http://b/591075479
@CydeWeys
CydeWeys force-pushed the timed-transition-fsm branch from 98ce8a0 to 9f1bf5a Compare December 4, 2026 21:49
@CydeWeys
CydeWeys requested a review from ptkach December 4, 2026 21:50

This branch has not been deployed

No deployments
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