Skip to content

Read 2027 bills with sponsors, text links and session dates - #243

Merged
DTrim99 merged 5 commits into
mainfrom
import-2027-sessions
Dec 3, 2026
Merged

DTrim99 merged 5 commits into
mainfrom
import-2027-sessions

Conversation

@DTrim99

@DTrim99 DTrim99 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Prefiling for the 2027 sessions has started. This PR makes the OpenStates import ready for it (Teamverse p450). It records what App v3's bill overview needs (sponsors, introduced date, bill text) and keeps each run inside the free tier. It builds on #239's session-aware identity, so it targets that branch.

What changes

  • More per bill. Each OpenStates bill is read with its sponsorships, abstracts, versions and sources. That costs no extra requests, since the extras come with the same page. processed_bills gains:
    • sponsors: primary first, with party, district and chamber;
    • introduced_date;
    • bill_text_url: the latest version's PDF or HTML, else the first source page;
    • the session's start and end dates and classification. These come from /jurisdictions, a request or two per run.
  • Migration. scripts/sql/009_add_bill_intake_metadata.sql adds those columns with ADD COLUMN IF NOT EXISTS. Until it is applied, saves leave the new columns out and print one warning, so the pipeline keeps working.
  • Wider searches. New queries: retirement income, Social Security, property tax credit, renters' credit, working families credit, overtime and tip income. Queries run in priority order, and each search reads at most an even share of the request budget left (1 to 10 pages), so the queries at the end still run. Changes to the relevance filter:
    • An income tax surcharge, a property tax credit claimed on the income tax return, a circuit breaker and a military retirement exclusion are no longer dropped by the property tax, surcharge and military rules.
    • Credits on a vehicle's or home's assessed value ("personal property tax", "real property tax credit") are dropped when the text has no income tax context ("income tax", "circuit breaker", Tax Law 606). New York's real property tax credit, an income tax credit, stays in.
    • Overtime bills pass only as income tax changes ("qualified overtime", "exclude overtime", or overtime with income tax context); labor law overtime bills drop.
  • Free-tier guards.
    • --since sets the discovery window: bills OpenStates created on or after a date, 45 days by default.
    • --max-requests stops a run before the daily quota, 150 by default, and counts retries. The day-3 pipeline uses 120, because the status refresh spends about 100 of the 250 a day.
    • The summary lists the queries the cap skipped or cut short, and those that stopped at their page cap or had a failed page. With --states, the run stops once the budget is used and names the states it didn't search.
  • Dry-run phase. bill-refresh.yml has a new intake_dry_run phase, with since and max_requests. It runs only the import with --dry-run and writes nothing.

First run

Run 46974689650 used this branch with since=2026-11-01 and a 40-request cap. It read sessions for 47 states, which led to the paging fix, and ran all 18 queries. Of its 532 search results (a bill can match more than one query), 523 were out of scope, 1 was already processed, and 8 distinct bills would be saved, each with a sponsor and a text link:

Bill What it does Introduced Sponsor
MT SB 7 Income tax deduction for qualified business income 2026-09-16 Greg Hertz
MT LC 1482 Repeal state tax on Social Security income (draft request) 2026-11-10 —
MO HB 39 Senior citizens property tax relief "circuit breaker" credit 2026-12-01 Steve Jordan
OH HB 1042 Drug markets act with an income tax provision 2026-11-16 Angela N. King
MO SB 72, 270, 367, 413 Property tax credits for disabled veterans 2026-12-01 Mike Jones, Jill Carter

The second commit fixes what this run showed:

  • The four Missouri veterans' credits are local property tax and now drop out.
  • introduced_date keeps only the date part of OpenStates' timestamp.
  • Sessions follow the /jurisdictions pages.

Triage still scores whatever passes this filter, so the filter favors recall.

Checks

  • uv run --with pytest --with requests pytest scripts/test_openstates_monitor.py scripts/test_bill_identity.py: 116 passed after Pavel's review (43 in test_openstates_monitor.py, 73 in test_bill_identity.py). They cover sponsors, text links, sessions and paging, the relevance cases above (income tax context, overtime), the page share, retries counted against the budget, partial queries, the --states stop, and the save fallback before 009.
  • The dry run above, on GitHub Actions with the repository's secrets.

Not in this PR

  • Applying migration 009 to Supabase.
  • Triage v2, which reads the bill text: the next PR for p450.
  • Whether to add LegiScan or move to a paid OpenStates tier. That decision is open, and this PR keeps OpenStates' free tier.

🤖 Generated with Claude Code

DTrim99 and others added 2 commits December 2, 2026 16:28
- Each OpenStates bill is read with its sponsorships, abstracts, versions
  and sources: processed_bills gains sponsors (primary first, with party
  and district), introduced_date, bill_text_url and the session's dates
  and kind, from one /jurisdictions request per run.
- scripts/sql/009_add_bill_intake_metadata.sql adds those columns. Until
  it runs, saves drop them with one warning instead of failing.
- Searches widen to retirement income, Social Security, property tax and
  renters' credits, overtime and tips. Income tax surcharges, property tax
  credits on the income tax return and military retirement exclusions are
  no longer excluded by the property tax, surcharge and military rules.
- A recency window (--since, default 45 days) and a request budget
  (--max-requests) keep a run inside the free tier; the day-3 pipeline
  stops discovery at 120 requests. A new intake_dry_run phase prints what
  the importer would save and writes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… credits

From the first dry run on the 2027 prefiles:
- OpenStates gives first_action_date as a timestamp; introduced_date is a
  date column, so it keeps the date part.
- Sessions came back for 47 states from one /jurisdictions page; the call
  now follows the pages.
- Four Missouri credits on vehicles' and homes' assessed values passed on
  "property tax credit". "personal property tax" and "real property tax
  credit" are now out before the always-relevant phrases; the senior
  circuit breaker and Connecticut's income tax property credit stay in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 8a6568a

This PR prepares the OpenStates import for the 2027 sessions. Each bill now carries its sponsors, introduced date, a bill text link, and the session's start date, end date and classification. Migration 009 adds these columns, and the save drops them with one warning until the migration runs. The PR also adds search queries and relevance rules, a --since discovery window (45 days by default), a --max-requests request cap (120 in the day-3 pipeline), and an intake_dry_run workflow phase. The PR targets the #239 branch (session-aware-bill-identity), so #239 must merge first. #244 (triage v2) is stacked on this branch.

Verdict: REQUEST_CHANGES

SHOULD ADDRESS

1. The new never_relevant rule drops in-scope income tax bills. scripts/openstates_monitor.py:476 and :606

The rule runs before every other rule, on the title, the description and the abstracts together. Any bill whose text contains "real property tax credit" or "personal property tax" is dropped, also when it is an income tax bill. Triage never sees these bills, so it cannot recover them. I ran is_relevant_bill on these titles:

Title Result
Relates to the real property tax credit for qualified taxpayers under section 606 of the tax law False
Increases the real property tax credit (circuit breaker) under the personal income tax False
Income tax; child tax credit; increase; exempts certain personal property tax False
Homeowners' property tax credit; personal income tax; eligibility True

New York's real property tax credit (Tax Law 606(e), form IT-214) is a refundable income tax credit. PolicyEngine models it as ny_real_property_tax_credit. Bills that change it are in scope, but this rule drops all of them. The third row shows that one phrase in a long abstract also drops a child tax credit bill.

Fix: Apply never_relevant only when the text has no income tax context. For example, skip the rule when the text contains "income tax", "tax law 606" or "circuit breaker". Alternatively, match the Missouri pattern more narrowly ("property tax credit for disabled veterans", "assessed value"). Add the first three rows above as test cases that expect True.

SUGGESTION

2. Under peak load, the cap always skips the same queries. scripts/openstates_monitor.py:59-77, :745-748

