Repository navigation
Define the fields App v3 reads for a 2027 bill report - #241
Conversation
- docs/APP_V3_BILL_CONTRACT.md: the lifecycle from import to approval, each field App v3 reads with its writer, the comparison row format, and the saved App v3 report. - scripts/sql/010_add_app_v3_bill_fields.sql: research gains the session, sponsors, introduced date, bill text link, App v3 report id and link, review PR and approval time; validation_metadata gains comparisons and calibration_check. - publish-bill.yml records approved_at and the review PR when a bill-review PR merges, falling back to the status alone until 010 runs. The PR's branch name and URL now reach the shell and Python only through environment variables, and the reform id must be a plain research id: this pull_request_target job holds the Supabase and Modal secrets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at 1f2c0c1
This PR defines the data contract between the bill pipeline and App v3 for 2027 bills. It adds docs/APP_V3_BILL_CONTRACT.md and migration 010, which adds nine columns to research and two to validation_metadata. It changes publish-bill.yml to record approved_at and review_pr_url when a bill-review PR merges. It also closes a shell and Python injection path: the branch name now reaches the scripts only through env:, and the reform id must match ^[a-z0-9][a-z0-9-]*$.
Verdict: REQUEST_CHANGES
The code is correct. The two items below are statements in the contract document that do not match how App v3 reads the tracker today. Because this document is the contract, a later change in App v3 or in the pipeline can follow them and break.
SHOULD ADDRESS
-
docs/APP_V3_BILL_CONTRACT.md:31:
validation_metadatahas the same fixed-column hazard asprocessed_bills, but the document warns only aboutprocessed_bills.
App v3 (fetchTrackerBillsinapp/src/api/billFeed.ts, also at policyengine-app-v2#1646 headdba4aaa) readsvalidation_metadatawith a fixed list:id,fiscal_note_source,…,verified_at,validated_against. That list does not includecomparisonsorcalibration_check. Case: an App v3 change addscomparisonsto that list before010is applied. PostgREST then rejects the read, and the whole bill feed fails, the same way the paragraph describes forprocessed_bills.
Fix: in the paragraph at line 31, namevalidation_metadatatoo. Say that App v3 addscomparisonsandcalibration_checkonly after010is applied, or reads them in a separate query that can fail alone (as App v3 already does forreform_impacts.baseline_params). -
docs/APP_V3_BILL_CONTRACT.md:14: "App v3's feed shows
publishedbill rows only" is not what App v3 does.
isBillRecordinbillFeed.tskeeps a row when its type isbill(or empty) and its status is notin_review. Case: a bill row with statusin_progressorplanned(both values that001_create_tables.sqllists forresearch.status) shows in App v3, although it was never approved. The lifecycle stays safe only because/encode-billalways writesin_review.
Fix: change the sentence to "App v3's feed hidesin_reviewrows, so merging the review PR is what lists a bill". Or, if "published only" is the intended rule, record it as a required App v3 change and filter onstatus = publishedthere.
SUGGESTION
- docs/APP_V3_BILL_CONTRACT.md:57: define
ratioand the band edges. The example impliesratio = pe_estimate / estimate(−697,798,094 / −680,000,000 = 1.03). Write that formula. Also say which band takes an exact edge, for example |ratio − 1| = 0.10 goes to10_to_25. - docs/APP_V3_BILL_CONTRACT.md:29: give the shape of
calibration_check. Section 3 fixes the shape ofcomparisons, butcalibration_checkhas no shape. A link to the output format ofscripts/readiness_lookup.py(tracker #242) is enough. - .github/workflows/publish-bill.yml:72: plan to remove the fallback after
010is applied. After that, a PGRST204 error means something is wrong, but the job still publishes and only prints a line. Add a TODO that names010, so the fallback does not stay in place for good.
What I checked
- Contract against App v3 (policyengine-app-v2#1646 at
dba4aaa).intakeFieldsreadssponsors,introduced_date,session_name,session_year,bill_text_url,app_report_urlandapproved_atfromresearch. All seven are in010, with types that suit the reader:session_yearis INTEGER (App v3 checksNumber.isInteger), and the dates arrive as ISO strings. App v3 readsresearchwithselect=*, as the document says. It does not readapp_report_idorreview_pr_urlyet, which is fine. - Contract against the importer (tracker #243 at
8a6568a).009addssponsors,introduced_date,bill_text_url,session_start_date,session_end_dateandsession_classificationtoprocessed_bills. These match the table in section 2. The sponsor objects that #243 writes (name,primary,party,district, and more) contain the keys App v3 reads.session_nameis already onprocessed_bills. - Other series PRs. #239, #242 and #244 do not write any
010column yet. #239 gives ids such asky-hb1-2027, which pass the new reform id check. - Workflow probe. I extracted both changed steps from the YAML and ran them locally. The extract step accepted
bill/ga-sb168andbill/ky-hb1-2027. It rejectedbill/$(touch pwned),bill/x";id;",bill/GA-SB1,bill/ga_sb1,bill/andfeature/x, and no command ran. Against a fake Supabase client, the publish step wrote all three fields, fell back to the status alone on a PGRST204 error, exited 1 when no row matched, and raised again on other errors. - Reform id check against history. All 35 merged
bill-reviewPR branches pass^[a-z0-9][a-z0-9-]*$. - Lifecycle claims. The triage score below 20 is
not_modelable(scripts/auto_triage.py), and/encode-billwritesin_review. Both match the document. - Tests. vitest: 82 passed in 8 files. pytest on
test_compute_impacts_datasets.pyandtest_publish_analysis.py: 37 passed.test_auto_triage.pydoes not collect here, becausehypothesisis not installed (not related to this PR). eslint: 0 errors and 9 warnings, the same as on main. The PR changes no app code, so I did not run a separate build for it. - The branch contains main (
cdaec13) and merges cleanly. No CI checks run on this branch.
Pavel's review of #241: - validation_metadata is read with a fixed column list too, so the doc now says new columns there go in a separate query that can fail alone (as app-v2 #1658 does for comparisons) or wait for the migration. - "Published rows only" is what app-v2 #1658 does; until it's live the feed hides in_review rows, and the doc says what that requires. - research.session_name is the OpenStates identifier, so App v3 reads the session from session_year (app-v2 #1646). - ratio and the band edges are defined (an exact edge goes to the wider band, as band_of does), and calibration_check points to readiness_lookup's result. - 009-012 are applied in production (3 December), so publish-bill.yml no longer falls back to the status alone on a missing column. - The credential section names the secrets Anthony added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Pavel. Fixed in ea9c1e6. Should address
Suggestions
Also changed
#247, which is stacked on this branch, now includes these changes. |
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at ea9c1e6
This PR defines the data contract between the bill pipeline and App v3 for 2027 bills. It adds docs/APP_V3_BILL_CONTRACT.md and migration 010, and it makes publish-bill.yml record approved_at and review_pr_url when a bill-review PR merges. It also closes the shell and Python injection path through the branch name. Since 1f2c0c1, one commit (ea9c1e6) changes the contract text to match the App v3 readers in policyengine-app-v2#1646 and #1658, and removes the 010 fallback from the publish step.
Verdict: APPROVE
Both SHOULD ADDRESS items from the last review are fixed. I found no new CRITICAL or SHOULD ADDRESS items. The new items below are small text fixes.
Earlier items
- SHOULD ADDRESS 1,
validation_metadatafixed list: fixed. Line 31 now namesprocessed_billsandvalidation_metadata. It says to read a new column in a separate query, or to add it to the fixed list only after the migration. policyengine-app-v2#1658 (head59a897c) does this: it readsid,comparisonsin its owntrackerSelectwith.catch(() => null), and the fixedvalidation_metadatalist is unchanged. - SHOULD ADDRESS 2, "published rows only": fixed. #1658 changes
isBillRecordto keep a bill row only when its status ispublishedor empty. Line 14 cites #1658 and states the rule that applies until it is live (the feed hidesin_review). Both statements match the code.research.statusisNOT NULL, so the empty case applies only to unusual rows. - SUGGESTION 1,
ratioand band edges: fixed, with one small error. See new suggestion 1 and 2. - SUGGESTION 2, shape of
calibration_check: fixed. Line 61 points tolookup()inscripts/readiness_lookup.py(tracker #242).calibration_check()in #246 returns that result. - SUGGESTION 3, the
010fallback: fixed. The step now writes the status and both approval fields in one update. Any error fails the step. See new suggestion 3 for a stale comment.
SUGGESTION
- docs/APP_V3_BILL_CONTRACT.md:57: the example does not match "rounded to four places". −697,798,094 / −680,000,000 rounded to four places is 1.0262, not 1.03.
compare_estimates.py(#246) storesround(ratio, 4), so it writes 1.0262 for this example. Fix: change the text to "= 1.0262", and change"ratio": 1.03in the JSON example at line 48 to1.0262. - docs/APP_V3_BILL_CONTRACT.md:58: an exact edge below 1 goes to the narrower band.
band_ofcomputesabs(ratio - 1) < 0.10on the unrounded float. For ratio 1.1 the gap is 0.10000000000000009, so it goes to10_to_25, as the text says. For ratio 0.9 (PE −612,000,000, estimate −680,000,000) the gap is 0.09999999999999998, so it goes tounder_10. Fix: in #246, round the gap before the compare (for exampleround(abs(ratio - 1), 4)), or remove the "exact edge" sentence from the contract. - .github/workflows/publish-bill.yml:41: the comment above the step still describes the removed fallback. It says "Before scripts/sql/010 is applied those columns don't exist, so it falls back to the status alone." The step no longer falls back, and the new comment at line 66 says the opposite. Fix: remove the last sentence of the comment at lines 41–43.
- docs/APP_V3_BILL_CONTRACT.md:24: App v3 does not read
session_start_date,session_end_dateorsession_classification. The fixedprocessed_billslist in #1658 isbill_id,state,bill_number,status,legiscan_url,last_action_date. The session view inbillSessions.tsuses onlysession_year. Fix: mark this row's App v3 use as planned. The same applies tocalibration_checkat line 29, which no App v3 PR reads yet.
What I checked
- Contract against App v3. I read the full diffs of policyengine-app-v2#1646 (head
98a993f) and #1658 (head59a897c, stacked on #1646), andbillFeed.tsat59a897c.intakeFieldsreadssponsors,introduced_date,session_name,session_year,bill_text_url,app_report_urlandapproved_atfromresearch. The overview names the session fromsession_year, as line 23 now says.comparisonsFromreadssource,tier,kind,estimate,window,pe_estimate,urlandnote, all in the section 3 shape. App v3 computes its own ratio and does not readratio,bandorunit. - Helpers that the contract cites.
band_ofand the ratio rounding inscripts/compare_estimates.py(tracker #246 atdb0e51d).lookup()inscripts/readiness_lookup.py(tracker #242 at1c1b333). I ran the two edge cases above in Python. - Workflow probe. I extracted the new publish step from the YAML and ran it against a fake Supabase client. A matching row: exit 0, one update with all three fields. No matching row: exit 1. A missing-column error (PGRST204): exit 1. Another error: exit 1. The extract step did not change since
1f2c0c1. - Migration claim. The author states that 009 to 012 are applied to production. I cannot check the production database, so I did not verify this. The publish step now depends on it.
- Tests. vitest: 82 passed in 8 files. pytest on
test_compute_impacts_datasets.pyandtest_publish_analysis.py: 37 passed. eslint: 0 errors and 9 warnings, the same as before. The workflow YAML parses. The PR changes no app code, so I did not run a build. - The branch contains main (
cdaec13) and merges cleanly. No CI checks run on this branch. The head wasea9c1e6at the start and at the end of this review.
… band Pavel's review of #241: abs(0.9 - 1) is 0.09999999999999998 in floating point, so a ratio of exactly 0.9 fell in under_10 while 1.1 went to 10_to_25. The gap is now rounded to four places, matching the stored ratio and the contract's rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contract doc follow-ups from the #241 review
From the 2027 sessions on, bill analyses are scored and published through App v3 (Teamverse p301, milestones p451, p453 and p454). This PR fixes the data contract between the bill pipeline and App v3, so the pipeline, App v3 and the CRM build against the same fields.
What changes
docs/APP_V3_BILL_CONTRACT.mdsets out:comparisonsrow format (tier, kind, estimate, ratio, band);/encode-billwill save an App v3 report through the Public API.scripts/sql/010_add_app_v3_bill_fields.sqladds columns, all withADD COLUMN IF NOT EXISTS:research:session_name,session_year,sponsors,introduced_date,bill_text_url,app_report_id,app_report_url,review_pr_url,approved_at;validation_metadata:comparisonsandcalibration_check.It runs after
009from the import PR.publish-bill.ymlnow records the approval when a bill-review PR merges:approved_at(the merge time) andreview_pr_url.010was applied to production on 3 December, so the fallback that published the status alone is gone (after Pavel's review); a missing column is now a real error.publish-bill.ymlsecurity fix. Thispull_request_targetjob holds the Supabase and Modal secrets. It pasted the PR's branch name into a shell script and into Python source, so a branch name containing$(…)could run code with those secrets. The branch name, reform id, PR URL and merge time now reach the scripts only throughenv:, and the reform id must match^[a-z0-9][a-z0-9-]*$.Why copies on
researchApp v3's bill feed reads
researchwithselect=*, so new columns there reach it without an App v3 change. It readsprocessed_billsandvalidation_metadatawith fixed column lists, and naming a column that doesn't exist yet fails the whole read. So/encode-billcopies sponsors, introduced date and bill text link ontoresearch, and App v3 readscomparisonsin a separate query that can fail on its own (policyengine-app-v2#1658).Not in this PR
009and010to the Supabase project./encode-billwriting the new fields. That comes with the switch to scoring through the Public API (p451). Anthony added the machine credential as repo secrets on 3 December; the API accepts it after API v1's next production deploy.Related: the import PR (
009, sponsors and sessions), the readiness lookup PR (calibration_check), and tracker #239 (session-aware ids).🤖 Generated with Claude Code