fix: Ensure mock adapter returns packages with package_id in all code paths #655
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.
Summary
Fixed bug where mock adapter and
create_media_buytool were improperly handling pending/async responses, causing confusion about media buy state and returning fake IDs to clients.Problem
The mock adapter was returning fake
media_buy_idvalues like"pending_question_..."or"pending_step_..."for async/pending operations. This is wrong because:Additionally,
media_buy_create.pywas trying to save non-existent media buys to the database and process packages even when the operation wasn't complete.Root Cause Analysis
Architecture: AdCP protocol uses two layers:
CreateMediaBuyResponse) - Business dataProtocolEnvelope) - Wraps withstatusfieldFor pending/async operations:
media_buy_id=None(doesn't exist yet)packages=[](not created yet)status="working"or"input-required"task_id(workflow_step_id) for trackingThe client uses
task_idto poll or wait for webhook, NOT a fake media_buy_id.Solution (3 commits)
Commit 1 (1d42301): Initial defensive fix - ensure mock adapter returns packages with package_id
Commit 2 (924c408): Skip package processing for pending responses
media_buy_id.startswith("pending_")orNoneCommit 3 (aaaea9c): Remove fake media_buy_id from pending responses
media_buy_id=Nonefor async/question scenariospackages=[]for pendingmedia_buy_id=NoneproperlyHow It Works Now
For completed operations:
{ "status": "completed", "payload": { "media_buy_id": "mb_abc123", "packages": [{...}] } }For pending/async operations:
{ "status": "working", "task_id": "workflow_step_xyz", "message": "Processing your media buy...", "payload": { "buyer_ref": "buyer_123", "media_buy_id": null, "packages": [] } }Client uses
task_idto track, not a fake media_buy_id.Testing
Impact
🤖 Generated with Claude Code