Skip to content

Release history backend: measure each published Microcosm data file on a pinned engine - #304

Draft
juaristi22 wants to merge 21 commits into
mainfrom
release-history-backend-224
Draft

juaristi22 wants to merge 21 commits into
mainfrom
release-history-backend-224

Conversation

@juaristi22

@juaristi22 juaristi22 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The first PR for #224, covering the backend only; the page is the next PR. For each country, it measures every
national data file the country's release repository publishes, as its releases.json lists the builds, on that
country's pinned reference engine, and stores the results in private Blob. A move between two releases is then
a property of the data, not the model.

How it works:

  • Spec-driven, with a fixed output vocabulary. A country is a folder with a spec (a baseline variables list
    and simple reform definitions), its official references and its own engine lockfile. No code branches on a
    country code.
  • Cheap by construction. One baseline simulation plus one per reform, on policyengine.py's lazy path, one
    alive at a time. Reform outputs come in levels (targets, budget, distribution, poverty); a
    targets-only reform computes only its target's dependency chain.
  • A point is one data file on one panel. Its id hashes the panel id and the file's sha256 only, so a file
    published under two build names is measured once, and a file replaced under one name is measured again.
  • The series comes from releases.json. A spec names release lines and, optionally, a start date
    (since). The series command reads the record, with the release writer's own reader
    (microcosm-emitter-interface), and each build's release manifest at one commit, and writes a series record
    per country. Publish times, current and withdrawn flags live there, never in a point, so a
    corrected publish time re-orders the timeline with no re-run.
  • Countries are independent. A panel id hashes the country, its engine pins, the producer version, the
    point format version and the spec's number-changing part, so bumping one country never re-runs another. Each
    country's panel id is pinned in a test.
  • Engine moves. Only runs of the default branch pin. A top-up there measures every file its panel lacks:
    the new builds on the served panel, or the whole series on a panel the page doesn't show yet (a country's
    first, or one after an engine, spec or producer change), at most 200 files a run. The page moves to the new
    panel once it is complete, with no manual backfill. A run from another ref measures into its own engine's
    panel and never touches the served page.
  • Failures are states. Only results and the refusals a file itself causes are stored. A failure a run
    causes leaves an attempt report instead: the file is retried, marked failed after three attempts (or at once
    when it is over the runner's budget), and retry starts it over.
  • Official references. Each baseline item and reform names its official figure, resolved from Chronicle
    into a committed lock and never typed by hand. The UK uses the OBR EFO of October 2026 and DWP's spring 2026
    tables. Its reforms are the seven tax changes HMRC's ready reckoner costs, at its steps; the reckoner isn't in
    Chronicle yet, so they carry citations.
  • Runner limits. A file within 20% of a runner limit (the measure step's time, the runner's memory, the
    file-size budget) is flagged on the run's page and in the manifest, and so is a plan within 20% of the
    200-file cap. Each point records the limits it ran under and the ones it came near, computed once by the
    producer.
  • Model compatibility in the timeline. Each timeline build carries whether the reference model is inside
    the range the build declares, and the file's columns the model drops, so the page can flag them.
  • A post-build option, off. release-history measure --build-dir measures a build folder before it is
    published, as a Microcosm post-build step would, with no Hugging Face read and no Blob token. Nothing calls
    it yet.
  • Checked formats and types. JSON Schemas for every document the two languages hand each other: the
    point, panel, series record, labels, timeline, attempt report and planned point. The producer's TypedDicts are
    compared with them key by key, and CI checks the producer with strict Pyright; the TypeScript types are
    generated from them. Each country's fixtures are made from its real spec on a synthetic world that draws the
    same numbers on every platform, and the TypeScript side builds each country's timeline fixture from them, so
    the two languages can't drift apart.
  • Weekly, off by default. A Sunday run tops up each country listed in the repository variable
    RELEASE_HISTORY_WEEKLY (unset: none). Backfills are manual until a country is switched on.

Preview

Release history preview draws the first timelines, from
the local trial of 9–10 November, through this PR's buildTimeline, as the page in PR 2 might show them: the UK's
11 cuts from 19 October to 7 November, and 9 US releases from July to September. UK values resting on fewer
than 3 survey households are withheld.

What's here

  • release_history/: the Python producer, on Python 3.13 (spec, series, references, engine identity, release
    resolution, measurement, disclosure, document types, local store, export, CLI), its schemas, and tests on fake
    and synthetic models.
  • release_history/countries/uk/: seven reckoner reforms for 2026-27, 33 baseline items, and the disclosure
    policy source_household_small_cells with a floor of 3 distinct survey households. Its series starts on
    19 October 2026.
  • release_history/countries/us/: a minimal trial spec for manual runs, with two federal reforms from
    Microcosm's US reform-validation registry at the targets level.
  • frontend/lib/microcosm/release-history-store.ts: the Blob layout, the per-country manifest with
    conditional writes, the plan and finalize rules, and the timeline builder. The next PR's routes reuse it.
  • frontend/scripts/release-history.ts: plan, upload, finalize, pull, timeline.
  • frontend/scripts/generate-release-history-types.ts: the TypeScript document types, generated from the
    schemas into frontend/lib/microcosm/release-history-documents.ts.
  • .github/workflows/release-history.yml: weekly top-ups and manual topup, backfill, release and retry
    runs.
  • A release-history CI job, and docs/release-history.md.

The workflow reads two repository secrets: HF_RELEASE_READ_TOKEN, the read-only token for the private release
repositories that the deploy workflow also reads, and RELEASE_HISTORY_BLOB_READ_WRITE_TOKEN, a read-write token
for the Blob store the dashboard reads, which has to be added before the first run. Logs carry ids, statuses,
counts and timings only, an unexpected error prints its class only, and nothing is stored as an Actions artifact
or cache. RELEASE_HISTORY_ENABLED=FALSE stops every run.

Testing

  • cd release_history && uv run pytest -q: 131 passed. ruff check, ruff format --check and pyright
    (strict on the producer) are clean.
  • release-history validate-spec passes for the UK on policyengine-uk 2.174.1 and for the US on
    policyengine-us 2.2.1, with no data.
  • cd frontend && bun test lib/microcosm/release-history-store.test.ts scripts/release-history.test.ts scripts/generate-release-history-types.test.ts: 34 passed. The whole frontend suite (624) passes, and
    bun run lint is clean.
  • A read-only release-history series against both live repositories lists 17 UK builds from 19 October
    (17 files) and 5 US builds (4 files: two builds share one).
  • Local trials of the measurement on 9 November, before this PR's storage changes (what is computed is
    unchanged):
    • UK, the 7 November national cut: the baseline and all seven reforms ok, in 11 minutes on a laptop,
      peaking at 7.8 GB;
    • US, the certified 15 September release: both reforms ok, about 3 minutes per simulation, peaking at
      7.0 GB.
  • Not yet run: the workflow itself, which needs to be on main for manual dispatch. Once merged, the steps are
    a UK dry run, one point on a runner, the UK backfill, and a US run.

Follow-ups

  • The page: the capability, routes and statistics, read from timeline.json, including which panel it opens
    after an engine move and how it shows withdrawn builds.
  • A Chronicle request for HMRC's ready reckoner, so the UK reform references gain values.
  • Webhook and policyengine-release triggers.
  • A Modal runner for files over the runner budget.
  • If the post-build option is switched on: a Microcosm hook that calls it, and a collector intake for its
    results.
  • More reforms, periods and household types.
  • "Why did it move" views over the stored provenance.

🤖 Generated with Claude Code

juaristi22 and others added 11 commits November 9, 2026 19:23
The Python producer for #224. It measures one published national Microcosm
release build on its country's pinned reference engine, on policyengine.py's
lazy path, with one baseline simulation plus one per reform. It writes one
immutable point in the store layout.

- countries/<code>/: a spec (the baseline variables list and simple reform
  definitions), official references with their lock resolved from Chronicle,
  and the country's own engine lockfile. A panel id hashes only that country's
  engine, spec and the producer version, so countries never move each other.
- Releases are re-read at their pinned commit. Only a default national
  release is measured, and its H5 is checked against the manifest's sha256.
- Disclosure runs before anything is written. The UK's floor is 3 distinct
  survey households, with complementary withholding inside each table; no
  support count is stored.
- The UK spec: the seven tax changes HMRC's ready reckoner costs, for
  2026-27. The US trial spec: two federal reforms from Microcosm's US
  reform-validation registry, targets-only, manual runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…imeline

The TypeScript half of #224's backend: everything that touches Blob or the
dashboard's release inventory.

- lib/microcosm/release-history-store.ts covers the layout, the conditional
  manifest writes, and the plan, finalize and timeline logic.
  - Points are immutable, panel.json is written once, and references.json
    and timeline.json are replaced.
  - Every manifest write is conditional on the version read, re-applied on a
    lost race, and never unconditional. A run touches only its own country.
  - A weekly top-up waits while a new panel awaits its manual backfill. A
    point without a stored measurement counts an attempt and fails after
    three. The panel becomes current once complete.
  - The timeline holds every stored number in release order. Each value
    carries its change from the nearest earlier release (withheld beside a
    withheld cell) and the output's official reference.
- scripts/release-history.ts adds plan, upload, finalize, pull and timeline.
  The series is what the release picker lists: the calibration-tree
  manifest's release entries, less builds that releases.json withdraws.

