Repository navigation
Read 2027 bills with sponsors, text links and session dates - #243
Conversation
- 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>
…o import-2027-sessions
PavelMakarchuk
left a comment
There was a problem hiding this comment.
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 checkon the changed files: 12 findings at the head, 7 on the base. The new ones are a blindexceptinfetch_sessions, adatetime.UTCalias, and test style. The repository does not run ruff in CI.- A probe of
is_relevant_billwith the titles in items 1 and 4. A probe ofnormalize_billwith 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 thatnormalize_billstores insession_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_runinputs go throughenv, 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
PGRST204for 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_dateandbill_text_urlintoresearch, 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>
|
Thanks, Pavel. Commit 72c4ec7 addresses items 1 through 7. Line numbers below refer to that commit.
Lint: Tests: The description is updated to match. #239's review fixes will merge into this branch once they're pushed. |
…o import-2027-sessions
PavelMakarchuk
left a comment
There was a problem hiding this comment.
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-diffis empty). The PR has no CI checks. pytest scripts/test_openstates_monitor.py scripts/test_bill_identity.pyon Python 3.11: 129 passed (43 + 86). The reply says 116 at 72c4ec7. The #239 merge adds the other 13. The module now importsdatetime.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,SIMon 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_billwith 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_scanwith a fake OpenStates server: the page share at a cap of 120, 429 retries, the--statespath 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).
mainhas 001 to 008.
Relevance filter follow-ups from the #243 review: NY property tax credit, film credits
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
processed_billsgains: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;/jurisdictions, a request or two per run.scripts/sql/009_add_bill_intake_metadata.sqladds those columns withADD COLUMN IF NOT EXISTS. Until it is applied, saves leave the new columns out and print one warning, so the pipeline keeps working.--sincesets the discovery window: bills OpenStates created on or after a date, 45 days by default.--max-requestsstops 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.--states, the run stops once the budget is used and names the states it didn't search.bill-refresh.ymlhas a newintake_dry_runphase, withsinceandmax_requests. It runs only the import with--dry-runand writes nothing.First run
Run 46974689650 used this branch with
since=2026-11-01and 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:The second commit fixes what this run showed:
introduced_datekeeps only the date part of OpenStates' timestamp./jurisdictionspages.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 intest_openstates_monitor.py, 73 intest_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--statesstop, and the save fallback before 009.Not in this PR
🤖 Generated with Claude Code