Each query can read up to 10 pages. 18 queries can thus use 180 requests, but the day-3 cap is 120. In January, many queries will reach several pages. The queries at the end of the list ("SNAP benefits", "EITC", "tip income", "overtime income tax") will then be skipped in each run. With a 45-day window, the bills they alone find can leave the window before a run reaches them. "EITC" overlaps with "earned income tax credit", but "SNAP benefits" is the only SNAP query. Consider one of these:

  • a per-query page cap (for example max_pages = cap // len(queries)), or
  • a start query that rotates per run, or
  • "SNAP benefits" placed earlier in the list.

3. Retries do not count against the budget. scripts/openstates_monitor.py:161

BUDGET.spend() runs once, before the retry loop. One logical request can send up to four HTTP requests (three attempts plus the final attempt) on 429 or 5xx responses. The day-3 total is 100 + 120 = 220 of 250, so many retries can use up the remaining 30. Consider a call to BUDGET.spend() before each HTTP request.

4. The new keywords bypass the exclusion list. scripts/openstates_monitor.py:469-470, :483-490

always_relevant returns True before exclude_keywords runs. Also, "overtime", "income tax credit" and "income tax deduction" now match bills outside household tax. These titles all pass the filter:

  • "Requires overtime compensation for agricultural workers"
  • "Circuit breaker requirements for electrical installations"
  • "Business property tax credit for data centers"
  • "Income tax credit for film production"

The description says that the filter favors recall and that triage removes the noise. That is a valid choice. Consider "overtime income", "overtime compensation; income tax" or "exclude overtime" in place of the bare "overtime", because labor law bills about overtime pay are frequent.

5. Migration 009 has the same number as the migration in #229. scripts/sql/009_add_bill_intake_metadata.sql

#229 adds scripts/sql/009_processed_bills_rls.sql. #241 says "009, then 010", and #244 adds 011. Agree on one order before these PRs merge, and rename one of the two 009 files.

6. Small budget gaps in the --states path. scripts/openstates_monitor.py:228-230, :752-775

When the budget runs out during a query, that query is not added to skipped_queries, so the summary does not show the partial query. With --states, the loop continues through the remaining states. It prints "0 results" and sleeps 6 seconds for each state. Consider a check of BUDGET.exhausted() in the state loop, and a "partial" entry in the summary.

7. The introduced date keeps the date as OpenStates writes it. scripts/openstates_monitor.py:415

[:10] keeps the date part of the offset that OpenStates sends. This is correct for "2026-11-16T05:00:00+00:00" (midnight Eastern). A late-evening local action written in UTC would move to the next day. This is a small risk. A comment can say that the slice expects midnight-local timestamps.

What I checked

  • The PR description, the three commits, and the diff against the #239 branch (merge base 9e70d20). The PR has no comments or reviews. The PR has no CI checks.
  • uv run --with pytest --with requests pytest scripts/test_openstates_monitor.py scripts/test_bill_identity.py: 97 passed. The description says 93; the merge of #239 adds the other 4.
  • ruff check on the changed files: 12 findings at the head, 7 on the base. The new ones are a blind except in fetch_sessions, a datetime.UTC alias, and test style. The repository does not run ruff in CI.
  • A probe of is_relevant_bill with the titles in items 1 and 4. A probe of normalize_bill with a primary sponsor listed second, an undated PDF version, and a timestamp with an offset. Sponsors sort primary first. The latest dated version's link wins. The session dates and classification come through.
  • Sponsor fields against the OpenStates v3 sponsorship shape (person.party, person.current_role.district, org_classification). Session identifiers come from the same field that normalize_bill stores in session_name, so the lookup also matches special sessions.
  • refresh_bill_status.py: one request per bill, so the day-3 total is about 100 + 120 = 220 of 250.
  • The workflow: the intake_dry_run inputs go through env, not into the script text. All other steps use == conditions, so the dry run runs only the import. The federal refresh condition change keeps the dry run from running it.
  • The save fallback: PostgREST returns PGRST204 for an unknown column, and the fallback retries without the six columns. The fallback runs once per run. Other errors still print a warning and return False.
  • Secrets: the API key goes only in the request header. Error messages print the URL and query parameters, which do not contain the key.
  • The overlap with #229 (migration number) and #241 (its 010 migration copies sponsors, introduced_date and bill_text_url into research, so it needs this PR's columns first).

Review fixes for #243:
- The local property tax rule ("personal property tax", "real property
  tax credit") now drops a bill only when nothing in its text puts it on
  the income tax ("income tax", "circuit breaker", Tax Law 606). The
  generic "property tax" exclusion steps aside the same way. New York's
  real property tax credit and a child tax credit bill that mentions a
  personal property tax now pass; the Missouri local credits still drop.
- Bare "overtime" is gone: overtime counts as an income tax exclusion or
  deduction phrase, or next to income tax context. "Film production" is
  excluded, so "income tax credit for film production" drops.
- Each search reads at most an even share of the budget left (1 to 10
  pages), so long queries cannot starve the tail; SNAP benefits runs
  fifth.
- Every HTTP attempt, retries included, spends the budget.
- A query the budget cuts short is listed as partial; the --states loop
  stops once the budget is used instead of printing 0 results and
  sleeping per state. Page-capped and failed queries are listed too.
- Comment on the introduced-date slice; narrow fetch_sessions' except;
  datetime.UTC; test file wrapped to 88 columns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DTrim99

DTrim99 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, Pavel. Commit 72c4ec7 addresses items 1 through 7. Line numbers below refer to that commit.

  1. never_relevant drops income tax bills. Fixed. INCOME_TAX_CONTEXT (scripts/openstates_monitor.py:487) holds "income tax", "circuit breaker" and the Tax Law 606 phrasings. The local property tax pair now drops a bill only when its text has none of those (:693). For the same bills, the generic "property tax" exclusion also steps aside (:703). That second change is needed for your third row, because the older "property tax" exclusion dropped it too. All four of your rows are in test_relevance and expect True (scripts/test_openstates_monitor.py:189-204). test_missouri_local_property_tax_credits_stay_out (:220) checks that a vehicle credit and a homestead credit, with assessed-value abstracts and no income tax, still drop.
  2. The cap skips the same queries. Fixed. Each search now reads at most page_share() pages (:285): the budget left, divided by the searches still to run, from 1 to 10. It is worked out again before each search, so pages a short query leaves unread go to the later ones. At the day-3 cap (120, with one request spent on sessions), every query reads 6 or 7 pages and none is skipped. "SNAP benefits" now runs fifth (:67). I left out the rotating start. With the share in place, the order matters only when the budget is smaller than the number of searches, and a rotation would make runs harder to compare. Tests: :322, :339, :348.
  3. Retries don't count. Fixed. BUDGET.spend() now runs before every HTTP attempt, the final one included (:181, :206). When the budget can't pay for a retry, the retry isn't sent, and the search stops with "budget". Test: :353.
  4. Keywords bypass the exclusions. Bare "overtime" is gone. Overtime now counts only through a tax phrase in OVERTIME_TAX_PHRASES (:500, for example "qualified overtime", "tax on overtime", "overtime income", "exclude overtime", "overtime deduction"), or as "overtime" with income tax context (:711). Both checks run after the exclusions. Your agricultural workers bill now drops, and income tax overtime bills still pass (tests :206-211). I kept "income tax credit" and "income tax deduction" for recall. They run after the exclusions, and I added "film production" there (:588), so your film example drops (:213). "Circuit breaker requirements for electrical installations" and "Business property tax credit for data centers" still pass through always_relevant. I left those to triage, since tax searches rarely return either kind.
  5. Migration 009 shares a number with Add row level security to processed_bills #229. No rename here. 009 through 012 are already applied in production under these file names. Add row level security to processed_bills #229's migration should take the next free number after 012.
  6. Budget gaps in the --states path. Fixed. The search now returns why it stopped (:256, :268, :277). When the budget runs out during a query, run_search_scan records it as partial (:895), and the summary prints it (:982). The --states loop checks the budget before each state and stops, printing the states it didn't search (:864). It no longer sleeps once the budget is used. The summary also lists queries that stopped at their page cap and queries with a failed page. Tests: :382, :398.
  7. Introduced date. Added a comment on the slice. It expects midnight-local timestamps and notes the late-evening case (:459-462).

Lint: fetch_sessions now catches (requests.RequestException, ValueError, BudgetExhausted) (:322), and the module uses datetime.UTC (:49). The test file is wrapped to 88 columns, and its parametrize names are a tuple. I ran ruff check --select E,F,W,UP,B,BLE,PT,SIM. The changed files have 10 findings, all of which are also on the base (the base has 12), and the test file is clean.

Tests: uv run --with pytest --with requests pytest scripts/test_openstates_monitor.py scripts/test_bill_identity.py: 116 passed (43 + 73).

The description is updated to match. #239's review fixes will merge into this branch once they're pushed.

@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 e0cd58b

This PR prepares the OpenStates import for the 2027 sessions. Each bill carries its sponsors, introduced date, bill text link, and session dates. The import also has a --since window, a --max-requests cap, and an intake_dry_run workflow phase. Since the last review (8a6568a), commit 72c4ec7 changes the relevance filter and the request budget. Then e0cd58b merges the current #239 branch (b916ac4) without conflicts. This review covers 72c4ec7 and checks each earlier item.

Verdict: APPROVE

Earlier items

# Item Status
1 never_relevant drops income tax bills (SHOULD ADDRESS) Fixed
2 The cap always skips the same queries Fixed
3 Retries do not count against the budget Fixed
4 New keywords bypass the exclusions Fixed (two examples left to triage, by choice)
5 Migration 009 has the same number as #229 Not fixed here (by choice, see below)
6 Budget gaps in the --states path Fixed
7 Introduced date slice Fixed (comment added)

1. Fixed. scripts/openstates_monitor.py:487, :691-705. never_relevant now drops a bill only when the text has no income tax context. The generic "property tax" exclusion also steps aside for those bills. All four titles from the last review now give True, and they are in test_relevance. The Missouri vehicle and homestead credits still drop (test_missouri_local_property_tax_credits_stay_out). An abstract that says "section 606 of the tax law" also keeps a short-titled bill. See new item A for one remaining case.

2. Fixed. :67, :285. page_share() gives each search an even share of the budget that is left. I simulated 18 queries with 10 pages each, a cap of 120 and one request for the sessions. Each query read 6 or 7 pages, and no query was skipped. "SNAP benefits" now runs fifth.

3. Fixed. :181, :206. BUDGET.spend() now runs before each HTTP attempt. In the simulation, three 429 responses used three more requests, and the later queries got smaller shares. The total stayed at 120. With a cap of 2 and a 429 on page 1, the retry used the last request, and the search stopped with "budget".

4. Fixed. Bare "overtime" is gone. OVERTIME_TAX_PHRASES (:500) and the income tax context now decide it, after the exclusions. "Requires overtime compensation for agricultural workers" and "Overtime pay for nurses; prohibits mandatory overtime" now drop. "Excludes overtime pay from Kentucky income tax" and "No tax on overtime act" pass. "Income tax credit for film production" drops. The electrical "circuit breaker" title and the data center credit still pass. The author leaves these two to triage, which is a valid choice.

5. Not fixed here, by choice. The reply says that 009 to 012 are already applied in production under these file names. Thus #229 must take the next free number (013 or later). #229 still adds 009_processed_bills_rls.sql, and its access.test.js names that file. Please leave a note on #229 so that it renames the file and the constant before it merges.

6. Fixed. :864, :895. The search returns why it stopped. The summary lists skipped, partial, capped and failed queries. I ran --states NY,CA,TX with a cap of 40. The loop stopped in the "renters credit" query and marked it partial. The last four queries were listed as skipped. No sleep ran after the budget was used.

7. Fixed. :459-462. The comment says that the slice expects midnight-local timestamps.

SUGGESTION

A. A New York bill with a short title still drops. scripts/openstates_monitor.py:561, :691

The income tax context comes only from the title, description and abstracts. Many New York bills have a short title, for example "Relates to the real property tax credit". If the abstract does not say "income tax" or name section 606, the bill still drops. I could not confirm how often OpenStates abstracts for New York carry the section number. Consider one of these:

  • Count a New York jurisdiction as income tax context for "real property tax credit".
  • Add a test with a real New York abstract from OpenStates, to show that the 606 phrasings match.

B. The new "film production" exclusion also drops omnibus bills. scripts/openstates_monitor.py:588, :705-708

The exclusions run before all of relevant_keywords, not only before the broad "income tax credit". Thus "film production" now drops these titles, which passed at 8a6568a:

  • "Earned income tax credit; film production workers"
  • "Relating to film production tax credit; income tax credit"

The same applies to an omnibus tax bill whose abstract lists an income tax rate cut and a film production credit. The older "film," exclusion had this effect for some texts, but the new phrase reaches more of them. Consider one of these:

  • Apply "film production" only when the broad keywords ("income tax credit", "income tax deduction") are the only match.
  • Move the specific keywords ("earned income tax credit", "child tax credit", "income tax rate") ahead of the exclusions.

Add one omnibus title as a test that expects True.

What I checked

  • The author's reply, commit 72c4ec7, and the merge e0cd58b. The merge has no conflict changes (git show --remerge-diff is empty). The PR has no CI checks.
  • pytest scripts/test_openstates_monitor.py scripts/test_bill_identity.py on Python 3.11: 129 passed (43 + 86). The reply says 116 at 72c4ec7. The #239 merge adds the other 13. The module now imports datetime.UTC, so it needs Python 3.11 or later. All workflows use 3.11 or 3.12.
  • bunx vitest run: 123 passed in 9 files. bun run build: exit 0.
  • ruff check --select E,F,W,UP,B,BLE,PT,SIM on the two changed files: 10 findings. All 10 are in code that this PR does not change. The test file is clean.
  • A probe of is_relevant_bill with 20 titles at 8a6568a and at e0cd58b, which includes the titles in items 1 and 4 and in new items A and B.
  • A simulation of run_search_scan with a fake OpenStates server: the page share at a cap of 120, 429 retries, the --states path at a cap of 40, and a retry that uses the last request.
  • The open PRs that add migrations: #229 (009), #241 (010), #244 (011), #245 (012). main has 001 to 008.

@DTrim99
DTrim99 changed the base branch from session-aware-bill-identity to main December 3, 2026 21:11
@DTrim99
DTrim99 merged commit 552f256 into main Dec 3, 2026
DTrim99 added a commit that referenced this pull request Dec 4, 2026
Relevance filter follow-ups from the #243 review: NY property tax credit, film credits
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