Repository navigation
Tell bills apart by session, ahead of the 2027 sessions - #239
Conversation
Bill numbers repeat every session, but discovery, triage and the status
refresh identified a bill by state and number alone, so a 2027 HB 1 would
be skipped as the 2026 HB 1 it shares a number with.
- bill_identity.py: one shared definition of when two rows are the same
bill (OpenStates-derived bill_id, or state + normalized number + an
overlapping session), reading every session label shape in the table:
year labels, ordinal legislatures anchored to their years, special
sessions, and Virginia-style terms where bills carry over between
single-year labels.
- openstates_monitor: dedup on that rule, read processed bills in bill_id
order (unordered range pages loaded 989 of 1,480 keys on 11/28), and
take the target year from the clock unless TARGET_SESSION_YEAR is set.
- auto_triage: a research row covers a bill by bill_id or by the bill's
session-aware research ID ("ky-hb1" for 2026, "ky-hb1-2027" for 2027).
- refresh_bill_status: skip OpenStates matches from a different session.
- congress_monitor: compute the sitting Congress (120th from 2027-01-03).
Checked against all 1,569 processed_bills rows: the 128 same-number
pairs are still judged the same bill, and the 61 rows marked encoded are
unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Encode under bill_identity.research_id and set legiscan_bill_id, so App v3 and triage link a research row to that exact bill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From 2027, research IDs end in the session's first year ("ky-hb1-2027").
The bill lookups joined every ID part, so such an ID would key as
"KY:HB12027" and miss its bill. One helper now strips the year, as App v3
already does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LegiScan-era processed bills keep the source's padding ("SB00078",
"A05661"), while research IDs were written without it ("ct-sb78"), so
is_encoded missed 11 analyzed bills (CT, NY, UT) on live data: triage
would score them again and auto-encoding would encode them again.
is_encoded now also compares research IDs with leading zeros dropped from
the bill number (research_id_key). research_id itself is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
One more commit, 9e70d20: |
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at 9e70d20
This PR makes bill identity session-aware before the 2027 sessions open. A new module, scripts/bill_identity.py, reads session labels into years and decides when two processed_bills rows are the same bill. Discovery, auto-triage and the status refresh now use that rule. Research IDs from the 2027 sessions on get a year suffix (ky-hb1-2027), and older IDs do not change. The tracker UI strips the suffix when it builds its bill lookup keys. The PR has no database migration and changes no stored row.
Verdict: REQUEST_CHANGES
Thanks, David. The Python side is careful and well tested, and the live-data check in the description is useful. Two items need a change or a clear decision before the 2027 sessions open.
SHOULD ADDRESS
-
The tracker UI still joins bills to research by state and number only.
src/components/RedesignHome.jsx:168-170,src/components/RedesignHome.jsx:214,src/components/BillActivityFeed.jsx:394-397,src/components/BillActivityFeed.jsx:408,src/components/BillActivityFeed.jsx:1098-1108.- Case: research has
ky-hb1for the 2026 KY HB 1. In January 2027, discovery adds the 2027 KY HB 1.researchBillKey("ky-hb1")isKY:HB1, and the processed-bill key of the 2027 row is alsoKY:HB1. So the 2027 row shows as analyzed, and a click opens the 2026 analysis.StateBillActivityhides the 2027 bill from the unanalyzed list, so a reader cannot request an analysis for it. When bothky-hb1andky-hb1-2027exist, they write the samebillToResearchIdkey, and the last row wins.billMetaByKeyhas the same problem, so a research item can get the year of the other session's bill. - The Python side now tells these bills apart, but the UI in this repository does not. The "Not in this PR" list names the App v3 fallback, but not these tracker components.
- Fix: match a processed bill to research by
research.legiscan_bill_idfirst, because/encode-billnow sets it. For the fallback, compareparseResearchId(id).sessionYearwith the session start year of the processed row (no suffix means a session that started before 2027). A follow-up PR before January is acceptable if the description lists it.
- Case: research has
-
Migration 006 still adds a unique index on
(state, bill_number).scripts/sql/006_add_bill_source.sql:13-15.- Case: the description says 006 looks unapplied, and that saving
source_idneeds it. If a later change applies 006 as written, the index creation fails on the 128 same-number pairs. If someone first removes those pairs, the index then blocks every 2027 bill whose number exists in 2026.save_processed_billcatches the error and prints only a warning, so the monitor drops the 2027 bills without a failure. - Fix: change 006 so that it adds only the two columns, or make the index
(state, bill_number, session_name)with a comment that bill numbers repeat across sessions. Alternatively, add a note in 006 that the index conflicts withbill_identity.
- Case: the description says 006 looks unapplied, and that saving
SUGGESTION
-
A research ID whose bill part ends in four digits after a dash reads as a session year.
src/lib/researchId.js:16-17.- Case: Colorado bill numbers on OpenStates have the form
HB26-1062.research_id("CO", "HB26-1062", "2026A")givesco-hb26-1062.parseResearchIdthen reads1062as the session year, andresearchBillKeygivesCO:HB26. I confirmed this with a vitest probe. Two Colorado bills,co-hb26-1062andco-hb26-1001, get the same key.extractBillNumbershows "HB26" instead of "HB26-1062" when the title is long. Before this PR, the key wasCO:HB261062, which also did not match the processed keyCO:HB26-1062, so the join was already broken for these IDs. - Fix: accept the last part as a year only in a plausible range, for example 2000 to 2099. Add
co-hb26-1062toresearchId.test.js.
- Case: Colorado bill numbers on OpenStates have the form
-
Texas called-session labels give a far-future year.
scripts/bill_identity.py:107-112.- Case: OpenStates labels Texas called sessions as
891,892._ORDINAL_REreads891as the 891st legislature, sosession_years("891", "TX")is{3629, 3630}, andresearch_id("TX", "HB 1", "891")istx-hb1-3629. Dedup is still correct, because891does not overlap89. - Fix: accept an ordinal only within a small distance of the anchor (for example 10), or read the Texas
{ordinal}{n}form as a special session of that legislature.
- Case: OpenStates labels Texas called sessions as
-
Add one test for the session check in the status refresh.
scripts/refresh_bill_status.py:247-255. The new skip has no test. A test with a stubbedopenstates_requestthat returns a 2026 and a 2027 result for the same number would lock in the rule.
Dependencies
- #243 uses this branch (
session-aware-bill-identity) as its base, and #244 uses #243's branch. Merge this PR first. - #241, #242 and policyengine-app-v2#1646 use
mainas their base and do not depend on this PR.
What I checked
- Diff.
1f192d0..9e70d20: 14 files, all read. I readbill_identity.pyin full, and the callers inopenstates_monitor.py,auto_triage.py,refresh_bill_status.pyandcongress_monitor.py. - Comments. I read the one comment (the leading-zeros commit). The PR has no reviews or inline threads.
- Schema.
processed_bills.bill_idis the integer primary key, so the neworder("bill_id")paging is stable. The PR changes no table. Migration 006 is discussed above. - Identity rule. I checked the session-year rules for the carry-over states (VA, HI, NC, WI). Their bill numbers continue within the two-year term, so the widened years are correct. I checked
current_congressat January 2 and January 3 of 2025 and 2027. - Probes (Python). A 2026 KY HB 1 research row does not cover the 2027 bill. A 2027 KY HB 1 is not deduplicated against the 2026 row. A legacy row with an empty session label does not deduplicate a new row with the same number, as the docstring says.
research_id_keydrops leading zeros (ct-sb00078-2027toct-sb78-2027). - Tests.
pytest scripts/test_bill_identity.py scripts/test_auto_triage.py: 79 passed (73 + 6), withanthropic>=1.9as in the workflow. An older SDK fails the 6 auto-triage tests onoutput_config, which is not related to this PR.bun run test(vitest): 79 passed in 8 files. eslint on the changed JS files: 0 errors, 2 warnings that are already on main.bun run build: passes. - Lint.
ruff --select F,E9on the changed scripts: 5 findings, all on main too (main has 6). - CI. The repository has no workflow that runs on pull requests.
- Not checked. I did not read the live Supabase tables or call OpenStates. The Colorado and Texas label formats come from OpenStates conventions, not from rows in this database.
OpenStates labels Texas called sessions "891", "892": the 89th Legislature's first and second called sessions. session_years read "891" as the 891st legislature, so a bill got the research ID "tx-hb1-3629". It now reads the form as a called session of that legislature (years 2025-2026), and same_session matches a called session only with itself, so "891" stays apart from "89" and "892". Ordinals further than 10 legislatures from a state's anchor no longer read as legislatures at all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tracker UI joined processed bills to research by state and number, so in January 2027 the new KY HB 1 would show as analyzed and open the 2026 analysis, and StateBillActivity would hide it from the unanalyzed list. The lookups in RecentActivitySidebar, StateBillActivity, RedesignHome (billToResearchId, billMetaByKey) and StatePanel's stage badge now match by research.legiscan_bill_id first, then by a session-aware key: the research ID's year suffix against the processed row's session start year, read as bill_identity.py reads it. processed_bills reads now include bill_id and session_name. parseResearchId reads a trailing number as a session year only from 2027 to 2099, so Colorado's "co-hb26-1062" keeps its number. A vitest check fails if the session tables drift from bill_identity.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bill numbers repeat across sessions, so a unique index on (state, bill_number) would reject every 2027 bill whose number exists in 2026, and save_processed_bill only warns. The index now covers (state, bill_number, session_name). 006 is not applied in production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stubbed OpenStates search returns a 2026 and a 2027 KY HB 1 with the same title; the refresh must pick the bill from the row's session in either order, skip a reused number from another session, keep a Virginia bill continued within its term, and keep title scoring for rows without session years. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Pavel. All five items are addressed in 9d87da5..b916ac4. Should address
Suggestions
Checks:
The description is updated. #243, #244 and #245 will take this branch next. |
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at b916ac4
This PR makes bill identity session-aware before the 2027 sessions open. scripts/bill_identity.py reads session labels into years and decides when two processed_bills rows are the same bill. Discovery, auto-triage and the status refresh use that rule, and research IDs from the 2027 sessions on get a year suffix (ky-hb1-2027). Since the last review, the tracker UI joins processed bills to research by research.legiscan_bill_id first, then by a session-aware key. Migration 006 now indexes by session, and Texas called-session labels read as sessions of their legislature.
Verdict: APPROVE
Thanks, David. All five items from the review at 9e70d20 are fixed, and each fix has a test that fails without it. I found one new point, a suggestion about special sessions.
Earlier items
- SHOULD ADDRESS 1, the UI join by state and number only: fixed.
src/lib/researchId.js:137-230addsindexBillResearch,findBillResearch,indexProcessedBillsandfindProcessedValue.RecentActivitySidebar,StateBillActivity,RedesignHomeandStatePanelnow use them, anduseProcessedBillsselectsbill_idandsession_name. With onlyky-hb1, the 2027 KY HB 1 is unanalyzed and shows in the request list. With both IDs, each session opens its own analysis in either row order. I ran the newBillActivityFeed.test.jsxagainst the 9e70d20 code: all 3 tests fail there, and they pass at b916ac4. - SHOULD ADDRESS 2, the migration 006 index: fixed.
scripts/sql/006_add_bill_source.sql:13-22indexes(state, bill_number, session_name). The comment states that numbers repeat across sessions, that the index catches only exact label matches, and that exact duplicates must be deleted first. No script upserts on this index (openstates_monitor.pyupserts on the primary key,congress_monitor.pyonbill_id). - SUGGESTION 1, Colorado IDs read as a session year: fixed.
parseResearchIdaccepts a suffix only from 2027 to 2099 (researchId.js:113-129).co-hb26-1062now keys asCO:HB261062on both sides, so the Colorado join also works now. - SUGGESTION 2, Texas called sessions gave a far-future year: fixed.
891reads as 2025-2026,901as 2027-2028, and891stays apart from89and892(bill_identity.py:126-168,:184-187). Ordinals more than 10 legislatures from the anchor give no years. - SUGGESTION 3, no test for the refresh session check: fixed.
scripts/test_refresh_bill_status.pyhas 8 tests. I removed the skip atrefresh_bill_status.py:247-255in a copy: 4 of the 8 tests fail, as the reply says.
SUGGESTION
- A special-session bill from 2027 on gets the same research ID as the regular-session bill with its number.
scripts/bill_identity.py:206-218,scripts/bill_identity.py:229-241,src/lib/researchId.js:155-158,src/lib/researchId.js:187-194.- Case: research has
ky-hb1-2027for the 2027 KY regular HB 1. Discovery then adds HB 1 from a 2027 special session (2027S1).research_id("KY", "HB 1", "2027S1")isky-hb1-2027, sois_encodedreturns True and triage does not score the new bill. The UI key is alsoKY:HB1:2027, so the special-session bill shows as analyzed and opens the regular-session analysis. I confirmed both with a probe. The same applies to Texas901and2027 First Special Session, which both givetx-hb1-2027. ProcessedBillsalready keeps these bills apart (a special session never matches a regular one), so only the research ID and the UI key merge them. Before 9d87da5, the Texas901label gavetx-hb1-3629, which was wrong but did not collide. The general special-session case was already in the PR at 9e70d20, and I did not raise it then.- Fix: add a special-session marker to the suffix from 2027 on, for example
ky-hb1-2027s1, inresearch_idand inbillKey. Alternatively, list special sessions under "Not in this PR" and open an issue before the first 2027 special session.
- Case: research has
Dependencies
- #243 uses this branch as its base, and #244 uses #243's branch. Merge this PR first. The new commits do not change any interface that those PRs call.
- The branch merges cleanly with the current
main(cdaec13).
What I checked
- Diff.
9e70d20..b916ac4: 4 commits, 11 files, all read. - Comments. I read the reply of December 3 at 2:34pm EST, which answers each item. No other reviews or inline threads were added.
- Parity probe. I compared
bill_identity.session_yearswithsessionYearsinresearchId.jsfor 47 labels in 17 states (799 cases), including Texas called sessions, ordinals, year pairs and special sessions. I also comparedprocessedBillKeywithresearchBillKey(research_id(...))for the same cases. There were 0 mismatches. - Probes. The 2027 Texas
901HB 1 is not deduplicated against the90HB 1. A Virginia 2026 bill continued under2027keeps the unsuffixed key. A row with no session label keys as a pre-2027 bill, as inis_encoded. - Tests.
pytest scripts/: 110 passed (86test_bill_identity.py, 6test_auto_triage.py, 8test_refresh_bill_status.py, 10test_compute_impacts_datasets.py), withanthropic>=1.9andhypothesis.bun run test(vitest): 123 passed in 9 files.bun run build: passes. - Lint. eslint on the changed JS files: 0 errors, 2 warnings that are already on main.
ruff --select F,E9on the changed scripts: the same 5 findings as at 9e70d20, all already on main. The new files have no findings. - CI. The repository has no workflow that runs on pull requests.
- Not checked. I did not read the live Supabase tables or call OpenStates. I did not check how often
research.legiscan_bill_idis set on live rows.
Summary
Bill numbers repeat every session, but the tracker identified a bill by state and number alone. Once the 2027 sessions open, a new 2027 HB 1 would be skipped by discovery as the 2026 HB 1, hidden from triage as already encoded, and its status could be refreshed from the wrong bill. This PR makes bill identity session-aware without a database migration.
What changes
scripts/bill_identity.py(new): one shared rule for when two rows are the same bill. They must share the OpenStates-derivedbill_id, or the same state, normalized number (A05661=A 5661) and an overlapping session. It reads every session label shape inprocessed_bills:2025-2026 Regular Session,20252026,2025_26,2026rs)103rd Legislatureis 2025–2026 in Michigan,222is 2026–2027 in New Jersey,57th-2nd-regularis 2026 in Arizona)891is the 89th Legislature's first called session) match only themselves2027, and it keeps its number.openstates_monitor.py:bill_idorder. The unordered range pages loaded 989 of 1,480 keys on 11/28, which is how duplicate rows got in.TARGET_SESSION_YEARis set.auto_triage.py: a research row covers a bill bybill_id, or by the bill's session-aware research ID.refresh_bill_status.py: skips OpenStates matches from a different session.congress_monitor.py: computes the sitting Congress (120th from noon January 3, 2027) instead of hardcoding 119.DISCOVERY_CURRENT_CONGRESSstill overrides it.{state}-{bill}. Nothing existing changes.{state}-{bill}-{year}, for exampleky-hb1-2027. A Virginia bill continued within its 2026–2027 term keepsva-hb979./encode-bill,/triage-billsand the db-writer agent now compute the ID withbill_identity.research_id, and setlegiscan_bill_idso App v3 links the exact bill.legiscan_bill_id, then by number and session: the research ID's year suffix against the row's session start year. So a 2026 analysis never covers the 2027 bill with the same number.src/lib/researchId.jsmirrors the session-year rules, and a vitest check fails if its tables drift frombill_identity.py. A trailing number counts as a session year only from 2027 to 2099, soco-hb26-1062stays one Colorado bill.Checked
test_bill_identity.py86,test_auto_triage.py6 andtest_refresh_bill_status.py8 (100 together, withhypothesis).processed_billsrows (read-only pull on 11/30):bun run test: 123 passed in 9 files.eslinton the changed files: no errors (the same two warnings as main).bun run build: passes.ruff checkon the changed scripts: clean.Not in this PR
src/data/states.jsand the "2026 State Legislative Tracker" title.RedesignHome.jsx.source_id. The column isn't in the live table, so migration 006 looks unapplied. Its unique index is now on(state, bill_number, session_name); delete exact duplicate rows before applying it.processedBillForkeys rows by state and number. Withlegiscan_bill_idset on new research rows it links exactly; making its fallback session-aware is a small app-v2 follow-up.🤖 Generated with Claude Code