Skip to content

Tell bills apart by session, ahead of the 2027 sessions - #239

Merged
DTrim99 merged 8 commits into
mainfrom
session-aware-bill-identity
Dec 3, 2026
Merged

DTrim99 merged 8 commits into
mainfrom
session-aware-bill-identity

Conversation

@DTrim99

@DTrim99 DTrim99 commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

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-derived bill_id, or the same state, normalized number (A05661 = A 5661) and an overlapping session. It reads every session label shape in processed_bills:
    • year labels (2025-2026 Regular Session, 20252026, 2025_26, 2026rs)
    • ordinal legislatures anchored to their years (103rd Legislature is 2025–2026 in Michigan, 222 is 2026–2027 in New Jersey, 57th-2nd-regular is 2026 in Arizona)
    • special sessions, which never match a regular session; Texas called sessions (891 is the 89th Legislature's first called session) match only themselves
    • single-year labels in states whose bills carry over for the whole term (VA, HI, NC, WI). OpenStates files a Virginia 2026 bill "Continued from last session" under 2027, and it keeps its number.
  • openstates_monitor.py:
    • Dedups on that rule.
    • Reads processed bills in bill_id order. The unordered range pages loaded 989 of 1,480 keys on 11/28, which is how duplicate rows got in.
    • Takes the target year from the clock unless TARGET_SESSION_YEAR is set.
  • auto_triage.py: a research row covers a bill by bill_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_CONGRESS still overrides it.
  • Research IDs:
    • Bills from sessions that started before 2027 keep {state}-{bill}. Nothing existing changes.
    • From the 2027 sessions on, IDs are {state}-{bill}-{year}, for example ky-hb1-2027. A Virginia bill continued within its 2026–2027 term keeps va-hb979.
    • /encode-bill, /triage-bills and the db-writer agent now compute the ID with bill_identity.research_id, and set legiscan_bill_id so App v3 links the exact bill.
  • Tracker UI: the bill lookups (home page, activity sidebar, state bill list, stage badges) match a processed bill to research by 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.js mirrors the session-year rules, and a vitest check fails if its tables drift from bill_identity.py. A trailing number counts as a session year only from 2027 to 2099, so co-hb26-1062 stays one Colorado bill.

Checked

  • After Pavel's review: pytest test_bill_identity.py 86, test_auto_triage.py 6 and test_refresh_bill_status.py 8 (100 together, with hypothesis).
  • Against all 1,569 processed_bills rows (read-only pull on 11/30):
    • all 128 same-number pairs are still judged the same bill
    • the 61 rows marked encoded are unchanged, including the three Virginia bills continued into 2027
    • re-checked on 12/3 after the Texas change: all 83 session labels in the table (1,572 rows) read the same years and IDs as before, and all 165 same-state label pairs get the same same-session answer
  • bun run test: 123 passed in 9 files. eslint on the changed files: no errors (the same two warnings as main). bun run build: passes.
  • ruff check on the changed scripts: clean.

Not in this PR

  • The 2027 session calendars in src/data/states.js and the "2026 State Legislative Tracker" title.
  • Per-session triage issues and archiving 2026 bills at sine die.
  • The federal "current" filter in RedesignHome.jsx.
  • Saving 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.
  • App v3's processedBillFor keys rows by state and number. With legiscan_bill_id set on new research rows it links exactly; making its fallback session-aware is a small app-v2 follow-up.

🤖 Generated with Claude Code

DTrim99 and others added 3 commits November 30, 2026 15:01
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>
@DTrim99

DTrim99 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

One more commit, 9e70d20: is_encoded now compares research IDs with leading zeros dropped from the bill number (research_id_key). LegiScan-era processed bills keep the source's padding ("SB00078", "A05661") while their research IDs don't ("ct-sb78"), so on live data it missed 11 analyzed CT, NY and UT bills, which triage would score again. research_id itself is unchanged. Tests: 73 passed.

@PavelMakarchuk PavelMakarchuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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-hb1 for the 2026 KY HB 1. In January 2027, discovery adds the 2027 KY HB 1. researchBillKey("ky-hb1") is KY:HB1, and the processed-bill key of the 2027 row is also KY:HB1. So the 2027 row shows as analyzed, and a click opens the 2026 analysis. StateBillActivity hides the 2027 bill from the unanalyzed list, so a reader cannot request an analysis for it. When both ky-hb1 and ky-hb1-2027 exist, they write the same billToResearchId key, and the last row wins. billMetaByKey has 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_id first, because /encode-bill now sets it. For the fallback, compare parseResearchId(id).sessionYear with 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.
  2. 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_id needs 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_bill catches 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 with bill_identity.

SUGGESTION

  1. 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") gives co-hb26-1062. parseResearchId then reads 1062 as the session year, and researchBillKey gives CO:HB26. I confirmed this with a vitest probe. Two Colorado bills, co-hb26-1062 and co-hb26-1001, get the same key. extractBillNumber shows "HB26" instead of "HB26-1062" when the title is long. Before this PR, the key was CO:HB261062, which also did not match the processed key CO: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-1062 to researchId.test.js.
  2. 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_RE reads 891 as the 891st legislature, so session_years("891", "TX") is {3629, 3630}, and research_id("TX", "HB 1", "891") is tx-hb1-3629. Dedup is still correct, because 891 does not overlap 89.
    • 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.
  3. 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 stubbed openstates_request that 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 main as their base and do not depend on this PR.

What I checked

  • Diff. 1f192d0..9e70d20: 14 files, all read. I read bill_identity.py in full, and the callers in openstates_monitor.py, auto_triage.py, refresh_bill_status.py and congress_monitor.py.
  • Comments. I read the one comment (the leading-zeros commit). The PR has no reviews or inline threads.
  • Schema. processed_bills.bill_id is the integer primary key, so the new order("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_congress at 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_key drops leading zeros (ct-sb00078-2027 to ct-sb78-2027).
  • Tests. pytest scripts/test_bill_identity.py scripts/test_auto_triage.py: 79 passed (73 + 6), with anthropic>=1.9 as in the workflow. An older SDK fails the 6 auto-triage tests on output_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,E9 on 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.

DTrim99 and others added 4 commits December 3, 2026 14:31
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>
@DTrim99

DTrim99 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, Pavel. All five items are addressed in 9d87da5..b916ac4.

Should address

  1. Fixed in this PR (9929474). The UI now matches a processed bill to research by research.legiscan_bill_id = processed_bills.bill_id first. The fallback is a session-aware key: KY:HB1 for a session that started before 2027, KY:HB1:2027 from 2027 on (src/lib/researchId.js:131-228). The processed row's start year comes from sessionStartYear (researchId.js:66-110), a port of bill_identity.session_years.

    • Callers: RecentActivitySidebar (BillActivityFeed.jsx:390-397, :555), StateBillActivity (BillActivityFeed.jsx:1078-1083), and RedesignHome, where researchForBill replaces billToResearchId (RedesignHome.jsx:173-177) and billMeta replaces billMetaByKey (:197-209, :286). StatePanel's stage badge used the same join, so I fixed it too (StatePanel.jsx:101-105, :331-334).
    • useProcessedBills now selects bill_id, session_name (BillActivityFeed.jsx:335), and mapBillItem passes legiscanBillId (DataContext.jsx:175).
    • Tests: your KY HB 1 case is in researchId.test.js:131-179. With only ky-hb1, the 2027 row is unanalyzed. With both IDs, each session opens its own analysis in either row order, and each research item gets its own session's metadata. BillActivityFeed.test.jsx:42-70 renders the same case: StateBillActivity lists the 2027 bill, and the sidebar opens ky-hb1 or ky-hb1-2027. These three tests fail on 9e70d20.
    • researchId.test.js:181-214 fails if the JS session tables drift from bill_identity.py.
  2. Changed (94620f8). 006_add_bill_source.sql:13-22 now indexes (state, bill_number, session_name). The comment says that bill numbers repeat across sessions, that the index catches only exact label matches (bill_identity dedups the rest), and that exact duplicates must be deleted before 006 is applied.

Suggestions

  1. Done (9929474). parseResearchId reads a trailing number as a session year only from 2027 to 2099, the years research_id can produce (researchId.js:113-129). co-hb26-1062 is tested at researchId.test.js:36 and :60-68. Both keys drop dashes, so co-hb26-1062 now also joins its HB26-1062 row. Python has no suffix parser to match (is_encoded builds the ID and compares it). One consequence: the hand-written ga-hb463-2026 keys as it did on main (GA:HB4632026), so it links to its bill only through legiscan_bill_id, as in is_encoded.

  2. Done (9d87da5). Texas {legislature}{n} labels now read as a called session of that legislature: 891 covers 2025-2026 and 901 covers 2027-2028, so research_id("TX", "HB 1", "901") is tx-hb1-2027 (bill_identity.py:60-65, :126-168). same_session matches a called session only with the same called session (:184-187), so 891 stays apart from 89 and 892. Ordinals more than 10 legislatures from the anchor no longer read as legislatures. A distance check alone would leave 901 with no years, and a 2027 called-session HB 1 would then get tx-hb1, the 2025 ID. Tests: test_bill_identity.py:75-83, :115-119, :141-142.

  3. Done (b916ac4). scripts/test_refresh_bill_status.py stubs openstates_request to return a 2026 and a 2027 KY HB 1 with the same title. The tests check that the refresh picks the row's own session in either result order, skips the other session's bill, keeps a Virginia bill continued into 2027, and falls back to title scoring when the row has no session years. With the skip removed, 4 of the 8 tests fail.

Checks:

  • pytest: 100 passed (test_bill_identity.py 86, test_auto_triage.py 6, test_refresh_bill_status.py 8).
  • bun run test: 123 passed.
  • eslint: no errors.
  • bun run build: passes.
  • ruff check: clean.
  • I re-ran the live-data check read-only after the Texas change. All 83 session labels in processed_bills (1,572 rows) read the same years and research IDs as at 9e70d20, and all 165 same-state label pairs get the same same-session answer. So dedup and the encoded rows are unchanged.
  • The anon key can read processed_bills.bill_id and session_name, which the UI now selects.

The description is updated. #243, #244 and #245 will take this branch next.

@PavelMakarchuk PavelMakarchuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. SHOULD ADDRESS 1, the UI join by state and number only: fixed. src/lib/researchId.js:137-230 adds indexBillResearch, findBillResearch, indexProcessedBills and findProcessedValue. RecentActivitySidebar, StateBillActivity, RedesignHome and StatePanel now use them, and useProcessedBills selects bill_id and session_name. With only ky-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 new BillActivityFeed.test.jsx against the 9e70d20 code: all 3 tests fail there, and they pass at b916ac4.
  2. SHOULD ADDRESS 2, the migration 006 index: fixed. scripts/sql/006_add_bill_source.sql:13-22 indexes (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.py upserts on the primary key, congress_monitor.py on bill_id).
  3. SUGGESTION 1, Colorado IDs read as a session year: fixed. parseResearchId accepts a suffix only from 2027 to 2099 (researchId.js:113-129). co-hb26-1062 now keys as CO:HB261062 on both sides, so the Colorado join also works now.
  4. SUGGESTION 2, Texas called sessions gave a far-future year: fixed. 891 reads as 2025-2026, 901 as 2027-2028, and 891 stays apart from 89 and 892 (bill_identity.py:126-168, :184-187). Ordinals more than 10 legislatures from the anchor give no years.
  5. SUGGESTION 3, no test for the refresh session check: fixed. scripts/test_refresh_bill_status.py has 8 tests. I removed the skip at refresh_bill_status.py:247-255 in a copy: 4 of the 8 tests fail, as the reply says.

SUGGESTION

  1. 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-2027 for the 2027 KY regular HB 1. Discovery then adds HB 1 from a 2027 special session (2027S1). research_id("KY", "HB 1", "2027S1") is ky-hb1-2027, so is_encoded returns True and triage does not score the new bill. The UI key is also KY: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 Texas 901 and 2027 First Special Session, which both give tx-hb1-2027.
    • ProcessedBills already 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 Texas 901 label gave tx-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, in research_id and in billKey. Alternatively, list special sessions under "Not in this PR" and open an issue before the first 2027 special session.

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_years with sessionYears in researchId.js for 47 labels in 17 states (799 cases), including Texas called sessions, ordinals, year pairs and special sessions. I also compared processedBillKey with researchBillKey(research_id(...)) for the same cases. There were 0 mismatches.
  • Probes. The 2027 Texas 901 HB 1 is not deduplicated against the 90 HB 1. A Virginia 2026 bill continued under 2027 keeps the unsuffixed key. A row with no session label keys as a pre-2027 bill, as in is_encoded.
  • Tests. pytest scripts/: 110 passed (86 test_bill_identity.py, 6 test_auto_triage.py, 8 test_refresh_bill_status.py, 10 test_compute_impacts_datasets.py), with anthropic>=1.9 and hypothesis. 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,E9 on 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_id is set on live rows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants