Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/review-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: API review validation (no publication)
on:
pull_request:
branches: [main]
push:
branches: [overhaul/scoring-alignment-2026-11-16]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: api-review-${{ github.event.pull_request.head.sha || github.sha }}
cancel-in-progress: true
jobs:
check:
runs-on: ubuntu-24.04
timeout-minutes: 20
env:
NEXT_TELEMETRY_DISABLED: '1'
DATABASE_URL: postgresql://validation:validation@127.0.0.1:1/validation
NEXT_PUBLIC_SUPABASE_URL: https://example.invalid
NEXT_PUBLIC_SUPABASE_ANON_KEY: validation-only
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
persist-credentials: false
- uses: actions/setup-node@v5
with:
node-version: '24'
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
- run: git diff --check
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## [1.4.6] - 2026-11-18
### Fixed
- Gate bill/model similarity and donor alignment on the official-prose-v2 provenance contract, official XML extraction version, hashes and passage/coverage evidence. Legacy raw similarity cannot bypass the gate, including when filtering the global bills endpoint.
- Distinguish unavailable analysis from a verified non-match while preserving raw records and response keys.

## [1.4.5] - 2026-11-18
### Documentation
- Clarify that the Python scoring function is an upstream reference, not a runtime import: the API fetches JSON and computes its breakdown locally.

## [1.4.4] - 2026-11-18
### Fixed
- Exclude unverified SEC identity matches and unavailable retrievals from computed score components and SEC-derived flags, preserving raw upstream fields and the response contract.
- Document identity/retrieval eligibility and coordinated upstream rollout.

## [1.4.3] - 2026-11-16
### Fixed
- Align score breakdown with corrected CongressWatch methodology: suspend campaign-receipt wealth estimates, exclude future trade/travel dates, and use delegate/sample-aware attendance scoring with 25% saturation.
- Preserve all existing response fields and maxima; clarify component descriptions and methodology drift.

## [1.4.2] - 2026-10-20
### Changed
- Moved the footer logo to the right of "Powered by OSP".
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ Rate limits: free 1,000/hr · discounted 10,000/hr · paid 10,000/hr · admin un

## Notable implementation details

**The score breakdown is recomputed, not read.** CongressWatch persists only the final integer `score`; the six weighted components are discarded. Every *input* survives in the JSON, so `lib/scoring.ts` is a port of its `compute_score()` (`fetch_finance.py:312`) that returns the components. Verified: running CongressWatch's own Python function against the same live JSON produces identical totals.
**The score breakdown is recomputed locally.** The API does not fetch or execute `fetch_finance.py`. That file's `compute_score_components()` is the upstream reference for the TypeScript implementation in `lib/scoring.ts`; references to it are documentation, not runtime imports. The `/api/v1/members/:bioguide_id/score` route fetches `members.json` and `details/:bioguide_id.json` through `lib/congress.ts`, then calls the local `computeScore()` function. The JSON base URL remains `CONGRESS_DATA_URL` (default `https://congresswatch.vercel.app/data`). Existing response keys and component maxima are preserved for compatibility. `wealth_gap` now always scores zero: campaign receipts are not personal wealth. Trade activity and sponsored travel exclude future dates. Attendance requires at least 20 recorded votes, exempts non-voting House delegates and the Resident Commissioner, and reaches its five-point maximum at 25% missed votes.

The `/score` response therefore returns `stored` (what CongressWatch saved), `total` (recomputed now), and `drift` between them. Drift is usually 0 but is legitimately non-zero — the score is only recomputed by CongressWatch's finance job, while votes/trades/travel refresh on their own schedules, so a stored score can lag its own inputs.
SEC signals contribute only when upstream supplies explicit verified identity, an exact matching nonempty CIK, a nonempty HTTPS evidence URL list, available retrieval status, and a finite nonnegative count. Legacy automatic/name-only matches and failed retrievals contribute zero and cannot retain the SEC-derived `trade` flag in `/score`. Raw upstream CIK/count/provenance remain available unchanged through the source-data endpoints. These endpoints still expose upstream stored scores/flags, so deploy the coordinated CongressWatch correction first; `/score.stored` and `drift` deliberately retain that audit trail.

