Skip to content

Record each API v2 report run's region, year, report type and .py version on its coordinator log record - #1203

Merged
anth-volk merged 6 commits into
mainfrom
claude/v2-coordinator-report-fields
Dec 4, 2026
Merged

anth-volk merged 6 commits into
mainfrom
claude/v2-coordinator-report-fields

Conversation

@anth-volk

@anth-volk anth-volk commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1201

What this changes

API v2's report coordinator (coordinate_report) now records the report it runs on its stage12_coordinator_execution log record, under the attribute names and values API v1's run_simulation records use. The run-time summary can then group API v2 report runs the same way as API v1's.

  • Contract library. ReportExecutionInput gains report_type (ReportType: single_year or budget_window_year, API v1's two values), which defaults to single_year. The request's JSON leaves the field out when it is single_year (exclude_if, as cliff_result_id does). So every single-year request stays byte-for-byte as before, and a v2 app deployed before this change still accepts it. BUDGET_WINDOW_YEAR_REPORT_TYPE and SINGLE_YEAR_REPORT_TYPE are typed Final[ReportType].

  • Simulation service. report_run_calculation takes report_type as a required keyword argument:

    • A new budget window's first year and both window re-run calls pass budget_window_year.
    • Later years' requests are copied from an earlier year's by year_calculation, so they keep the value.
    • Single-year submissions and re-runs pass single_year.
  • Coordinator. coordinate_report:

    • names modal_app_name;
    • passes the app's bundled .py version as the runtime's service version, as the v2 simulation workers do;
    • adds what stage12_runtime.report_record_attributes reads from its own request: country, region (the region code, such as state/ca), scope, simulation_year (an integer), report_type, and breakdown: local_areas for a UK-wide or nation report on the local-area dataset.

    A request that can't be read names none of these, and a failing local-area check leaves breakdown out. Either way the call goes on: telemetry never fails a request.

  • Docs. docs/engineering/skills/observability.md has a new section, "API v2 coordinator report fields". It covers:

    • each field's values;
    • selecting API v2 report runs by the operation name plus database_table = report_runs, not by execution_mode;
    • keeping the longest successful record of each report run, since deduplicated calls and retries write records too;
    • how local_areas work differs between the APIs;
    • which calls lack the fields.

    Changelog fragment: changelog.d/v2-coordinator-report-fields.added.md.

No deployment code changes, and no environment variable is added or read, so there is no environment-variable table.

Tests

The tests are committed before the change (18116ae9); the change is 01d90e8e. Each test was run on its own by pytest node ID:

  • Before the change: 12 of the 14 new tests fail, 11 on their assertions and 1 with a validation error because the field doesn't exist yet. The other 2 pass, as intended: they check that an unknown report_type is refused and that an unreadable request still runs.
  • After the change: all 14 pass.
  • At the head: the 17 tests the branch adds or changes all pass. That is the 14, one more coordinator test from the review fixes (the local-area check raising), and two existing simulation service tests that now pass report_type. The new local-area test fails when the except it covers is removed.
Package Tests
Contract library test_stage12_budget_window_years.py: 3
Simulation service test_budget_window_submissions.py: 1, test_economy_reruns.py: 2, test_economy_submissions.py: 1, test_economy_calculation_inputs.py: 2 changed
Executor test_v2_coordinator_record.py: 8

Ruff 0.15.22 format and lint are clean on every changed Python file. Pyright 1.1.414 reports 0 errors on the changed source modules and on the API v1 modules that use the two constants.

Review rounds

Three rounds of adversarial review, each in a fresh clone:

  • Round 1 (…-review-round1-2026-12-04.md). Two low-priority bugs:

    1. A v2 app deployed before this change refuses a budget-window year's report_type if it still receives the new service's requests.
    2. Budget windows that span the deploy record every year as single_year.

    Fixes in 831a99a8:

    • report_type is now required in report_run_calculation;
    • the constants are typed Final[ReportType];
    • a test makes the local-area check raise;
    • the test that reads a real record covers breakdown;
    • the new guide section documents bug 2.
  • Round 2 (…-review-round2-2026-12-04.md). One medium-priority bug: round 1's bug 1 can also happen when a .py update is released together with this change, or when the v2 default already names an older app. No code change: the one-PR scope was decided. It is handled by the checks before merging below. Guide fixes in 7aa81098.

  • Round 3 (…-review-round3-2026-12-04.md). Two low-priority gaps in those checks:

    1. The default-move job succeeds without moving the default when a newer default stays, so the checks read its release_is_default output.
    2. A failed release of this change followed by a .py pin change; see the note below.

    Guide wording fixes in be5fb8e0.

After #1193 merged, which stores budget_window as a report's type, 91aca5fc stops listing that field's values in the guide.

Bugs left (all low priority):

  • A .py update merged during the few minutes of this merge's own release job would be released together with it. Budget-window years would then fail between the new service's promotion and the default move.
  • If this change's release fails before production has the new coordinator, and the next release changes the .py pin, the same window opens in that release.
  • A beta deployment started by hand from another branch can leave beta's default on an app without this change.

What the merge waits for

Every earlier task in the tracker (substage 1.8 of "Report runtimes") is complete. None of their deployments is needed: this PR changes only API v2's coordinator request and log records, and the summary query (1.8 · 4) reads those records once they exist.

Task Must reach State Why
1.8 · 1 Create the permanent run table and its weekly copy done done action task
1.8 · 2 Record the tracker's decisions done done action task
1.8 · 3 Submit a weekly scheduled report of each type merged done order only
1.8 · 3a Send the weekly job's reports through the right API merged merged order only
1.8 · 4 Add the tracker summary query and version the weekly copy merged merged order only; reads these records later
1.8 · 5 Schedule and publish the summary file done done action task
1.8 · 6 Add a Run times page to the developer tools merged merged order only

Checks right before merging (read-only; if any fails, the merge waits):

  1. This PR doesn't change the .py pin (policyengine[models]==6.20.5).
  2. No Deploy Simulation API run on main is in progress or queued.
  3. The latest completed one succeeded, and its publish_stage12_v2_default job printed release_is_default=true in both beta and prod.
  4. No .py update PR is open.

For whoever merges the next .py pin change: please wait until this change's release has moved the production v2 default (its publish_stage12_v2_default job printed release_is_default=true in prod). Until then, a v2 app deployed before this change could still receive budget-window years carrying report_type, and it would refuse them.

The merge uses gh pr merge --admin --merge --match-head-commit <head>, on Anthony's instruction for this PR only. It skips only the required approving review, once every required check has passed. The repository rule sim.process.agents-never-bypass otherwise forbids --admin.

🤖 Generated with Claude Code

anth-volk and others added 5 commits December 4, 2026 01:50
Tests that fail before the change: API v2's coordinator request carries
report_type (single_year unless the simulation service names a budget
window's year budget_window_year, which later years copy), and the
coordinator's operation names the report's country, region, breakdown,
scope, simulation year and report type, with the app's .py version as its
service version and the Modal app's name, as API v1's run_simulation
records and the v2 workers' records do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
API v2's coordinator request (ReportExecutionInput) carries report_type,
as API v1's run_simulation requests do: the simulation service names a
budget window's first year budget_window_year, on a new window and on a
window re-run, and every later year copies it through year_calculation.
The field is left out of the request's JSON when single_year, so a v2
application deployed before it accepts every other report.

The coordinator's operation names the report's country, region,
breakdown (local_areas for a UK report on the local-area dataset), scope,
simulation year and report type, read from its own request under API v1's
attribute names, plus modal_app_name; its runtime carries the app's .py
version as service.version, as the v2 workers' do. A request that can't
be read names none of them and the call goes on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 fixes:

- report_run_calculation takes report_type as a required keyword, so each
  caller names single_year or budget_window_year; the two report-type
  constants are typed Final[ReportType].
- A coordinator test makes the local-area check raise and confirms the
  call still runs without a breakdown; the test reading a real operation
  record now covers breakdown too.
- The observability guide gets its own section on the coordinator's
  report fields: which calls lack them, how to select API v2 report runs
  (database_table = report_runs), the household scope, and how
  local_areas work differs from API v1's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 fixes in the observability guide's coordinator section:

- Select API v2 report runs by the operation name and
  database_table = report_runs, since household report runs name the
  same table.
- Deduplicated calls and preempted calls' retries write records with the
  same fields, so a run-time summary keeps one per database_row_id.
- A household scope appears only on failed calls; API v1's segmented
  national runs record simulation_year as a string; the run record's
  report_type differs from the report_type API v2 stores on a report.
- Later years' requests are copied from an earlier year's, here and in
  the contract's field comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3 fixes: API v2's reports row stores type as economy or
household; the release routes the constituency and local-authority
regions to the local-area dataset; nothing marks a deduplicated call's
record, so a run-time summary keeps the longest successful record of
each report run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review December 3, 2026 23:17
Since #1193 the reports row also stores budget_window as a report's type,
so the guide no longer lists its values; it only says the run record's
report_type is a different field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk merged commit 54d5e92 into main Dec 4, 2026
28 of 30 checks passed
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.

Record each API v2 report run's region, year, report type and .py version on its coordinator log record

1 participant