Repository navigation
Add policyengine-api-access and stop sending browser code to the Public API - #116
Conversation
Adds tests/test_api_access_skill.py for a new policyengine-api-access skill. They fail until the skill exists: they check its frontmatter, its place in the five bundles that build dashboards or call the Public API and in the catalog, that the wrapper build ships it, and that it names the dashboard API's four operations, @policyengine/api-client's exports, the server credential headers, tenants and variables, the refusal bodies, and a row for 401, 403, 429 and 503. Browser-language examples may not name a Public API host, and no credential may sit in a NEXT_PUBLIC_ or VITE_ variable. The token template's tests check that one token serves many requests and is shared between instances through the shared store, is replaced five minutes before it expires, that a refused request is retried once with a new token, and that redirects are never followed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and servers The Public API is becoming callable only by PolicyEngine's own servers. The new skill tells dashboard developers and agents how to reach it: - the rules: browser code never calls api.policyengine.org or the Public API's Cloud Run addresses, and no Public API credential or address goes in a NEXT_PUBLIC_ or VITE_ variable; - from pages: www.policyengine.org's four dashboard operations through @policyengine/api-client, with their request and answer shapes, polling, the origins the dashboard API accepts and its rate limits, all taken from policyengine-app-v2's merged website routes, forwarding package and client; - from servers: an Auth0 client-credentials token from the Public API's own tenant in Authorization, one client per caller, cached across instances, and how a client gets on the Public API's allow list before it sends a token; - local development and previews, asking for a new dashboard operation, and a table of the dashboard API's and the Public API's errors. templates/public_api_token.py is a copyable Python token cache for Modal backends, Cloud Run services and scripts: it shares one token between instances, replaces it five minutes before it expires, retries a 401 once with a new token, and never follows redirects. The skill is in the analysis-tools, api-development, app-development, complete and dashboard-builder bundles and the catalog; the plugin version moves to 4.2.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… API Adds tests/test_public_api_browser_guidance.py. It fails until the guidance is updated: TypeScript and JavaScript examples in skills/, targets/ and docs/ may not name a Public API host (api.policyengine.org or its Cloud Run addresses; the household API and the v2 alpha hosts are not matched), no NEXT_PUBLIC_ or VITE_ variable may be set to one or named like a credential, the skills, agents and commands that guide dashboard and app work must point to policyengine-api-access, the policyengine-api skill must list /health and /v2/openapi.json instead of the removed /specification and liveness and readiness checks, and the tools skill's Pattern B must use @policyengine/api-client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…blic API The Public API is becoming callable only by PolicyEngine's servers, so the catalog stops telling browser code to call api.policyengine.org: - policyengine-api says who may call v1 (servers with their own credential), that pages use the dashboard API, and lists /health and /v2/openapi.json instead of the removed /specification and liveness and readiness checks; - policyengine-tools' Pattern B is the dashboard API through @policyengine/api-client, and a Pattern C backend that calls the Public API gets its own client and cached token; - policyengine-app says the calculator's direct browser calls are moving to app.policyengine.org's own allow-listed route, and new code goes through it; - backend-builder and new-tool build Pattern B on @policyengine/api-client; the dashboard planner, scaffold and integrator load policyengine-api-access and describe the pattern by what the dashboard API offers; - the policyengine skill, the app-v2 Codex routing and docs/when-to-use.md point to policyengine-api-access; the guide's catalog counts are current. The data_pattern value policyengine-api is kept, so existing plan.yaml files still validate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Vercel firewall rate limits on www.policyengine.org are live: over a limit the firewall answers 429 itself, as text/plain "Too Many Requests", with no Retry-After and no CORS headers. The new test fails until the skill says so, names the client's 60-second wait for that case, and gives the firewall and the Public API's load balancer a 429 row each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rate limits on www.policyengine.org are live. The skill now says they are counted per IP address in fixed 60-second windows, per Vercel region, and shared by everyone behind one address; that the firewall answers 429 itself, as text/plain "Too Many Requests", with no Retry-After and no CORS headers, so a page on another origin such as localhost sees a network failure; and that requests are accepted again when the window ends. compareEconomy's polling text covers both client versions: one that exports DEFAULT_RATE_LIMIT_WAIT_MILLISECONDS waits 60 seconds after such a 429, and an earlier one waits one interval. The errors table gives the firewall and the Public API's load balancer a 429 row each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/pipeline/test_when_to_use_guide.py reads skill IDs from the committed dashboard/src/data/manifest.json, so the stacked guidance PR, whose guide names the new skill, failed in CI. This test fails until the manifest is rebuilt with the skill and its five bundles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Regenerated with `uv run python scripts/build_manifest.py`. Besides the new skill, its bundle entries and edges, and the bundles' 4.2.0 version, the rebuild also picks up what earlier merges left unbuilt: the policyengine-data skill's description and target repositories from #108. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…i-browser-guidance Brings in the rebuilt dashboard manifest, which the when-to-use guide test reads, and the skill's description of the firewall's 429. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s-check Brings in the rebuilt dashboard manifest, which the when-to-use guide test reads, and the skill's description of the firewall's 429. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A 401 from the Public API is raised without requesting another token, on every call: a new token would be refused too, and each one counts against the tenant's monthly machine-to-machine allowance. - A redirected token request becomes PublicApiTokenError and stores nothing, and the provider uses the no-redirect opener by default. - The polling text names RATE_LIMIT_WAIT_MILLISECONDS, as merged in PolicyEngine/policyengine-app-v2#1543, and no longer says a 429 counts towards the gateway retries. - The errors table has a 401 row for the server's own token and one for a forwarded user token (error="invalid_token"), and neither says to retry with a new token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The token template no longer answers a 401 with a new token. A 401 means the client is not on the allow list in that environment, or its tenant or audience is wrong, so each new token was refused too and used up the tenant's monthly machine-to-machine allowance, once per call per instance. It now raises the 401, as app-v2's forwarder does, and the unused forget() is gone. The shared store's type is a Protocol with get and item assignment, which modal.Dict and dict both satisfy. - The polling text follows the merged client (app-v2#1543, which the first npm publish includes): RATE_LIMIT_WAIT_MILLISECONDS, 429s that never end polling, the fourth gateway failure since the last answer, and polling stopping with status null on another origin. - The errors table has a 401 row for the server's own token and one for a forwarded user token (WWW-Authenticate: Bearer error="invalid_token"), and the 502 row adds Auth0 refusing the token request and a policies answer with no ID. - Smaller corrections: only the comparison route checks query parameters; the Public API's 401 and 503 bodies have no result field; Cloud Run with a few long-lived instances can keep the token in memory; the Vercel Runtime Cache snippet treats a miss as null or undefined and never sets a zero or negative ttl. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ents - The guard's self-test now includes forms it missed: Cloud Run's per-project addresses, ~~~ and four-backtick fences, html, vue, svelte and cjs blocks, a TypeScript block nested in a Markdown block, JSON keys, a || fallback in inline code, and public-prefix names tied to the Public API's client or key. It also includes names it must accept: a browser's own Auth0 sign-in settings, a Mapbox token, and a TypeScript block marked as server code. - The dashboard scaffold must load policyengine-api-access. - The tools skill's Pattern C and /new-tool's advice must not send a parameter reform's economy-wide comparison to a custom Modal backend, since the dashboard API offers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The guard matches Cloud Run's per-project addresses; ``` and ~~~ fences of any length, closed by the same fence; html, vue, svelte, cjs and astro blocks; examples nested in Markdown blocks; JSON keys and || fallbacks; and public-prefix names that hold a secret or are named for the Public API's address or server client. It no longer flags a browser's own Auth0 sign-in settings or other services' public tokens, and a block marked <!-- server-code --> may name the Public API. Code files in the catalog are checked too. - The tools skill's Pattern C and /new-tool no longer send a parameter reform's economy-wide comparison to a custom Modal backend, which the dashboard API offers; they name structural reforms and microsimulation output beyond that comparison. - The dashboard scaffold loads policyengine-api-access. - backend-builder: the household type fits US and UK entities, the comment says when a dashboard's own *.vercel.app host is allowed, and the tests mock the package, since the client is built when the module loads. The integrator says what the policyengine-api pattern passes and gets back. - The app skill says the route keeps the Public API's paths under /api/policyengine. - dashboard/src/data/manifest.json is rebuilt for the changed skills, agents and command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The token template's Modal wiring adds its module to the image, which Modal 1.0 no longer does on its own; its settings never print the client secret; it keeps working when the shared store fails; a short token is replaced halfway through its life. - The skill says the dashboard API's calculation returns only the variables the household asks for, with null for the year. - The guard catches a fence with a space before its language, ?? fallbacks and unqualified public-prefix token and key names, scans .vue and .svelte files, and accepts the browser sign-in audience and a qualified Mapbox access token. - The integrator varies a household in one calculation with axes, types buildHouseholdDict as Household, and CONTRIBUTING.md documents the server-code marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Token template: the Modal wiring adds the module to the image with add_local_python_source, which Modal 1.0 no longer does on its own; the settings' repr leaves out the client secret; the opener has a Protocol type, and call_public_api lists every error it raises. - Skill: the dashboard API's calculation adds no omitted variables, so outputs are asked for with null, and a chart varies an input in one calculation with axes, not one per point (30 a minute); the polling waits match the merged client; the first 401 row also names a user route that received no forwarded user credential. - Integrator: a variation chart for the policyengine-api pattern is one calculation with axes, buildHouseholdDict returns Household, and the transformers read the calculated household's own shape. backend-builder's Household type takes axes and any entity group; the scaffold declares client types as type aliases. - Guard: a fence may have a space before its language, ?? fallbacks and unqualified token and key names are caught, .vue and .svelte files are scanned, and *_AUDIENCE names, which hold the sign-in audience, are accepted. The skill's own test module drops its divergent copy of these checks; the guard already scans every skill. CONTRIBUTING.md documents the rule and the <!-- server-code --> marker. - The API skill cites fastapi_routes for its public routes, and the dashboard manifest is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The token template's Opener Protocol takes the request positionally and the timeout by keyword, as urllib's opener does, and its docstring says how to drop a revoked token. - The skill's household example asks for an output with null. - The guard catches API_ACCESS_TOKEN and API_BEARER_TOKEN names and accepts app-v2's NEXT_PUBLIC_POLICYENGINE_API_V2_URL and a token named for another service. - backend-builder offers a typed readVariable() for the calculated household and the integrator uses it; the integrator debounces form values before calculating and runs the variation chart for the UK too. - The first 401 row no longer says a malformed PolicyEngine-Unauthenticated-User gets the same answer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- backend-builder: CalculatedHousehold is Record<string, unknown> with a typed readVariable() helper, since result.households.household... does not compile against an unknown index signature (TS18046 under strict); CalculatedValue includes the lists axes return. The integrator reads results through readVariable(). - Integrator: the policyengine-api pattern calculates from debounced form values (useDebouncedValue, compared by content), keyed in React Query, so typing or dragging sends one calculation per pause instead of one per keystroke against the 30-a-minute limit; the variation chart is debounced too and runs for UK households, which have no state. - Token template: the Opener Protocol takes the request by position and the timeout by keyword, as urllib's opener does; _is_usable is a TypeGuard and the template passes mypy --strict. Its docstring says how to drop a token that Auth0 has revoked. - Skill: the household example asks for household_net_income with null; the first 401 row no longer claims a malformed PolicyEngine-Unauthenticated-User gets the same answer. - Guard: API_ACCESS_TOKEN and API_BEARER_TOKEN names are caught; NEXT_PUBLIC_POLICYENGINE_API_V2_URL and tokens named for another service are accepted. - The dashboard manifest is rebuilt. The examples in backend-builder's Pattern B and the integrator's Steps 4 and 6 type-check together under strict against @policyengine/api-client 0.1.0's source (TypeScript 5.9). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Heads-up: #107 merged into main (8315e46). It adds a CI job, git fetch origin && git rebase origin/main
uv run python scripts/build_manifest.py
uv run python scripts/build_manifest.py --checkThen commit the rebuilt manifest. The builder now needs PyYAML, which |
- policyengine-tools, the dashboard planner and backend-builder ask the same four questions in the same order: precomputed files, the dashboard API, a new dashboard operation, the dashboard's own backend. - Each says the Public API's model version and rate limits are not reasons for an own backend; /new-tool says so too. - policyengine-api-access keeps pages at half of each rate limit, says when to ask for a new operation, and has new dashboard backends run policyengine themselves rather than get a Public API client. - The planner's household page calculates custom inputs through the dashboard API rather than a Modal backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- policyengine-tools sends a structural reform into the country package as a contributed reform switched on by a `gov.contrib` parameter, and a general gap to the Public API, rather than to a dashboard backend. - A server a page needs for something other than PolicyEngine results leaves its PolicyEngine calculations on the dashboard API. - policyengine-api-access precomputes a feature over the call budget before sending it to the dashboard's own backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- policyengine-tools' "Data and backend patterns" now checks, in order: precomputed files; the dashboard API's four operations; a new dashboard operation for a Public API route used unchanged; and, for what is left, the dashboard's own backend running policyengine without a Public API client. The dashboard planner, backend-builder and /new-tool follow it. - Gaps are fixed where they are: a structural reform becomes a contributed reform in the country package, switched on by a gov.contrib parameter; a general gap is a change to the Public API; a server needed only for other work (an LLM call, email) leaves calculations on the dashboard API. - The Public API's model version and rate limits are not reasons for an own backend. - policyengine-api-access keeps a page at half of each rate limit (15 household calculations, 60 economy-comparison reads, 150 policy creations and metadata reads a minute), with one calculation per action, axes for charted inputs, and at most five comparisons polling at once. A feature over that budget is precomputed first. - The planner's household page sends custom inputs to the dashboard API instead of a Modal backend. - New dashboard backends run policyengine themselves; the server-client section is for PolicyEngine services, CI jobs and backends that already have a client. - The dashboard manifest is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #92, #107 and #110. - Versions: keep 4.2.0 in every bundle and the marketplace template; main is at 4.1.1, and this branch adds a skill. - skills/policyengine-tools/SKILL.md: keep #92's sentences on what a data file holds, followed by this branch's ordered data-pattern checks. - dashboard/src/data/manifest.json: rebuilt with main's builder (scripts/build_manifest.py), not merged by hand; --check passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the heads-up. I merged
The branch is now level with |
Brings in #111. The only conflict was the generated dashboard/src/data/manifest.json, rebuilt with scripts/build_manifest.py; --check passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… host The dashboard API allows a dashboard's own *.vercel.app host only when appZoneRoutes.ts names it. The skill said a dashboard served from anywhere else, such as a Modal URL, could reach the dashboard API only through its www.policyengine.org path; once PolicyEngine/policyengine-app-v2#1552 deploys, the bill tracker's Modal host is allowed too, so that was about to stop being true. The skill now tells developers to add the rewrite and deploy it before, or with, the first release that calls the dashboard API. A dashboard on any other host gets 403 (a CORS error in the browser) until its exact host is in the allow list in website/src/lib/dashboardApi/cors.ts; the list never takes patterns. The 403 row in the error table and new-tool say the same. Tests first; the manifest is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DTrim99
left a comment
There was a problem hiding this comment.
Review from a dashboard builder's side
I read the new skill and the agent and command changes at ab1924d, tested the live dashboard API on November 12, and compared the guidance with the dashboards I maintain. The page route works as the skill describes, and the skill's own examples run as written.
Merge order
The existing dashboards that call api.policyengine.org/us/calculate from the browser are still being moved to the dashboard API. As of November 12:
- PRs open, not merged: PolicyEngine/us-state-eitcs-ctcs#34, PolicyEngine/state-legislative-tracker#234, and the host allow list in PolicyEngine/policyengine-app-v2#1552.
dashboard-api-clientbranches pushed on November 11, still no PR: keep-your-pay-act, missouri-income-tax-elimination, oregon-kicker-refund, utah-2026-tax-changes, working-parents-tax-relief-act, working-Americans-tax-cut-act-, wv-sb392-tax-cut, south-carolina-2026-tax-changes, georgia-2026-tax-changes and nc-stein-2027-tax-proposals.
Please hold this PR until those are merged and deployed. I can review the ten dashboard PRs as they open; request me on them. Two things the skill should also say, since every dashboard owner will ask:
- the date or trigger for switching the credential requirement on;
- where to ask for a server client. "The Public API's maintainers" doesn't tell a builder where to go, and the description lists it as open.
What I tested
POST https://www.policyengine.org/api/household/calculate, same small household each time:
| Caller | Answer |
|---|---|
Origin: http://localhost:3000 |
200, with Access-Control-Allow-Origin |
Origin: https://keep-your-pay-act.vercel.app (in appZoneRoutes.ts) |
200, with Access-Control-Allow-Origin |
| An origin not on the allow list | 403, "Pages on this origin may not call the dashboard API." |
Origin: https://policyengine--state-legislative-tracker.modal.run |
403 today; it is in app-v2#1552's list, so the bill tracker needs that PR deployed first |
No Origin header (a script) |
200 |
The skill's examples, sent as written:
- the household with the CTC
policy: 200; - the
axesexample (employment_income, 0 to 200,000,count: 41): 200, andhousehold_net_incomecomes back as a list of 41 values.
GET /api/metadata/us reports version 2.2.1. @policyengine/api-client is on npm; latest is 0.1.1 (published November 11), and the description says 0.1.0.
The host rule added in ab1924d matches what the API does: a host in appZoneRoutes.ts is answered, and the Modal host is refused until its exact entry is deployed.
Should address
1. Precompute scripts are told two different things. Five dashboards build their preset households with a Python script that posts to /us/calculate: scripts/compute_example_households.py in wv-sb392-tax-cut, south-carolina-2026-tax-changes and nc-stein-2027-tax-proposals, and scripts/precompute_households.py in edaa-dashboard and ecpa-dashboard. The dashboard-api-client branches leave those scripts as they are. The planner still tells builders to work this way: "one fast /calculate call per grid slice", in the paragraph this PR edits. The description lists that line under "Left as they are" and says it stops working once the credential requirement is on. The skill's route table says a script needs its own Auth0 client or the policyengine package, so these scripts will get 401. Meanwhile a script with no Origin header gets 200 from the dashboard API today. Which is intended?
- If scripts may use the dashboard API for presets, say so in the skill, with the rate budget. It also keeps presets on the same model version as the live calculator (see 2).
- If not, change the planner line to the
policyenginepackage in this PR rather than leaving it, and say whether the no-Originpath will be closed.
Once that's settled I'll update the five scripts.
2. "The Public API's model is older" is the reason most of our Modal backends exist. The API reports policyengine-us 2.2.1; the package on PyPI is 2.117.4. For 2027 the API still returns a $16,550 single standard deduction, and the package has the IRS's $16,600, merged November 10. Five dashboards run their own backend for exactly this: edaa-dashboard and ecpa-dashboard ("Pinned to the same policyengine-us as the data pipelines, so the household calculator never depends on what api.policyengine.org has deployed"), nj-ctc-increase, nj-ctc-eitc-expansion and ma-family-tax-credits ("does not yet run a policyengine-us release with the Massachusetts contributed reforms"). The head tells a builder to plan the dashboard API anyway and "say which model release the dashboard waits for". Under that rule, none of these five could have launched until the API caught up. Two requests:
- Either allow it as a time-limited reason for Pattern C (the plan names the release it waits for and the dashboard moves to B afterwards), or state how soon after a country-package release the Public API updates, so a builder can plan a launch date.
- The planner's "precomputed presets, live custom inputs" pattern puts two model versions on one page when presets come from the package and custom inputs from the API. The same household can then show two answers. Tell builders to precompute with the release in the metadata's
result.version, or through the dashboard API.
Suggestions
- Retry on 429. The integrator's hooks set
retry: 1. TanStack Query's default delay retries after about a second, inside the same 60-second window, which the errors table says never to do. The dashboard branches already retry only 502, 503 and 504; the integrator could do the same. - First deploy of a new dashboard. The skill now says to deploy the
appZoneRoutes.tsrewrite before, or with, the first release that calls the dashboard API./deploy-dashboarddoes it the other way round: it deploys first, because Vercel hasn't assigned a production URL yet, then adds the rewrite, and it editswebsite/next.config.ts. That order works when the project keeps its team host, sincecors.tsallows any*-policy-engine.vercel.apphost. It fails for a renamed alias such askeep-your-pay-act.vercel.app. A sentence in the skill saying which case needs the route first would stop a builder from reading the two as a conflict. The description leaves/deploy-dashboardfor a follow-up, which is fine. - Shared addresses. 30 household calculations a minute per IP is shared by everyone in a workshop or an office during a demo. The half-budget rule is per person. A line on what the page should show on a 429 would help.
- Metadata size. The US metadata is 74.7 MB uncompressed. "Read the metadata once per page load" could become "don't load it in a dashboard page unless the page needs it; take the names you need at build time".
- Countries. The dashboard API takes
usandukonly. Say what a Canada dashboard should do. - Client version. Confirm the polling description still matches 0.1.1.
- Model version: the Public API's model being older than a dashboard needs is a reason for an own backend only while the policyengine package's model bundle isn't updated weekly. policyengine-tools says how to check: read requires_dist for the last four weeks of policyengine releases on PyPI and see whether the country's pin in the models extra changed each week. The planner, backend-builder and new-tool follow it; rate limits stay no reason. - Precompute scripts call the dashboard API (no credential, no Origin), within the budget, so presets and live calculations share one model release. The access skill has a Python example; the planner's preset and grid text no longer sends scripts to /calculate. - Developers ask for a server client or a new dashboard operation in a new issue (policyengine-api or policyengine-app-v2), in Slack, or both. - The integrator's hooks retry once, only after 502, 503 or 504, after Retry-After; never after a 429. - A <project>-policy-engine.vercel.app host is allowed before the rewrite; only the shorter host and other aliases need the rewrite first. ab1924d said every Vercel host outside appZoneRoutes.ts got 403. - Pages take metadata names at build time (the US metadata is about 75 MB uncompressed), say what happened after a 429 on a shared network, and a dashboard for another country (Canada) precomputes or runs its own package. Tests first; the manifest is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@DTrim99 thanks for the review, and for testing the live routes. Merge order. We'll merge this without waiting for the dashboard migrations. Nothing in it depends on them, the dashboard API it points to is live, and the host text is true before and after PolicyEngine/policyengine-app-v2#1552. Thanks for offering to review the dashboard PRs; we'll request you on them. The credential requirement's date. The skill won't give one. Where to ask. For a server client, a new issue in PolicyEngine/policyengine-api, PolicyEngine's Slack, or both. For a new dashboard operation, a new issue in PolicyEngine/policyengine-app-v2, Slack, or both. 1. Precompute scripts. They use the dashboard API. The skill's route table has a row for a dashboard's precompute script, and a Python example sends no credential, stays at 15 calculations a minute and waits for the next window after a 429. The planner's preset and grid text sends the precompute script to the dashboard API's household calculation instead of 2. Model version. The Public API's model version is now a reason for an own backend only while the On the two-versions point: a page that calculates live through the dashboard API now computes its presets through the dashboard API too, so the page shows one model release. Suggestions, all in
Twelve new test cases cover these. They failed before the text changed and pass now, with the PR's other tests, each selected by node ID. |
PolicyEngine/policyengine-app-v2#1560 (91e6795) raised the dashboard API's wait for a household calculation from 100 s to 750 s (HOUSEHOLD_CALCULATION_WAIT_MILLISECONDS = 750_000, maxDuration 800), the same as the calculator's route. Policies and comparison reads keep 40 s, metadata 60 s. The 504 row in the error table now says so. Test first; the manifest is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DTrim99
left a comment
There was a problem hiding this comment.
Review, round 2
Summary
I read everything since ab1924d (2fc3f18 and eb10c64) at eb10c64, tested the live dashboard API again, and checked the PyPI and npm claims against the registries. Each round-1 item is either fixed or declined for a reason I accept. The precompute route, the retry, the host text, and the metadata, country and 429 lines all match the live service and app-v2's code on main.
One gap remains from round 1's point 2. The planner still sends a custom-modal dashboard's presets to the dashboard API. Under the new model-version rule, that puts two model releases on one page. It's a two-sentence fix. Everything else below is a suggestion.
Round-1 items
| Item | Status | Evidence |
|---|---|---|
| Merge order: hold until the dashboard migrations are merged and deployed | Declined; reasonable | app-v2#1552 merged today at 19:28 UTC and is live: the bill tracker's Modal origin now gets 200 with Access-Control-Allow-Origin, where round 1 got 403. us-state-eitcs-ctcs#34 and state-legislative-tracker#234 are still open, but nothing in the skill depends on them. Merging guidance changes no deployed dashboard, every route it points builders to answers today, and existing dashboards keep working on the Public API until the credential requirement is switched on, which this PR doesn't do. |
| Date or trigger for the credential requirement | Declined; fine | The skill says what happens once the requirement is on and gives no date. A date in a skill would go stale. Dashboard owners need it where the migrations are tracked, not here. |
| Where to ask for a server client | Resolved | "Getting a client", step 1: a new issue in PolicyEngine/policyengine-api, PolicyEngine's Slack, or both. A new dashboard operation: a new issue in PolicyEngine/policyengine-app-v2, Slack, or both. |
| 1. Precompute scripts told two different things | Resolved | The route table has a row for "A dashboard's precompute script", and a new section, "From a dashboard's precompute script", has a Python example. The planner's preset and grid text now uses the dashboard API's household calculation and no longer says "/calculate call". In app-v2, checkOrigin returns no-origin for a request without Origin unless Sec-Fetch-Site names another site, so the path is deliberate. I'll move the five scripts over. |
| 2a. The Public API's model version as a reason for an own backend | Resolved | The tools skill, the planner, backend-builder and /new-tool now allow C while the policyengine bundle isn't updated weekly, and give a PyPI check for it. The facts behind it hold (see What I tested). The check could be more precise; see the suggestions. |
| 2b. Two model versions on one page | Partly resolved | Done for a page on B: its presets now go through the dashboard API. Still open for a page on C: see Should address 1. |
| Retry on 429 | Resolved | retryServerErrors returns true only when failureCount < 1 and the error is a PolicyEngineApiError with status 502, 503 or 504. A 429 or a null status is never retried. retryDelayFromAnswer waits for Retry-After, or 5 s. TanStack Query passes failureCount 0 on the first failure, so this gives exactly one retry. Both hooks use it. |
| First deploy of a new dashboard, preview hosts | Resolved | The skill now says a <project>-policy-engine.vercel.app host is allowed from the first deploy, and only the shorter host or another alias needs the rewrite first. That matches TEAM_PREVIEW_HOST_PATTERN (/^[a-z0-9-]+-policy-engine\.vercel\.app$/) in app-v2's cors.ts on main. /deploy-dashboard's rewrite example uses a -policy-engine.vercel.app URL, so the two now agree. |
| Shared addresses | Resolved in the skill | "Stay at half of each limit" now says to keep the last answer on screen and explain that the network shares the limit. The integrator's code doesn't do this yet; see the suggestions. |
| Metadata size | Resolved | Pages take the names they need at build time. "About 75 MB" matches what I downloaded: 74.7 MB. |
| Countries | Resolved | The skill says the dashboard API serves us and uk only. A Canada dashboard precomputes with policyengine-canada or runs it in its own backend. |
| Client version 0.1.1 | Resolved | The code is unchanged; see What I tested. |
New findings
Should address
1. A custom-modal dashboard's presets still come from a different model. The planner's "Precomputed presets, live custom inputs" paragraph says a Modal backend calculates custom inputs "only when Step 4 gives custom-modal". It then says, with no condition: "The presets' precompute script calls the same dashboard API's household calculation, so presets and custom inputs use the same model release." That isn't true on a custom-modal dashboard, and the new rule makes that the usual case. Any US dashboard that needs a release newer than the Public API's 2.2.1 may now run its own backend, and today the check allows it for every such dashboard. Custom inputs then run the backend's release (policyengine-us 2.118.4 is on PyPI today), presets run 2.2.1, and the same household gets two answers on one page. That was round 1's point 2. edaa-dashboard and ecpa-dashboard are in that state now. The route table's precompute row has no condition either, while the skill's own bullet does ("A page that also calculates live through the dashboard API computes its presets through the dashboard API too").
Please say in the planner and the route table that presets and fixed grids come from the same place as the page's live calculations: the dashboard API on B, and the backend's pinned release on C.
A related gap: a precomputed-only dashboard whose reform needs a newer release has no route. The table sends its script to the dashboard API, and the weekly check only allows C. Let the same check allow that script to run the pinned package, so the dashboard isn't pushed onto a Modal backend just to get a newer model.
Suggestions
- Make the weekly check give one answer. For the US the answer is clear today: every
policyenginerelease from 6.1.2 (September 27) to 6.17.2 pins policyengine-us 2.2.1 inmodels. The UK is borderline, and the text leaves out what decides it.- The UK pin moved three times in four weeks (2.130.1, then 2.132.6, 2.151.0 and 2.174.1), with no change between October 27 and November 9. Whether that counts as weekly depends on where a builder starts counting weeks. Counted in 7-day periods ending today, one period has no change, so the answer is no. Counted from Tuesdays, every period has one, so the answer is yes.
- 6.16.2 was uploaded today, after 6.17.2, and pins policyengine-uk 2.165.1, older than 6.17.2's 2.174.1. Read by upload date, the UK pin "changed" this week by going backwards.
- Proposed wording: "updated weekly when, in each of the four 7-day periods ending today, a release raised the country's pin above every earlier release's pin; releases that lower it don't count."
- The check measures the bundle, but a page gets what the Public API deploys. policyengine-api's
pyproject.tomlpinspolicyengine[models]==6.17.1, so a bundle updated weekly doesn't guarantee an API updated weekly. Comparing the metadata'sresult.versionwith the newest pin would cover that. - A plan that takes C under this rule could also name the release it needs and say it moves to B once the check passes. That was the time limit round 1 asked for.
- The precompute example's timeout.
eb10c64raised the household calculation's wait to 750 s (app-v2#1560,maxDuration800), but the example still sendstimeout=300. A slow preset raisesReadTimeoutat 300 s; the route's own comment says a variation chart can take minutes. The route stops when the caller disconnects, so the Public API's work is thrown away. Use a timeout above 800 s, or say why it's 300. Related: the integrator's one retry after a 504 can now mean about 25 minutes on one calculation. Consider showing the failure instead of retrying a 504 from the household calculation. - The integrator's error state doesn't follow the new 429 text. The skill says to keep the last answer on screen, say the limit is shared, and not calculate again until the minute is up. The integrator's Step 5 shows "Something went wrong. Please try again." with a Retry button. Its hooks also lose the last answer when the debounced inputs change, because they don't set
placeholderData: keepPreviousData. A short branch for a 429 or anullstatus would line them up. - Say what keeps a script on the precompute row. The no-
Originpath is consistent with the skill's rules: the credential stays on www.policyengine.org's server, andOriginonly restricts browsers, since a script can send any value it likes. But the table now shows "A dashboard's precompute script" with no credential next to "Any other CI job or script" with its own Auth0 client, and only purpose separates them. One sentence would settle it: the no-credential path is for a dashboard's own build-time presets and grids, at most 15 calculations a minute, and any other script, especially a larger or recurring one, gets its own client. A long grid run from an office network also takes half that network's limit for the length of the run. Running sweeps from CI avoids that. /create-dashboard's headless precompute. It still creates policies withPOST /us/policyand reads/economy/{policy}/over/{baseline}on the Public API. The description lists it under "Left as they are", which was fair while no other route existed. The skill now sends fixed comparisons in a precompute script through/api/policiesand/api/economy/compare, so this paragraph could move here or in the follow-up.- Two older sentences in
/new-tool. Its pattern menu still names "structural reforms" as a reason for C, which its own Step 4 note and the tools skill rule out. Its host paragraph says any host not named inappZoneRoutes.tsneeds an exact allow-list entry.2fc3f18corrected that wording in the skill: a<project>-policy-engine.vercel.apphost doesn't need one.
What I tested
POST https://www.policyengine.org/api/household/calculate on November 12 with one adult aged 40, $50,000 employment income in 2026, asking for household_net_income:
| Caller | Answer |
|---|---|
No Origin header |
200, household_net_income 40,704.9 |
No Origin, User-Agent: python-requests/2.32.3 (what the example sends) |
200 |
Origin: https://keep-your-pay-act-policy-engine.vercel.app |
200, Access-Control-Allow-Origin returns that origin |
Origin: https://example.com |
403, "Pages on this origin may not call the dashboard API." |
Origin: https://policyengine--state-legislative-tracker.modal.run |
200 with Access-Control-Allow-Origin (403 in round 1), so app-v2#1552 is deployed |
Other checks:
GET /api/metadata/usis 74.7 MB uncompressed, withversion2.2.1 andcurrent_law_id2. PyPI's latest releases are policyengine-us 2.118.4 and policyengine-uk 2.178.5.- I read
requires_distfor all 45policyenginereleases from 6.1.2 to 6.17.2. Every one pinspolicyengine-us==2.2.1; extra == "models", so "every release since 6.7.0 pins 2.2.1" is right, and in fact holds back to September. The UK pin changes in 6.4.1 (2.130.1, October 15), 6.10.0 (2.132.6, October 21), 6.11.1 (2.151.0, October 27) and 6.16.1 (2.174.1, November 9). 6.16.2, uploaded today, pins 2.165.1. policyengine-api'spyproject.tomlon master pinspolicyengine[models]==6.17.1. - npm: I diffed the extracted 0.1.0 and 0.1.1 tarballs. The eight files under
dist/andLICENSEare identical. Onlypackage.json(the version and ayamldev dependency) andREADME.md(publishing notes) differ. "Same code, only README and package metadata changed" is right, and the polling text still matches the code (RATE_LIMIT_WAIT_MILLISECONDS60000, a 30-minute limit). - The Python example sends no credential and no
Origin, sincerequestsadds none. It waits 4 s after each answer, so at most 15 a minute; waits 60 s after a 429 and never retries at once; and raises on anything else. The text around it asks foraxes, which is right for a generic helper. Only the timeout is off. - On app-v2 main I read
cors.ts,checkOriginand the household route. The 750-s wait isHOUSEHOLD_CALCULATION_WAIT_MILLISECONDSfrom app-v2#1560, merged today at 20:54 UTC. - The new tests: twelve cases in
2fc3f18and one ineb10c64. They check that the new text is present. None would catch the custom-modal preset case or the timeout.
CI
All four checks pass at eb10c64: test, skill-examples, manifest (3.11) and manifest (3.15). The manifest was rebuilt in the last commit.
Recommendation: REQUEST_CHANGES
- Presets and fixed grids come from the same place as the page's live calculations: the dashboard API on Pattern B, the backend's pinned policyengine release on Pattern C. The planner, backend-builder and the route table say so; on custom-modal, presets from the dashboard API would show an older model's answer next to the backend's. - The weekly check gives one answer: in each of the four 7-day periods ending today, a release raised the country's pin above every earlier release's pin (lowering releases don't count), and the dashboard API's result.version is no older than the highest pin from seven days ago. When it fails, a precomputed dashboard's script may run the release it needs with the policyengine package, and a plan on C names that release and moves to B once the check passes. - The precompute example's timeout is 900 s, above the household route's 800-s limit. The integrator retries only 502 and 503: a 504 comes after a 750-s wait, so the page shows it. - The integrator's hooks keep the previous answer while the next one calculates, and its error state explains a 429 (or a null status) without a Retry button, keeping the last answer on screen. - The no-credential path is only for a dashboard's own build-time presets and grids; any other script gets its own client. - /create-dashboard's headless precompute reads comparisons through the dashboard API instead of POST /us/policy on the Public API. - /new-tool's pattern menu no longer lists structural reforms as a reason for Pattern C, and its host text allows the team's <project>-policy-engine.vercel.app host before the rewrite. Tests first; the manifest is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@DTrim99 thanks for the second round. Should address 1, presets on a custom-modal dashboard. Presets and fixed grids now come from the same place as the page's live calculations, so one page shows one model release: the dashboard API on Pattern B, and the backend's pinned On the related gap: when the weekly check fails, a precomputed-only dashboard's script may run the release it needs with the The weekly check now uses your wording. In each of the four 7-day periods ending today, a release must have raised the country's pin above every earlier release's pin; releases that lower it, such as 6.16.2, don't count. It also checks the Public API: the release the dashboard API's metadata reports ( Suggestions:
On the tests: you're right that they check for text. The new ones pin the specific failures you found: the conditional preset wording for |
DTrim99
left a comment
There was a problem hiding this comment.
Review, round 3
Summary
I read 4229b7e against eb10c64, then read every changed passage in full at 4229b7e. I also rechecked the weekly-check numbers against PyPI and the dashboard API's metadata. All eight round-2 items are resolved: the should-address, its related gap, and the six suggestions. On a custom-modal dashboard, presets now come from the backend's pinned release. A precomputed-only dashboard has a route to a newer release. The weekly check gives one answer, and my numbers give the same one: on November 12 it fails for both countries. The retry list is [502, 503], and the precompute example waits 900 s, longer than the route's 800-s limit.
Nothing below blocks merging. There are three suggestions. The most useful one is about the new isRateLimited: on www.policyengine.org, a null status is a dropped connection, not a 429. I proposed treating them the same in round 2, and that was too broad.
Round-2 items
| Item | Status | Evidence |
|---|---|---|
| Should address 1: a custom-modal dashboard's presets came from a different model | Resolved | The planner's "Precomputed presets, live custom inputs" paragraph now says "Presets come from the same place as the custom inputs, so both use one model release". Then it gives both cases: on policyengine-api the script calls the dashboard API, and "On custom-modal, it runs the backend's pinned policyengine release in its own process, never the dashboard API." The route table's precompute row says the same for Pattern B and Pattern C. backend-builder adds "A custom-modal dashboard's presets come from its backend's pinned release, not the dashboard API, so the page shows one model release." The "Stay at half" bullet was already conditional. One sentence still reads unconditionally; see suggestion 3. |
| Related gap: a precomputed-only dashboard needing a newer release had no route | Resolved | The tools skill says that when the check fails, "a precomputed dashboard's script may run that release with the policyengine package instead of calling the dashboard API". The same rule appears in the planner's Step 4, in its precomputed-grid sentence ("or with the pinned package when Step 4's model-version check allows it") and in the route table's row. The planner keeps that grid household-level. |
| Make the weekly check give one answer | Resolved | The text now lists releases in upload order. It requires a raise above every earlier release's pin in each of the four 7-day periods ending today, says releases that lower a pin don't count, and adds the result.version condition. A plan on C names the release it needs and moves to B once the check passes. I get the same answer: the check fails for both countries on November 12 (What I checked). The answer doesn't depend on where the periods start. The UK pin didn't rise between 6.11.1 (October 27, 01:31 UTC) and 6.16.1 (November 9, 14:24 UTC), a gap of 13.5 days, so every way of cutting the weeks leaves one with no raise. One thing in the reply is off, though nothing in the skill depends on it. The Public API's 6.17.1 pin isn't a reason the check fails. The second condition holds for both countries: the metadata reports 2.2.1 for the US, the highest US pin, and 2.174.1 for the UK, above 2.151.0, the highest UK pin as of November 5. The check fails on the first condition alone. |
| The precompute example's timeout; retrying a 504 | Resolved | The example sends timeout=900, with a comment giving the route's 750-s wait and 800-s limit. On app-v2 main, the household route's maxDuration is 800. The integrator's RETRYABLE_STATUSES is [502, 503]. Its text says "Don't retry a 504: the household calculation has already waited 750 s", and the error table's 504 row now says a page shows that failure instead of retrying. The one retry still waits for Retry-After, or 5 s. |
The integrator's error state and keepPreviousData |
Resolved | Both hooks set placeholderData: keepPreviousData. That's TanStack Query v5's export; the scaffold installs @tanstack/react-query unpinned, which gives v5, and the file already uses v5's isPending. The error state now has an isRateLimited branch with no Retry button and the shared-network message, and a useLastAnswer hook keeps the last answer on screen. The hook doesn't leak, and once a later calculation succeeds it shows the new answer. See suggestion 1 for how it handles a null status on www.policyengine.org, the empty state, and a one-render lag. |
| Say what keeps a script on the precompute row | Resolved | "This path is only for a dashboard's own build-time presets and grids. Any other script, especially a larger or recurring one, gets its own client", followed by "Run a long sweep from CI rather than from an office network". |
/create-dashboard's headless precompute |
Resolved | It now creates the policy with POST https://www.policyengine.org/api/policies and reads GET https://www.policyengine.org/api/economy/compare until status is ok, with no Public API path left. The PR description no longer lists it under "Left as they are". On app-v2 main, the comparison and policy routes go through the same handleDashboardApiRequest as the household route, so a script that sends no Origin reaches them the same way. The polling rules could be spelled out; see suggestion 2. |
Two older sentences in /new-tool |
Resolved | The pattern menu now gives C only "when the dashboard API doesn't cover it and precomputing can't", lists the weekly-bundle case, and says "a structural reform goes into the country package as a contributed reform instead". The host paragraph says the <project>-policy-engine.vercel.app host "is allowed from the first deploy, before the rewrite exists", which matches the skill. |
New findings
Should address
None.
Suggestions
-
On www.policyengine.org, a
nullstatus isn't a 429. In round 2 I suggested one branch for "a 429 or anullstatus". That's right onlocalhostand the*-policy-engine.vercel.apphosts, where the firewall's 429 reaches the page asnull. A dashboard served through its www.policyengine.org rewrite, as the skill asks, can read the 429, and the skill says so twice ("429 on www.policyengine.org,statusnullelsewhere"). There,nullmeans no answer arrived at all, for example because the reader's connection dropped.isRateLimitedreturns true fornullon every origin. So a reader on a flaky connection is told that too many calculations came from their network, and gets no Retry button. Countingnullas a rate limit only when the page isn't onhttps://www.policyengine.orgwould fix it. So would givingnullits own message that covers both causes. Three smaller points in the same code:- The empty state still checks
!mutation.data && !mutation.isPending. After a refused calculationmutation.datais undefined, so "Enter your details and click Calculate to see results." shows up under the kept answer and the rate-limit notice. The empty state should read the kept answer too. useLastAnswerreturns the old answer for one render after a new one arrives, becauseuseEffectruns after the paint.return answer !== undefined ? answer : lastAnswer;returns the new answer straight away and still holds the last one through a failure.- The kept answer belongs to the previous inputs while the form shows the new ones. The notice could say "The results below are for your previous entries."
- The empty state still checks
-
Spell out the polling rules for a script.
/create-dashboardreads the comparison "every few seconds until itsstatusisok" and points to the precompute section, which also gives it one sentence. Neither says whatcompareEconomydoes for pages: read every 5 seconds, give up after 30 minutes, wait 60 seconds after a 429, and stop at once on a failed comparison (502,status: "error",retry_after_seconds). A loop written as "untilstatusisok" keeps polling a failed comparison until the CI job hits its time limit. GitHub Actions' default is six hours. One sentence in the precompute section would cover all four rules, and/create-dashboardalready points there. A headless run would then record a failed or timed-out comparison in the result file'swarnings. -
Small wording points.
- The precompute section still opens unconditionally: "A Python script that builds a dashboard's presets or fixed grids at build time calls the same dashboard API, so its results match what the page calculates live." On Pattern C, that's the case this round's fix rules out. Starting it with "On Pattern B," would match the route table.
- "the dashboard moves to B once the check passes" (tools skill) and "moves to
policyengine-api" (planner) fit a C dashboard. A precomputed dashboard staysprecomputed; only its script moves back to the dashboard API. - The planner's plan.yaml example still gives
reason: "Needs microsimulation with custom CTC phase-out parameter"forcustom-modal. The line is older than this PR and I missed it in round 2. A parameter reform's economy-wide effect is B's comparison, so the example now shows a reason that Step 4 rules out. - Optional: "the highest pin from seven days ago" can be read as "as of seven days ago" or as "in the last seven days". Both readings give the same answer today. "Releases uploaded at least seven days ago" would settle it.
What I checked
-
The compare diff
eb10c64...4229b7e, which touches nine files: the two skills, backend-builder, the integrator, the planner,/create-dashboard,/new-tool, the tests and the manifest. At4229b7eI read in full the route table, the precompute section, the rate-limit and error sections, the tools skill's "Data and backend patterns", the planner's presets paragraph and Step 4, backend-builder's pattern rules and Pattern B hooks, the integrator's Steps 4 to 6,/create-dashboard's headless section and/new-tool's menu and host text. -
PyPI,
policyenginereleases. 6.18.0 was uploaded today at 21:47 UTC, after round 2, and pins policyengine-us 2.2.1 and policyengine-uk 2.174.1. I also rechecked 6.11.1 (UK 2.151.0), 6.16.0 (2.151.0), 6.16.1 (2.174.1) and 6.17.1 (2.174.1); every one pins US 2.2.1. Together with round 2's reads of 6.1.2 to 6.17.2 and 6.16.2, the four periods ending November 12 look like this:Period Raises the UK pin Raises the US pin November 6 to 12 6.16.1 (November 9), to 2.174.1 None October 30 to November 5 None None October 23 to 29 6.11.1 (October 27), to 2.151.0 None October 16 to 22 6.10.0 (October 21), to 2.132.6 None -
The dashboard API's metadata, read live:
GET /api/metadata/usreturned 200, 74.7 MB, withresult.version2.2.1 andcurrent_law_id2.GET /api/metadata/ukreturned 200, 2.9 MB, withresult.version2.174.1 andcurrent_law_id1. policyengine-api'spyproject.tomlpinspolicyengine[models]==6.17.1, which pins UK 2.174.1, so the live metadata matches the pin. -
app-v2 main: the household route's
maxDurationis 800. The comparison route waits 40 s for headers, which matches the 504 row. All three POST and GET routes go throughhandleDashboardApiRequest. -
The TypeScript:
retryServerErrorsreturns true only for aPolicyEngineApiErrorwith status 502 or 503 andfailureCount < 1, and anullstatus never passes it.retryDelayFromAnsweris unchanged. backend-builder'suseCalculationmutation sets no retry, and TanStack's default for mutations is none, so a 429 isn't retried there either. WithkeepPreviousData, a query'sdatais the previous answer while loading and undefined after a failure, which is exactly the caseuseLastAnswercovers. -
The Python example:
timeout=900. It waits 60 s after a 429, waits 4 s after each answer and raises on anything else, so a 504 fails the run instead of looping. -
The manifest was rebuilt in this commit: new
body_lengthvalues for the seven changed bodies,/create-dashboard's new links to policyengine-api and policyengine-api-access, and a newgenerated_at. -
The tests: nine new cases and one renamed. They check that the text is present. The exception is
test_precompute_example_waits_longer_than_the_route, which parses the example's timeouts. That's fine for skill text. None would catch thenull-on-www case or the polling gap.
CI
All four checks pass at 4229b7e: test, skill-examples, manifest (3.11) and manifest (3.15).
Recommendation: APPROVE
The only conflict was the generated dashboard/src/data/manifest.json, rebuilt with scripts/build_manifest.py; --check passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- dashboard-integrator: isRateLimited counts a null status as a 429 only off www.policyengine.org, where the firewall's 429 reaches a page that way; on the rewrite a null status is a dropped connection and gets the ordinary error. useLastAnswer returns a new answer in the same render, the empty state reads the kept answer, and both error states say the kept results are for the previous entries. - policyengine-api-access: the precompute section opens with the patterns it covers and gives scripts compareEconomy's polling rules (every 5 s, give up after 30 min, 60 s after a 429, at most four 502/503/504 in a row, stop at once on a failed comparison). - /create-dashboard: the headless precompute follows those rules and records a failed or timed-out comparison in the result file's warnings. - policyengine-tools and the planner: once the check passes, a C dashboard moves to B and a precomputed one keeps its pattern while its script goes back to the dashboard API; "the highest pin among releases uploaded at least seven days ago". - The planner's custom-modal example gives a reason Step 4 allows. Tests first: nine new or changed cases failed before the text changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #113
Fixes #114
Summary
The Public API (api.policyengine.org) is becoming callable only by PolicyEngine's own servers. This adds
policyengine-api-access, a skill that tells dashboard developers and agents how to reach it: from pages through www.policyengine.org's dashboard API and@policyengine/api-client, and from servers with their own Auth0 client-credentials token. It also stops the existing skills, agents and commands telling browser code to call the Public API, and points them to the new skill. Finally, it gives dashboard builders one ordered set of checks for how a dashboard gets its data, which keeps dashboards on the dashboard API unless they need something it can't give. After three rounds of dashboard-builder review, a dashboard's presets come from the same place as its live calculations (the dashboard API, or its own backend's pinned release), and the Public API's model version is a reason for an own backend only while thepolicyenginepackage's model bundle isn't updated weekly.@policyengine/api-client0.1.0, which the skill tells dashboards to install, is on npm: it was published by hand on 2026-11-10 from PolicyEngine/policyengine-app-v2mainat6030be089(licence MIT, dist-taglatest). That commit includes #1543, so the published client polls as the skill describes. 0.1.1 (2026-11-11) is nowlatest; its code is the same as 0.1.0's, and only its README and package metadata changed.The guidance changes were first opened as #117 and now merge here, with the skill they point to. The CI check script once planned for dashboards (#118, #115) is dropped; its branch
public-api-access-checkis kept.Changes: the new skill
skills/policyengine-api-access/SKILL.md:api.policyengine.orgor the Public API's Cloud Run addresses; no Public API credential or address goes in aNEXT_PUBLIC_*orVITE_*variable; one Auth0 client per calling server.@policyengine/api-clientusage, economy-comparison polling, the origins the dashboard API accepts (a new dashboard is served through a rewrite inappZoneRoutes.ts, deployed before or with its first release that calls the dashboard API; a dashboard on any other host gets 403, which the browser shows as a CORS error, until its exact host is in the allow list in PolicyEngine/policyengine-app-v2'swebsite/src/lib/dashboardApi/cors.ts, which never takes a pattern; a project's<project>-policy-engine.vercel.apphost is allowed from its first deploy, so only the shorter host needs the rewrite first), that the dashboard API servesusandukonly (a Canada dashboard precomputes withpolicyengine-canadaor runs it in its own backend), and its rate limits as the Vercel firewall applies them since 2026-11-10: over a limit it answers 429 itself, as text/plain, with noRetry-Afterand no CORS headers, so a page on another origin sees a network failure. The polling text follows the client as merged with @policyengine/api-client: wait out the firewall's 429 while polling policyengine-app-v2#1543 (RATE_LIMIT_WAIT_MILLISECONDS), which the published 0.1.0 includes.Authorization,PolicyEngine-User-AuthorizationandPolicyEngine-Unauthenticated-User; caching tokens across instances on Modal, Vercel and CI; no redirects; and the steps for getting a client ontoPUBLIC_API_SERVER_CLIENT_IDSbefore any token is sent, asked for in a new issue in PolicyEngine/policyengine-api, in PolicyEngine's Slack, or both.axes, answers kept in the page, fixed cases precomputed, and at most five economy comparisons polling at once (each reads 12 times a minute). A feature that can't fit is precomputed first. Pages don't load the US metadata (about 75 MB uncompressed) unless they need it, and take names at build time. After a 429 a page keeps its last answer and says that everyone on the same network shares the limit.policyenginerelease. The no-credential path is only for a dashboard's own build-time presets and grids; any other script gets its own client. A script that reads economy comparisons polls the waycompareEconomydoes: every 5 s, giving up after 30 minutes, 60 s after a 429, at most four 502, 503 or 504 answers in a row, and stopping at once on a failed comparison.policyenginethemselves and need no client; the server section is for PolicyEngine's services, CI jobs and the dashboard backends that already have a client.skills/policyengine-api-access/templates/public_api_token.py: a copyable Python token cache for Modal backends, Cloud Run services and scripts. It keeps one token in memory and in a store the instances share (amodal.Dicton Modal) until five minutes before it expires, raises a 401 without requesting another token (a new one would be refused too and use up the tenant's monthly allowance), never follows redirects, and never stores the client secret. It uses only the standard library.analysis-tools(which the create-dashboard workflow installs),api-development,app-development,completeanddashboard-builderbundles and in the catalog. The plugin version moves from 4.1.1,main's version since Require every reported number to come from a model run #92, to 4.2.0 in every bundle and the marketplace template.dashboard/src/data/manifest.jsonis rebuilt withuv run python scripts/build_manifest.py: the new skill, its five bundle edges and overlap entries, and the bundles' version and skill lists. The rebuild also picks up Stop the data skill steering agents to microimpute and uk-data #108's unbuilt change topolicyengine-data's description and target repositories.tests/pipeline/test_when_to_use_guide.pyreads skill IDs from this file, sodocs/when-to-use.md, which now names the skill, needs it. It is rebuilt again at74182b7,95936b4,2e751e5,c69b32d,ab1924d,2fc3f18,eb10c64,4229b7eand6afe365for the changed skills, agents and command: their descriptions, sizes and references, and new edges topolicyengine-api-access. At each merge ofmain(31d8527, bringing in Require every reported number to come from a model run #92, Require PyYAML for the dashboard manifest, check it on Linux in CI, and keep overlaps in artifact order #107 and Route UK data issues to the repo that builds the run's dataset #110;17e1471, bringing in Keep report-logger's data issues from failing on missing labels, and file none for Canada #111;8f387e9, bringing in Send no dataset to policyengine-api and read the run's dataset from its bundle #112) it is rebuilt withmain's builder rather than merged by hand, anduv run python scripts/build_manifest.py --checkpasses.Changes: the existing skills, agents and commands
skills/policyengine-api: says who may call v1 (servers with their own credential) and that pages use the dashboard API; drops "JS frontends" from when to use REST; lists/healthand/v2/openapi.jsoninstead of/specificationand the liveness and readiness checks, which the Public API removed (policyengine_api/migration_flags.py).skills/policyengine-tools: Pattern B is the dashboard API through@policyengine/api-client, with its four operations. "Data and backend patterns" now checks four options in order for each feature a page computes at run time: precomputed files; the dashboard API's four operations as they are; a new dashboard operation for a Public API route used unchanged; and, for what is left, the dashboard's own backend runningpolicyengine, with no Public API client. Gaps are fixed where they are: a structural reform becomes a contributed reform in the country package switched on by agov.contribparameter, a general gap is a change to the Public API, and a server needed only for other work (an LLM call, sending email) leaves the calculations on the dashboard API. Rate limits are not a reason for an own backend. The Public API's model version is one only while thepolicyenginepackage's model bundle isn't updated weekly: in each of the four 7-day periods ending today, somepolicyenginerelease on PyPI raised the country's pin in itsmodelsextra (fromrequires_dist) above every earlier release's pin, with releases that lower it not counting, and the dashboard API'sresult.versionis no older than the highest pin among releases uploaded at least seven days ago. When the check fails, a precomputed dashboard's script may run the release it needs with thepolicyenginepackage, and a plan on C names that release. Once the check passes, a dashboard on C moves to B, and a precomputed one keeps its pattern while its script goes back to the dashboard API. On 2026-11-12 it failed for both countries: every release from 6.1.2 (2026-09-27) to 6.17.2 pins policyengine-us 2.2.1; the UK pin rose on 2026-10-21, 2026-10-27 and 2026-11-09, with no rise from 2026-10-28 to 2026-11-08 (6.16.2, uploaded 2026-11-12, lowers it). It fails on the first condition alone: the Public API pinspolicyengine[models]==6.17.1, and the dashboard API reports policyengine-us 2.2.1 and policyengine-uk 2.174.1, no older than the highest pins.backend-builder's backend priority and/new-toolfollow the same order, and the planner's household page sends custom household inputs to the dashboard API instead of a Modal backend. Its presets and precomputed grids come from a precompute script: onpolicyengine-apiit calls the dashboard API's household calculation instead of/calculate, and oncustom-modalit runs the backend's pinned release. Thecustom-modalexample in itsplan.yamlnow gives a reason Step 4 allows (a newer model release while the check fails) instead of a parameter reform, which the dashboard API's comparison covers.targets/claude/agents/dashboard/dashboard-integrator.md: the dashboard API hooks retry once, only after a 502 or 503 and after itsRetry-After.retry: 1retried a 429 about a second later, inside the same 60-second window; a household calculation's 504 comes after a 750-s wait, so the page shows it. The hooks keep the previous answer while the next one calculates (placeholderData: keepPreviousData), and the error state explains a 429 without a Retry button, with the last answer still on screen and marked as being for the previous entries. Anullstatus counts as a 429 only off www.policyengine.org, where the firewall's 429 reaches a page that way; on the www.policyengine.org rewrite it means no answer arrived and gets the ordinary error. The empty state shows only before the first calculation.targets/claude/commands/create-dashboard.md: in headless runs, theprecomputedpattern reads comparisons through the dashboard API (POST /api/policies, thenGET /api/economy/comparewith the skill's polling rules, recording a failed or timed-out comparison in the result file'swarnings) instead ofPOST /us/policyand the economy endpoints on the Public API.targets/claude/commands/new-tool.md: the pattern menu no longer lists structural reforms as a reason for Pattern C, and the host text allows the team's<project>-policy-engine.vercel.apphost before the rewrite.skills/policyengine-app: the calculator's direct browser calls throughBASE_URLare moving to app.policyengine.org's own route,/api/policyengine/{Public API path}, which forwards only the operations inapp/src/libs/publicApiRoute/allowList.ts. New calculator code goes through that route.targets/claude/agents/dashboard/backend-builder.mdandtargets/claude/commands/new-tool.md: the Pattern B client wraps@policyengine/api-clientinstead of fetchinghttps://api.policyengine.org. The types aretypealiases, because the client takesRecord<string, unknown>and a TypeScriptinterfaceis not assignable to it.targets/claude/commands/new-tool.md: a tool served from a host not named inappZoneRoutes.ts, such as a Modal URL or a custom domain, needs an exact entry for that host in the dashboard API's allow list incors.tsbefore its pages call the dashboard API.policyengine-api-accessand describe Pattern B by what the dashboard API offers. Thedata_patternvalue stayspolicyengine-api, so existingplan.yamlfiles still validate.policyengineskill,targets/codex/agents/policyengine-app-v2/AGENTS.mdanddocs/when-to-use.mdpoint topolicyengine-api-access; the guide's catalog counts are current (25 skills).Sources
Every path, shape, header, origin rule and error comes from merged code:
mainat6030be089, the commit@policyengine/api-client0.1.0 was published from (it includes #1533 and #1543):website/src/app/api/,website/src/lib/dashboardApi/(operations.ts,cors.ts,handler.ts),packages/public-api-forwarding/(settings.ts,accessToken.ts,cors.ts,responses.ts),packages/api-client/, andapp/src/models/household/pythonPackageCodec.tsfor theaxesshape. The advice on dashboard hosts followscors.tsonmain, which allows a dashboard's own*.vercel.apphost only whenappZoneRoutes.tsnames it, and the open Dashboard API: allow the hosts of four dashboards moving onto it policyengine-app-v2#1552, which adds a list of exact hosts not served through those rewrites, among them the bill tracker's Modal host. The wording is true before and after #1552 merges.mainat2073325a:policyengine_api/request_caller.py(the credential check runs on every route,/healthincluded),policyengine_api/libs/server_credentials.py,policyengine_api/routes/household_routes.pyandservices/household_calculation_service.py(/calculateadds no omitted variables, and acceptsaxes), anddocs/migration/stage-12a-user-login.md(the user routes' 401).modelsextra of eachpolicyenginerelease since 6.7.0, and the latestpolicyengine-us(2.117.4). The dashboard API's US metadata on 2026-11-12: 74.7 MB uncompressed,result.version2.2.1.PolicyEngineApiError'sstatusandretryAfterSecondscome from the published 0.1.1 package.Left as they are
These call the Public API outside a browser: from an agent's shell, or from this repository's
analyze-policyandcreate-dashboardworkflows on GitHub Actions. None sends a credential, so each stops working once the credential requirement is on:targets/claude/agents/microsim-runner.md: Pythonrequeststo/us/policy,/us/economy/…and…/budget-window(its default "API path"); theanalyze-policyworkflow runs it through/analyze-policy.targets/claude/commands/analyze-policy.md: checks a parameter's deployed value through the metadata endpoint and probes/calculate.targets/claude/agents/model-corroborator.md:curlto/us/policyand/us/economy/….targets/claude/agents/parameter-locator.md:curlto/us/metadata.targets/claude/commands/text-to-reform.md: names the Public API as where a user might submit a reform.dashboard/src/pages/Guides.tsx: guide text describing microsim-runner's API path; it makes no request.analyses/*.md: dated records, kept as written.Not in this PR
Dashboard guidance that disagrees with itself but doesn't send browser code to the Public API, found in review rounds 2 and 3: the
frontend-builderagent, and the integrator's Step 4 example for a custom backend, use auseHouseholdSimulationhook thatbackend-builderdoesn't export (it exportsuseCalculation); and/deploy-dashboardadds a dashboard's rewrites towebsite/next.config.ts, while the dashboard API's allowed origins come fromwebsite/src/data/appZoneRoutes.ts. Each needs a decision about the dashboard workflow, so they are left for a follow-up.policyengine.org/us/ai-agents shows the catalog's counts from
website/src/app/[countryId]/ai-agents/pluginStats.jsonin app-v2. After this merges,skillsgoes from 24 to 25 there, in an app-v2 PR.Updating the
policyenginepackage's model bundle weekly, and the Public API's pin ofpolicyenginewith it. The Public API runs policyengine-us 2.2.1 today. Until the bundle is updated weekly, the skill lets a dashboard that needs a newer model run its own backend.Tests
The skill
tests/test_api_access_skill.pychecks the frontmatter; the five bundles, the catalog and the wrapper build; that the skill names the four operations, the client's exports, the server headers, tenants, audiences and variables, the 401, 503 and 403 bodies, the allowed origins, and a row for each of 401, 403, 429 and 503.tests/test_public_api_browser_guidance.pychecks every skill, this one included, for browser-language examples that name the Public API and for public-prefix variables that hold its address or a credential. The template's tests use a fake opener and a dict as the shared store: one token serves many requests and both instances, it is replaced five minutes before expiry, a 401 is raised on every call without another token request, a redirected token request becomes an error and stores nothing, partial settings are refused, a local server's 307 is not followed, a failing shared store does not stop it, a short token is replaced halfway through its life, the settings'reprhides the secret, and theOpenerProtocol takes the request by position and the timeout by keyword.e84b09c: 53 failed on their assertions, 1 passed (the pattern self-test); exit code 1.9e63be7: 54 passed; exit code 0. The green commit also registers the template module insys.modulesin the test loader, whichdataclassesneeds.5e0fbc1, wheretests/test_api_access_skill.py::test_skill_describes_the_dashboard_api_firewall_refusalfailed on its assertion (exit code 1); greene8cf0af, 55 passed (exit code 0).a139568, wheretest_template_raises_a_refused_request_without_requesting_another_token,test_skill_describes_the_dashboard_api_firewall_refusalandtest_errors_table_tells_a_refused_server_token_from_a_refused_user_tokenfailed on their assertions (exit code 1); green7e325d3, all 74 tests intests/test_api_access_skill.pyandtests/test_public_api_browser_guidance.pypassed (exit code 0).00261a0, wheretests/test_api_access_skill.py::test_dashboard_manifest_lists_the_skillfailed on its assertion (exit code 1); green9ac72ca, 56 passed (exit code 0).00261a0:tests/test_api_access_skill.py::test_dashboard_manifest_lists_the_skillfailed on its assertion, 1 failed and 263 passed; green 42886481119 at9ac72ca: both jobs passed. The earlier commits were pushed before the PR existed, so their red runs are the local ones above.The anti-rot lint's checks pass on every changed file. The wrapper build ships
skills/policyengine-api-access/SKILL.mdand the template.The data-pattern rule
Ten tests at the end of
tests/test_api_access_skill.py(14 cases): the tools skill, the planner's Step 4 andbackend-builderlist the four options in the same order, and each said the model version and rate limits are not reasons for an own backend, as/new-tooldid (both checks replaced in2fc3f18, under "Review changes"); the access skill states half of each limit and the five-comparison cap; its new-operation section says when to ask and suggests no client; its route table has new dashboard backends runpolicyenginethemselves; the planner's household page uses the dashboard API; the tools skill fixes gaps in the country package or the Public API first and keeps calculations on the dashboard API when a server is needed only for other work; and a feature over the budget is precomputed before it gets a backend.b7f3868: 11 failed on their assertions; exit code 1. Red,2c0e522: the 3 added tests failed on their assertions; exit code 1.c69b32d: all 14 passed, each selected by node ID; exit code 0.mainat31d8527: all 103 tests intests/test_api_access_skill.pyandtests/test_public_api_browser_guidance.pypass, each selected by node ID (exit code 0), and the anti-rot lint's checks pass on all 27 files this PR changes. The merge kept Require every reported number to come from a model run #92's sentences on what a data file holds ahead of the data-pattern checks inskills/policyengine-tools/SKILL.md.Dashboard hosts
Three tests at the end of
tests/test_api_access_skill.py: the access skill tells developers to deploy the rewrite before, or with, the first release that calls the dashboard API, names the exact-host allow list inwebsite/src/lib/dashboardApi/cors.tsand says it never takes a pattern, and no longer says a dashboard on a Modal URL can reach the dashboard API only through its www.policyengine.org path; the 403 row in its error table names the rewrite and the allow list; and/new-toolsays a host not inappZoneRoutes.tsneeds an exact entry in the allow list.ab1924d.ab1924d: the 3 pass along with the 103 earlier tests (106), each selected by node ID; exit code 0.uv run python scripts/build_manifest.py --checkpasses, and the stale-reference checks find nothing in the 4 changed files. This change has not been reviewed.Review changes
Ten tests in
tests/test_api_access_skill.py(12 cases). Two replace data-pattern tests that said the model version is never a reason for an own backend: rate limits are still not a reason in the tools skill, the planner andbackend-builder, each ties the model version to weekly bundle updates, and so does/new-tool. The others check that the tools skill gives the PyPI check and both outcomes; precompute scripts use the dashboard API (the route table, the Python example's 60-second wait after a 429, and the planner's preset text without/calculate); a server client and a new dashboard operation are asked for in a new issue or Slack; the integrator retries only 502, 503 and 504; a<project>-policy-engine.vercel.apphost works before the rewrite; pages take metadata names at build time; a page explains a 429 on a shared network; and the skill says what a dashboard for another country does.2fc3f18.2fc3f18: they pass with the PR's other tests, 114 cases, each selected by node ID; exit code 0.uv run python scripts/build_manifest.py --checkpasses, the stale-reference checks find nothing in the 8 changed files, and the new Python example compiles. This change has not been reviewed.eb10c64: the error table's 504 row gives a household calculation 750 s, the wait Dashboard API: wait as long as the calculator for a household calculation policyengine-app-v2#1560 set (HOUSEHOLD_CALCULATION_WAIT_MILLISECONDSis 750_000 onmain, withmaxDuration800); policies and comparison reads keep 40 s and metadata 60 s. Its test failed first, then passed with the others, 115 cases, each selected by node ID;--checkpasses.Review changes, round 2
Nine new tests in
tests/test_api_access_skill.pyand two changed ones. The new tests check that presets come from where the page calculates live (the planner oncustom-modal, the route table); the weekly check's 7-day periods, raised pins andresult.versioncondition; that a plan on C names its release and moves to B; that a precomputed dashboard may run the pinned package; that the example's timeout is above 800 s; the scope of the no-credential path; the integrator'skeepPreviousData,useLastAnswerand 429 message;/create-dashboard's dashboard API comparisons; and/new-tool's menu and host text. The integrator retry test now expects[502, 503], and the round-1 check test expects the 7-day wording.4229b7e.4229b7e: all 124 cases pass, each selected by node ID; exit code 0.--checkpasses, the stale-reference checks find nothing in the 9 changed files, and the Python example compiles. DTrim99 approved this commit.Review changes, round 3
6afe365takes the three suggestions in DTrim99's approval of4229b7e. Seven new tests intests/test_api_access_skill.pyand two changed ones. The new tests check that the integrator'sisRateLimitedcounts anullstatus as a 429 only off www.policyengine.org; thatuseLastAnswerreturns a new answer in the same render; that the empty state reads the kept answer; that both error states say the kept results are for the previous entries; that the precompute section gives scripts the comparison polling rules and/create-dashboardrecords a failed comparison inwarnings; that the precompute section opens with the patterns it covers; and that the planner'scustom-modalexample gives a reason Step 4 allows. The weekly-check test now expects "releases uploaded at least seven days ago", and the test for what happens once the check passes expects a C dashboard to move to B and a precomputed one to keep its pattern.6afe365.6afe365: all 131 cases pass, each selected by node ID; exit code 0.--checkpasses, the stale-reference checks find nothing in the 6 changed source files, and the Python example compiles. This change has not been reviewed.The existing guidance
tests/test_public_api_browser_guidance.py: TypeScript and JavaScript examples inskills/,targets/anddocs/may not name a Public API host (the household API and v2 hosts are not matched); noNEXT_PUBLIC_orVITE_variable may be set to one or named like a credential; eleven files that guide dashboard and app work must point topolicyengine-api-access; the API skill's public routes; and the tools skill's Pattern B.29b87d2: 15 failed on their assertions, 2 passed (no public-prefix violations existed, and the patterns' self-test); exit code 1.b6f3e85: 17 passed; exit code 0.703a72a, where seven tests in the two new test files failed on their assertions (exit code 1), among themtests/test_public_api_browser_guidance.py::test_calculated_household_is_read_through_a_typed_helperandtests/test_api_access_skill.py::test_template_opener_protocol_takes_the_request_positionally_and_timeout_by_keyword; green2e751e5, all 89 tests in the two files passed (exit code 0).2e751e5: the TypeScript inbackend-builder's Pattern B and the integrator's Steps 4 and 6 compiles together understrict(TypeScript 5.9) against@policyengine/api-client's source at6030be089, and the oldresult.households.household…read fails there with TS18046; the token template passesmypy --strict.68e4eaa, where eight tests in the two new test files failed on their assertions (exit code 1), among themtests/test_api_access_skill.py::test_template_modal_wiring_adds_the_module_to_the_imageandtests/test_public_api_browser_guidance.py::test_integrator_varies_a_household_in_one_calculation; green95936b4, all 83 tests in the two files passed (exit code 0), after the skill's test module dropped three checks that duplicated the guard.f69d880, wheretests/test_public_api_browser_guidance.py::test_guards_catch_the_patterns_they_name,::test_dashboard_scaffold_loads_the_access_skilland::test_custom_backend_guidance_agrees_with_what_the_dashboard_api_offersfailed on their assertions (exit code 1); green74182b7, all 77 tests in the two new test files passed (exit code 0). The guard now also covers~~~and longer fences, HTML, Vue and Svelte blocks, nested blocks, JSON keys,||fallbacks and Cloud Run's per-project addresses, and accepts a browser's own Auth0 sign-in settings.tests/pipeline/test_when_to_use_guide.py::test_skills_section_references_real_skills, because the guide namespolicyengine-api-accessand the dashboard manifest had not been rebuilt. The manifest commits above fix it.🤖 Generated with Claude Code