A fixture written by the Python producer keeps the two document shapes in
step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- release-history.yml runs one country per run.
  - plan validates the spec, names the pinned panel, publishes it with its
    references and plans the points.
  - measure handles one build per matrix job, six at a time.
  - finalize updates the manifest and rebuilds the timeline.
- A Monday schedule dispatches a top-up for each country whose spec says
  `weekly`. Backfills run only on a manual `backfill` dispatch.
- It uses the tree publisher's existing secrets. Logs carry ids, statuses and
  timings only; library output goes to a private file; nothing is stored as an
  Actions artifact or cache. RELEASE_HISTORY_ENABLED=FALSE stops it.
- CI gains a release-history job: the producer's tests and ruff, then each
  country's validate-spec on its own pinned engine, with no data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…isclosure

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he UK series at 19 Oct

The panel id hashed the whole spec, so listing a release in or out of the
series, changing the schedule or the runner limits, or renaming a reform gave
the country a new panel and left every stored point behind. The id now hashes
only the parts of a spec that can change a number (`measurement_definition`):
everything but the series, the schedule, the runner limits, and each reform's
label and source.

A `series.exclude` pattern is now matched against each build's release id as
well as its folder, in both languages, so a single build can be left out.

The UK series leaves out the 2 Oct and 14 Oct 2026 cuts. They number
households with 14-digit ids, which overflow policyengine-core's 32-bit
integers, so the disclosure check can't match households to their survey
records and refuses them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d export timelines

Microcosm publishes each build in its own folder since
PolicyEngine/microcosm#1534 and #1537. A build folder's release manifest names
its build in "build" as a string and keeps the build facts at the top level;
point provenance read "build" as an object and failed on every such release, so
the measure step stored nothing. Provenance now reads both layouts and records
the tag a moved build came from (`migrated_from`); the build manifest's build
name stands in for the attempt id.

The series listed the calibration-tree manifest's release entries by name. After
the move to build folders, that manifest holds each UK cut twice (its tag and
its build folder) plus the bare release folder. Where a repository has a
releases.json, the series now follows it, as the dashboard's release picker
does: each recorded build is read from its folder, dated by the record's
published_at, at the commit the tree manifest pins for it; a build with no tree
entry yet waits for a later run. A record that can't be read stops the plan
instead of falling back to the duplicated names. Repositories without a record
(the US) keep the name rule.

`release-history export` read snake_case keys from timeline.json, which the
TypeScript side writes in camelCase, so it failed on any real timeline. It now
reads the document as written and adds the change in percentage points and the
change status. tests/fixtures/timeline.json is the TypeScript side's output
(regenerate with UPDATE_FIXTURES=1) and the Python tests read it, so the two
can't drift apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… engine moves the served panel

Weekly top-ups were switched on by a `schedule` key in each country's spec, so
turning a country on or off took a pull request. The key is gone (a spec that
still has one is refused): the repository variable RELEASE_HISTORY_WEEKLY now
lists the countries whose top-ups run each Monday, as space- or
comma-separated codes, and runs none while unset. Every country with a folder
can be switched on the same way; both are off. The key was already outside the
spec digest, so no panel id changes.

Finishing a run always moved the country's pinned panel, and its served panel
once complete, to the panel just measured. A run dispatched from a ref that
pins another engine (to measure a release on that engine on request) would
have switched what the dashboard serves. `finalize` now moves them only with
`--pin`, which the workflow passes on the default branch alone; other runs fill
their own engine's panel. Every panel stays listed in the manifest with its
engine, which an engine selector on the page can read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n by engine rules

Implements the release-history decisions of 12 November for PR 1 of #224
(D1-D3, D7, D9-D11):

- A point is one data file on one panel: its id hashes the panel id and the
  file's sha256 only. One file under two build names is one point; a file
  replaced under one name is a new one.
- A point holds only facts that cannot change: the file (sha256, size), where
  it was fetched from and what that build declared, cells, disclosure, the
  environment with the engine lock digest, and the producer commit. Listing
  facts move to a series record per country (`release-history series`), read
  from releases.json and each build's release manifest at one commit of main.
- The panel id hashes the country, the engine pins, the producer version, the
  point format version and the spec digest. The spec digest leaves out the
  spec's format version, the release repository, the series rule, the runner
  limits, and display keys (label, source, note, description). Each document
  kind has its own format version. Panel ids and spec digests are pinned in
  tests.
- The series rule is release-line names plus an optional `since` date; regex
  patterns and `series.exclude` are refused. The plan no longer reads the
  dashboard's tree manifest.
- panel.json holds what the id hashes and the engine; labels and references
  are country files.
