fix: sales agent logic #602
Merged
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
This PR fixes multiple issues with media buy creation, package data consistency, and status reporting across auto-approved and manually-approved workflows.
Changes
1. Fixed Package Data Consistency (Auto-Approve vs Manual Approve)
Problem: Manual approval responses returned minimal package data (only 4 fields), while auto-approval returned complete data (budget, targeting, creative_ids, etc.).
Fix: Both manual approval paths now serialize the full package object using
model_dump_internal()to return consistent, complete data.Files Changed:
src/core/main.py(lines 4817-4833, 4987-5003)Impact: Buying agents now receive consistent package data regardless of approval path.
2. Added Package Data Fields to Auto-Approval Path
Problem: Auto-approved media buys weren't saving
product_id,budget, andtargeting_overlayto MediaPackage records, causing incomplete display in UI and inconsistent responses.Fix:
product_idandbudgetfields toMediaPackageschemaFiles Changed:
src/core/schemas.py(MediaPackage class)src/core/main.py(lines 5162-5188)Impact: Auto-approved packages now have complete metadata in database and responses.
3. Fixed Package Status Logic for Creative Approval
Problem: Package status was set to
COMPLETEDwhen creatives were assigned, even if they were still pending approval.Fix: Status now correctly reflects creative approval state:
INPUT_REQUIRED: Manual approval neededWORKING: Creatives still needed or pending approvalCOMPLETED: Creatives assigned AND approvedFiles Changed:
src/core/main.py(lines 5442-5452)Impact: Buying agents can now accurately determine if a media buy is truly ready.
4. Standardized TaskStatus Enum Usage
Problem: Manual approval paths used string literal
"pending_approval"instead of proper TaskStatus enum.Fix: Replaced all string status literals with
TaskStatus.INPUT_REQUIREDenum value.Files Changed:
src/core/main.py(lines 4821, 4991, 5002)Impact: Consistent status values across all response types.
5. Fixed Template Package Display
Problem: Media buy detail template tried to access package fields directly, but they're stored in
package_configJSONB.Fix: Updated template to access fields via
package.package_config.get().Files Changed:
templates/media_buy_detail.html(lines 128-148)Impact: Package details now display correctly for both approval paths.
6. Added Creative ID Display to Review Page
Problem: Creative review cards didn't show the
creative_id, making it hard to identify which creative to approve.Fix: Added creative_id display below the creative name in monospace font.
Files Changed:
templates/creative_management.html(lines 71-73)Impact: Easier identification of creatives during review.
Testing Notes
All fixes have been tested locally with Docker restart. Changes affect:
Breaking Changes
None - all changes are backwards compatible and fix existing inconsistencies.