Skip to content

decisioning.state_machines: export terminal statuses, and distinguish observed from requested media-buy transitions #1604

Description

@bokelley

Context

The Scope3 embedded sales agent (a sales agent built on adcp.server.serve() and adcp.decisioning) now decides a media buy's status in one place per adapter, and uses adcp.decisioning.state_machines as its lifecycle graph instead of its own. Two things we needed are not in the SDK, so we derived them locally for now. We would rather they lived here.

1. Terminal statuses as a public constant

Every adopter that reads MEDIA_BUY_TRANSITIONS ends up writing:

TERMINAL = frozenset(s for s, nxt in MEDIA_BUY_TRANSITIONS.items() if not nxt)

Proposal: export MEDIA_BUY_TERMINAL_STATUSES (and CREATIVE_TERMINAL_STATUSES if the creative graph ever has one) plus is_terminal_media_buy_status(status) -> bool. An unknown status returns False rather than raising, since adopters often hold internal pre-lifecycle statuses (pending_approval, draft) that the spec graph does not model.

2. Observed transitions are not requested transitions

MEDIA_BUY_TRANSITIONS describes what a buyer may ask for. A seller that mirrors its ad server also records transitions the ad server made on its own, and some of those are not edges in the graph:

Observed move Why it happens
pending_creatives → active A seller attached and approved creatives in the ad server directly, and the order is serving
pending_start → paused The order was paused in the ad server before its flight started
active → pending_start The flight start was moved later in the ad server
completed → active / paused The flight end was extended in the ad server, or a completed order was reopened

AdCP's media-buy lifecycle guidance says the seller's report wins every disagreement, in both directions, so a seller must record these, not refuse them with INVALID_STATE. Today the graph cannot tell an adopter which moves are "a buyer may request this" and which are "only the ad server can do this".

Proposal, either of:

  • a second graph, MEDIA_BUY_OBSERVED_TRANSITIONS, listing every move a seller may record from its platform (a superset of the requested graph), or
  • classify_media_buy_transition(from_state, to_state) -> Literal["requested", "observed", "illegal"].

assert_media_buy_transition stays as it is for buyer requests.

Optional: flight phase

Adopters whose platform holds an order "approved" without saying whether its flight is running (GAM's APPROVED, FreeWheel's BOOKED) all project the order through its flight dates: pending_start before, active within, completed after. A small flight_phase(start, end, now) helper that accepts date or datetime bounds would remove another copy from each adopter. Less important than 1 and 2.

Happy to send a PR for 1 and 2 if the shape is agreeable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions