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 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 & UpdateAllocationTokensCommand:
    • Fix BULK_PRICING renewalPrice zero check to use Money.isZero() instead of getAmount().intValue() == 0, which truncated $0.99 to 0.
    • Reject tokenStatusTransitions updates on tokens already in terminal status (ENDED or CANCELLED) via AllocationToken.isTerminalStatus.
    • Reload and re-validate tokens inside each saveBatch() transaction to close the TOCTOU window between init() and execute() for both bulk-pricing domain counts and terminal transitions, and log only the current batch rather than the full tokensToSave set.
  • CI Guardrail & Tests:
    • Add TimedTransitionPropertyUsageTest using ClassGraph and a minimal JDK ClassFile InvokeInstruction check 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 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 updates (update_allocation_tokens), and model validation.

BUG= http://b/591075479


This change is Reviewable

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 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 & UpdateAllocationTokensCommand:
  - Fix BULK_PRICING renewalPrice zero check to use Money.isZero()
    instead of getAmount().intValue() == 0, which truncated $0.99 to 0.
  - Reject tokenStatusTransitions updates on tokens already in terminal
    status (ENDED or CANCELLED) via AllocationToken.isTerminalStatus.
  - Reload and re-validate tokens inside each saveBatch() transaction
    to close the TOCTOU window between init() and execute() for both
    bulk-pricing domain counts and terminal transitions, and log only
    the current batch rather than the full tokensToSave set.
- CI Guardrail & Tests:
  - Add TimedTransitionPropertyUsageTest using ClassGraph and a minimal
    JDK ClassFile InvokeInstruction check 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 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
  updates (update_allocation_tokens), and model validation.

BUG= http://b/591075479
@CydeWeys
CydeWeys force-pushed the timed-transition-fsm branch from 22ce33f to 98ce8a0 Compare November 27, 2026 19:00

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