Skip to content

Auto-encode bills in the top triage band (p452) - #245

Draft
DTrim99 wants to merge 7 commits into
mainfrom
auto-encode
Draft

DTrim99 wants to merge 7 commits into
mainfrom
auto-encode

Conversation

@DTrim99

@DTrim99 DTrim99 commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Bills triage puts in the encode-automatically band (modelability 80+) now run /encode-bill headless and come out as review PRs (Teamverse p452, due 8 January). A person still approves each analysis by merging its PR. This targets #244, whose triage bands and priority scores it reads.

How it works

  1. Pick (scripts/select_for_encoding.py). Each day it takes state bills in the band that have:

    • no research row;
    • no open bill/{research-id} review PR;
    • no earlier outcome that settles them (a PR opened, structural, or not modelable);
    • no failure within the last 7 days, and fewer than two failures in all.

    They go highest priority first, then modelability, then the earliest introduced, up to the daily cap. Federal bills are left out: they are too large for the runner.

  2. Encode (.github/workflows/auto-encode.yml, daily at 13:30 UTC, after the 11:00 bill pipeline). Each picked bill runs claude -p "/encode-bill ST BILL --ci", one at a time, with --max-budget-usd.

  3. /encode-bill --ci:

    • It never asks a question: the two checkpoints' content goes into the PR body for the reviewer.
    • A bill found to need new code, or outside scope, stops before any Supabase write.
    • A result more than 50% off the external estimate, or with no estimate, opens as a draft labeled needs-attention.
    • Every PR carries bill-review and auto-encoded.
    • Every run writes /tmp/encode-bill-outcome.json.
  4. Record (select_for_encoding.py --record). It writes auto_encode_status, the attempt count, the run URL and the PR URL to processed_bills. claude -p exits 0 even when a command bails, so a missing outcome file counts as a failure.

Guardrails

Guardrail Setting
Off switch The daily run happens only when the repository variable AUTO_ENCODE_ENABLED is true. Manual runs default to dry_run, which only prints the picks.
Daily cap AUTO_ENCODE_DAILY_CAP, default 3, one bill at a time
Spend AUTO_ENCODE_MAX_USD per bill, default 8, passed to claude -p --max-budget-usd
Retries A failure is retried once, after 7 days
Duplicates One open review PR per bill
Approval Merging the PR. Nothing is published before that.
Inputs Bill fields reach the prompt through env:, never inline ${{ }}

Testing it before switching it on

  • no_writes input (/encode-bill --ci --no-writes). It runs the whole encoding and scores offline with compute_impacts.py --reform-json --output. It writes nothing to Supabase and opens no branch or PR. It uploads the PR body it would have opened (/tmp/encode-bill-pr.md) and the analysis JSON, and records no outcome.
  • A manual run on one named bill works before migrations 011 and 012 are applied, using the v1 scores.

The first live test is a manual run with bill set, dry_run off and no_writes on.

Seeing where bills stand

  • State triage issues gain an Auto-encode column: the PR link, "needs new code", "out of scope" or "run failed". A bill that encoding found structural or out of scope moves to the needs-a-person band.

  • scripts/intake_funnel.py, read only, reports for each session:

    • bills imported and triaged, by band;
    • auto-encode outcomes;
    • bills analyzed and published;
    • the median days from introduction to approval.

    Each run of the workflow writes it to the run summary. On live data today it shows 3 bills for 2027 (prefiles, all in the top band on v1 scores), 342 for 2026 and 1,222 for 2025. The band and days columns fill in once migrations 009–012 are applied.

Also in this PR

  • scripts/sql/012_add_auto_encode_fields.sql adds auto_encode_status, auto_encode_attempts, auto_encode_attempted_at, auto_encode_run_url and auto_encode_pr_url. The selector refuses to run without them, so a failing bill can't be retried every day.
  • /encode-bill's PR step used cd /Users/pavelmakarchuk/state-research-tracker. It now goes to the repository root. Credentials load from .env.local (the repository's convention), else .env, else the environment.

