Skip to content

Triage v2: score from the bill text and the parameter list, add a priority score - #244

Merged
DTrim99 merged 7 commits into
mainfrom
triage-v2
Dec 4, 2026
Merged

DTrim99 merged 7 commits into
mainfrom
triage-v2

Conversation

@DTrim99

@DTrim99 DTrim99 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Triage decides which introduced bills get analyzed. Before the 2027 sessions, this PR replaces its two diverging paths with one scoring function that reads the bill and checks the model's actual parameters, and adds a priority score (Teamverse p450). It targets #243, whose import supplies the bill text links and sponsors.

What changes

  • One scoring path (scripts/triage_core.py), used by the daily pipeline and by /triage-bills.

  • Two scores for each bill:

    • Modelability, 0–100, on the v1 rubric.

    • Priority, 0–100:

      • breadth (broad, targeted or niche) and fiscal size, both read by the model from the text;
      • stage, from the status label the status refresh writes (STAGE_LABELS; 0 for a dead or vetoed bill);
      • 5 points each for bipartisan sponsors (Minnesota's DFL and North Dakota's Democratic-NPL count as Democratic), a companion bill from the other chamber among all of the state's processed bills, and ten or more sponsors.

      The weights are documented, and the backtest below tests them. The stored score is the score on triage day. The state issues recompute it from the stored signals with each bill's current status and companions, so a bill that passes a chamber moves up, and an earlier bill gets its companion points when the later one arrives.

  • It reads the bill. The text comes from the import's bill_text_url, as PDF or HTML.

    • A bill longer than 40,000 characters is sent as an excerpt, and the score records that (triage_text_truncated).
    • Downloads stop at 10 MB; a larger PDF falls back to the summary. PDF pages stop once the excerpt is in hand.
    • An HTML page with no enacting clause or first section, such as a bill's landing page, is not used as text.
    • The bill goes to the model inside <bill>/<bill_text> delimiters, and the system prompt says it is data, not instructions.
    • Without a usable text, the model works from the title and summary, and the score records that too.
  • It checks the parameters. Each state's list comes from the installed policyengine-us package, which pip install --no-deps policyengine-us provides; the model is never imported.

    • The list covers every parameter, scale and breakdown, with descriptions, for the state and its local governments (gov/local): 85 for Georgia, 276 for New York (with New York City, Yonkers and the MCTD), and 380 for California. The federal list (IRS, all of USDA, SSA, HHS, ACA, HUD and Education) has 987, on policyengine-us 2.165.4. triage_version records the release, e.g. v2-2026-12+policyengine-us-2.165.4.
    • The model names the parameters a bill would change. A bracket of a listed scale or a category of a listed breakdown counts; any other name is dropped.
    • A score of 80 or more with no listed parameter left is capped at 79 (structural).
    • v1 tried api.policyengine.org/us/metadata, which has required a credential since 17 November, so it fell back to the model's memory.
  • The request.

    • It uses Claude Sonnet 5.5 (the model Move automated bill triage to Claude Sonnet 5.5 #222 chose; TRIAGE_MODEL overrides it), with structured outputs and the server-side refusal fallback (fallbacks: "default").
    • The system prompt and each state's list are the cached prefix, and bills run grouped by state, so a state's list is billed in full once.
    • triage_model stores the model that answered (response.model), so a server-side fallback is visible.
  • auto_triage.py gains new options:

    • --state limits the run to one state.
    • --propose FILE scores and writes the proposals to a file, saving nothing.
    • --apply FILE saves approved proposals, after a person has dropped or edited them.
    • --no-text scores from the title and summary only.
    • --retriage-changed rescores scored bills that have a new text version. The status refresh (refresh_bill_status.py) now reads each bill's versions in its one OpenStates request and moves bill_text_url to the latest version. Triage compares that link with the one the score was based on (priority_signals.text_url) before it fetches any text, and reads at most 30 texts a run. A text that changes at the same link is not detected.

    The per-state issues add a Priority column and order each band by current priority. If migration 011 is missing, the selects keep the 009 columns (sponsors and text links). If 009 is missing too, they fall back to the base columns. Each fallback prints what the run loses.

  • Bands, set from the backtest below and agreed on 2 December:

    • Encode automatically: modelability 80 or more. /encode-bill will run headless (p452), highest priority first, under a daily cap.
    • Needs a person: 60–79 with priority 50 or more.
    • Hold: everything else from 20 up.
    • Not modelable: below 20.

    triage_band holds the rule, and the state issues list the bands in that order, each by current priority. The day-3 pipeline also re-triages up to 30 bills with a new text version (30-minute step timeout).

  • Local runs can score through the Claude Code CLI (--via claude-code), so they use the local Claude Code login and need no API key. Bill reads now page past Supabase's 1,000-row limit; the unscored-bill query used to stop there.

  • /triage-bills now runs --propose, shows the table for approval, then --apply, so the interactive and daily scores are the same scores.

  • Migration. scripts/sql/011_add_triage_v2_fields.sql adds priority_score, priority_signals, candidate_parameters, triage_version, triage_model, triage_text_source, triage_text_truncated, bill_text_sha256 and triaged_at; priority_signals also holds text_url, the link the score read. Until it runs, saves keep the v1 columns and print one warning. Migrations 009 and 011 were applied in production on 3 December.

  • Workflows. Both install pyyaml, pypdf and policyengine-us --no-deps. Their manual inputs now reach the shell through env:. The status refresh steps also read versions, with no extra requests.

Backtest

scripts/triage_backtest.py re-scores every analyzed 2026 bill and a sample of the rest, then reports AUC and weighted precision and recall for v1's score and v2's modelability and priority, at several thresholds. That sets the bar for automatic encoding (p452).

  • The label is a proxy: a bill counts as analyzed if it has a research row, which reflects past choices as much as merit.
  • No bill text by default: most 2026 rows have no text link, and reading text for only some bills would bias the comparison.

triage.yml runs it with backtest_sample set and uploads the results as an artifact. Locally, --via claude-code runs it through the Claude Code CLI (claude -p) on the local login, and --workers 4 speeds it up.

First run (2 December, summaries only)

All 46 analyzed bills and 150 of the other 1,341 scored bills ran, with no errors. Claude Sonnet 5.5 ran through claude -p. Each sampled bill stands for 8.94, so the "flagged" counts are out of 1,387 scored bills.

Score AUC
v1 score 0.89
v2 modelability 0.90
v2 priority 0.84
Bar v1 flagged v1 precision v1 recall v2 flagged v2 precision v2 recall
60 428 10% 96% 329 13% 94%
70 287 13% 80% 182 16% 65%
80 240 14% 74% 102 21% 46%
90 96 17% 35% 17 47% 17%

v2 separates analyzed from unanalyzed bills as well as v1 does, but it is much stricter at the top.

  • Below 80: 25 analyzed bills scored under 80. None was cut by the 79 cap. Most were rate changes or credits whose details the summary doesn't give, so the model hedged at 65–78 ("judged from the title and summary only"). With the bill text, which production triage reads, these should score higher, so v2's recall at 80 is understated here.
  • At 80 or more, not analyzed: of the sampled unanalyzed bills, 9 scored 80 or more. They include rate cuts in GA, MA, RI and UT, a Hawaii EITC match and a Minnesota CTC threshold. These are bills a tracker might well have wanted.
  • Priority reaches an AUC of 0.84 on its own. At the 80 bar it barely changes what passes (102 → 100 at priority 40). At 60–79 it matters: modelability 60+ and priority 50+ flags 185, with 72% recall.
  • Stage bias (after Pavel's review). Those priority figures used each bill's end-of-session stage, and analyzed bills more often advanced. Holding every bill at "Introduced", as triage sees it, gives a priority AUC of 0.83 and, at modelability 60+ and priority 50+, 182 flagged with 65% recall (60+ and 40+: 302 flagged, 93% recall). I recomputed this from the saved scores and each bill's status, without new model calls; the same method reproduces the 0.84. The backtest script now reports both (v2_priority with the stage held at introduction, v2_priority_end_stage).

The label is past choices, there are only 46 positives, and this run read summaries only, so treat the numbers as a guide.

Checks

  • uv run --python 3.11 --with "anthropic>=1.9" --with pytest --with pyyaml --with pypdf --with requests --with hypothesis pytest on test_triage_core.py, test_auto_triage.py, test_triage_backtest.py, test_openstates_monitor.py, test_bill_identity.py, test_refresh_bill_text.py and test_refresh_bill_status.py: 216 passed after Pavel's review, with Read 2027 bills with sponsors, text links and session dates #243 and Tell bills apart by session, ahead of the 2027 sessions #239's fixes merged.
    • Added after the review: the version link in the status refresh, re-triage on a changed link and its fetch cap, companions across runs, current priority, stage labels, party prefixes, the two-step fallback, delimited text, response.model, the download cap and PDF page stop, and landing pages.
    • The request tests use the real SDK against a mock transport. They check that Sonnet 5.5 accepts the request, the cached prefix, the structured-output schema and the fallback setting, and that refusals and truncation are handled.
    • Other tests cover the parameter walk: nested parameters, scales, breakdowns, placeholder dates and index files.
    • They also cover the priority signals, the save fallback before 011, propose and apply, the issue ordering, and the backtest metrics.
  • The parameter lists above were built from a real --no-deps install. Every Georgia and New York parameter file yields its parameters.
  • ruff check on the new and changed scripts: clean.

Not in this PR

  • Choosing the threshold (the backtest above informs it).
  • Automatic encoding above the threshold (p452).
  • A full re-run of the backtest with bill text, now that production triage reads it.

🤖 Generated with Claude Code

DTrim99 and others added 2 commits December 2, 2026 17:03
…ority score

- scripts/triage_core.py is the one scoring path for /triage-bills and the
  daily pipeline. Each bill gets modelability (the v1 rubric) and a priority
  score (breadth and fiscal size from the model, plus stage, bipartisan
  sponsors, a companion bill and ten or more sponsors).
- The model reads the bill text (PDF or HTML from the import's
  bill_text_url; long bills as a marked excerpt) and the state's parameter
  list from the installed policyengine-us package: every parameter, scale
  and breakdown, read without importing the model. It names the parameters
  a bill would change; names not in the list are dropped, and a parametric
  score with none left is capped at 79.
- Structured outputs on Claude Sonnet 5.5 (the model #222 chose) with the
  server-side refusal fallback; the system prompt and each state's list are
  the cached prefix, and bills run grouped by state.
- auto_triage.py gains --state, --propose/--apply (the review round trip
  /triage-bills now uses), --no-text and --retriage-changed (rescore when a
  bill's text hash changes). Issue tables add a Priority column.
- scripts/sql/011_add_triage_v2_fields.sql adds the priority and provenance
  columns; until it runs, saves keep the v1 columns with one warning.
- scripts/triage_backtest.py measures v1 and v2 against which 2026 bills
  were analyzed; triage.yml runs it with backtest_sample and uploads the
  results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- triage_core.ClaudeCodeClient runs `claude -p` with the same system
  prompt, JSON schema and model (no tools, no saved session), so local
  runs use the Claude Code login (such as a Claude Max subscription)
  instead of an API key. auto_triage.py and triage_backtest.py take
  --via claude-code; the backtest also takes --workers. GitHub Actions
  keeps the API.
- Bill reads followed one 1,000-row page: the backtest saw 1,000 of the
  1,387 scored bills, and the unscored-bill query had the same cap.
  select_bills now pages by bill_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DTrim99
DTrim99 marked this pull request as ready for review December 3, 2026 03:08
- triage_band: modelability 80+ is encoded automatically (p452), 60-79
  with priority 50+ goes to a person, the rest from 20 up is held, and
  below 20 is not modelable. The constants record the backtest behind
  them (80+ flagged about 7% of scored bills, one in five analyzed in
  2026; 60-79 with priority 50+ lifts recall to about 72%).
- The state issues list the three bands, each by priority.
- The day-3 pipeline re-triages up to 30 bills whose text changed.
- /triage-bills documents the bands.

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 a496711

This PR replaces the two triage paths with one scoring module (scripts/triage_core.py). The module reads the bill text, gives the model the state's parameter list from the installed policyengine-us package, and keeps only listed parameter names. It caps a parametric score at 79 when no listed parameter is left. It adds a priority score (breadth, fiscal size, stage, sponsors, companion bill), the triage bands, propose/apply for /triage-bills, re-triage on a text change, a backtest script, and migration 011. The base branch is import-2027-sessions (#243, which sits on #239). The PR needs the #243 import fields (sponsors, bill_text_url, migration 009). #245 (auto-encode) builds on this branch and reads the bands. I found no file overlap with #241, #242 or #246, and no overlap with the recent change on main (#240).

The scoring core is solid. The parameter walk gives the same counts as the description on policyengine-us 2.165.3 (GA 85, NY 235, federal 858). Bracket and breakdown paths resolve correctly. The request and the refusal and truncation handling are tested against the real SDK. My items are about the priority signals and the re-triage path.

Verdict: REQUEST_CHANGES

SHOULD ADDRESS

1. --retriage-changed does not see a new bill version in most states. (scripts/auto_triage.py:107-132, .github/workflows/bill-refresh.yml re-triage step)

  • bill_text_url is written one time, at import. Discovery skips bills that are already processed. refresh_bill_status.py updates only status, last_action and last_action_date.
  • Most legislatures publish a new version (a committee substitute, an engrossed version) at a new URL. The stored URL continues to point to the introduced text, so its hash does not change, and the bill is never re-scored.
  • Also, the scan fetches the text of every scored, unencoded bill on each day-3 run until it finds 30 changes. When few texts change, that is one legislature request and one PDF parse for each bill, every third day, with no time limit on the job.
  • Concrete case: GA HB 10 is introduced, then a committee substitute is posted at a new LC number URL. Triage keeps the introduced score.
  • Fix: refresh bill_text_url from the latest OpenStates version when the status refresh runs (here or in #243), and compare URLs before the text is fetched. Alternatively, change the description and the workflow comment so that they say only same-URL changes are found. Put a limit on how many texts one run fetches.

2. The companion-bill signal only sees bills in the same run. (scripts/auto_triage.py:152, scripts/triage_core.py:351-373)

  • score_bills passes others=bills, which is the batch of unscored bills (or the changed bills, or the --state/--limit subset).
  • Triage runs every three days. If the House bill arrives in one run and the Senate companion arrives in a later run, neither bill gets the 5 points. The first bill is already scored, and the second bill's batch does not contain it.
  • Probe: priority_signals(SB 5, [HB 10, SB 5]) finds HB 10. priority_signals(SB 5, [SB 5]) finds nothing.
  • Fix: pass the titles, numbers and sessions of all processed bills in the state (select_bills already pages through them). Also give the earlier bill its point when the later bill arrives, or compute the signal when the issue is built.

3. The bipartisan check misses Minnesota and North Dakota. (scripts/triage_core.py:378-387)

  • The party key is the first word of the OpenStates party, lowercased. For "Democratic-Farmer-Labor" (MN) and "Democratic-NPL" (ND), the key is the whole hyphenated string. It never equals "democratic".
  • Probe: DFL + Republican sponsors give bipartisan: False. Democratic + Republican give True.
  • MN is one of the states with the most analyzed bills. The 5 points can move a bill across the priority-50 line of the "needs a person" band.
  • Fix: normalize the party with a prefix test (startswith("democrat"), startswith("republican")) and add tests for the DFL and NPL strings.

SUGGESTION

4. Stage points do not follow the stage labels, and they are never updated. (scripts/triage_core.py:330-348)

  • "Second Reading" gets 4, which is less than "Introduced" (6). "Passed Committee" gets 16, the same as "Passed One Chamber", because "passed" matches first. A last action such as "House Committee Amendment 1 adopted" also gets 16. "Vetoed" and "Died in committee" get 4 and 6.
  • The score is computed one time, at triage. A bill that later passes a chamber keeps its introduction stage points. For example, a targeted, medium bill goes from 46 to 56 when it passes a chamber, but the stored score stays at 46.
  • Fix: map the STAGE_LABELS values from refresh_bill_status.py directly, and give dead or vetoed bills 0. Recompute the priority from the stored priority_signals plus the current status when the issue is built.

5. A partial migration silently removes the text and sponsors. (scripts/auto_triage.py:57, 63-81)

  • EXTRA_COLUMNS mixes the 009 columns (sponsors, bill_text_url) with the 011 column (bill_text_sha256). If 009 is applied and 011 is not, the select falls back to the base columns.
  • Triage then reads only summaries and sees no sponsors. The only signals are the per-bill log ("read summary") and the save warning about 011.
  • Fix: fall back in two steps (009 columns, then base columns), or print a warning that names the effect. Alternatively, apply 009 and 011 together and say so in the 011 header.

6. Treat the bill text as data. (scripts/triage_core.py:407-435, 486-525)

  • The text comes from outside (legislature sites, or the OpenStates source page when there is no version). With #245, a score of 80 or more starts a headless encode run.
  • Put the text in delimiters and tell the model in the system prompt to treat it as data, not instructions.
  • When the server-side fallback runs, the stored triage_model still says claude-sonnet-5-5. Save response.model instead.

7. The parameter list does not cover some bills that the tracker follows. (scripts/triage_core.py:103, 220-247)

  • The federal list omits gov/aca, gov/hud, gov/ed and the USDA programs other than SNAP. The state lists omit gov/local, so a NY bill that changes NYC income tax rates finds no parameter and is capped at 79.
  • policyengine-us is installed without a version pin, and the score does not record the version. Save the package version with triage_version, so that a later change in the list can be traced.

8. Smaller points.

  • FISCAL_POINTS gives "unknown" 10 and "small" 5 (scripts/triage_core.py:340). If this is intentional, say why in the docstring.
  • fetch_bill_text reads the full response before it truncates to 40,000 characters, with no limit on size (scripts/triage_core.py:295-325). A large budget bill PDF is parsed in full. A source landing page longer than 200 characters is saved as bill_text.
  • Backtest: for the analyzed 2026 bills, the stage signal uses the end-of-session status, not the status at triage. This probably makes the priority AUC of 0.84 too high. Say so next to the result, or remove the stage points in the backtest.

What I checked

  • Read the description and all 10 changed files against the base import-2027-sessions. Also read the import (openstates_monitor.py) and the status refresh (refresh_bill_status.py) for the fields that triage reads. There are no comments or reviews yet.
  • pytest for test_triage_core.py, test_auto_triage.py, test_triage_backtest.py, test_openstates_monitor.py and test_bill_identity.py: 136 passed.
  • ruff check with the default rules on the new and changed scripts: clean. The PR changes no frontend files, so I did not run vitest, eslint or the build. No CI check runs on this branch.
  • Built the parameter lists from pip install --no-deps policyengine-us (2.165.3, Python 3.12). Results: GA 85, NY 235, MN 234, CA 244, federal 858. All 50 states and DC have a folder. Bracket paths (…single.brackets[0].rate) and breakdown categories (…standard.amount.JOINT) resolve, and invented paths are dropped. On Python 3.10, pip installs an old 1.x release with smaller lists, so the workflows' Python 3.11 is required.
  • Probed stage_points, priority_signals and priority_score with the labels from refresh_bill_status.py and OpenStates party strings.
  • Checked that the installed SDK (2.16.0) accepts fallbacks, output_config and betas, and that the claude -p flags in ClaudeCodeClient exist.
  • Series: this PR's base is #243 (on #239), and #245 uses this branch as its base. Main has moved since the base, but the new commit (#240) does not touch these files.

DTrim99 and others added 2 commits December 3, 2026 14:36
- The status refresh reads each bill's versions in its one OpenStates
  request and moves bill_text_url to the latest dated version's link
  (the importer's bill_text_url pick). Each score stores the link it was
  scored on (priority_signals.text_url); --retriage-changed compares links
  before fetching any text, reads at most --limit texts (default 30), and
  records a new link to the same text without rescoring. Same-link edits
  are not detected; the workflow comment says so, and the step has a
  30-minute timeout.
- The companion check searches every processed bill in the state, and the
  issue build recomputes priority from the stored signals with each bill's
  current status and companions (current_priority), so an earlier bill
  gets its points when its companion arrives and a bill that passes a
  chamber moves up.
- Stage points map refresh_bill_status.STAGE_LABELS directly (dead and
  vetoed score 0); the last action is no longer read.
- Party prefixes: Democratic-Farmer-Labor and Democratic-NPL count as
  Democratic.
- Selects fall back in two steps (009 columns, then base columns) and print
  what each missing migration costs.
- The bill goes to the model inside <bill>/<bill_text> tags, escaped, and
  the system prompt says it is data; triage_model saves response.model.
- Parameter lists add gov/local/{state} and, for federal bills, all of
  gov/usda plus gov/aca, gov/hud and gov/ed; triage_version records the
  policyengine-us version ("v2-2026-12+policyengine-us-2.165.4").
- Bill text downloads stop at 10 MB, PDF pages stop once the excerpt is in
  hand, and an HTML page with no enacting clause or first section (a bill
  landing page) is not saved as text.
- The backtest holds the stage at Introduced and reports the end-of-session
  priority beside it; FISCAL_POINTS explains "unknown".

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

DTrim99 commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks, Pavel. Fixed in 79e04cc.

  1. Re-triage misses new versions. Fixed.
    • The status refresh now asks for versions in its one /bills request per bill (scripts/refresh_bill_status.py:238). It moves bill_text_url to the latest dated version's link, using the importer's own bill_text_url pick (refresh_bill_status.py:41, 281-295, 451). The importer falls back to a source page when there is no version; the refresh never does, so a stored link is replaced only by a version.
    • Each score stores the link it was scored on in priority_signals.text_url (scripts/triage_core.py:748). --retriage-changed compares links before it fetches any text (scripts/auto_triage.py:172-222).
      • It reads at most --limit texts, 30 by default (auto_triage.py:83), highest priority first.
      • When a new link holds the same text, it records the link without rescoring (auto_triage.py:225).
    • Not detected: a text that changes at the same link, and bills the refresh never reaches (beyond the top 500). Bills scored before this change, including all v1 scores, have no text_url, so this path leaves them alone.
    • The workflow comment says what is detected, and the step has a 30-minute timeout (.github/workflows/bill-refresh.yml:121-133).
    • Tests: scripts/test_refresh_bill_text.py (one request per bill, the version pick, the update, dry run, the fallback without 009), plus test_retriage_compares_links_before_fetching and test_retriage_records_a_new_link_to_the_same_text in scripts/test_auto_triage.py:313-352.
  2. The companion signal only sees the same run. Fixed both ways.
    • Scoring passes every processed bill in the state (state_bills, auto_triage.py:135, 255, 504).
    • The issue build recomputes each bill's priority, companion included, from all of the state's bills (auto_triage.py:306-308). The earlier bill gets its 5 points as soon as the later one is imported.
    • Tests: test_companion_from_an_earlier_run_counts (scripts/test_triage_core.py:393); test_score_bills_finds_a_companion_from_an_earlier_run and test_issue_body_gives_the_earlier_bill_its_companion_points (test_auto_triage.py:241-273).
  3. Bipartisan check misses MN and ND. Fixed. party_key tests the prefix (triage_core.py:480). Tests cover DFL, Democratic-NPL, Democratic and Independent (test_triage_core.py:370-382).
  4. Stage points. Fixed.
    • STAGE_KEY_POINTS gives points for each STAGE_LABELS key, and STAGE_POINTS is built from the labels (triage_core.py:435-465). Dead and vetoed get 0, and the last action is no longer read.
      • Second Reading and Passed Committee get 12, Third Reading 14, and Passed One Chamber 16.
      • The importer's "Prefiled" and "Passed" and congress_monitor's "Sent to President" are mapped too.
    • current_priority recomputes the score from the stored signals and the current status (triage_core.py:557). The issue build uses it for the bands, the ordering and the Priority column (auto_triage.py:306-308). Your example goes from 46 to 56 and moves into "Needs a person" (test_auto_triage.py:228).
    • Auto-encode bills in the top triage band (p452) #245 still works unchanged: it orders picks by the stored priority_score, and the auto-encode band depends only on modelability.
  5. Partial migration. Fixed. select_bills tries 009+011, then 009, then the base columns. It prints once, by name, what each missing migration costs (auto_triage.py:70-128). Tests: test_auto_triage.py:129-148.
  6. Bill text as data. Fixed.
    • The bill goes to the model inside <bill> tags, with its text inside <bill_text>. Any copy of those tags in the outside text is escaped (triage_core.py:577-615).
    • The system prompt says the content is data, not instructions (triage_core.py:118).
    • triage_model saves response.model (triage_core.py:708, 752). The CLI path has no fallback, so it records TRIAGE_MODEL.
    • Tests: test_bill_text_is_delimited_as_data and test_records_the_model_that_answered_and_the_text_link.
  7. Parameter coverage and version. Fixed.
    • State lists add gov/local/{st} (triage_core.py:148). New York grows from 235 to 276 parameters (NYC, Yonkers, MCTD) and California from 244 to 380.
    • The federal list now has all of gov/usda (WIC, school meals, CSFP) plus gov/aca, gov/hud and gov/ed (triage_core.py:144): 987 parameters instead of 858, on 2.165.4.
    • The version goes into the existing triage_version string, e.g. v2-2026-12+policyengine-us-2.165.4 (triage_core.py:58-74, 751). No new column. Auto-encode bills in the top triage band (p452) #245 checks only whether it is set.
    • I left the install unpinned so the list follows each release. The stored version now traces any change.
  8. Smaller points.
    • FISCAL_POINTS: kept on purpose. "unknown" sits halfway between small and medium, so a bill isn't scored down for a missing text. The comment says so (triage_core.py:466-471).
    • fetch_bill_text: fixed.
      • It streams the download and stops at 10 MB. A PDF cut at the cap returns None, so triage reads the summary.
      • PDF pages stop once 80,000 characters are in hand, and the prompt marks the excerpt (triage_core.py:51-54, 333-425).
      • An HTML page with no enacting clause and no first section, such as a bill landing page, is not saved as text (triage_core.py:375).
      • Tests: test_triage_core.py:282-322.
    • Backtest: fixed. Priority now holds the stage at "Introduced". The end-of-session score is reported beside it as v2_priority_end_stage, with a note in the summary (scripts/triage_backtest.py:16-20, 84-88, 129-137). I recomputed the 2 December run that way from the saved scores and each bill's status, without new model calls; the same method reproduces the old 0.84. With the stage held at "Introduced", the priority AUC is 0.83, and modelability 60+ with priority 50+ flags 182 with 65% recall (it was 185 with 72%). The description now gives both.

Checks: after merging #243 (with #239's fixes), 216 tests pass across test_triage_core.py, test_auto_triage.py, test_triage_backtest.py, test_openstates_monitor.py, test_bill_identity.py, test_refresh_bill_text.py and test_refresh_bill_status.py (Python 3.11, with pyyaml and pypdf). ruff check on the changed scripts is clean; I also fixed four existing lint findings in refresh_bill_status.py.

The description is updated. #245 takes these changes 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 33798b0

This is a re-review after 79e04cc and the merge of import-2027-sessions (#243 at e0cd58b). The status refresh now reads each bill's versions and moves bill_text_url to the latest version. Re-triage compares links before it fetches text, and it reads at most 30 texts a run. The priority is recomputed when the issue is built, from the stored signals, the current status and a companion among all of the state's bills. The fix commit also maps the stage labels, normalizes the party, delimits the bill text and adds gov/local and more federal subtrees. All eight earlier items are fixed. I found one new problem in the re-triage cap.

Verdict: REQUEST_CHANGES

Earlier items

# Item Status
1 Re-triage does not see a new bill version Fixed. One new problem in the cap, see item 9.
2 Companion signal sees only the same run Fixed
3 Bipartisan check misses MN and ND Fixed
4 Stage points and stale priority Fixed
5 Partial migration removes text and sponsors Fixed
6 Bill text as data, triage_model Fixed
7 Parameter coverage and package version Fixed
8 Smaller points (fiscal "unknown", download size, backtest stage) Fixed

How I verified them:

  • 1. text_url_change returns the latest dated version's link. It returns None when OpenStates lists only a source page or the link is the same. retriage_candidates skips v1 scores (no text_url) and includes a bill scored from a summary (text_url is None). The search requests include=actions&include=versions, so the refresh makes no extra request. The fallback without migration 009 works. The workflow comment and the 30-minute timeout match the behavior.
  • 2. priority_signals(SF 5, [HF 10]) finds HF 10 from an earlier run. In the issue build, HF 10 goes from 46 to 51 when SF 5 is in the pool. A bill from another session does not match.
  • 3. "Democratic-Farmer-Labor" and "Democratic-NPL" now give democratic.
  • 4. Every STAGE_LABELS value has points: Second Reading 12, Passed Committee 12, Third Reading 14, Passed One Chamber 16, Vetoed 0, Dead/Withdrawn 0. The importer's and congress_monitor.py's statuses are also mapped. Your example goes from 46 to 56 after it passes a chamber, and to 40 when it dies.
  • 5. select_bills tries 009+011, then 009, then the base columns, and prints what each missing migration costs.
  • 6. The text is inside <bill> and <bill_text>, and copies of those tags are escaped (case-insensitive). triage_model saves response.model.
  • 7. On policyengine-us 2.165.5: GA 85, NY 276 (41 local), CA 380, MN 234, federal 987. triage_version is v2-2026-12+policyengine-us-2.165.5.
  • 8. The download stops at 10 MB, and PDF pages stop at 80,000 characters. The backtest now holds the stage at "Introduced" and reports the end-of-session score beside it.

SHOULD ADDRESS

9. A text that cannot be read blocks a re-triage slot on every run, and the blocked bills collect at the top. (scripts/auto_triage.py:193-222)

  • fetch_changed_bills takes the first 30 candidates by priority. When fetch_bill_text returns None, the bill is skipped and nothing is recorded, so the next run fetches it again.
  • Some failures do not go away: a PDF over 10 MB, an HTML version page with no enacting clause or first section (a resolution), a viewer page under 200 characters, or a legislature site that blocks the request.
  • Each such bill stays a candidate until it is encoded. The list is sorted by priority, so these bills stay in the first slots. When 30 of them collect, re-triage fetches the same 30 texts each run and rescores nothing. The log only says "Found 0 bills with a new text version".
  • Probe: 40 candidates with a fetch that returns None. Run 1 and run 2 both fetch new0 to new29, with 0 changed and 0 moved.
  • Fix: when the fetch for a new link fails, record the link (record_text_url) or rescore the bill from its summary. Alternatively, store the failed link in priority_signals and skip it until the link changes again. Add a test for two runs with a failed fetch.

SUGGESTION

10. Smaller points.

  • The landing-page check (scripts/triage_core.py:375) accepts a page that has "Enacted" anywhere, for example in a menu ("Enacted Legislation"). Probe: a bill page with that menu item and no bill text passes as bill text. Consider a check for the enacting clause near the start of the text, or a minimum share of the text after the marker.
  • The band comment at scripts/triage_core.py:78-80 still says "about 72%" recall. With the stage held at "Introduced", the backtest gives 65%. Update the comment to match the description.

What I checked

  • Head 33798b0 at the start and at the end. Read the 79e04cc diff (10 files) and the author's reply. The merge of #243 (e0cd58b) was clean and changes none of this PR's files.
  • Python 3.12 with policyengine-us 2.165.5: pytest on test_triage_core.py, test_auto_triage.py, test_triage_backtest.py, test_openstates_monitor.py, test_bill_identity.py, test_refresh_bill_text.py and test_refresh_bill_status.py: 216 passed.
  • ruff check with the default rules on the changed scripts and tests: clean.
  • Frontend at the head (from #243, not this PR): vitest 123 passed in 9 files, and the build passed.
  • Probes for text_url_change, retriage_candidates, fetch_changed_bills over two runs, priority_signals, current_priority, party_key, stage_points for every label, the tag escape and the landing-page check.
  • Series: #245 (auto-encode, af3a343) contains 79e04cc and merges with this head without conflict. This head also merges with main (cdaec13) without conflict, and main has not changed these scripts since the base. The order #239, #243, #244, #245 has no clash.

@DTrim99
DTrim99 changed the base branch from import-2027-sessions to main December 3, 2026 21:11
…bill-text check

A new link whose text cannot be read (a PDF over the cap, a page with no
bill text, a site that refuses the request) is counted in
priority_signals.text_fetch_failed. After RETRIAGE_FETCH_TRIES (2) runs it
leaves the re-triage list until its link changes, so unreadable bills no
longer take the first slots on every run. text_url still names the link the
score was made on.

The bill-text check now needs an enacting clause (be it enacted, do enact,
hereby enacts, enact:) or a first section; a bare "enact" in a menu item
such as "Enacted Legislation" no longer passes. The band comment gives the
65% recall with the stage held at Introduced.

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

DTrim99 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, Pavel. Fixed in 0695025. The PR now targets main, since #239 and #243 are merged.

  1. A text that can't be read holds a re-triage slot. Fixed.

    • fetch_changed_bills now also returns the bills whose new text couldn't be read. Outside --dry-run and --propose, record_fetch_failure stores priority_signals.text_fetch_failed = {"url", "tries"}. text_url still names the link the score was based on.
    • retriage_candidates skips a bill once its current link has failed RETRIAGE_FETCH_TRIES (2) runs. A transient failure gets one retry. A permanent one leaves the list until the status refresh records a new link, and then that link is tried. A rescore writes fresh signals, and record_text_url drops the key.
    • The run prints how many texts couldn't be read and what happens to them, so the log no longer says only "Found 0 bills".
    • test_a_text_that_cannot_be_read_stops_holding_a_retriage_slot is your probe over three runs: 40 candidates, the first 30 by priority unreadable, a cap of 30. Runs 1 and 2 read the 30 bad links, and run 3 reads the other 10 and rescores them. A later version of a skipped bill is read again. Two more tests cover the dry run (no write) and the key being cleared.
  2. Smaller points. Both fixed.

    • Landing-page check. A bare "enact" no longer counts. The text needs an enacting clause (be it enacted, do enact in CA, NY and WI, hereby enacts in PA, enact: in MI) or a first section (Section 1, Sec. 1, § 1). Your menu probe ("Enacted Legislation", no bill text) now returns None. A parametrized test covers the eight clause and section forms.
    • Band comment. It now gives 65% with the stage held at "Introduced", and 72% with each bill's end-of-session stage, matching the description.

pytest scripts/ (without test_compute_impacts_datasets.py, which needs numpy): 227 passed. ruff check on the four changed files: clean. #245 merged this head without conflicts and passes 250 tests.

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

This is a re-review after 0695025. The PR now targets main, because #239 and #243 are merged. When re-triage cannot read the text at a new link, record_fetch_failure now stores priority_signals.text_fetch_failed = {url, tries}. retriage_candidates skips the bill after two failed runs on the same link, and tries again when the link changes. The fix commit also makes the bill-text check stricter and updates the recall comment. Items 9 and 10 are fixed. I found no new problem that blocks the merge.

Verdict: APPROVE

Earlier items

# Item Status
1-8 Round 1 items Fixed (no change in this commit)
9 A text that cannot be read holds a re-triage slot Fixed
10 Landing-page check and band comment Fixed

How I verified them:

  • 9. I ran a probe over several runs with my own fake fetch:
    • 40 candidates, the first 30 by priority unreadable, a cap of 30. Runs 1 and 2 fetch the 30 bad links. Runs 3 and 4 fetch the other 10. The first bill stores {"url": ".../v2", "tries": 2}, and text_url still names the scored link.
    • A transient failure: run 1 fails (tries 1), run 2 reads the text and the bill is rescored. The rescore writes fresh signals without text_fetch_failed.
    • A link that changes after the skip: the new link starts at 0 tries, is tried on two runs, then is skipped. A link that changes back to the scored link is not a candidate. A later good link is read and rescored.
    • A new link to the same text clears the key (record_text_url).
    • Through main(): --propose and --dry-run write nothing. A normal run writes only priority_signals for the failed bill. The log line now says how many texts could not be read.
    • current_priority ignores the extra key. fetch_tries handles signals stored as a JSON string and a malformed value (0).
  • 10. The menu text "Enacted Legislation" and a status line "Enacted: 2025-05-01" no longer pass. The clause forms for KY, CA, NY, PA, MI, NC and OR pass, and so do "SECTION 1." and "Sec. 1.". The band comment now gives 65% with the stage held at "Introduced", and 72% with the end-of-session stage.

SUGGESTION

11. A link that fails on two runs is skipped until its link changes, and the log does not count the skipped bills. (scripts/auto_triage.py:192-193)

  • The workflow runs once a day (bill-refresh.yml, 6:00am EST). If a legislature site is down or refuses requests on two days in a row, each new version from that site is skipped for good. The bill keeps the score from its earlier text.
  • After the skip, the bill is not in the candidate count, so a site-wide block shows only on the first two runs.
  • Fix (optional): store the date of the last try and try the link again after some days (for example 7). Or print the number of bills that are skipped because of earlier failures, so the log shows a growing number.

12. Two enacting clauses are not in the list. (scripts/triage_core.py:379-383)

  • "It is hereby enacted" (VT) and "It is enacted" (RI) do not match. Their bills also have "Sec. 1." or "SECTION 1.", so the check still passes, and VT texts are PDFs, which skip this check. No change is necessary. You can add \b(?:hereby\s+)?enacted\b after "is" if you want the comment to cover them.

What I checked

  • Head 0695025 at the start and at the end. Read the 33798b0..0695025 diff (4 files) and the author's reply.
  • Python 3.12 with policyengine-us 2.165.5: pytest scripts at the head, without test_compute_impacts_datasets.py (needs numpy): 227 passed. The three new tests and the parametrized clause test are in that count.
  • ruff check --isolated on the four changed files: clean.
  • Merge with main (53aaa7d): no conflict. main changed no file of this PR since the base. Migration 010 on main changes research, and this PR's 011 changes processed_bills, so they do not clash. On the merged tree: pytest scripts (same exclusion) 266 passed, vitest 131 passed in 10 files, and next build passed.
  • #245 (auto-encode, c912652) contains 0695025 and merges with it without conflict. Its readers of priority_signals go through current_priority, which ignores the new key.
  • GitHub reports no CI checks on this branch.

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