Bill-derived scoring follows the `activity-v5-official-prose` contract. A bill must have `analysis_version=official-prose-overlap-v2`, `analysis_status=analyzed`, official GovInfo XML source metadata, the `govinfo-legislative-body-v2` extraction version, and source/text SHA-256 hashes. Model similarity additionally requires analyzed primary-model evidence tied to that target text, matched-source/text hashes, a finite passage length of at least 32 words, and at least 20% directional shingle coverage. Raw legacy `alec_best_similarity` cannot contribute by itself. The optional 0–1 `min_alec_similarity` filter on `/bills` likewise includes only bills with validated matching evidence. Unavailable primary-model corpora contribute zero, not a verified finding of no overlap. Donor alignment requires matching current bill/donor analysis versions and available status; otherwise it contributes zero. Historical values and provenance remain in the raw source records.

The legacy keys `trade_timing`, `donor_alignment`, and `foreign_travel` describe activity, donor-industry keyword overlap, and disclosed sponsored travel, not established misconduct or foreign-only travel. Bill similarity does not establish authorship. The suspended wealth component is not redistributed, so the currently attainable maximum is 75, while the response retains the historical 100-point scale.

The `/score` response returns `stored` (what CongressWatch saved), `total` (recomputed now), and `drift`. Drift can reflect data refresh lag, changed methodology, or sliding date windows. Deploy the corresponding CongressWatch update alongside this API change to minimize methodology drift.

**`/v1/trades` and `/v1/bills` build an index at runtime.** CongressWatch publishes trades and bills only *inside* per-member detail files, so there is no single document to page over. `lib/aggregate.ts` fans out across all 536 detail files (~15 MB, ~1–3 s cold, ~240 ms warm) and caches the flattened result for an hour. If CongressWatch ever emits `data/trades.json` and `data/bills.json`, delete that module and read them directly.

Expand Down
8 changes: 3 additions & 5 deletions app/api/v1/bills/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextRequest } from "next/server";
import { getIndex } from "@/lib/aggregate";
import { paginate } from "@/lib/congress";
import { validatedModelSimilarity } from "@/lib/scoring";
import { validateApiKey } from "@/lib/auth";
import { paginated, err, options } from "@/lib/response";

Expand Down Expand Up @@ -54,11 +55,8 @@ export async function GET(request: NextRequest) {
}

if (minAlecNum != null && !Number.isNaN(minAlecNum)) {
const best = Math.max(
b.alec_best_similarity ?? 0,
b.alec_match?.similarity_score ?? 0,
);
if (best < minAlecNum) return false;
const best = validatedModelSimilarity(b);
if (best === null || best < minAlecNum) return false;
}
return true;
});
Expand Down
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import parser from '@typescript-eslint/parser';
export default [{ignores:['node_modules/**','.next/**']},{files:['**/*.ts','**/*.tsx'],
languageOptions:{parser,parserOptions:{ecmaVersion:'latest',sourceType:'module',ecmaFeatures:{jsx:true}}},
rules:{'no-unreachable':'error','no-dupe-keys':'error','no-func-assign':'error','valid-typeof':'error'}}];
36 changes: 36 additions & 0 deletions lib/congress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export interface MemberSummary {
data_updated: string;
edgar_status: string;
edgar_cik: string | null;
/** Identity verification and retrieval provenance; absent on legacy records. */
edgar_identity_status?: string;
edgar_identity_cik?: string | null;
edgar_identity_evidence?: string[];
edgar_identity_evidence_checks?: {
url?: string; cik?: string; status?: string; resolved_url?: string;
checked_at?: string; sha256?: string; bytes?: number; error?: string;
}[];
edgar_data_status?: string;
corporate_insider_signals: number;
score: number;
flags: string[];
Expand All @@ -53,12 +62,36 @@ export interface Vote {
url: string;
}

export interface BillTextSource {
source_format?: string;
extraction_version?: string;
source_url?: string;
source_sha256?: string;
text_sha256?: string;
[k: string]: unknown;
}

export interface ModelMatchEvidence {
target_text_sha256?: string;
matched_source_sha256?: string;
matched_text_sha256?: string;
longest_passage_words?: number;
target_shingle_coverage?: number;
matched_shingle_coverage?: number;
[k: string]: unknown;
}

export interface AlecMatch {
evidence?: ModelMatchEvidence;
similarity_score?: number;
[k: string]: unknown;
}

export interface Bill {
analysis_version?: string;
analysis_status?: string;
model_analysis_status?: string;
text_source?: BillTextSource;
bill_id: string;
title: string;
type: string;
Expand Down Expand Up @@ -129,6 +162,9 @@ export interface MemberDetail extends MemberSummary {
bills_updated?: string;
bills_count?: number;
donor_alignment_score?: number;
bills_analysis_version?: string;
donor_alignment_analysis_version?: string;
donor_alignment_status?: string;
alec_match_count?: number;
donor_match_count?: number;

Expand Down
Loading
Loading