Checks

  • uv run --with "anthropic>=1.9" --with pytest --with pyyaml --with pypdf --with requests --with hypothesis pytest scripts/test_select_for_encoding.py scripts/test_intake_funnel.py plus the triage and import tests: 149 passed. The new tests cover ordering and the cap, every skip reason, retry after a week, the session-aware research IDs and branch names, paging, the missing-migration error, and recording each outcome.
  • The workflow YAML parses. ruff check is clean.

Not done yet

  • No live run yet.
    • First, a manual run on one bill with no_writes on, which works before the migrations.
    • Then, once migrations 011 and 012 are applied, the same run with no_writes off.
    • Then turn on AUTO_ENCODE_ENABLED.
  • Scoring still uses compute_impacts.py. When p451 lands, /encode-bill will score through the Public API and the comparison step instead. This PR's selection, guardrails and outcome contract stay the same.
  • CRM record on merge (p454).

🤖 Generated with Claude Code

DTrim99 and others added 4 commits December 2, 2026 22:14
- scripts/select_for_encoding.py picks today's bills: state bills triage
  put in the encode-automatically band (modelability 80+) with no research
  row, no open review PR, and no recent or repeated failure, highest
  priority first, up to the daily cap. --record writes each run's outcome.
- .github/workflows/auto-encode.yml runs daily after the bill pipeline,
  only when the AUTO_ENCODE_ENABLED repository variable is "true" (manual
  runs default to a dry run). Each bill runs `claude -p "/encode-bill ST
  BILL --ci"` one at a time with a per-bill budget, then records the
  outcome; logs are uploaded.
- /encode-bill --ci never asks: checkpoint content goes into the PR body,
  structural or out-of-scope bills stop before any database write, and a
  result more than 50% off the external estimate (or with none) opens as a
  draft labelled needs-attention. Every run writes an outcome file the
  workflow checks. The PR step no longer cds into one person's checkout,
  and credentials load from .env.local, .env or the environment.
- scripts/sql/012_add_auto_encode_fields.sql adds the status columns; the
  selector refuses to run without them.

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

- /encode-bill --ci --no-writes encodes and scores a bill offline
  (compute_impacts.py --reform-json --output), writes the would-be PR body
  to /tmp/encode-bill-pr.md, and changes nothing: no Supabase write, no
  branch, no PR. auto-encode.yml exposes it as the no_writes input and
  uploads the PR body and analysis; such a run records no outcome.
- A manual run on one named bill works before migrations 011/012, on the
  v1 scores, so the first live test needn't wait for them.
- State triage issues gain an Auto-encode column (the PR link, needs new
  code, out of scope, run failed), and a bill encoding found structural
  or out of scope moves to the needs-a-person band.
- scripts/intake_funnel.py: by session, imported, triaged by band,
  auto-encode outcomes, analyzed, published and the median days from
  introduction to approval; the workflow writes it to the run summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A preview on live data after migrations 009-012 picked three 2025-26
bills: v1 triage scored 197 older bills at 80+, and that backlog was never
meant to be encoded automatically. The daily queue now requires a session
starting in AUTO_ENCODE_MIN_SESSION_YEAR (2027) or later and a triage v2
score (triage_version); a manual run on one named bill skips both checks.
Today's preview picks nothing: 227 older bills, and the three 2027
prefiles wait for their v2 scores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Anthony added PUBLIC_API_CLIENT_ID and PUBLIC_API_CLIENT_SECRET as repo
secrets on 3 December. #246 scores through the Public API when they are
set; without this the auto-encode job never sees them and keeps scoring
with compute_impacts.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the issue-build column fallback: the auto-encode columns stay
first, with priority_signals in every set, and the issue keeps triage
v2's current priority. select_for_encoding orders picks, and
intake_funnel counts the bands, by the same current priority the state
issues show (stored signals with today's stage, and companions in the
funnel).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant