Repository navigation
Conversation
The UK model and data cover 2024 to 2032, but the Build page and the report's adjust panel offer budget windows of 1, 3, 5 or 10 years from the report year, so a ten-year UK window from 2026 asks for 2033 to 2035. Those years fail, and opening one shows "Society-wide calculation failed (502):" followed by the Public API's raw JSON response. These tests describe the intended behaviour and fail on main: - the report adjust panel and the Build page offer no window that ends after the last year in the country metadata's economy_options.time_period, and a longer window is shortened to end on that year; - a report run asks for no year after that last year; - a 400 with the DATASET_YEAR_UNAVAILABLE error code is described with the Public API's message as it came, without offering a retry; - a failed window year shows a readable message, not the raw response. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Budget windows now end by the last year in the country metadata's
economy_options.time_period, which the app already loads from the Public
API's /{country}/metadata endpoint for every calculator page:
- getLastSupportedYear (metadataUtils) reads that last year; it is null
until the metadata loads, and then nothing is shortened.
- windowSizeWithin and windowSizeChoices (libs/flagship/supportedYears)
shorten a window to end on that year, never below the start year.
- The report's adjust panel and the Build page's years picker offer only
the shortened windows (from 2026 with 2032 the last UK year: 1, 3, 5
and 7 years), and run what they show. A draft keeps the length chosen.
- useRunFlagshipReport shortens any window it is asked to run, so a
re-run of an older ten-year report stays within the covered years too.
The US metadata lists 2022 to 2035, so US windows from 2026 are
unchanged; a US window starting later now also ends on 2035.
A failed window year now shows describeCalculationError's text instead
of the raw "Society-wide calculation failed (502): {...}" response, with
a retry only when one can help. A 400 with the DATASET_YEAR_UNAVAILABLE
code is described with the Public API's message as it came and is not
retryable; before, its _UNAVAILABLE suffix made it read as a temporary
server fault.
The existing Build page budget window test seeded US years 2025 to 2027,
which now shortens its ten-year window; it seeds the US metadata's real
last year, 2035, and its assertions are unchanged.
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.
Fixes #1452
Summary
UK budget windows ran to 2035, but the UK model and data cover 2024 to 2032, so the years after 2032 failed and showed the Public API's raw JSON response. This PR keeps every window within the years the country metadata lists, and shows a failed year's error as readable text. It is the app part of a change that also touches the simulation service and the Public API, and it works whether or not those changes are deployed.
Window lengths follow the metadata's years
getLastSupportedYear(libs/metadataUtils.ts) reads the latest year ineconomy_options.time_period. The app already loads that list from the Public API's/{country}/metadataendpoint for every calculator page (MetadataBootstrapincalculator-app). Until the metadata loads it isnull, and nothing is shortened.windowSizeWithinandwindowSizeChoices(newlibs/flagship/supportedYears.ts) shorten a window so it ends on that year, never below one year.useRunFlagshipReportshortens any window it runs, so re-running an older ten-year report from Your reforms also stays within the covered years. That covers the per-year requests and the budget window request it starts.UK today and after the Public API change: the Public API's UK metadata lists 2024 to 2030 today, so UK windows end on 2030 until the Public API change (which lists 2024 to 2032) is deployed. After that, they end on 2032. No app change is needed when it deploys.
US: the US metadata lists 2022 to 2035, so windows from 2026, including ten years, are unchanged. A US window that starts later, which the Build page's year picker allows, now ends on 2035 instead of running past it.
Readable error for a failed year
describeCalculationErrorinstead of showing the raw "Society-wide calculation failed (…): {…}" response. Try again shows only when a retry can help.describeCalculationErrorhandles the error codeDATASET_YEAR_UNAVAILABLEfirst. It returns the Public API'smessageexactly as sent, with the title "The model does not cover this year", and does not offer a retry. Before this PR, the code's_UNAVAILABLEsuffix matched the check for temporarily unavailable servers, so the error read as "The API could not run this right now" and offered a retry. The match is on the code, not the message text.Tests (red, then green)
mainbecause of the behaviour being fixed. In those failures the adjust panel and the years picker offer "2026–2035 · 10 years" and a 10-year run, the year error showsSociety-wide calculation failed (400): {"status":"error",…}with Try again, anddescribeCalculationErrorreturns retryable "servers were not ready" text forDATASET_YEAR_UNAVAILABLE.Checks run locally on Node 26.10.0:
make lint: passesmake typecheck: passes (app, website, calculator)bun run prettierinapp/: passesmake test: passes. The app suite went from 5933 passed and 10 skipped in 459 files onmainto 5958 passed and 10 skipped in 461 files. The website suite has 483 passed in 53 files.🤖 Generated with Claude Code