Skip to content

Conversation

@anth-volk
Copy link
Collaborator

@anth-volk anth-volk commented Jan 14, 2026

Fixes #3064
Requires PolicyEngine/policyengine-api-v2#383

Summary

Adds Modal simulation API support alongside the existing GCP Workflows implementation, allowing the economy report endpoint to use either backend via environment variable configuration.

Changes

New Files

  • policyengine_api/libs/simulation_api_modal.py - HTTP client for Modal API
  • policyengine_api/libs/simulation_api_factory.py - Factory to select GCP or Modal backend
  • tests/unit/libs/test_simulation_api_modal.py - Unit tests for Modal client (20 tests)
  • tests/unit/libs/test_simulation_api_factory.py - Unit tests for factory (7 tests)
  • tests/fixtures/libs/simulation_api_modal.py - Test fixtures for Modal client
  • tests/fixtures/libs/simulation_api_factory.py - Test fixtures for factory

Modified Files

  • policyengine_api/constants.py - Added status constants for GCP and Modal
  • policyengine_api/services/economy_service.py - Uses factory, handles both status formats
  • setup.py - Added httpx>=0.27.0 dependency
  • tests/fixtures/services/economy_service.py - Added Modal test fixtures
  • tests/unit/services/test_economy_service.py - Added Modal status tests (5 tests)

How to Enable Modal

# Enable Modal backend
USE_MODAL_SIMULATION_API=true

# Optional: Override Modal API URL
SIMULATION_API_URL=https://policyengine--policyengine-simulation-web-app.modal.run

By default (USE_MODAL_SIMULATION_API unset or false), the existing GCP Workflows backend is used.

Test plan

  • Unit tests pass for SimulationAPIModal (20 tests)
  • Unit tests pass for factory function (7 tests)
  • Unit tests pass for Modal status handling in EconomyService (5 tests)
  • Manual integration test with Modal backend passes (Utah state reform)
  • CI integration tests pass (requires Modal to have matching package version deployed)

Notes

  • The model_version field is mapped to version for the Modal API
  • data_version is removed as Modal doesn't use it
  • No database schema changes - execution_id column works with both ID formats
  • Integration tests require the local policyengine_us version to match a version deployed on Modal

🤖 Generated with Claude Code

anth-volk and others added 6 commits January 14, 2026 00:38
- Add changelog entry for v3.31.0 describing Modal API support
- Format code with black (line length 79)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Change default Modal API URL from policyengine-simulation to
policyengine-simulation-gateway project.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add changelog entry to changelog_entry.yaml for Modal API support
- Fix test to check for simulation-gateway URL instead of old URL

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@anth-volk anth-volk marked this pull request as ready for review January 14, 2026 20:14
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 91.30435% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.05%. Comparing base (9c84311) to head (b1dfe06).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
policyengine_api/libs/simulation_api_modal.py 86.44% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3065      +/-   ##
==========================================
+ Coverage   70.25%   71.05%   +0.80%     
==========================================
  Files          55       57       +2     
  Lines        2353     2436      +83     
  Branches      333      339       +6     
==========================================
+ Hits         1653     1731      +78     
- Misses        639      644       +5     
  Partials       61       61              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anth-volk anth-volk merged commit 124a635 into master Jan 14, 2026
7 checks passed
@anth-volk anth-volk deleted the feat/migrate-to-modal branch January 14, 2026 20:30
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.

Migrate API from GCP to Modal

2 participants