fix(handlers): sync MEDIA_BUY_STATE_MACHINE with spec v3 enum#289
Open
fix(handlers): sync MEDIA_BUY_STATE_MACHINE with spec v3 enum#289
Conversation
`pending_activation` was removed from `enums/media-buy-status.json` in
the AdCP v3 spec; `pending_start` and `pending_creatives` are the
correct replacements. The state machine dict and its test were still
using the stale key, causing `valid_actions_for_status("pending_start")`
to return `[]` and `valid_actions_for_status("pending_activation")` to
return a non-empty list for a status that no longer exists.
Also updates the `valid_actions_for_status` docstring to enumerate valid
status strings, and corrects the stale `pending_activation → active`
webhook example in `skills/build-seller-agent/SKILL.md`.
Closes #288
https://claude.ai/code/session_01Q4gEoNmiYsfqnfFSR71JLg
Acting on python-expert review of this PR: - Add ``test_pending_activation_is_not_recognized`` so a copy-paste from old SDK code or pre-3.0 spec docs surfaces as an empty action list (the documented contract) and never accidentally re-matches via a future stale entry. - Add ``test_state_machine_keys_match_spec_enum`` asserting the dict contains exactly the seven canonical statuses from ``enums/media-buy-status.json`` (pending_creatives, pending_start, active, paused, completed, rejected, canceled). Guards against future silent drift between the spec enum and the dispatcher table — the regression that produced this bug originally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #288
Summary
Issue #288 identified schema drift between the SDK and AdCP v3 spec. Most reported drift was already resolved in v4.0.0 (the
MediaBuyStatusgenerated enum andAggregatedTotalsfields are correct). One residual bug remained:MEDIA_BUY_STATE_MACHINEinsrc/adcp/server/helpers.pystill had"pending_activation"as its pre-flight key — a status that no longer exists inenums/media-buy-status.json. This causedvalid_actions_for_status("pending_start")to return[]instead of the correct pre-flight action list, andvalid_actions_for_status("pending_activation")to return a non-empty list for a spec-invalid status.Changes:
"pending_activation"key with"pending_start"(same pre-flight actions) and"pending_creatives"(addssync_creatives— the buyer must attach creatives before the buy can serve)valid_actions_for_statusdocstring to enumerate all valid status strings and document the[]fallbacktests/test_server_helpers.py: renametest_pending_activation_allows_cancel→test_pending_start_allows_cancel, addtest_pending_creatives_allows_sync_creativespending_activation → activewebhook transition example inskills/build-seller-agent/SKILL.md→pending_creatives → pending_start → activeWhat was tested
pytest tests/test_server_helpers.py— 43 passedruff check src/adcp/server/helpers.py— cleanmypy src/adcp/server/helpers.py— no issuesPre-PR review
is_terminal_statushard-codes its terminal set independently ofMEDIA_BUY_STATE_MACHINE(same drift risk pattern, currently consistent); nit:test_pending_start_allows_cancelcould addassert "sync_creatives" not in actionsnegative assertionpending_startexplainingsync_creativesis intentionally absent (creatives locked once flight-date-pending); same negative assertion nit as aboveNits surfaced (not fixed — reviewer discretion)
is_terminal_statushard-codes("completed", "rejected", "canceled")separately from the state machine; currently consistent but divergence risk on future spec updatestest_pending_start_allows_cancelcould assert"sync_creatives" not in actionsto make thepending_creativesvspending_startdistinction explicitpending_startaction block could carry a one-line comment:# sync_creatives intentionally absent — creatives are locked once flight-date-pendingSession: https://claude.ai/code/session_01Q4gEoNmiYsfqnfFSR71JLg
Generated by Claude Code