Skip to content

Conversation

@anth-volk
Copy link
Collaborator

Summary

Fixes #3111

Adds ingredient metadata to society-wide economic calculation calls so that Logfire can trace errors back to specific policy IDs.

Changes

Modified policyengine_api/services/economy_service.py in the _handle_create_impact method to include a _metadata field in the simulation API call parameters:

sim_params = sim_config.model_dump()
sim_params["_metadata"] = {
    "reform_policy_id": setup_options.reform_policy_id,
    "baseline_policy_id": setup_options.baseline_policy_id,
    "process_id": setup_options.process_id,
}
sim_api_execution = simulation_api.run(sim_params)

How it works

  1. The Logfire span in the simulation API (app.py) captures input_params=params before validation
  2. The _metadata field is included in that capture
  3. SimulationOptions.model_validate() silently ignores the extra _metadata field (Pydantic v2 default behavior)
  4. No changes required to the simulation API itself

Benefits

  • Enables direct correlation between Logfire errors and database records
  • Helps debug issues like the Virginia policy bug where parameter values were incorrectly stored
  • Minimal code change with high debugging value

Test plan

  • Verify simulation API calls still work correctly
  • Check Logfire to confirm _metadata appears in the run_simulation span

🤖 Generated with Claude Code

anth-volk and others added 2 commits January 21, 2026 20:18
…cing

Adds a _metadata field to simulation API call parameters containing:
- reform_policy_id
- baseline_policy_id
- process_id

This metadata is captured by Logfire spans in the simulation API before
SimulationOptions validation, enabling direct correlation between errors
and database records. The metadata is silently ignored by Pydantic v2's
default validation behavior.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds a unit test that verifies the _metadata field is included in the
params passed to simulation_api.run() with correct policy IDs and
process ID.

Also adds changelog entry for the feature.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.56%. Comparing base (647768b) to head (250f65e).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3112      +/-   ##
==========================================
+ Coverage   70.53%   70.56%   +0.02%     
==========================================
  Files          55       55              
  Lines        2386     2388       +2     
  Branches      339      339              
==========================================
+ Hits         1683     1685       +2     
  Misses        642      642              
  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 marked this pull request as ready for review January 21, 2026 18:08
@anth-volk anth-volk requested a review from SakshiKekre January 21, 2026 18:10
@anth-volk anth-volk changed the title Fixes #3111: Add ingredient metadata to simulation API calls Add ingredient metadata to simulation API calls Jan 21, 2026
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.

Add ingredient metadata to society-wide economic calculation calls

2 participants