Skip to content

v3 run bar: hold the time estimate inside the API's reported stage - #1285

Merged
PavelMakarchuk merged 1 commit into
mainfrom
feat/v3-run-progress-from-api
Oct 15, 2026
Merged

PavelMakarchuk merged 1 commit into
mainfrom
feat/v3-run-progress-from-api

Conversation

@PavelMakarchuk

Copy link
Copy Markdown
Contributor

The v3 report bar divides elapsed time by a typical duration. PolicyEngine/policyengine-sim-api#781 adds the run's real stage to the job status, and PolicyEngine/policyengine-api#3916 relays it on the economy response (stage, progress, progress_max, segments). This PR uses those fields in the v3 bar. Until they deploy, nothing changes.

Behaviour

  • Stage range: the bar keeps its time estimate, but holds it between progress (where the current stage starts) and progress_max (just before the next stage). A run in reform cannot show less than 67% or more than 96%.
  • Never backwards: RunProgress keeps the highest value shown. While a run is queued the API cannot know its path, so the next stage's range can start lower.
  • Caption: the line under the title names the stage ("Waiting for a worker", "Loading the data", "Running current law", "Running the reform", "Running the regions, 19 of 20 done", "Calculating the results"). A queue position still takes precedence. An unknown stage gets no line.
  • Duration: both v3 pages now use getDurationForRegion, the follow-up from Estimate society-wide run time by region #1257.

Why a time estimate inside the stage, not the API's progress alone: a backtest on the 6–13 October production timings gave the stage-only bar 10–32 points of mean error when one stage is long, and the time estimate held inside the stage 3–15.

Changes

  • SocietyWideCalculationResponse: optional stage fields.
  • SocietyWideCalcStrategy: passes them on as CalcStatus.runStage (stage, floor, max, segments) for opted-in v3 runs only (estimateByRegion). Legacy v2 statuses are unchanged.
  • useCalculationStatus and useBillEconomy: expose runStage.
  • RunProgress: runStage prop, runProgressValue, runStageCaption, high-water mark.
  • Report.page and BillReport.page: pass runStage; region duration estimate.

Checks

  • New tests: the value inside and outside a stage range, captions (segments, unknown stage), the bar not moving backwards, queue detail taking precedence, and the strategy passing runStage only for v3 runs with stage fields.
  • bun run vitest: 4,930 passed, 10 skipped. bun run typecheck and bun run prettier: pass.
  • bun run lint: eslint passes; stylelint reports one existing error in src/app.css, which this PR does not touch.

Merge order

Safe to merge before the API PRs: without the stage fields the bar behaves as it does today.

🤖 Generated with Claude Code

When the economy API reports a run's stage (policyengine-sim-api#781,
relayed by policyengine-api#3916), the v3 bar holds its time estimate
between progress (where the stage starts) and progress_max (just before
the next one), names the stage under the title, and never moves
backwards. Without the fields, nothing changes.

The strategy passes the fields on as CalcStatus.runStage for opted-in v3
runs only (estimateByRegion); legacy v2 statuses are unchanged. Both v3
report pages now use the region duration estimate.

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

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
policyengine-calculator-next Ready Ready Preview Oct 15, 2026 1:57pm UTC
policyengine-website Ready Ready Preview Oct 15, 2026 1:57pm UTC

Request Review

@PavelMakarchuk
PavelMakarchuk merged commit 8e44602 into main Oct 15, 2026
12 checks passed
anth-volk added a commit that referenced this pull request Oct 15, 2026
…audit and report re-runs

Brought over from main: the v3 audit fixes (#1273, #1274, #1277, #1278,
#1280, #1281, #1283, #1284, #1285), run progress from the API, a report
that opens from its stored output and records a failed run, a wait for
the reform policy, the report year switcher and All years view (#1292),
dated edits in the adjust panel (#1294), each country's own draft, and
Your reforms' read-only reform detail with a parameters table, "View
results", "Re-run" and the delete prompt (#1288), with the other merged
fixes (#1289, #1290, #1293, #1295, #1296).

How the conflicts were resolved:

- Report page: a link is still a saved report's ID, read through the
  credential-free shared-report route, with the v1 report's number only
  without accounts. The v1 report it names (the shared row's
  legacy_report_id) gets main's run lifecycle: stored output, recorded
  failures, the household guard, the wait for the reform policy (for any
  link that resolved), the unknown-baseline state and the year switcher.
- Reforms page and ReformReports: main's read-only detail, parameters
  table, delete prompt, View results and Re-run, on this session's stores
  and session-scoped query keys. "View results", "Open" and "View full
  impact report" go to reportLink(report), never the v1 report's number.
  The detail keeps this branch's guards: a reform whose changes did not
  load cannot run and says so, a reform that changes nothing cannot run,
  and the run sends what Build would. A record without a year reads it
  from the API's record.
- Build's run bar: still "Save and run", which saves first and runs
  nothing when the save fails; it now saves only the values that differ
  from current law, leaves a reused reform (and its name) as it is, and
  names a budget window's years. A new reform has nothing to save when
  nothing differs.
- Adjust panel: main's dated edits, budget window and unknown-baseline
  guard on this session's reform store; recompute still waits until a
  value differs from current law.
- draftReform: loadProvisionsIntoDraft takes both the saved reform it
  edits and main's window and source.
- Tests: main's run-hook tests sit beside this branch's store tests; the
  run bar test that ran a report after a failed save is dropped, as a
  failed save runs nothing here.

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

This branch was successfully deployed

2 active deployments
Preview – policyengine-calculator-next — b8f47d3c Deployed Oct 15, 2026 by vercel[bot]
Preview – policyengine-website — b8f47d3c Deployed Oct 15, 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.

1 participant