Repository navigation
Give the economy progress bars one shared model that keeps each run's start time and highest value - #1610
Merged
Conversation
Tests for a pure function that computes an economy run's bar from its cached start time, highest value and stage; for the strategy, query options and hooks that keep each run's first start time and highest value in the query cache; and for each budget-window year, bill and own year's bar using it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The existing pending-status test asserted that an economy run's progress was the synthetic timer's. With the shared model it is the run's cached highest value at a poll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A report's own year, its other budget-window years and bill reports now take their bar's value from one pure function in libs/calculations/runProgress.ts, on the same clock curve as UK local areas and state district runs: - runProgressAt: the clock since the run's first request, held inside its current stage, never below the highest value reached at a poll. - highestProgressAtPoll: what the strategy keeps in the query cache at each poll, counting the bar by the last poll's stage too, so a bar that moved between polls is never above the cached value. - economyRunStartedAt: a computing run keeps its first start time; a new run, or a retry after a failure, starts now. The strategy's straight-line estimate and, for economy runs only, the synthetic timer in useCalculationStatus are replaced by it. The metadata function forEconomyRun accepts now receives the cached status, so other years and bills keep their start time across polls and remounts and return it. The own year's run starts its clock from the report's saved request time (CalcStartConfig.startedAt). RunProgress no longer holds a run's cached highest value inside the current stage, and each other year gets its own bar, so leaving a year and returning never lowers it. pollRun computes its progress with the same function, unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…equest - A computing year keeps its first start time after the page is left for longer than React Query keeps unused queries by default (5 minutes). - forEconomyRun keeps its cache entry for the session. - A bar shown before the run's first request measures from that request once it is sent, as a bar shown later for the same run does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irst request - forEconomyRun sets gcTime: Infinity, as UK local areas and state district runs do, so a computing year's or bill's start time and highest progress outlast a visit to another page longer than React Query's default 5 minutes. - RunProgress measures from the run's start time once the clock reaches it, not only when it is earlier than the mount. A bill's bar that appears while its reform policy is still being created then agrees with a bar shown later for the same run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At Anthony's choice (option A after review round 2), a bar that appears before its run's first request keeps counting from when it appeared, as on main. The round 1 test that expected it to switch to the request time is replaced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reverts round 1's change to RunProgress's clock, at Anthony's choice (option A). A start time later than the bar's mount, such as a bill's first request sent after its reform policy is created, counts from the mount again, so the elapsed time never steps back. Known limit, bills only: a bar shown again for the same run is lower by the time spent before the request (about 2 points for 5 s in a 190 s state run). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The economy progress bars of a report's own year, its other budget-window years and bill reports now compute their value with one shared function. It uses the same clock curve (85% at the typical time, then easing toward 95%) as UK local areas and state district runs. Each run's query cache entry keeps the run's start time and the highest value its bar reached at a poll.
This is task 1.7 · 2 of the "Report runtimes" project. It is the app-side groundwork for the later task that moves the bars by the simulation API's measured stage durations. The function takes its duration estimate as a separate object (
{ expectedMs }), so that task can add the server's stage durations.What changes for the reader
mainit shows the stage's starting percent, 5%.mainall years shared one bar, so 2027 could show 2028's value.mainit showed 4%.maintheir clock restarted.How
app/src/libs/calculations/runProgress.ts:runProgressAt(state, now, estimate): the clock since the run's first request, held inside its current stage, and never below the highest value reached at a poll. For a given state it never decreases as time passes.highestProgressAtPoll(...): the value the strategy keeps at each poll. It also counts the bar at that moment by the previous poll's stage, so a bar that moved between polls is never above the cached value. The previous state counts only for the same run, meaning the same start time.economyRunStartedAt(cachedStatus): a computing run keeps its start time. A new run, or a retry after a failure, starts now.clockProgressandrunProgressValuemove here fromRunProgress.tsx, unchanged.SocietyWideCalcStrategy: its progress comes fromhighestProgressAtPolland the previous cached status, in place of the straight line capped at 95%.calculationQueries.forEconomyRun:gcTime: Infinity, as the UK local-area and state district queries already use, so a run's state outlasts a visit to another page.useReportYearEconomiesanduseReportYearEconomynow share one query builder, and both returnstartedAt;useBillEconomykeeps its start time in the cache instead of auseMemo, and returns it.useCalculationStatus: the synthetic timer runs for household calculations only. Economy runs return their cached progress and message.CalcStartConfig.startedAtcarries the report's saved request time intoCalcOrchestrator. A time ahead of the browser's clock starts now.RunProgress:runProgressAt, so a run's cached highest value is no longer limited to its current stage's range;key={year}and its start time;pollRun: it computes its progress withrunProgressAt, with the same results as before.Intended behaviour changes outside the three bars
SocietyWideReportOutput) reads the strategy's cached progress, so it now follows the clock curve: 85% at the typical time instead of 95% at 0.95 of it.Known limit
main, so its elapsed time never steps back. A bar shown again for the same run, after a tab switch, is lower by the time spent before the request: about 2 points for 5 seconds in a 190-second state run.Out of scope
useV2ReportYearEconomies,V2EconomyReportPage) is not touched. It can reuserunProgress.ts.Commits
d8a04d427Add failing tests for one shared economy progress model. The new function's tests, a page test for the other years' bars and the own year's start time, and updated strategy, query, hook,RunProgress, orchestrator and bill page tests.155cc9015Expect an economy run's cached progress from the status hook. One existing test asserted the economy synthetic timer's value.1b571532dGive the economy progress bars one shared model in the query cache. The change itself.7ab901928Add failing tests for review round 1: cache lifetime and late first request. From the first review round.9ad6786b2Keep economy runs in the cache for the session; measure from a late first request. The first part stays. The second part is reverted by500c21306.720ded267Expect a bar's elapsed time never to step back when its run starts late. Replaces the round 1 test for the reverted part.500c21306Count a late-starting run's bar from when it appeared, as on main. The revert.Each test was committed and run failing before the change that makes it pass. Two rounds of adversarial review ran on the diff. Round 1 found the 5-minute cache lifetime and a bill's late first request. Round 2 found no severe bugs; it confirmed the queued-at-24% case end to end and found the bill limit above.
Test plan
make typecheckmake lintapp/:bun run vitest -- src/tests/unit/libs/calculations/runProgress.test.tsbun run vitest -- src/tests/unit/pages/flagship/ReportYearProgress.test.tsxapp/, each run on its own:src/tests/unit/libs/calculations/strategies/SocietyWideCalcStrategy.test.tssrc/tests/unit/libs/queries/calculationQueries.test.tssrc/tests/unit/hooks/useReportYearEconomy.test.tsxsrc/tests/unit/hooks/useBillEconomy.test.tsxsrc/tests/unit/hooks/useCalculationStatus.test.tsxsrc/tests/unit/components/flagship/report/RunProgress.test.tsxsrc/tests/unit/libs/calculations/CalcOrchestrator.test.tssrc/tests/unit/pages/flagship/BillReport.test.tsxsrc/tests/unit/libs/calculations/polledRun.test.ts(import path only)src/tests/unit/hooks/useStateDistrictRuns.test.tsx(import path only)🤖 Generated with Claude Code