Skip to content

Name the report type in every run_simulation record - #1183

Open
anth-volk wants to merge 3 commits into
mainfrom
claude/report-type-in-run-records
Open

anth-volk wants to merge 3 commits into
mainfrom
claude/report-type-in-run-records

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #1182

What this changes

Every run_simulation log record now names its report type in the attribute report_type:

  • budget_window_year: one year of a multi-year (budget-window) report. build_child_simulation_request adds it to every year's request that run_budget_window_batch spawns, for every country and region, whether or not the year runs in segments.
  • single_year: every other request. _run_simulation adds it to a request that has no report_type, before it records the operation and before it dispatches the calculation.

Other details:

  • Constants: the field name and its two values are constants in a new contract-library module, policyengine_simulation_contract.report_type, so API v2's records can use the same names.
  • Segments: the label is set in the request's parameters, so the region-group children of a segmented run copy it into their run_simulation_segment records.
  • What is unchanged: the calculation ignores the field. The gateway's request models don't declare it and still refuse it from callers, so only the batch can mark a job budget_window_year.
  • Docs: docs/engineering/skills/observability.md has a new "Annual job report type" section.

Why: the weekly run-times summary identifies budget-window years by a request's segmented: false and a missing job_queue_seconds. A later change runs plain US national budget-window years in segments, by no longer setting segmented: false on them, and the summary would then count those years as single-year runs. This label gives the summary a direct marker.

Tests

The tests were added in 141bb052, before the change, and each was run on its own on both commits:

Test Before the change (141bb052) After (319064c2)
test_budget_window_context.py::test_build_child_simulation_request_marks_every_year_as_a_budget_window_year (US national, US state, UK) 3 failed on assertions 3 passed
test_job_progress.py::TestModalRunSimulation::test__a_request_without_a_report_type_runs_as_a_single_year_report failed on an assertion passed
test_job_progress.py::TestModalRunSimulation::test__the_calculation_never_sees_the_submission_time (changed: the dispatched parameters now include report_type: single_year) failed on an assertion passed
test_job_progress.py::TestModalRunSimulation::test__a_budget_window_year_keeps_its_report_type passed: it checks existing behaviour the change relies on (the worker keeps a request's own value) passed
test_segmented_national.py::TestBuildGroupChildPayload::test__children_copy_the_parents_report_type (both values) 2 passed: they check existing behaviour the change relies on (segment requests copy the field) 2 passed

The single-year test reads the completion record written by the real policyengine-observability runtime, so it also shows that report_type gets through the library's attribute-name filter.

Other checks, on the changed files only:

  • Ruff 0.15.22 (CI's version), format and lint: clean.
  • Pyright 1.1.414 on the three changed source files: 0 errors.
  • scripts/run_quality_guards.py: all six guards passed.

Review

There was one round of adversarial review: report-runtimes-reviews/policyengine-sim-api-claude-report-type-in-run-records-review-round1-2026-12-03.md, kept outside the repository. It found no bugs (high 0, medium 0, low 0), so no further rounds ran. It checked:

  • every caller of SimulationWorker.run_simulation;
  • every path from the batch and the gateway to the calculation, for models or checks that would refuse the field;
  • cache, job and identity keys;
  • the observability filter;
  • image wiring;
  • compatibility with older versioned apps.

It made four code-quality notes:

  1. Missing documentation: the observability guide lists the other run_simulation attributes but not report_type. Fixed in 773201fd, which is documentation only and has not been reviewed.
  2. Typing (left as is): the values are plain string constants rather than a StrEnum, and _with_report_type keeps any value that isn't None.
  3. Missing tests (left as is): nothing checks that the gateway's request models refuse report_type, and the branch that replaces None has no test.
  4. Test layout (left as is): the new worker-test helper repeats the existing queue-time test's setup. test_job_progress.py is at 1,417 of its 1,500 allowed lines.

Bugs left: none.

What the merge waits for

  • Earlier tasks: none. This is the first task of its group, and a later change to the same function (build_child_simulation_request) merges after this one and merges main in.
  • Before merging: the PR's own checks, plus the approving review that main requires. Following this repository's rule sim.process.agents-never-bypass, it will not be merged with --admin.
  • Deployment: a merge to main releases and deploys the executor app. Records from apps deployed before this change carry no report_type, so readers keep their older rule for those records.

This builds on main only. No deployment code changed.

🤖 Generated with Claude Code

anth-volk and others added 3 commits December 3, 2026 01:13
Each year of a budget window should carry report_type budget_window_year
in its request, and the worker should label any other request single_year
in its parameters, so its run record and its segments' records carry it.
These tests fail before the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The budget-window batch puts report_type budget_window_year on each year's
request, and the worker puts report_type single_year on any request that
names none, before it records and runs it. The worker records the field
with the request's other fields, and a segmented run's children copy it,
so the run-times summary can leave budget-window years out without
reading them from segmented: false and a missing queue time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 1 of the review found no bugs and noted that the guide lists the
other attributes run_simulation records carry but not report_type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review December 2, 2026 21:58

This branch has not been deployed

No deployments
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.

Name the report type in every run_simulation record

1 participant