Skip to content

Deprecate region:"us"/"uk" as the national request spelling #638

Description

@anth-volk

Context

National macro requests are spelled two ways today:

  • Omit region — the sim API's own convention (contract tests, integration tests, docs examples).
  • region: "us" — what API v1 sends on every national US macro run (SimulationOptions.region is a required string in policyengine-api/policyengine_api/services/economy_service.py:79; the value is stored in a NOT NULL DB column on job records). v1 is the only production caller using this spelling.

The worker accepts both via the normalisation shim at simulation_runtime.py:212-218 (None/empty/"us"/"uk" → country), and as of #637 the segmented-national eligibility does too (is_plain_national_macro). Two spellings for the same semantics means every national-detection site must remember both — #637's review caught exactly this class of drift (eligibility initially treated region:"us" as regional, which would have excluded all v1 production traffic from segmentation).

Goal

One national spelling: omit region. region:"us"/"uk" becomes deprecated, then rejected.

Migration checklist

Phase 1 — v1 stops sending it (policyengine-api):

  • economy_service.py: make SimulationOptions.region optional; send no region for national runs (:79, _setup_sim_options :972-1006, _setup_region :1137-1149)
  • _classify_simulation_geography (:1254) currently detects national via region == country_id — needs the omitted-region case
  • reform_impact table: region VARCHAR(32) NOT NULL — decide sentinel (e.g. national) or schema change
  • Routes that 400 on missing region query param (economy_routes.py:52, :105-107)

Phase 2 — contract + budget window (policyengine-sim-api):

  • BudgetWindowBatchRequest.region is a required str (gateway_models.py:178) — national budget windows currently must send region:"us"; make it optional with omitted == national (golden + client regen)
  • Document in gateway_models.py that national == omit region (or use region_group)

Phase 3 — deprecation signal, then removal (policyengine-sim-api):

  • Emit a deprecation warning + telemetry attribute in the _normalise_region_code shim (simulation_runtime.py:212-218) when region in {"us","uk"}
  • Once telemetry shows zero region:"us" traffic: remove the shim, remove the region in ("", country) acceptance in segmented_national.is_plain_national_macro, and reject the spelling with a clear error

Interim state

Until Phase 1 lands, the sim API MUST keep treating region:"us" as national everywhere — it is the production national traffic. #637 aligned segmentation eligibility with the worker shim so both spellings behave identically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions