Repository navigation
Fix three latent ingest bugs: computed counts, childcare lock order, AB2025 rebuild cost - #263
Merged
Merged
Conversation
The NZ Treasury ingest counted a claim as computed when its latest result was anything but not_computed, and harvest's advance_computed_lanes counted any claim with any result. Both now count a claim only when its latest result, by computed_at then id, carries a PolicyEngine value: the rule export_populations and populations.ts use for "with a value", and the one PR #261's _write_lane follows. A valueless pe_gap or mismatch as the latest row no longer makes a lane computed, and NZ's regressed note now says the claims retain no PolicyEngine value. No harvest or NZ claim has a valueless latest result today, so the built database and feeds do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ingest_uk_childcare_100k read the registry's old claims before any write lock, so two overlapping ingests could both read an empty registry. Both then deleted nothing and each inserted every result, leaving each claim's result twice per run. The ingest now takes BEGIN IMMEDIATE before the read, as ingest_fiscal_lab does in PR #261, so overlapping runs serialise. The connection now closes in a finally block, so a lock timeout or a failed write no longer leaves it open. The new test starts two ingests on one database and holds each at its registry read until the other reads, then compares the rows with a single ingest's. On the old code the two reads meet and every pe_results row is doubled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stage() tallied each source's merged twins by scanning the kept claims for every row and rehashing each one: about 1.9 million claim_id hashes for 8,881 rows. That took about 14 of a full build_db's 27 seconds. Each score is now hashed once, and the kept claims are indexed by id. The tally is a transliteration of the old one: a row counts as a merged twin when its claim id is kept by a different row (the first kept row with that id), and the tally goes to the family of the last row with that id. stage()'s full return (every score row in order, and the accounting dict in its key order) is byte-identical to origin/main's, and stage() now takes 0.26 s. The new test counts claim_id calls through stage(). The old code hashes one score 1,147 times; the new code hashes each at most four times. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An in-session adversarial check of 62bc0ce found two gaps (P2): - Every test inserted rows in date order, so a latest-row rule ordered by id alone still passed. - No test had a lane with both valued and valueless claims, so nothing checked that N and updated_at come from the counted claims alone. New harvest cases insert a newer-dated row before an older one, either way round. New mixed-lane tests (harvest and NZ) check "1 of N", the lane's date and, for NZ, the populations feed's count. The old modules fail 10 of these tests, an id-only ORDER BY fails 3, and an NZ date taken over every latest row fails 1. Two small cleanups: the second harvest read skips a claim missing from the first, as the old code did, rather than raising KeyError; and an over-long NZ docstring line is rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 1 (Subfleet 20261127-095844-scorecard-263-review) raised two P2s against the new tests: 1. The AB2025 test counted claim_id() calls only. A tally that hashes each score once but scans cached ids per row is still quadratic, and it passed. The test now also counts comparisons between claim ids, through a str subclass. The bounds are loosened to allow another linear pass (at most 8 hashes per score, 4 per row read, and 1 comparison per row read). The original code fails at 1,147 hashes of one score, a cached-id scan at 961,087 comparisons, and an extra uniqueness pass still passes. 2. The childcare overlap test waited at most a second for the other ingest's registry read. When one ingest started over a second late, the old code passed. Each ingest now holds at its read until the other has either read or started BEGIN IMMEDIATE, and a wait that times out fails the test. A new parameter starts either ingest half a second late. The old module fails all three cases, with a 1.5 s delay too, on doubled pe_results rows; the fixed module passes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 found that the stage-level test, which counts claim-id hashes and comparisons, passes an identity scan of `kept` per row (quadratic, uncounted) and fails a harmless extra linear pass. Move the tally into `_merged_twins(mine, kept)`, which stage() calls when rows were merged. Its output and stage()'s are unchanged: the staged scores and accounting match main byte for byte, and two builds give content hash e451ad6b... with no feed drift. Test the helper directly: - the tally goes to the last row's family, in either row order; - its traced Python steps grow at most 6x when the input grows 4x. The helper grows 4.0x. The old nested lookup grows 15.7x; an identity scan, an `in` scan, a cached-id scan and a cached-id index grow 15-16x; an extra linear uniqueness pass passes. The stage-level hash bound stays, loosened to 8 per score and 4 per row read, so a regression in stage() itself still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes three latent bugs in the ingest modules. Independent reviews of #261 found them; they sit outside #261's scope, and #261 fixed the same first two patterns in its own ingest. The built database does not change.
Changes
not_computed. Harvest'sadvance_computed_lanescounted any claim with any result.computed_at, thenid) has a value (computed_value IS NOT NULL). That is the "with a value" rule inexport_populations.pyandapp/src/populations.ts, and the one Add Fiscal Lab's Memo Bill Scores as an external source #261's_write_laneuses.ingest_uk_childcare_100k.ingestread the registry's old claims before taking any write lock. Two overlapping ingests could both read an empty registry, and each insert every result, leaving each claim's result twice per run.BEGIN IMMEDIATEbefore the read, as Add Fiscal Lab's Memo Bill Scores as an external source #261'singest_fiscal_lab.ingestdoes.finally.ingest_uk_ab2025.stagetallied merged republications by rescanning the kept claims for every row and rehashing each one: 1,943,155claim_id()hashes for 8,881 rows.stage()drops from 14.8 s to 0.26 s, and a fullbuild_dbfrom 27 s to 10–11 s._merged_twins(mine, kept), so a test can measure its scaling directly.stage()'s output is unchanged.Tests (each fails on the old code)
test_lane_counts_only_a_latest_result_with_a_value(NZ) checks a latestpe_gaporconcept_mismatchwith no value, against ones with a value, and checks the lane's count against the populations feed.test_a_newer_valueless_gap_regresses_a_computed_lane(NZ) checks a newer valueless gap after a value.test_counts_a_claim_only_when_its_latest_result_has_a_value(harvest) covers four cases: a gap only, a newer gap after a value, a tie oncomputed_at, and a newer value after a gap.test_overlapping_ingests_leave_what_one_ingest_leavesholds two ingests at their registry reads and compares the rows with a single ingest's. On the old code it failed 3 of 3 runs, and everype_results(claim, run) row was doubled. It never hit a lock timeout.test_the_twin_tally_grows_linearlycounts the Python steps_merged_twinstakes (viasys.settrace) on 500 and 2,000 rows, every claim printed twice, and allows at most a 6x rise for the 4x input. The helper rises 4.0x. The old nested lookup rises 15.7x. An identity scan, aninscan, a cached-id scan and a cached-id index all rise 15–16x and fail. An extra linear uniqueness pass passes. The test catches scans written in Python only: a scan that runs in C, such asid(s) not in [id(k) for k in kept], fires no trace events and passes.test_merged_twins_charge_the_last_row_s_familypins which family each tally goes to, in either row order.test_stage_hashes_each_score_a_bounded_number_of_timescountsclaim_id()calls throughstage()(at most 8 per score, 4 per row read). The old code hashes one score 1,147 times.Checks
stage()output: its full return (score rows in order, and the accounting dict in key order) is byte-identical toorigin/main's.e451ad6b…, the same asorigin/main771c028, andgit diff --exit-codeis clean.uvx ruff format --check be nz scorecard_db tests pipelineis clean.--python 3.12and a scratch--basetemp). The tree had no drift afterwards. At cd91477, which adds only tests, a.getand a docstring rewrap, the touched test files pass (75); CI runs the full suite on that head.Review
20261127-095844-scorecard-263-review, codex-2 sol62, at cd91477). The verdict line read APPROVE, but the round raised two in-scope P2s, both about the new tests, so by the levels it did not agree. Both are fixed in 30e9da8:BEGIN IMMEDIATE, and a timed-out wait fails the test. The old module fails all three timing cases, a 1.5 s delay included.~/reviews/scorecard-ingest-robustness-2026-11-27/runs/review-1/andfix-1/.20261127-115544-scorecard-263-review-r2, at 30e9da8): REQUEST_CHANGES on one P2, with no P0 or P1. Under the PR guide's round rule the review has finished; the P2 is fixed, not filed.keptper row (980,662 uncounted comparisons passed) and failed a harmless extra linear pass (11,597 counted against a limit of 8,881). 429037d moves the tally into_merged_twinsand tests its traced steps' growth instead; see Fix 3 above.runs/review-2/andruns/fix-2/under~/reviews/scorecard-ingest-robustness-2026-11-27/.stage()'s full return is byte-identical toorigin/main's.e451ad6b…, andgit diff --exit-codeis clean.ruff format --checkis clean.Not in this PR
sync_lane_feedis sync_lane_feed: overlapping ingests can lose or tear data/lanes.json #262.🤖 Generated with Claude Code