- Top-ups pin: they measure files no pinned engine holds and, after an engine
  move, the last build the previous engine measured. A country's first panel
  is pinned only by its backfill. Only pinning runs replace the country files
  and rebuild every panel's timeline. The plan also skips points already in
  the store, and caps a run at 200 files.
- The timeline follows the series record: a step only between neighbours, no
  step to or from a withdrawn build, no orphan point, and no reason on a
  withheld cell.
- Only results and refusals the file itself causes are stored; a failure the
  run causes writes nothing and exits 3. An unexpected error prints its class
  only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…once for the size budget

D4 of the 12 November release-history decisions (#224):

- A failure the run causes stores no point. The leg writes the file's attempt
  report (`<panel>/attempts/<digest>.json`): `interrupted` before opening the
  release, the download and each simulation, so a run killed mid-way still
  leaves one; `failed` with the stage and reason on a handled failure; removed
  once the point or a stored gap is written.
- Finalize keeps such a file as `retrying`, or `failed` after its last attempt
  or at once when it is over the runner's budget. The attempt count is the
  plan's, so finalizing one run twice charges nothing more; a report from
  another attempt is ignored; a cancelled run charges no leg that left no
  report. States: measured, gap, retrying, failed; never run is no entry.
- New `retry` mode (optionally one build) plans failed files from attempt 1.
- The measure job installs bun before measuring, gives the measure step a
  timeout below the job's, and uploads with `if: ${{ !cancelled() }}`; the
  upload sends reports first and carries on past a failed file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e per country

D8 of the 12 November release-history decisions (#224):

- JSON Schemas (draft 2020-12) for the point, the panel, the series record
  and the timeline in `release_history/schemas/`. Version 1's keys are all
  required and no other key is allowed; a key added later is declared, not
  required, so stored points stay valid and no format version moves. Maps
  copied from upstream manifests or keyed by reform ids stay open.
- A synthetic model world (`tests/synthetic.py`) answers any variable and
  parameter a spec names, with each variable's role taken from the spec, never
  from a country code. Each country's real spec is measured on it into
  `tests/fixtures/<country>/`: panel, series record (one file under two
  builds, a current, a withdrawn and a refused build), labels and points (a
  stored gap where the spec reads source ids). The UK's withholds small and
  complementary cells. Every value is synthetic; no real point is committed.
- The measure command and the fixtures share one step for disclosure and the
  stored document; the document writes explicit nulls (reform records, error
  records, the engine bundle, the model wheel digest).
- The TypeScript test builds each country's timeline fixture from them and
  the country's committed references; Python checks it against its schema.
  The old shared `zz` fixtures are gone. `jsonschema` is a dev dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ailures and formats

D12 of the 12 November release-history decisions (#224): the weekly cron is
`0 5 * * 0` (Sunday 05:00 UTC, the same time as before). The docs describe
the series rule (release lines plus `since`), what the panel id hashes and the
spec format rule, the point as one file on one panel with no listing fact,
the storage layout with the country files and attempt reports, which runs
pin, the timeline on the series axis, the failure states and `retry`, the
document formats and schemas, and local runs with the series record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
calibration-diagnostics Ready Ready Preview Nov 26, 2026 2:00pm UTC

Request Review

…mes next

`docs/release-history-roadmap.md` gives a short overview of how the release
history backend works (#224), then discussion points for the page, which is
the next pull request, and longer-term improvement points. Only the overview
is decided; each point is a start for a discussion. `docs/release-history.md`
links to it. The document holds no build result and no survey figure.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anth-volk

Copy link
Copy Markdown
Contributor

Thanks for this, María. I read through the backend and have a few thoughts, mostly about where the scoring runs and which change the page should show. None of it is a blocker, and I'm happy to talk it through.

1. Full re-runs grow with the history. The weekly runs are cheap (2–3 files). But every engine, spec or producer bump re-measures every file for that country, and the served panel waits for that backfill. At the workflow's estimate of ~25 minutes per UK file and 2–3 UK builds a week, a backfill a year from now is roughly 140 files: about 60 runner-hours, or 10 hours wall clock at 6 parallel jobs. Those jobs also count against the organization's limit on concurrent GitHub-hosted jobs, which everyone's CI shares.

2. One policyengine-uk version across every build may not give like-for-like numbers. Each UK build declares compatibility only with its own exact version (compatible_model_packages is policyengine-uk==<built-with version>). The 15 national builds use 11 different versions, from 2.100.0 to 2.177.7, so a 2.174.1 reference engine runs 13 of them outside their declared range. Most mismatches won't raise an error: policyengine-uk drops columns it doesn't define, and inputs a file lacks take their defaults. The points record reference_model_compatibility and unknown_columns, but timeline.json carries neither, so the page can't flag them.

3. The change users see includes the model change. Someone using build N runs it on build N's own engine, so the move they experience between builds is the data change and the model change together. The fixed engine isolates the data part, which helps explain a move, but it isn't the number users see. Could the page lead with the as-built change? Scoring each build on its declared engine has no compatibility problem, and an engine bump never makes it re-run.

4. Could the scoring be a Microcosm post-build step? US builds already score reforms after the build in reform_validation.json, including federal.cbo_rates_plus_1pt and federal.arpa_ctc_2021, though only 1 of the 4 published US builds has the file. UK builds score no reforms. The UK score_vs_reference.json already compares the new build with the previous current build in the new build's environment, on calibration targets. A UK step could do the same for reforms:

  • score the reforms on the build's own engine, which gives the as-built value;
  • score the previous build on that same engine, so the difference gives the data part with a one-version gap rather than dozens.

The results would go to the collector as submissions. That would also mean this repository's workflow doesn't need HF_TOKEN and BLOB_READ_WRITE_TOKEN, the calibration-tree publisher's secrets, which the collector work is removing. Your producer (spec, measurement, disclosure, references) looks like it could be that step with few changes.

5. Past builds can be filled in. All 15 UK national files are still on Hugging Face, and each build manifest records the policyengine-uk and policyengine-core versions it was built with, so each build can be scored on its own engine (11 environments for the UK). tools/probe_us_post_export.py already runs the US post-build steps on any written release file; a UK equivalent would cover the backfill. The 4 and 15 October builds would still need the 14-digit household id issue resolved for the small-cell check.

@anth-volk

Copy link
Copy Markdown
Contributor

A follow-up to my earlier comment: we're going to set aside what I said there about the policyengine-uk version. Please ignore point 2 (builds measured outside their declared version range), point 3 (leading with the as-built change), and the parts of points 4 and 5 about scoring each build on its own engine version.

One change I'd recommend instead: start the backfill automatically after a version change.

Here's what happens now after a PR changes a country's pinned version:

  • The weekly topup measures new builds only on the new version, plus one overlap build, into a result set the page doesn't show yet (planPanel, frontend/lib/microcosm/release-history-store.ts:592-606).
  • The page stays on the old version's set until the new set has every build (finalizeCountry, :776-779), and only a manual backfill measures the older builds on the new version.
  • So every build published between the version change and someone running the backfill shows on the page with no value. If nobody runs the backfill, that lasts indefinitely.

One way to do it: when a topup on the default branch runs on a set the page doesn't show yet, plan every file that set is missing, as backfill does. The first weekly run after a version change would then measure the whole series, and the page would switch to the new version once that set is complete. A spec change or a PRODUCER_VERSION bump creates a new set the same way, so it would get the same treatment.

…mits, and carry model compatibility

From Anthony's review of #304:

- A top-up on the default branch now measures every file its panel lacks, as
  a backfill does. On the served panel that is the new builds; on a panel the
  page doesn't show yet (a country's first, or one after an engine, spec or
  producer change) it is the whole series, so the page moves to the new panel
  once it is complete, with no manual backfill. The overlap-build rule goes.
  A single release or a retry still never pins a country's first panel.
- A run that comes within 20% of a runner limit is flagged: the measure
  step's time, the runner's memory and the file-size budget, now all in the
  spec's runner block (outside the panel id), and recorded on each point as
  the limits it ran under. The flag is a GitHub Actions warning on the run's
  page, a column in finalize's summary and `nearLimits` in the manifest. A
  plan of 160 files or more (80% of the cap) is flagged too.
- timeline.json carries, per build, whether the reference model is inside the
  range the build declares and the columns the model drops, so the page can
  flag them. The export gains both columns.
- `release-history measure --build-dir` measures a build folder before it is
  published, as a Microcosm post-build step would, with no Hugging Face read
  and no Blob token. Nothing calls it yet: the workflow keeps measuring
  published builds, and a collector intake is not built.

Docs, the roadmap, the schemas and both countries' fixtures follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juaristi22

Copy link
Copy Markdown
Collaborator Author

Thanks, Anthony. These are in 9798550:

  • Your recommendation: a top-up on the default branch now plans every file its panel lacks, as a backfill
    does. On the served panel that's the new builds; on a panel the page doesn't show yet (a country's first, or
    one after an engine, spec or producer change) it's the whole series, and the page switches once that panel
    is complete. The overlap-build rule is gone. Weekly runs stay off until RELEASE_HISTORY_WEEKLY names a
    country.
  • 1, cost: a run now flags any file within 20% of a runner limit (the measure step's 110 minutes, the
    runner's 16 GB, the spec's file-size budget) with a warning on the run page, a column in finalize's summary
    and nearLimits in the manifest. A plan of 160 files or more, 80% of the 200-file cap, is flagged too. Each
    point records the limits it ran under, and the limits sit in each spec's runner block.
  • 2, compatibility: we're keeping one reference engine per country, but timeline.json now carries each
    build's referenceModelCompatibility and unknownColumns, so the page can flag them.
  • 4, a post-build step: the producer side is built and switched off. release-history measure --build-dir measures a build folder before it's published, with no Hugging Face read and no Blob token.
    Nothing calls it yet; the Microcosm hook and a collector intake would be their own PRs if we turn it on.
  • 3 and 5: set aside for now.

@anth-volk

Copy link
Copy Markdown
Contributor

Thanks, María. 9798550 covers what we discussed. I also read through it for code quality. Overall it's carefully built, and the TypeScript reads like the rest of the dashboard. A few suggestions:

1. Enforce types in the Python. CI lints release_history with ruff but runs no type checker, so no type annotation is ever checked.

  • Add a type checker (mypy or pyright, in strict mode) to the release-history CI job.
  • Give the documents real types. Points, series records, attempt reports and timelines move through the producer as dict[str, Any], which appears 85 times. TypedDicts or dataclasses matching release_history/schemas/ would let the checker catch a wrong key.
  • Add a Protocol for the release source. measure --build-dir passes a LocalBuildFolder (cli.py:484) to functions annotated hub: HubClient (releases.py:304, releases.py:335, series.py:111, :132, :190, cli.py:368). It works because the two classes happen to share method names. A Protocol both satisfy would make that a checked contract, the way SimulationView and Backend already do in simulate.py.

2. Use the existing releases.json reader. series.parse_record (series.py:56) re-implements the release writer's checks. That makes it a third copy of the same rules:

  • the writer's own module, microcosm_emitter_interface.releases. ReleasesRecord.parse(content: bytes) is in microcosm-emitter-interface 0.16.0 on PyPI, which has no dependencies.
  • the dashboard's reader, parseReleasesRecordBytes and recordedBuilds from @policyengine/calibration-tree/release-record, which ports that module to TypeScript.

Since the producer is Python, importing ReleasesRecord.parse is the direct route, and the series-specific check on published_at can stay on top of it. Its requires-python is >=3.13, which the country projects already pin, so release_history/pyproject.toml's >=3.11 would rise to match.

3. Blob code in this repository is fine. The release-history Blob store module and the script that writes to it can stay here, as an exception to the rule that Blob I/O and publishers live in microcosm-collector. Could you add that exception to the AI guidance, so agents don't flag it or move it? The rule sits in AGENTS.md:11 and CLAUDE.md:6.

4. Smaller things:

  • Long functions. _reform_cells (measure.py:288, 167 lines) runs four separate output sections (targets, budget, distribution, poverty) and would split into one function per section. cmd_measure (cli.py:466, 163 lines), parse_spec (spec.py:322, 127 lines) and buildTimeline (release-history-store.ts:934, about 170 lines) would also read more easily in smaller pieces.
  • Names. Please spell out short names such as hw and pw (household and person weights, measure.py:293, :362), loop variables such as for v, for r, for d and for p, and arrow parameters such as (p) => and (s) =>.
  • Rules written in both languages. The point id is computed in document.py:31 and again in release-history.ts:129. The near-limit share is computed in document.py:83-101 and again in release-history-store.ts:642-661. The 0.8 threshold is set in four places. Each rule could be computed once, with the other side reading the result, or at least pinned by one shared test case.
  • TypeScript copies of the Python documents. The interfaces at release-history-store.ts:448, :614 and :666 are written by hand. Generating them from the JSON schemas would keep them from drifting.
  • Ruff settings. release_history/pyproject.toml targets Python 3.11 and doesn't enable the naming (N) or whitespace (W) rules. telemetry-service uses both.
  • CI. tests/test_country_fixtures.py::test_each_country_s_fixtures_are_what_the_producer_writes still fails for both [uk] and [us], so the ruff and spec-validation steps after it never run.

juaristi22 and others added 7 commits November 26, 2026 11:23
… rounds alike

The release-history CI job failed test_each_country_s_fixtures_are_what_the_producer_writes
for uk and us: 112 cell values in the four point fixtures differed from CI's in
their last one or two digits. The synthetic world drew weights with numpy's
`uniform` and amounts with its `gamma`. Both compute `a + b * x` inside one C
expression, which numpy's arm64 build rounds once (a fused multiply-add) and its
x86_64 build rounds twice, so about one draw in eight differed in the last bit
between a Mac and CI's Linux. Regenerating on a Mac with two-rounding draws gives
exactly CI's 112 values, so the producer itself computes alike on both.

The world now draws only numpy's `random` and `integers` (`_Draws`), which are
the same everywhere, and builds weights and amounts from them in separate numpy
operations. The fixtures are regenerated (pytest, bun, pytest); only synthetic
values change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…planned points and labels schemas

The producer and the TypeScript finalize each computed how close a run came to
its runner limits, with the 0.8 threshold repeated as a fallback on both sides.
The producer now computes it once, when it writes the point, and stores it as
`runtime.near_limits` (each limit at or over `limits.warn_at`, with the share
used); `measure` prints its warnings from there, and finalize will read it.

The attempt report, the planned point and the labels cross between the two
languages but had no schema, so the TypeScript copies were written by hand (the
attempt report's had already lost its `producer` block). They now have schemas
in `release_history/schemas/`, and the tests hold every attempt report the
measure tests write, a planned point and each country's labels to them.

`Point.from_json` read a planned point with a null commit as the commit "None";
it now refuses it. One fixture point per country runs 5,400 of its 6,600
seconds, so the fixtures carry a near-limit run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`series.parse_record` re-implemented the release writer's checks on
releases.json, a third copy of rules that live in microcosm-emitter's
`microcosm_emitter_interface.releases` (and in the dashboard's TypeScript port).
The series now reads the record with `ReleasesRecord.parse`, which checks the
exact shape, safe names, the 4 MB cap and the `current` and `default` rules;
the series' own rule, an ISO 8601 publish time on every build, stays on top.

microcosm-emitter-interface needs Python 3.13, which both country projects
already pin, so the shared producer's requires-python rises from 3.11 to 3.13
(its lock drops the numpy that only 3.11 needed; the country locks only gain
the package). Ruff now targets py313 and adds the naming (N) and whitespace (W)
rules; the four exceptions without an Error suffix are renamed
(EngineMismatchError, ImmutableConflictError, ReferencesError,
ReleaseRefusedError).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `_reform_cells` (167 lines) runs one function per output section:
  `_target_cells`, `_budget_cells`, `_distribution_cells` and `_poverty_cells`,
  sharing a `ReformPeriod` (the reform's simulation in one period beside its
  baseline). `measure` splits into the baseline simulation, the reform
  definitions and one reform's simulation.
- `cmd_measure` (163 lines) sets up a `_MeasureRun` and calls one step per job:
  open the planned file, fetch it, measure it, store a gap or a point. A step
  that fails because of the run raises `_AttemptFailedError`, which the command
  turns into the attempt report and the exit code.
- `parse_spec` (127 lines) reads each section in its own function: the series
  rule, periods, groups, output levels, item checks, disclosure and runner
  limits, in the same order, so each error still comes from the same check.
- Short names are spelled out across the package and its tests (`hw` and `pw`
  are household and person weights; loop and lambda variables say what they
  hold). The fixtures and both spec digests are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…from its schema

CI linted `release_history` with ruff but checked no annotation. The release-history
job now runs Pyright (1.1.414, the emitter's pinned version): strict on the producer,
the standard mode on its tests. It reports no error.

- Documents: `release_history/documents.py` types every document as a TypedDict
  with its schema's keys and nesting (the point, panel, series record, labels,
  attempt report, planned point and timeline), and `tests/test_documents.py`
  compares each with its schema at every level, so a key added to one and not
  the other fails. The producer builds and reads documents through them in
  place of `dict[str, Any]`.
- Release sources: `ReleaseSource` is the Protocol `HubClient`, `LocalBuildFolder`
  and the tests' `FakeHub` satisfy, so `measure --build-dir` passing a build folder
  is a checked contract. A Hub read without a commit is refused rather than
  reading the branch's head. `SimulationView` gains the engine `bundle` measure
  already read.
- Untyped JSON (manifests, records, spec sections) is read through
  `json_object`/`json_list`, and spec sections that must be mappings say so.
- What the checker found: optional arrays and spec variables a reform output
  needs are checked before use; `Measurement` has no unused baseline status;
  reform records carry every key from the start. The fixtures, spec digests and
  every test are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mits from each point, and split buildTimeline

- Generated types: `scripts/generate-release-history-types.ts` compiles every
  schema in `release_history/schemas/` into `lib/microcosm/release-history-documents.ts`
  with json-schema-to-typescript (16.0.0, pinned exactly), and a test fails while
  the committed file is stale. The point, panel, series record, timeline, attempt
  report, planned point and labels are now those types, so the timeline writer is
  checked against timeline.schema.json at compile time; the hand-written copies
  (the attempt report's had lost its `producer` block) are gone.
- One computation per rule: finalize reads each point's `runtime.near_limits`,
  which the producer computes once, instead of recomputing the shares, and the
  0.8 fallback is gone. Tests on both countries' fixtures pin the rest: every
  point's id is `measurementIdFor(panel_id, file.sha256)`, every point's
  `runtime.limits.warn_at` equals the plan cap's `WARN_AT`, and finalizing the
  fixtures flags exactly the run that used 82% of its time limit.
- `buildTimeline` joins five helpers (the builds and their states, the rows, the
  values and their steps, the step itself, the official figure), and short names
  are spelled out. Both timeline fixtures are byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ter here

The guidance says Blob I/O and publishers live only in microcosm-collector's
calibration tree package. The release history's Blob store module and the script
that writes to it are the agreed exception, so AGENTS.md and CLAUDE.md now say to
leave them in this repository and not flag them as copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juaristi22

Copy link
Copy Markdown
Collaborator Author

Thanks, Anthony. These are all in, in seven commits on top of 9798550 (40ae2e3 to deedc38):

  • CI. The fixture test failed because the synthetic world drew its weights with numpy's uniform and its
    amounts with gamma. Both compute a + b * x inside one C expression, which numpy's arm64 build rounds once
    (a fused multiply-add) and its x86_64 build rounds twice, so about one draw in eight differed in its last bit
    between a Mac and CI. Regenerating the fixtures on a Mac with two-rounding draws gives exactly CI's values, so
    the producer itself computes the same on both. The synthetic world now draws only random and integers,
    which are the same everywhere (40ae2e3). The ruff and spec-validation steps pass locally too.
  • 1, types. The release-history job now runs Pyright 1.1.414, the version microcosm-emitter pins: strict on
    the producer and standard on its tests, with no errors (e04f64e).
    • release_history/documents.py types every document as a TypedDict, and tests/test_documents.py compares
      each with its schema at every level.
    • ReleaseSource is the Protocol that HubClient, LocalBuildFolder and the tests' FakeHub satisfy.
      SimulationView gained the bundle that measure was reading through getattr.
    • The checker found a few real gaps, now fixed. Optional baseline arrays and spec variables were used without
      a check. A planned point with a null commit was read as the commit "None". A Hub read now refuses a
      missing commit rather than reading the branch head.
  • 2, releases.json. The series reads it with ReleasesRecord.parse from microcosm-emitter-interface (0.17.0
    locked), keeping the ISO 8601 published_at check on top. requires-python is now >=3.13 (5673851). A
    read-only listing of both live repositories still works.
  • 3, guidance. AGENTS.md and CLAUDE.md now name the release history's Blob store module and its script
    as the exception (deedc38).
  • 4.
    • Long functions: _reform_cells is one function per section. measure, cmd_measure and parse_spec are
      split into steps, and buildTimeline joins five helpers (c4d0da4, f96057d).
    • Names: short names are spelled out in the producer, the TypeScript and the tests.
    • Rules in both languages: the producer computes each point's near-limit shares once and stores them as
      runtime.near_limits, and finalize reads them (b6213d1, f96057d). The point id and the 0.8 threshold keep
      one definition per language, pinned by tests on both countries' fixtures. Every fixture point's id equals
      measurementIdFor(panel_id, file.sha256), and every point's warn_at equals the plan cap's WARN_AT.
    • TypeScript copies: the document types are generated from the schemas with json-schema-to-typescript, and a
      test fails while the generated file is stale (f96057d). The attempt report, planned point and labels got
      schemas for this; the hand-written attempt report had already lost its producer block.
    • Ruff: it now targets Python 3.13 and adds the N and W rules, and the four exception classes without an
      Error suffix are renamed (5673851).

One type stays hand-written: the references lock's. Its entries take different keys by status (resolved,
citation, none), so a schema for it is a change of its own.

…ith a secret of its own

Main retired the dashboard's GitHub Actions tree publisher: the collector
builds and stores calibration trees, and the publisher's repository secrets
HF_TOKEN and BLOB_READ_WRITE_TOKEN are to be deleted. Main's guard test
(test_no_workflow_reads_the_former_tree_publisher_settings) fails any
workflow that still reads them, which failed the hosted Python job on this
PR's merge with main, and the release history's runs would have read empty
tokens once they were deleted.

The workflow now reads HF_RELEASE_READ_TOKEN, the fine-grained read-only
token for the private release repositories that the deploy workflow also
reads (the US release repository is public), and
RELEASE_HISTORY_BLOB_READ_WRITE_TOKEN, a read-write token for the Blob store
the dashboard reads, which has to be added before the first run. The steps
still see them as HF_TOKEN and BLOB_READ_WRITE_TOKEN, the names the producer
and @vercel/blob read. The workflow header and docs/release-history.md say
so. Main's workflow tests pass with this file (26 passed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 319646c2 Deployed Nov 26, 2026 by vercel[bot]
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.

2 participants