From 848c348f804a934d3c7ccb09f66417bfcfbe9497 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 08:57:15 -0400 Subject: [PATCH 1/6] Fold seven entity-drift lineages into their economy/aggregate siblings Max's ruling d353 (2026-09-27): the hand-recorded May 2026 rows of seven series carry a different entity from every resolver print of the same series, so the catalog kept two lineages for each. Alias inheritance never crosses an entity slice, and the curated-merge recipe restores the split on regeneration (reproduced 2026-09-22). - build_series_catalog.py reads a curated seed, ledger/seeds/entity_folds.json (chronicle_entity_folds_v1). Before identities are grouped, current rows of a fold's concept and geography carrying the absorbed entity are read as carrying the survivor entity; the observation file is never changed. The absorbed row's names join the survivor's aliases, its binding retires with the --remint-note, and the catalog commits to the seed as entity_folds_sha256 (absent without a seed). - Once a committed catalog declares the digest, regenerating without the seed is a hard error. A fold that matches no current row is inert; a fold must name an absorbed identity the registry has bound and a survivor the committed catalog holds. - The default seed path is seeds/entity_folds.json beside the catalog, so the Thesis resolver's staged regeneration and temporary test repos resolve it without new flags. - Regenerated with --allow-remint: 228 -> 221 series, seven retire lines, no mint, no supersede; observation_count still sums to the 233 current rows. Co-Authored-By: Claude Opus 5.5 --- ledger/seeds/entity_folds.json | 125 ++++++++++++ ledger/series_catalog.json | 307 ++++------------------------- ledger/series_uuid_registry.jsonl | 7 + scripts/build_series_catalog.py | 248 ++++++++++++++++++++++- tests/test_build_series_catalog.py | 45 ++++- 5 files changed, 456 insertions(+), 276 deletions(-) create mode 100644 ledger/seeds/entity_folds.json diff --git a/ledger/seeds/entity_folds.json b/ledger/seeds/entity_folds.json new file mode 100644 index 00000000..eb3d1757 --- /dev/null +++ b/ledger/seeds/entity_folds.json @@ -0,0 +1,125 @@ +{ + "schemaVersion": "chronicle_entity_folds_v1", + "comment": "Curated cross-entity folds for scripts/build_series_catalog.py. Each fold reads every current observation of the concept and geography that carries absorbed_entity as carrying survivor_entity when the catalog groups identities; the observation file is never changed. Undo a fold by removing it from this list, never by deleting the file. The seven folds below are the entity-drift families in docs/catalog-curation-backlog.md, folded into their economy/aggregate lineages by Max's ruling d353 (2026-09-27).", + "folds": [ + { + "concept": "bls.cpi.u.core_mom", + "geography": { + "level": "country", + "id": "0100000US", + "vintage": "current" + }, + "absorbed_entity": { + "name": "household", + "role": "cpi_u_less_food_energy" + }, + "survivor_entity": { + "name": "economy", + "role": "aggregate" + }, + "note": "Hand-recorded ledger line 15 carries household/cpi_u_less_food_energy; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." + }, + { + "concept": "bls.cpi.u.headline_mom", + "geography": { + "level": "country", + "id": "0100000US", + "vintage": "current" + }, + "absorbed_entity": { + "name": "household", + "role": "cpi_u_all_items" + }, + "survivor_entity": { + "name": "economy", + "role": "aggregate" + }, + "note": "Hand-recorded ledger line 14 carries household/cpi_u_all_items; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." + }, + { + "concept": "bls.cps.unemployment_rate", + "geography": { + "level": "country", + "id": "0100000US", + "vintage": "current" + }, + "absorbed_entity": { + "name": "person", + "role": "civilian_labor_force" + }, + "survivor_entity": { + "name": "economy", + "role": "aggregate" + }, + "note": "Hand-recorded ledger line 2 carries person/civilian_labor_force; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." + }, + { + "concept": "bls.import_price_index.all_imports_mom", + "geography": { + "level": "country", + "id": "0100000US", + "vintage": "current" + }, + "absorbed_entity": { + "name": "household", + "role": "all_imports" + }, + "survivor_entity": { + "name": "economy", + "role": "aggregate" + }, + "note": "Hand-recorded its May 2026 print carries household/all_imports; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." + }, + { + "concept": "census.housing_starts.saar", + "geography": { + "level": "country", + "id": "0100000US", + "vintage": "current" + }, + "absorbed_entity": { + "name": "dwelling", + "role": "housing_start" + }, + "survivor_entity": { + "name": "economy", + "role": "aggregate" + }, + "note": "Hand-recorded its May 2026 prints carries dwelling/housing_start; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." + }, + { + "concept": "fed.g17.capacity_utilization.total_industry", + "geography": { + "level": "country", + "id": "0100000US", + "vintage": "current" + }, + "absorbed_entity": { + "name": "institutional_sector", + "role": "total_industry_capacity" + }, + "survivor_entity": { + "name": "economy", + "role": "aggregate" + }, + "note": "Hand-recorded its May 2026 print carries institutional_sector/total_industry_capacity; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." + }, + { + "concept": "fed.g17.industrial_production.total_index_mom", + "geography": { + "level": "country", + "id": "0100000US", + "vintage": "current" + }, + "absorbed_entity": { + "name": "institutional_sector", + "role": "total_industrial_production" + }, + "survivor_entity": { + "name": "economy", + "role": "aggregate" + }, + "note": "Hand-recorded its May 2026 prints carries institutional_sector/total_industrial_production; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." + } + ] +} diff --git a/ledger/series_catalog.json b/ledger/series_catalog.json index afdd0e65..23ae9523 100644 --- a/ledger/series_catalog.json +++ b/ledger/series_catalog.json @@ -5,7 +5,8 @@ "observation_rows": 233, "current_assertion_rows": 233, "docket_seed_sha256": "5914192517350e0166045afd9064a515ea312acbea1844d9cb594cc9f525dbb9", - "uuid_registry_sha256": "6cf24b1eff573ac6e8d7de21c7f3e0091bb92a96e72fa2073379be59fbffd683", + "entity_folds_sha256": "442739aba771eadf57984ed968391f702f5b826c8b98ba4cae1e04cc1587e572", + "uuid_registry_sha256": "272d8fd6b2e82151d781d8a9bc69f0f7abaf934a837279c47d2f534683443f31", "suspect_segments": [ "LNU02374597" ], @@ -1472,56 +1473,24 @@ "role": "aggregate" }, "sources": [ + "bls", "bls_cpi" ], "aliases": [ "bls.cpi.u.core_mom.july_2026", - "bls.cpi.u.core_mom.june_2026" - ], - "source_concepts": [ - "CPILFESL" - ], - "rid_patterns": [ - "bls.cpi.u.core_mom.{P}.first_print" - ], - "first_observed_period": "2026-06", - "last_observed_period": "2026-07", - "observation_count": 2 - }, - { - "uuid": "d85c3c7f-874b-4caa-bfad-1ec7a473c293", - "concept": "bls.cpi.u.core_mom", - "family_patterns": [ - "bls.cpi.u.core_mom.{P}" - ], - "status": "observed", - "unit": "percent_growth", - "cadence": "month", - "geography": { - "level": "country", - "id": "0100000US", - "vintage": "current", - "name": "United States" - }, - "entity": { - "name": "household", - "role": "cpi_u_less_food_energy" - }, - "sources": [ - "bls" - ], - "aliases": [ + "bls.cpi.u.core_mom.june_2026", "bls.cpi.u.core_mom.may_2026" ], "source_concepts": [ + "CPILFESL", "bls.cpi.u.core_mom.may_2026" ], "rid_patterns": [ "bls.cpi.u.core_mom.{P}.first_print" ], "first_observed_period": "2026-05", - "last_observed_period": "2026-05", - "observation_count": 1 + "last_observed_period": "2026-07", + "observation_count": 3 }, { "uuid": "70ca2ecf-4323-4453-b42f-23350cb95f22", @@ -1543,56 +1512,24 @@ "role": "aggregate" }, "sources": [ + "bls", "bls_cpi" ], "aliases": [ "bls.cpi.u.headline_mom.july_2026", - "bls.cpi.u.headline_mom.june_2026" - ], - "source_concepts": [ - "CPIAUCSL" - ], - "rid_patterns": [ - "bls.cpi.u.headline_mom.{P}.first_print" - ], - "first_observed_period": "2026-06", - "last_observed_period": "2026-07", - "observation_count": 2 - }, - { - "uuid": "3e796803-a194-4c83-9dc9-27cc870ff08e", - "concept": "bls.cpi.u.headline_mom", - "family_patterns": [ - "bls.cpi.u.headline_mom.{P}" - ], - "status": "observed", - "unit": "percent_growth", - "cadence": "month", - "geography": { - "level": "country", - "id": "0100000US", - "vintage": "current", - "name": "United States" - }, - "entity": { - "name": "household", - "role": "cpi_u_all_items" - }, - "sources": [ - "bls" - ], - "aliases": [ + "bls.cpi.u.headline_mom.june_2026", "bls.cpi.u.headline_mom.may_2026" ], "source_concepts": [ + "CPIAUCSL", "bls.cpi.u.headline_mom.may_2026" ], "rid_patterns": [ "bls.cpi.u.headline_mom.{P}.first_print" ], "first_observed_period": "2026-05", - "last_observed_period": "2026-05", - "observation_count": 1 + "last_observed_period": "2026-07", + "observation_count": 3 }, { "uuid": "34af6867-ce27-468a-a49b-e9a1dc9dfef2", @@ -1932,6 +1869,7 @@ "uuid": "db2f3857-e0fa-48f8-9ab1-6c8989307fd2", "concept": "bls.cps.unemployment_rate", "family_patterns": [ + "bls.cps.unemployment_rate", "bls.cps.unemployment_rate.{P}" ], "status": "observed", @@ -1948,6 +1886,7 @@ "role": "aggregate" }, "sources": [ + "bls", "bls_cps" ], "aliases": [ @@ -1955,47 +1894,15 @@ "bls.cps.unemployment_rate.june_2026" ], "source_concepts": [ - "UNRATE" - ], - "rid_patterns": [ - "bls.cps.unemployment_rate.{P}.first_print" - ], - "first_observed_period": "2026-06", - "last_observed_period": "2026-07", - "observation_count": 2 - }, - { - "uuid": "8dbbd54f-4bfd-4735-ad0d-5b55b8bb4ec5", - "concept": "bls.cps.unemployment_rate", - "family_patterns": [ - "bls.cps.unemployment_rate" - ], - "status": "observed", - "unit": "percent", - "cadence": "month", - "geography": { - "level": "country", - "id": "0100000US", - "vintage": "current", - "name": "United States" - }, - "entity": { - "name": "person", - "role": "civilian_labor_force" - }, - "sources": [ - "bls" - ], - "aliases": [], - "source_concepts": [ + "UNRATE", "bls.cps.unemployment_rate" ], "rid_patterns": [ "bls.cps.unemployment_rate.{P}.first_print" ], "first_observed_period": "2026-05", - "last_observed_period": "2026-05", - "observation_count": 1 + "last_observed_period": "2026-07", + "observation_count": 3 }, { "uuid": "6d2e1191-9e14-4719-a2bb-c3561fca49e6", @@ -2122,56 +2029,24 @@ "role": "aggregate" }, "sources": [ + "bls", "bls_import_export_prices" ], "aliases": [ "bls.import_price_index.all_imports_mom.2026-06", - "bls.import_price_index.all_imports_mom.2026-07" - ], - "source_concepts": [ - "IR" - ], - "rid_patterns": [ - "bls.import_price_index.all_imports_mom.{P}.first_print" - ], - "first_observed_period": "2026-06", - "last_observed_period": "2026-07", - "observation_count": 2 - }, - { - "uuid": "e8e6e43e-2c46-4620-a070-91d2da004b1c", - "concept": "bls.import_price_index.all_imports_mom", - "family_patterns": [ - "bls.import_price_index.all_imports_mom.{P}" - ], - "status": "observed", - "unit": "percent_growth", - "cadence": "month", - "geography": { - "level": "country", - "id": "0100000US", - "vintage": "current", - "name": "United States" - }, - "entity": { - "name": "household", - "role": "all_imports" - }, - "sources": [ - "bls" - ], - "aliases": [ + "bls.import_price_index.all_imports_mom.2026-07", "bls.import_price_index.all_imports_mom.may_2026" ], "source_concepts": [ + "IR", "bls.import_price_index.all_imports" ], "rid_patterns": [ "bls.import_price_index.all_imports_mom.{P}.first_print" ], "first_observed_period": "2026-05", - "last_observed_period": "2026-05", - "observation_count": 1 + "last_observed_period": "2026-07", + "observation_count": 3 }, { "uuid": "3bddc6d0-e581-42dc-9c13-b731a9ede21f", @@ -2663,7 +2538,7 @@ "observation_count": 1 }, { - "uuid": "d0212a1e-b360-460a-80a8-1cf4ad5ce427", + "uuid": "8c999902-84e2-4e90-b49c-325cd535062a", "concept": "census.housing_starts.saar", "family_patterns": [ "census.housing_starts.saar.{P}", @@ -2679,18 +2554,22 @@ "name": "United States" }, "entity": { - "name": "dwelling", - "role": "housing_start" + "name": "economy", + "role": "aggregate" }, "sources": [ - "census" + "census", + "census_housing" ], "aliases": [ + "census.housing_starts.saar.2026-06", + "census.housing_starts.saar.2026-07", "census.housing_starts.saar.may_2026", "us.census.housing_starts.total_saar", "us.census.housing_starts.total_saar.2026_05" ], "source_concepts": [ + "HOUST", "census.housing_starts.saar" ], "rid_patterns": [ @@ -2698,44 +2577,8 @@ "us.census.housing_starts.total_saar.{P}" ], "first_observed_period": "2026-05", - "last_observed_period": "2026-05", - "observation_count": 2 - }, - { - "uuid": "8c999902-84e2-4e90-b49c-325cd535062a", - "concept": "census.housing_starts.saar", - "family_patterns": [ - "census.housing_starts.saar.{P}" - ], - "status": "observed", - "unit": "millions", - "cadence": "month", - "geography": { - "level": "country", - "id": "0100000US", - "vintage": "current", - "name": "United States" - }, - "entity": { - "name": "economy", - "role": "aggregate" - }, - "sources": [ - "census_housing" - ], - "aliases": [ - "census.housing_starts.saar.2026-06", - "census.housing_starts.saar.2026-07" - ], - "source_concepts": [ - "HOUST" - ], - "rid_patterns": [ - "census.housing_starts.saar.{P}.first_print" - ], - "first_observed_period": "2026-06", "last_observed_period": "2026-07", - "observation_count": 2 + "observation_count": 4 }, { "uuid": "294d82e8-3711-4d0d-89f6-a5a7a087f1be", @@ -3592,62 +3435,31 @@ "role": "aggregate" }, "sources": [ + "fed", "federal_reserve_g17" ], "aliases": [ "fed.g17.capacity_utilization.total_industry.2026-06", - "fed.g17.capacity_utilization.total_industry.2026-07" - ], - "source_concepts": [ - "TCU" - ], - "rid_patterns": [ - "fed.g17.capacity_utilization.total_industry.{P}.first_print" - ], - "first_observed_period": "2026-06", - "last_observed_period": "2026-07", - "observation_count": 2 - }, - { - "uuid": "978252a9-c452-41eb-aece-323340e796fc", - "concept": "fed.g17.capacity_utilization.total_industry", - "family_patterns": [ - "fed.g17.capacity_utilization.total_industry.{P}" - ], - "status": "observed", - "unit": "percent", - "cadence": "month", - "geography": { - "level": "country", - "id": "0100000US", - "vintage": "current", - "name": "United States" - }, - "entity": { - "name": "institutional_sector", - "role": "total_industry_capacity" - }, - "sources": [ - "fed" - ], - "aliases": [ + "fed.g17.capacity_utilization.total_industry.2026-07", "fed.g17.capacity_utilization.total_industry.may_2026" ], "source_concepts": [ + "TCU", "fed.g17.capacity_utilization.total_industry" ], "rid_patterns": [ "fed.g17.capacity_utilization.total_industry.{P}.first_print" ], "first_observed_period": "2026-05", - "last_observed_period": "2026-05", - "observation_count": 1 + "last_observed_period": "2026-07", + "observation_count": 3 }, { "uuid": "dbfd5050-e5df-40af-8922-dc8927d6363a", "concept": "fed.g17.industrial_production.total_index_mom", "family_patterns": [ - "fed.g17.industrial_production.total_index_mom.{P}" + "fed.g17.industrial_production.total_index_mom.{P}", + "us.frb.industrial_production.total.mom_sa.{P}" ], "status": "observed", "unit": "percent_growth", @@ -3663,51 +3475,18 @@ "role": "aggregate" }, "sources": [ + "fed", "federal_reserve_g17" ], "aliases": [ "fed.g17.industrial_production.total_index_mom.2026-06", - "fed.g17.industrial_production.total_index_mom.2026-07" - ], - "source_concepts": [ - "INDPRO" - ], - "rid_patterns": [ - "fed.g17.industrial_production.total_index_mom.{P}.first_print" - ], - "first_observed_period": "2026-06", - "last_observed_period": "2026-07", - "observation_count": 2 - }, - { - "uuid": "d5634fc4-dbe0-4203-a5b7-728708b85a14", - "concept": "fed.g17.industrial_production.total_index_mom", - "family_patterns": [ - "fed.g17.industrial_production.total_index_mom.{P}", - "us.frb.industrial_production.total.mom_sa.{P}" - ], - "status": "observed", - "unit": "percent_growth", - "cadence": "month", - "geography": { - "level": "country", - "id": "0100000US", - "vintage": "current", - "name": "United States" - }, - "entity": { - "name": "institutional_sector", - "role": "total_industrial_production" - }, - "sources": [ - "fed" - ], - "aliases": [ + "fed.g17.industrial_production.total_index_mom.2026-07", "fed.g17.industrial_production.total_index_mom.may_2026", "us.frb.industrial_production.total.mom_sa", "us.frb.industrial_production.total.mom_sa.2026_05" ], "source_concepts": [ + "INDPRO", "fed.g17.industrial_production.total_index_mom" ], "rid_patterns": [ @@ -3715,8 +3494,8 @@ "us.frb.industrial_production.total.mom_sa.{P}" ], "first_observed_period": "2026-05", - "last_observed_period": "2026-05", - "observation_count": 2 + "last_observed_period": "2026-07", + "observation_count": 4 }, { "uuid": "41d26958-709c-44ab-a5ab-b385157db0ac", diff --git a/ledger/series_uuid_registry.jsonl b/ledger/series_uuid_registry.jsonl index 540dbbe2..49aaf044 100644 --- a/ledger/series_uuid_registry.jsonl +++ b/ledger/series_uuid_registry.jsonl @@ -274,3 +274,10 @@ {"concept": "census.new_residential_sales.new_single_family_houses_sold_saar", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "economy", "role": "aggregate"}, "uuid": "5654403e-f6c5-412e-94e0-feeda778ad81", "succeeds": {"concept": "census.new_residential_sales.new_single_family_houses_sold_saar", "geography": null, "entity": null}} {"concept": "bea.trade.goods_services_deficit", "geography": null, "entity": null, "uuid": "7be75093-832c-4734-a002-a0ff19c610ce", "retired": true, "note": "docket placeholder enriched by first observed identity"} {"concept": "bea.trade.goods_services_deficit", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "economy", "role": "aggregate"}, "uuid": "7be75093-832c-4734-a002-a0ff19c610ce", "succeeds": {"concept": "bea.trade.goods_services_deficit", "geography": null, "entity": null}} +{"concept": "bls.cpi.u.core_mom", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "household", "role": "cpi_u_less_food_energy"}, "uuid": "d85c3c7f-874b-4caa-bfad-1ec7a473c293", "retired": true, "note": "curated entity fold (d353): hand-recorded May 2026 rows join the resolver economy/aggregate lineage"} +{"concept": "bls.cpi.u.headline_mom", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "household", "role": "cpi_u_all_items"}, "uuid": "3e796803-a194-4c83-9dc9-27cc870ff08e", "retired": true, "note": "curated entity fold (d353): hand-recorded May 2026 rows join the resolver economy/aggregate lineage"} +{"concept": "bls.cps.unemployment_rate", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "person", "role": "civilian_labor_force"}, "uuid": "8dbbd54f-4bfd-4735-ad0d-5b55b8bb4ec5", "retired": true, "note": "curated entity fold (d353): hand-recorded May 2026 rows join the resolver economy/aggregate lineage"} +{"concept": "bls.import_price_index.all_imports_mom", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "household", "role": "all_imports"}, "uuid": "e8e6e43e-2c46-4620-a070-91d2da004b1c", "retired": true, "note": "curated entity fold (d353): hand-recorded May 2026 rows join the resolver economy/aggregate lineage"} +{"concept": "census.housing_starts.saar", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "dwelling", "role": "housing_start"}, "uuid": "d0212a1e-b360-460a-80a8-1cf4ad5ce427", "retired": true, "note": "curated entity fold (d353): hand-recorded May 2026 rows join the resolver economy/aggregate lineage"} +{"concept": "fed.g17.capacity_utilization.total_industry", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "institutional_sector", "role": "total_industry_capacity"}, "uuid": "978252a9-c452-41eb-aece-323340e796fc", "retired": true, "note": "curated entity fold (d353): hand-recorded May 2026 rows join the resolver economy/aggregate lineage"} +{"concept": "fed.g17.industrial_production.total_index_mom", "geography": {"level": "country", "id": "0100000US", "vintage": "current"}, "entity": {"name": "institutional_sector", "role": "total_industrial_production"}, "uuid": "d5634fc4-dbe0-4203-a5b7-728708b85a14", "retired": true, "note": "curated entity fold (d353): hand-recorded May 2026 rows join the resolver economy/aggregate lineage"} diff --git a/scripts/build_series_catalog.py b/scripts/build_series_catalog.py index de6f4380..1dcce240 100644 --- a/scripts/build_series_catalog.py +++ b/scripts/build_series_catalog.py @@ -79,6 +79,28 @@ a retire line for the absorbed binding (its old UUID goes dormant with it). +Curated entity folds cover the one merge that recipe cannot express: two +committed lineages of one series whose rows carry different entities (a +hand-recorded early row and a resolver row written with the default +``economy/aggregate``). Alias inheritance never crosses an entity slice, so +regeneration would restore the split. The seed at +``ledger/seeds/entity_folds.json`` (``chronicle_entity_folds_v1``) lists +folds as (concept, geography, absorbed_entity, survivor_entity, note). +Before identities are grouped, every current row of that concept and +geography carrying the absorbed entity is read as carrying the survivor +entity; the observation file itself is never changed. The absorbed row's +curated names join the survivor's ``aliases``, its live binding is retired +with the ``--remint-note``, and the survivor keeps its UUID. The catalog +commits to the seed as ``entity_folds_sha256`` (absent when there is no +seed). Once a committed catalog declares it, regenerating without the seed +is a hard error, because it would silently split the folded lineages again; +an emptied ``folds`` list is the reviewed way to undo a fold, and the +absorbed identities then revive with their original UUIDs. A fold that +matches no current row (its rows superseded, say) is inert, so a later +correction can never block regeneration; a fold must still name an +absorbed identity the registry has bound and a survivor the committed +catalog holds, so a mistyped fold is refused instead of ignored. + Inputs are pinned: the observation JSONL (``observations_sha256``), the committed docket seed at ``ledger/seeds/thesis_docket_series.json`` (``docket_seed_sha256``) — a MISSING seed is a hard error, never a silent @@ -112,6 +134,11 @@ CATALOG = ROOT / "ledger" / "series_catalog.json" DOCKET_SEED = ROOT / "ledger" / "seeds" / "thesis_docket_series.json" UUID_REGISTRY = ROOT / "ledger" / "series_uuid_registry.jsonl" +ENTITY_FOLDS = ROOT / "ledger" / "seeds" / "entity_folds.json" +ENTITY_FOLDS_SCHEMA = "chronicle_entity_folds_v1" +ENTITY_FOLD_FIELDS = ( + "concept", "geography", "absorbed_entity", "survivor_entity", "note", +) GENERATOR_VERSION = 3 @@ -571,6 +598,165 @@ def canonical_uuid_problem(value: object) -> str | None: return None +def load_entity_folds(path: pathlib.Path | None) -> tuple[list[dict], bytes | None]: + """The curated entity-fold seed: (folds, raw bytes), or ([], None). + + Strict JSON, closed-world keys, and the same identity-field rules as + observation rows, so a fold can only name an identity a row could carry. + """ + if path is None or not path.exists(): + return [], None + raw = path.read_bytes() + try: + doc = json.loads( + raw.decode("utf-8"), + object_pairs_hook=_reject_duplicate_keys, + parse_constant=_reject_json_constants, + ) + except (UnicodeDecodeError, ValueError) as exc: + raise SystemExit(f"entity folds {path}: not strict JSON ({exc})") + if not isinstance(doc, dict): + raise SystemExit(f"entity folds {path}: must be a JSON object") + unknown = set(doc) - {"schemaVersion", "comment", "folds"} + if unknown: + raise SystemExit(f"entity folds {path}: unknown fields {sorted(unknown)}") + if doc.get("schemaVersion") != ENTITY_FOLDS_SCHEMA: + raise SystemExit( + f"entity folds {path}: schemaVersion must be {ENTITY_FOLDS_SCHEMA!r}" + ) + if "comment" in doc and not isinstance(doc["comment"], str): + raise SystemExit(f"entity folds {path}: comment must be a string") + folds = doc.get("folds") + if not isinstance(folds, list): + raise SystemExit(f"entity folds {path}: folds must be a list") + seen: set[tuple[str, str, str]] = set() + absorbed_keys: set[tuple[str, str, str]] = set() + survivor_keys: set[tuple[str, str, str]] = set() + for index, fold in enumerate(folds): + where = f"entity folds {path}: fold {index}" + if not isinstance(fold, dict): + raise SystemExit(f"{where} must be an object") + if set(fold) != set(ENTITY_FOLD_FIELDS): + raise SystemExit( + f"{where} must have exactly the fields {list(ENTITY_FOLD_FIELDS)}" + ) + concept = fold["concept"] + if not isinstance(concept, str) or not concept: + raise SystemExit(f"{where}: concept must be a nonempty string") + for problem in ( + _reserved_segment_problem(concept), + _cosmetic_problem(concept), + ): + if problem: + raise SystemExit(f"{where}: concept {problem}") + problem = _dimension_problem( + fold["geography"], ("level", "id", "vintage", "name"), + "geography", ("level", "id"), + ) + if problem or fold["geography"] is None: + raise SystemExit(f"{where}: {problem or 'geography is required'}") + for side in ("absorbed_entity", "survivor_entity"): + problem = _dimension_problem( + fold[side], ("name", "role"), side, ("name", "role") + ) + if problem or fold[side] is None: + raise SystemExit(f"{where}: {problem or side + ' is required'}") + if not _usable_note(fold["note"]): + raise SystemExit(f"{where}: note must be a nonempty string") + geo_key = _geo_key(fold["geography"]) + absorbed_key = (concept, geo_key, _entity_key(fold["absorbed_entity"])) + survivor_key = (concept, geo_key, _entity_key(fold["survivor_entity"])) + if absorbed_key == survivor_key: + raise SystemExit(f"{where} folds an entity into itself") + if absorbed_key in seen: + raise SystemExit(f"{where} repeats the fold of {absorbed_key}") + seen.add(absorbed_key) + absorbed_keys.add(absorbed_key) + survivor_keys.add(survivor_key) + chained = absorbed_keys & survivor_keys + if chained: + raise SystemExit( + f"entity folds {path}: {sorted(chained)} is both absorbed and a " + "survivor — fold straight into the final survivor" + ) + return folds, raw + + +def prepare_entity_folds( + folds: list[dict], existing: "ExistingCatalog", registry: "UuidRegistry" +) -> dict[tuple[str, str], dict[str, dict]]: + """Validate folds against committed state and move naming memory. + + Returns the row matcher: (geo_key, absorbed entity_key) -> concept + spelling -> fold. The spellings are the fold concept plus every curated + name of the survivor, which after the first fold include the absorbed + row's names, so alias-spelled absorbed rows fold too. + """ + matcher: dict[tuple[str, str], dict[str, dict]] = {} + for fold in folds: + concept = fold["concept"] + geo_key = _geo_key(fold["geography"]) + absorbed_key = (concept, geo_key, _entity_key(fold["absorbed_entity"])) + survivor_key = (concept, geo_key, _entity_key(fold["survivor_entity"])) + survivor = existing.by_identity.get(survivor_key) + if survivor is None or survivor.get("status") != "observed": + raise SystemExit( + f"entity fold {absorbed_key} -> {survivor_key}: the survivor " + "has no committed observed catalog row" + ) + if registry.latest.get(absorbed_key) is None: + raise SystemExit( + f"entity fold {absorbed_key}: the registry has never bound " + "the absorbed identity — check the concept, geography and " + "entity spelling" + ) + if absorbed_key in existing.by_identity: + existing.absorb(absorbed_key, survivor) + names = {concept, survivor["concept"], *survivor.get("aliases", [])} + slot = matcher.setdefault((geo_key, absorbed_key[2]), {}) + for name in names: + slot[name] = fold + return matcher + + +def apply_entity_folds( + rows: list[dict], matcher: dict[tuple[str, str], dict[str, dict]] +) -> tuple[list[dict], Counter]: + """Rows with folded entities read as their survivor entity. + + Matched rows are copied, never mutated, so the observation journal and + every caller's rows keep the entity they were recorded with. Returns the + rows and a count of folded rows per absorbed identity. + """ + if not matcher: + return rows, Counter() + applied: Counter = Counter() + out: list[dict] = [] + for row in rows: + slot = matcher.get( + (_geo_key(row.get("geography")), _entity_key(row.get("entity"))) + ) + fold = None + if slot: + measure = row.get("measure") or {} + concept = concept_for( + family_pattern(measure.get("concept", ""), row.get("period") or {}) + ) + fold = slot.get(concept) + if fold is None: + out.append(row) + continue + folded = dict(row) + folded["entity"] = dict(fold["survivor_entity"]) + out.append(folded) + applied[( + fold["concept"], + _geo_key(fold["geography"]), + _entity_key(fold["absorbed_entity"]), + )] += 1 + return out, applied + + def build_identities(rows: list[dict]) -> dict[tuple[str, str, str], dict]: """Group observation rows by (concept, geography, entity) identity.""" identities: dict[tuple[str, str, str], dict] = {} @@ -740,9 +926,11 @@ def __init__(self, path: pathlib.Path) -> None: self.by_identity: dict[tuple[str, str, str], dict] = {} self.by_dim: dict[tuple[str, str], list[dict]] = {} self.docket_rows: list[dict] = [] + self.entity_folds_sha256: str | None = None if not path.exists(): return catalog = json.loads(path.read_text(encoding="utf-8")) + self.entity_folds_sha256 = catalog.get("entity_folds_sha256") for row in catalog.get("series", []): for alias in row.get("aliases", []): problem = _reserved_segment_problem(alias) @@ -761,6 +949,9 @@ def __init__(self, path: pathlib.Path) -> None: self.by_dim.setdefault((key[1], key[2]), []).append(row) if row.get("status") == "docket-only": self.docket_rows.append(row) + self._index_names() + + def _index_names(self) -> None: alias_holders = Counter( alias for row in self.rows for alias in row.get("aliases", []) ) @@ -774,6 +965,25 @@ def __init__(self, path: pathlib.Path) -> None: if count > 1 or alias in canonical } + def absorb(self, absorbed_key: tuple[str, str, str], survivor: dict) -> None: + """Fold a committed row into ``survivor``'s naming memory. + + The absorbed row's concept and curated aliases become survivor + aliases, and the row leaves every index, so the two-UUID guard never + sees both priors and the absorbed binding retires through the + ordinary liveness check. + """ + absorbed = self.by_identity.pop(absorbed_key) + self.rows.remove(absorbed) + self.by_dim[(absorbed_key[1], absorbed_key[2])].remove(absorbed) + if absorbed in self.docket_rows: + self.docket_rows.remove(absorbed) + names = {absorbed["concept"], *absorbed.get("aliases", [])} + survivor["aliases"] = sorted( + (set(survivor.get("aliases", [])) | names) - {survivor["concept"]} + ) + self._index_names() + def _row_names(self, row: dict) -> set[str]: return {row["concept"], *row.get("aliases", [])} - self.ambiguous_names @@ -1441,6 +1651,7 @@ def build_catalog( docket_path: pathlib.Path | None, existing: ExistingCatalog, registry: UuidRegistry, + entity_folds_path: pathlib.Path | None = None, ) -> tuple[dict, dict]: """Build the catalog and the identity plan. @@ -1527,7 +1738,17 @@ def build_catalog( f"check_thesis_facts_append (receipt package required): {exc}" ) current_rows = effective_current_rows(rows) - identities = build_identities(current_rows) + folds, folds_raw = load_entity_folds(entity_folds_path) + if folds_raw is None and existing.entity_folds_sha256 is not None: + raise SystemExit( + f"entity-fold seed missing: {entity_folds_path} — the committed " + "catalog declares entity_folds_sha256, and regenerating without " + "the seed would split the folded lineages again. To undo a fold, " + "remove it from the seed's folds list; never delete the file." + ) + fold_matcher = prepare_entity_folds(folds, existing, registry) + identity_rows, folds_applied = apply_entity_folds(current_rows, fold_matcher) + identities = build_identities(identity_rows) # Canonicalize each observed bucket through the existing catalog: an # exact identity hit, a same-dimension curated-alias hit, or a @@ -2044,6 +2265,11 @@ def resolve_uuid( "docket_seed_sha256": ( hashlib.sha256(docket_raw).hexdigest() if docket_raw else None ), + **( + {"entity_folds_sha256": hashlib.sha256(folds_raw).hexdigest()} + if folds_raw is not None + else {} + ), "uuid_registry_sha256": None, "suspect_segments": sorted(all_suspects), "stripped_segments": { @@ -2053,6 +2279,9 @@ def resolve_uuid( "ambiguous_aliases": ambiguous_aliases, "series": series, } + plan["entity_folds_applied"] = { + json.dumps(list(key)): count for key, count in sorted(folds_applied.items()) + } return catalog, plan @@ -2188,6 +2417,16 @@ def main(argv: list[str] | None = None) -> int: "(default: the committed seed; pass a path to update it)" ), ) + parser.add_argument( + "--entity-folds", + type=pathlib.Path, + default=None, + help=( + "curated entity-fold seed (default: seeds/entity_folds.json " + "beside the catalog, i.e. ledger/seeds/entity_folds.json for " + "the committed catalog)" + ), + ) parser.add_argument( "--check", action="store_true", @@ -2247,7 +2486,12 @@ def main(argv: list[str] | None = None) -> int: _check_registry_vs_head(registry) existing = ExistingCatalog(args.catalog) - catalog, plan = build_catalog(args.observations, args.docket, existing, registry) + entity_folds = args.entity_folds or ( + args.catalog.parent / "seeds" / "entity_folds.json" + ) + catalog, plan = build_catalog( + args.observations, args.docket, existing, registry, entity_folds + ) identity_changes = [ f"remint {UuidRegistry.entry_key(e)}: {e['supersedes']} -> {e['uuid']}" diff --git a/tests/test_build_series_catalog.py b/tests/test_build_series_catalog.py index 584cb707..d5ca9503 100644 --- a/tests/test_build_series_catalog.py +++ b/tests/test_build_series_catalog.py @@ -762,6 +762,7 @@ def test_committed_catalog_is_current_and_valid() -> None: bsc.DOCKET_SEED, bsc.ExistingCatalog(bsc.CATALOG), registry, + bsc.ENTITY_FOLDS, ) assert not plan["mints"] and not plan["supersedes"] and not plan["dropped"] catalog["uuid_registry_sha256"] = registry.sha256() @@ -785,16 +786,22 @@ def test_committed_catalog_is_current_and_valid() -> None: # EVERY stripped spelling is auditable, mapped to the canonical # concepts it touched — a statute or edition label colliding with a # period spelling can only be caught here. + # Re-pinned 2026-10-12 to the catalog at d7e45bc5 for the d353 entity + # fold (the fold changes no strip). New since 55bbf3d: the 2026_08 + # ABS CPI print (abs.cpi.all_groups.yoy.2026_08, line 231, its own + # period with an underscore) and weekly claims prints through + # week_2026-09-19. #309 replaces this list with a reviewed audit. assert sorted(committed["stripped_segments"]) == [ - "2026-05", "2026-06", "2026-06-18", "2026-07", "2026_05", - "2026_06", "2026_06_18", "2026_07", "2026_q2", "after_june_2026", + "2026-05", "2026-06", "2026-06-18", "2026-07", "2026_05", "2026_06", + "2026_06_18", "2026_07", "2026_08", "2026_q2", "after_june_2026", "after_mpc_june_2026", "april_2026", "feb_2026", - "february_to_april_2026", "fy2024", "fy2025", "july_2026", - "june_2026", "may_2026", "q1_2026", "week_2026-06-13", - "week_2026-06-20", "week_2026-06-27", "week_2026-07-04", - "week_2026-07-11", "week_2026-07-13", "week_2026-07-18", - "week_2026-07-25", "week_2026-08-01", "week_2026-08-08", - "week_2026-08-15", "week_2026-08-22", "week_2026_06_13", + "february_to_april_2026", "fy2024", "fy2025", "july_2026", "june_2026", + "may_2026", "q1_2026", "week_2026-06-13", "week_2026-06-20", + "week_2026-06-27", "week_2026-07-04", "week_2026-07-11", + "week_2026-07-13", "week_2026-07-18", "week_2026-07-25", + "week_2026-08-01", "week_2026-08-08", "week_2026-08-15", + "week_2026-08-22", "week_2026-08-29", "week_2026-09-05", + "week_2026-09-12", "week_2026-09-19", "week_2026_06_13", "week_ending_2026_06_06", ] assert committed["stripped_segments"]["after_mpc_june_2026"] == [ @@ -807,7 +814,12 @@ def test_committed_catalog_is_current_and_valid() -> None: assert committed["docket_seed_sha256"] is not None assert committed["uuid_registry_sha256"] == registry.sha256() assert bsc.DOCKET_SEED.exists() - assert len(committed["series"]) == 228 + # 228 -> 221 at the d353 entity fold (2026-10-12): seven hand-recorded + # May 2026 lineages folded into their economy/aggregate siblings. + assert committed["entity_folds_sha256"] == bsc.hashlib.sha256( + bsc.ENTITY_FOLDS.read_bytes() + ).hexdigest() + assert len(committed["series"]) == 221 def test_rebuild_without_prior_catalog_is_gated( @@ -1262,8 +1274,21 @@ def test_identity_uuid_map_matches_reviewed_anchor() -> None: # is not involved), which is why the three Colorado-named concepts carry # country-level geography: the observations were recorded that way. The # other 211 live bindings are byte-unchanged (219 -> 228). + # Updated 2026-10-12 alongside seven registry retire events (Max's + # ruling d353, ledger/seeds/entity_folds.json): the entity-drift families + # of docs/catalog-curation-backlog.md fold into their economy/aggregate + # lineages. Retired, with their rows' observations joining the survivor: + # 8dbbd54f (bls.cps.unemployment_rate person/civilian_labor_force), + # 3e796803 (bls.cpi.u.headline_mom household/cpi_u_all_items), d85c3c7f + # (bls.cpi.u.core_mom household/cpi_u_less_food_energy), e8e6e43e + # (bls.import_price_index.all_imports_mom household/all_imports), + # d0212a1e (census.housing_starts.saar dwelling/housing_start), 978252a9 + # (fed.g17.capacity_utilization.total_industry institutional_sector) and + # d5634fc4 (fed.g17.industrial_production.total_index_mom + # institutional_sector). No mint, no supersede; the other 221 live + # bindings keep their UUIDs (228 -> 221). assert digest == ( - "da63b697ad0e4444d4f834671fc15e979c67b47545aba836fb6f043d75e8404d" + "56bb47bc6928206b1aad67e25a1ebe8a92ff4d02e53ec3923f540fefe7c57cad" ) From a803f08265269448b9058e5be87d89448a13957b Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 09:12:21 -0400 Subject: [PATCH 2/6] Test the entity fold's invariants and record the folded families - Behaviour: two drift lineages fold into one, the survivor keeps its UUID, the absorbed binding retires with the note, the catalog commits to the seed, and regeneration is byte-identical. A first fold is refused without --allow-remint and pending under --check. - Ratchet: deleting the seed under a catalog that declares it is a hard error. Emptying a fold revives the absorbed UUID. A fold matching no current row is inert. Alias-spelled absorbed rows fold too. - Refusals: closed seed schema (twelve cases), strict JSON, an absorbed identity the registry never bound, a survivor with no committed row. - Property (Hypothesis, any split of one series across two entities, overlapping months allowed): observations are conserved, nothing is minted or superseded, exactly the absorbed UUID retires, the survivor spans every period, regeneration is byte-identical, and an emptied fold revives exactly the absorbed UUID. - docs/catalog-curation-backlog.md: the seven entity-drift families move from blocked to folded, with the survivors, the retired bindings, the two unfolded sibling pairs and how to undo a fold. Co-Authored-By: Claude Opus 5.5 --- docs/catalog-curation-backlog.md | 66 +++-- pyproject.toml | 2 + tests/test_build_series_catalog.py | 373 +++++++++++++++++++++++++++++ uv.lock | 96 +++++++- 4 files changed, 517 insertions(+), 20 deletions(-) diff --git a/docs/catalog-curation-backlog.md b/docs/catalog-curation-backlog.md index 564a378a..2b7d65f1 100644 --- a/docs/catalog-curation-backlog.md +++ b/docs/catalog-curation-backlog.md @@ -1,26 +1,54 @@ # Catalog curation backlog -These series lineages remain split because the catalog builder scopes -concept and alias inheritance to an exact geography and entity slice. -Curating an alias cannot move an observation across entity keys, and the -catalog must not lose observations merely to present one lineage. +## Entity-drift families: folded 2026-10-12 -On 2026-08-07, a disposable-copy experiment attempted each entity-drift -fold by deleting the unpinned row and adding its canonical concept to the -docket-pinned row. Regeneration restored both rows and produced a catalog -and UUID registry byte-identical to the originals: all seven pairs still -held one observation on each entity. They must remain split until the -upstream observation metadata is corrected. +Seven series each held two observed lineages because their hand-recorded +May 2026 rows carry a bespoke entity while every resolver print carries +`economy/aggregate`, the default entity the Thesis resolver writes. The +catalog builder scopes concept and alias inheritance to one geography and +entity slice, so curating an alias could not join them: on 2026-08-07 a +disposable-copy experiment deleted the unpinned row and aliased its concept +on the docket-pinned row, and regeneration restored both rows byte for +byte. The same experiment was repeated on 2026-09-22 with the same result. -| Concept | Docket-pinned entity and UUID | Other entity and UUID | Blocker | -| --- | --- | --- | --- | -| `bls.cpi.u.headline_mom` | `household/cpi_u_all_items`, `3e796803-a194-4c83-9dc9-27cc870ff08e` | `economy/aggregate`, `70ca2ecf-4323-4453-b42f-23350cb95f22` | May and June observations disagree on entity. | -| `bls.cpi.u.core_mom` | `household/cpi_u_less_food_energy`, `d85c3c7f-874b-4caa-bfad-1ec7a473c293` | `economy/aggregate`, `e5e402d5-1a65-4c5d-a67a-07e3cf03cbf8` | May and June observations disagree on entity. | -| `bls.cps.unemployment_rate` | `person/civilian_labor_force`, `8dbbd54f-4bfd-4735-ad0d-5b55b8bb4ec5` | `economy/aggregate`, `db2f3857-e0fa-48f8-9ab1-6c8989307fd2` | May and June observations disagree on entity. | -| `fed.g17.industrial_production.total_index_mom` | `economy/aggregate`, `dbfd5050-e5df-40af-8922-dc8927d6363a` | `institutional_sector/total_industrial_production`, `d5634fc4-dbe0-4203-a5b7-728708b85a14` | May and June observations disagree on entity. The same-dimension `us.frb` spelling is folded into the latter row separately. | -| `fed.g17.capacity_utilization.total_industry` | `economy/aggregate`, `9668ecdb-5f61-422d-a653-8e8956257ade` | `institutional_sector/total_industry_capacity`, `978252a9-c452-41eb-aece-323340e796fc` | May and June observations disagree on entity. | -| `census.housing_starts.saar` | `economy/aggregate`, `8c999902-84e2-4e90-b49c-325cd535062a` | `dwelling/housing_start`, `d0212a1e-b360-460a-80a8-1cf4ad5ce427` | May and June observations disagree on entity. The same-dimension `us.census` spelling is folded into the latter row separately. | -| `bls.import_price_index.all_imports_mom` | `economy/aggregate`, `1d271205-0e71-4a74-9d5f-47e77577e2b2` | `household/all_imports`, `e8e6e43e-2c46-4620-a070-91d2da004b1c` | May and June observations disagree on entity. | +Max ruled on 2026-09-27 (d353) that the `economy/aggregate` lineage +survives for all seven. The builder gained curated entity folds +(`ledger/seeds/entity_folds.json`, described in the +`build_series_catalog.py` module docstring): before identities are grouped, +a fold reads the absorbed entity's current rows as carrying the survivor +entity, without changing the observation file. Regenerating with the seven +folds retired seven bindings and kept every survivor's UUID; the catalog +went from 228 to 221 series and the observed `observation_count` still sums +to the 233 current rows. + +| Concept | Survivor (`economy/aggregate`) | Retired | +| --- | --- | --- | +| `bls.cpi.u.headline_mom` | `70ca2ecf-4323-4453-b42f-23350cb95f22` | `household/cpi_u_all_items`, `3e796803-a194-4c83-9dc9-27cc870ff08e` | +| `bls.cpi.u.core_mom` | `e5e402d5-1a65-4c5d-a67a-07e3cf03cbf8` | `household/cpi_u_less_food_energy`, `d85c3c7f-874b-4caa-bfad-1ec7a473c293` | +| `bls.cps.unemployment_rate` | `db2f3857-e0fa-48f8-9ab1-6c8989307fd2` | `person/civilian_labor_force`, `8dbbd54f-4bfd-4735-ad0d-5b55b8bb4ec5` | +| `fed.g17.industrial_production.total_index_mom` | `dbfd5050-e5df-40af-8922-dc8927d6363a` | `institutional_sector/total_industrial_production`, `d5634fc4-dbe0-4203-a5b7-728708b85a14` (its folded `us.frb` spelling joins too) | +| `fed.g17.capacity_utilization.total_industry` | `9668ecdb-5f61-422d-a653-8e8956257ade` | `institutional_sector/total_industry_capacity`, `978252a9-c452-41eb-aece-323340e796fc` | +| `census.housing_starts.saar` | `8c999902-84e2-4e90-b49c-325cd535062a` | `dwelling/housing_start`, `d0212a1e-b360-460a-80a8-1cf4ad5ce427` (its folded `us.census` spelling joins too) | +| `bls.import_price_index.all_imports_mom` | `1d271205-0e71-4a74-9d5f-47e77577e2b2` | `household/all_imports`, `e8e6e43e-2c46-4620-a070-91d2da004b1c` | + +Three of these were docket-pinned to the retired lineage +(`bls.cps.unemployment_rate`, `bls.cpi.u.headline_mom`, +`bls.cpi.u.core_mom`); Thesis re-stamps those pins in the same rollout. + +Two more concepts still hold sibling lineages and were not folded: +`bls.ces.total_nonfarm_payroll_change` (`person/nonfarm_payroll_employee` +from May beside `economy/aggregate` from June; the Thesis docket observes a +third concept, `bls.ces.nonfarm_payrolls.change`) and +`statcan.employment_insurance.regular_beneficiaries.canada` (two +hand-chosen person roles, April and May). Fold them with a seed entry and +a reviewed regeneration if a consumer ever needs one lineage. + +To undo a fold, remove its entry from the seed's `folds` list and +regenerate: the absorbed identity revives with its original UUID. The +names the fold moved onto the survivor's `aliases` stay there as curated +memory; remove them by hand if they should go. Never delete the seed file +while the committed catalog declares `entity_folds_sha256`; the builder +refuses that, because it would split the lineages silently. ## Initial claims cadence metadata diff --git a/pyproject.toml b/pyproject.toml index d96fd965..332d75ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ dependencies = [ [project.optional-dependencies] dev = [ + "hypothesis>=6.100,<7", "pytest>=8.0.0,<9", "ruff>=0.5.0", ] @@ -56,5 +57,6 @@ target-version = "py311" [dependency-groups] dev = [ + "hypothesis>=6.100,<7", "pytest>=8.0.0,<9", ] diff --git a/tests/test_build_series_catalog.py b/tests/test_build_series_catalog.py index d5ca9503..0efa3863 100644 --- a/tests/test_build_series_catalog.py +++ b/tests/test_build_series_catalog.py @@ -16,6 +16,8 @@ import sys import pytest +from hypothesis import HealthCheck, given, settings +from hypothesis import strategies as st ROOT = pathlib.Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "scripts")) @@ -2505,3 +2507,374 @@ def test_stale_catalog_uuid_after_supersede_fails_before_write( bsc.main(argv) assert (tmp_path / "catalog.json").read_bytes() == catalog_before assert (tmp_path / "registry.jsonl").read_bytes() == registry_before + + +# --- curated entity folds (Max's ruling d353, 2026-09-27) ------------------- + +HAND_ENTITY = {"name": "person", "role": "civilian_labor_force"} +ECONOMY = {"name": "economy", "role": "aggregate"} +US_IDENTITY = {"level": "country", "id": "0100000US", "vintage": "current"} +FOLD_NOTE = "test fold: hand-recorded rows join the resolver lineage" + + +def _fold_month(value: str) -> dict: + return {"type": "month", "value": value} + + +def _drift_rows(hand_months=("2026-05",), economy_months=("2026-06", "2026-07")): + """One series recorded twice: hand rows with a bespoke entity, resolver + rows with economy/aggregate — the shape of the seven families.""" + rows = [] + for month in hand_months: + rows.append(_row( + "bls.cps.unemployment_rate", + rid=f"bls.cps.unemployment_rate.{month}.hand", + period=_fold_month(month), + entity=dict(HAND_ENTITY), + source_concept="bls.cps.unemployment_rate", + )) + for month in economy_months: + rows.append(_row( + f"bls.cps.unemployment_rate.{month}", + rid=f"bls.cps.unemployment_rate.{month}.first_print", + period=_fold_month(month), + source_concept="UNRATE", + )) + return rows + + +def _fold(**overrides) -> dict: + fold = { + "concept": "bls.cps.unemployment_rate", + "geography": dict(US_IDENTITY), + "absorbed_entity": dict(HAND_ENTITY), + "survivor_entity": dict(ECONOMY), + "note": FOLD_NOTE, + } + fold.update(overrides) + return fold + + +def _write_folds(tmp_path: pathlib.Path, folds: list, **doc_overrides) -> bytes: + doc = {"schemaVersion": bsc.ENTITY_FOLDS_SCHEMA, "folds": folds} + doc.update(doc_overrides) + (tmp_path / "seeds").mkdir(exist_ok=True) + raw = (json.dumps(doc, indent=2) + "\n").encode() + (tmp_path / "seeds" / "entity_folds.json").write_bytes(raw) + return raw + + +def _observed(tmp_path: pathlib.Path, concept: str) -> list[dict]: + catalog = json.loads((tmp_path / "catalog.json").read_text()) + return [ + r for r in catalog["series"] + if r["concept"] == concept and r["status"] == "observed" + ] + + +def _uuid_for(rows: list[dict], entity: dict) -> str: + (row,) = [r for r in rows if r["entity"] == entity] + return row["uuid"] + + +def _folded_repo(tmp_path: pathlib.Path, rows=None) -> tuple[list[str], str, str]: + """A repo whose two drift lineages were folded; returns argv and the + survivor and absorbed uuids.""" + argv = _repo(tmp_path, rows or _drift_rows()) + assert bsc.main(argv) == 0 + before = _observed(tmp_path, "bls.cps.unemployment_rate") + survivor = _uuid_for(before, ECONOMY) + absorbed = _uuid_for(before, HAND_ENTITY) + _write_folds(tmp_path, [_fold()]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 + return argv, survivor, absorbed + + +def test_entity_fold_joins_the_lineages_and_retires_the_absorbed_binding( + tmp_path: pathlib.Path, +) -> None: + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + before = _observed(tmp_path, "bls.cps.unemployment_rate") + assert len(before) == 2 + survivor = _uuid_for(before, ECONOMY) + absorbed = _uuid_for(before, HAND_ENTITY) + seed = _write_folds(tmp_path, [_fold()]) + registry_before = (tmp_path / "registry.jsonl").read_bytes() + # A first fold retires a live binding: refused without the ceremony, + # pending under --check, and nothing written. + assert bsc.main(argv) == 1 + assert bsc.main(argv + ["--check"]) == 1 + assert (tmp_path / "registry.jsonl").read_bytes() == registry_before + assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 + + (row,) = _observed(tmp_path, "bls.cps.unemployment_rate") + assert row["uuid"] == survivor and row["entity"] == ECONOMY + assert row["observation_count"] == 3 + assert row["first_observed_period"] == "2026-05" + assert row["last_observed_period"] == "2026-07" + assert set(row["source_concepts"]) == {"UNRATE", "bls.cps.unemployment_rate"} + catalog = json.loads((tmp_path / "catalog.json").read_text()) + assert catalog["entity_folds_sha256"] == bsc.hashlib.sha256(seed).hexdigest() + assert absorbed not in {r["uuid"] for r in catalog["series"]} + + lines = (tmp_path / "registry.jsonl").read_text().splitlines() + retire = json.loads(lines[-1]) + assert retire["retired"] is True and retire["uuid"] == absorbed + assert retire["entity"] == HAND_ENTITY and retire["note"] == FOLD_NOTE + assert len(lines) == len(registry_before.decode().splitlines()) + 1 + + assert bsc.main(argv + ["--check"]) == 0 + catalog_bytes = (tmp_path / "catalog.json").read_bytes() + registry_bytes = (tmp_path / "registry.jsonl").read_bytes() + assert bsc.main(argv) == 0 + assert (tmp_path / "catalog.json").read_bytes() == catalog_bytes + assert (tmp_path / "registry.jsonl").read_bytes() == registry_bytes + + +def test_entity_fold_never_writes_the_observation_journal( + tmp_path: pathlib.Path, +) -> None: + rows = _drift_rows() + journal = "".join(json.dumps(r) + "\n" for r in rows).encode() + argv, _, _ = _folded_repo(tmp_path, rows) + assert (tmp_path / "obs.jsonl").read_bytes() == journal + assert bsc.main(argv) == 0 + assert (tmp_path / "obs.jsonl").read_bytes() == journal + + +def test_entity_fold_seed_cannot_silently_vanish(tmp_path: pathlib.Path) -> None: + argv, _, _ = _folded_repo(tmp_path) + (tmp_path / "seeds" / "entity_folds.json").unlink() + with pytest.raises(SystemExit, match="entity-fold seed missing"): + bsc.main(argv) + with pytest.raises(SystemExit, match="entity-fold seed missing"): + bsc.main(argv + ["--check"]) + + +def test_emptied_entity_fold_revives_the_absorbed_uuid( + tmp_path: pathlib.Path, +) -> None: + argv, survivor, absorbed = _folded_repo(tmp_path) + empty = _write_folds(tmp_path, []) + # Reviving is the generator's automatic, ungated event. + assert bsc.main(argv) == 0 + rows = _observed(tmp_path, "bls.cps.unemployment_rate") + assert _uuid_for(rows, ECONOMY) == survivor + assert _uuid_for(rows, HAND_ENTITY) == absorbed + revive = json.loads( + (tmp_path / "registry.jsonl").read_text().splitlines()[-1] + ) + assert revive["revived"] is True and revive["uuid"] == absorbed + catalog = json.loads((tmp_path / "catalog.json").read_text()) + assert catalog["entity_folds_sha256"] == bsc.hashlib.sha256(empty).hexdigest() + assert bsc.main(argv + ["--check"]) == 0 + + +def test_entity_fold_matching_no_current_row_is_inert( + tmp_path: pathlib.Path, +) -> None: + # A later correction can leave the absorbed entity with no current row; + # that must never block regeneration (the Thesis resolver regenerates on + # every append). + argv, survivor, _ = _folded_repo(tmp_path) + registry_bytes = (tmp_path / "registry.jsonl").read_bytes() + (tmp_path / "obs.jsonl").write_text( + "".join(json.dumps(r) + "\n" for r in _drift_rows(hand_months=())), + encoding="utf-8", + ) + assert bsc.main(argv) == 0 + (row,) = _observed(tmp_path, "bls.cps.unemployment_rate") + assert row["uuid"] == survivor and row["observation_count"] == 2 + assert (tmp_path / "registry.jsonl").read_bytes() == registry_bytes + assert bsc.main(argv + ["--check"]) == 0 + + +def test_entity_fold_reaches_rows_spelled_by_a_curated_alias( + tmp_path: pathlib.Path, +) -> None: + # The shape of census.housing_starts.saar and the G.17 industrial + # production pair: the hand lineage already absorbed a second spelling by + # a same-dimension curated merge, and those rows must fold too. + sector = {"name": "institutional_sector", "role": "total_industrial_production"} + rows = [ + _row("fed.g17.ip.mom.may_2026", rid="fed.g17.ip.mom.may_2026.hand", + period=_fold_month("2026-05"), entity=dict(sector)), + _row("us.frb.ip.mom.2026_04", rid="us.frb.ip.mom.2026_04.hand", + period=_fold_month("2026-04"), entity=dict(sector)), + _row("fed.g17.ip.mom.2026-06", rid="fed.g17.ip.mom.2026-06.first_print", + period=_fold_month("2026-06"), source_concept="INDPRO"), + ] + argv = _repo(tmp_path, rows) + assert bsc.main(argv) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + spelled = next(r for r in catalog["series"] if r["concept"] == "us.frb.ip.mom") + hand = next( + r for r in catalog["series"] + if r["concept"] == "fed.g17.ip.mom" and r["entity"] == sector + ) + catalog["series"].remove(spelled) + hand["aliases"] = sorted({*hand["aliases"], "us.frb.ip.mom"}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + assert bsc.main(argv + ["--allow-remint", "--remint-note", "spelling"]) == 0 + economy = _uuid_for(_observed(tmp_path, "fed.g17.ip.mom"), ECONOMY) + + _write_folds(tmp_path, [_fold(concept="fed.g17.ip.mom", absorbed_entity=sector)]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 + (row,) = _observed(tmp_path, "fed.g17.ip.mom") + assert row["uuid"] == economy and row["observation_count"] == 3 + assert "us.frb.ip.mom.{P}" in row["family_patterns"] + assert not _observed(tmp_path, "us.frb.ip.mom") + assert bsc.main(argv + ["--check"]) == 0 + + +def test_entity_fold_naming_an_unbound_identity_is_refused( + tmp_path: pathlib.Path, +) -> None: + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + typo = {"name": "person", "role": "civilian_labour_force"} + _write_folds(tmp_path, [_fold(absorbed_entity=typo)]) + with pytest.raises(SystemExit, match="registry has never bound"): + bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) + + +def test_entity_fold_without_a_committed_survivor_is_refused( + tmp_path: pathlib.Path, +) -> None: + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + _write_folds( + tmp_path, + [_fold(survivor_entity={"name": "household", "role": "aggregate"})], + ) + with pytest.raises(SystemExit, match="no committed observed catalog row"): + bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) + + +@pytest.mark.parametrize( + ("folds", "doc", "match"), + [ + ([_fold()], {"extra": 1}, "unknown fields"), + ([_fold()], {"schemaVersion": "v0"}, "schemaVersion must be"), + ([_fold()], {"comment": 3}, "comment must be a string"), + ([{k: v for k, v in _fold().items() if k != "note"}], {}, "exactly the fields"), + ([{**_fold(), "extra": 1}], {}, "exactly the fields"), + ([_fold(note=" ")], {}, "note must be a nonempty string"), + ([_fold(survivor_entity=dict(HAND_ENTITY))], {}, "into itself"), + ([_fold(), _fold()], {}, "repeats the fold"), + ( + [ + _fold(), + _fold( + absorbed_entity=dict(ECONOMY), + survivor_entity={"name": "household", "role": "aggregate"}, + ), + ], + {}, + "both absorbed and a survivor", + ), + ([_fold(geography={"level": "country"})], {}, "geography.id is required"), + ([_fold(absorbed_entity={"name": "person"})], {}, "absorbed_entity.role"), + ([_fold(concept="bls.cps.unemployment_rate.{P}")], {}, "concept"), + ], +) +def test_entity_fold_seed_schema_is_closed( + tmp_path: pathlib.Path, folds: list, doc: dict, match: str +) -> None: + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + _write_folds(tmp_path, folds, **doc) + with pytest.raises(SystemExit, match=match): + bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) + + +def test_entity_fold_seed_must_be_strict_json(tmp_path: pathlib.Path) -> None: + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + (tmp_path / "seeds").mkdir() + (tmp_path / "seeds" / "entity_folds.json").write_text( + '{"schemaVersion": "chronicle_entity_folds_v1", "folds": [], ' + '"folds": [NaN]}', encoding="utf-8", + ) + with pytest.raises(SystemExit, match="not strict JSON"): + bsc.main(argv) + + +def test_entity_fold_default_path_sits_beside_the_catalog( + tmp_path: pathlib.Path, +) -> None: + # The Thesis resolver runs the generator with no arguments inside a + # staged tree; the seed must resolve from the catalog's own directory. + argv, _, _ = _folded_repo(tmp_path) + explicit = argv + ["--entity-folds", str(tmp_path / "seeds" / "entity_folds.json")] + assert bsc.main(explicit + ["--check"]) == 0 + assert bsc.main(argv + ["--check"]) == 0 + assert bsc.ENTITY_FOLDS == bsc.CATALOG.parent / "seeds" / "entity_folds.json" + + +@settings( + max_examples=40, + deadline=None, + suppress_health_check=[HealthCheck.function_scoped_fixture], +) +@given( + hand=st.sets(st.sampled_from(["2026-01", "2026-02", "2026-03", "2026-04", "2026-05"]), + min_size=1, max_size=3), + economy=st.sets(st.sampled_from(["2026-04", "2026-05", "2026-06", "2026-07", "2026-08"]), + min_size=1, max_size=3), +) +def test_entity_fold_invariants_hold_for_any_split( + tmp_path_factory: pytest.TempPathFactory, hand: set, economy: set +) -> None: + """For every split of one series across two entities (months may + overlap): the fold conserves observations, mints nothing, keeps the + survivor's UUID, retires exactly the absorbed one, is byte-idempotent, + and an emptied fold revives exactly the absorbed UUID.""" + tmp_path = tmp_path_factory.mktemp("fold") + rows = _drift_rows(hand_months=sorted(hand), economy_months=sorted(economy)) + argv = _repo(tmp_path, rows) + assert bsc.main(argv) == 0 + before = json.loads((tmp_path / "catalog.json").read_text()) + unfolded = _observed(tmp_path, "bls.cps.unemployment_rate") + survivor, absorbed = _uuid_for(unfolded, ECONOMY), _uuid_for(unfolded, HAND_ENTITY) + + _write_folds(tmp_path, [_fold()]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 + after = json.loads((tmp_path / "catalog.json").read_text()) + + def observed_total(catalog: dict) -> int: + return sum( + r["observation_count"] for r in catalog["series"] + if r["status"] == "observed" + ) + + assert observed_total(after) == after["current_assertion_rows"] == len(rows) + assert observed_total(before) == observed_total(after) + before_uuids = {r["uuid"] for r in before["series"]} + after_uuids = {r["uuid"] for r in after["series"]} + assert before_uuids - after_uuids == {absorbed} + assert after_uuids <= before_uuids + (row,) = _observed(tmp_path, "bls.cps.unemployment_rate") + assert row["uuid"] == survivor + assert row["observation_count"] == len(rows) + assert row["first_observed_period"] == min(hand | economy) + assert row["last_observed_period"] == max(hand | economy) + events = [ + json.loads(line) + for line in (tmp_path / "registry.jsonl").read_text().splitlines() + ] + assert [e["uuid"] for e in events if e.get("retired")] == [absorbed] + assert not any("supersedes" in e for e in events) + + snapshot = (tmp_path / "catalog.json").read_bytes() + assert bsc.main(argv) == 0 + assert (tmp_path / "catalog.json").read_bytes() == snapshot + + _write_folds(tmp_path, []) + assert bsc.main(argv) == 0 + restored = _observed(tmp_path, "bls.cps.unemployment_rate") + assert {r["uuid"] for r in restored} == {survivor, absorbed} + assert bsc.main(argv + ["--check"]) == 0 diff --git a/uv.lock b/uv.lock index 3a5807ed..1d609318 100644 --- a/uv.lock +++ b/uv.lock @@ -635,6 +635,94 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/48/30/47d0bf6072f7252e6521f3447ccfa40b421b6824517f82854703d0f5a98b/hyperframe-6.1.0-py3-none-any.whl", hash = "sha256:b03380493a519fce58ea5af42e4a42317bf9bd425596f7a0835ffce80f1a42e5", size = 13007, upload-time = "2025-01-22T21:41:47.295Z" }, ] +[[package]] +name = "hypothesis" +version = "6.168.3" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "sortedcontainers" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/09/b7/13118bbc45d6d8b9d04e2de779e2a4ff23145ea39efa692b994fb874ca72/hypothesis-6.168.3.tar.gz", hash = "sha256:a43388f9067678fef6e13bdff325b6cfa6961a590498bb37f7ff31589c83bc75", size = 511022, upload-time = "2026-09-28T05:20:58.499Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2b/cd/746a2fc1e5e5ba34f07ea6ee1ad07525a3dde5ff4836db3a7980af49a891/hypothesis-6.168.3-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:d20972ca134e652e9928ecd200966a8a2857adc2812c1d74b12a872e5cd503eb", size = 791536, upload-time = "2026-09-28T05:18:57.162Z" }, + { url = "https://files.pythonhosted.org/packages/c3/0f/7a158e377b69556c8e12c25c8fd811d0103e54c24a12dab1f3b9819f202e/hypothesis-6.168.3-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:eafbec09d3e87d13d8242411d1f5868b5e879f1bd6d95e233e9ff80c527bea1c", size = 787313, upload-time = "2026-09-28T05:20:18.122Z" }, + { url = "https://files.pythonhosted.org/packages/45/c6/7df9104ee359e8fcd77791781c47e70794964ca69673665e0de2a6590f4c/hypothesis-6.168.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:73c5627497968cc62d140e9fde1ea21e12cac7b64dc419fea8286cd34ff1ad4e", size = 1124036, upload-time = "2026-09-28T05:20:04.372Z" }, + { url = "https://files.pythonhosted.org/packages/92/0f/8a61715404a73b9a82cb1f976803428d603cdea976a9c30266c72ad6a7ce/hypothesis-6.168.3-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:29dc56e6dc6eeb0aeb08ac463f847279bde2336c4786faf7ee0af4b93cd031a7", size = 1147875, upload-time = "2026-09-28T05:19:15.495Z" }, + { url = "https://files.pythonhosted.org/packages/e4/3f/2b16e95cc3b9a069afa23830a012aefe377ce4a457a227e5a5026eb827ff/hypothesis-6.168.3-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:753bb501f8560d2e321ed3b62596b4496c56f15668b0a0669231ccc3e6c4e80d", size = 1149489, upload-time = "2026-09-28T05:19:18.886Z" }, + { url = "https://files.pythonhosted.org/packages/f6/e7/d7cf6dc068bb02732b2a6e38a35a0dcb7f2137608198fc79d740f69d197c/hypothesis-6.168.3-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:71ab606c472449cb872ef2a7acaec679ee4f651b7f0a477a04ebc85d8933ef8c", size = 1191992, upload-time = "2026-09-28T05:19:21.83Z" }, + { url = "https://files.pythonhosted.org/packages/5f/26/f1e5b25dec15998e8375d722825ec3dae1075cbe7cb1f74221b2312a2e33/hypothesis-6.168.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:26928956c54748e4dfa587333741ab750246123b93484955646ff316cca27eef", size = 1169911, upload-time = "2026-09-28T05:19:27.996Z" }, + { url = "https://files.pythonhosted.org/packages/03/36/901234a49147e6bf8a5b9e54b775706a223c2b52befea1106ea2aaf15d48/hypothesis-6.168.3-cp310-abi3-manylinux_2_31_riscv64.whl", hash = "sha256:0bdfc53c041b61c854fa3761735736b991bc2bddafee45a361cfe4d43027c1ef", size = 1129406, upload-time = "2026-09-28T05:18:42.632Z" }, + { url = "https://files.pythonhosted.org/packages/55/c1/5fc9ff91ec9fba6bb527833386c66812524b5cc75fe7d4a4f9122ee1c420/hypothesis-6.168.3-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:650528e2b1e2a45e95c2df624d4b9364b8ac5a027ba84e1eea2bc5398dd01dcd", size = 1160399, upload-time = "2026-09-28T05:20:23.911Z" }, + { url = "https://files.pythonhosted.org/packages/9b/d2/49ad1ef5c55547c8abfd0fc571b3493806dda530fd5cb3d8263dbad86a72/hypothesis-6.168.3-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:209dc54cdb1b4d6d7020ad8d09e44c49756361b7183adacea4d6f5705085b595", size = 1299906, upload-time = "2026-09-28T05:18:58.417Z" }, + { url = "https://files.pythonhosted.org/packages/0d/5f/f98a26094c4f462c4215807bed0f9a6b5508b27a3c329bcba1bc8adc7ac7/hypothesis-6.168.3-cp310-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:af8ca98cd11dc7f9427bb90483abcd9688d4df2e8e63893a30a2423b027ebb11", size = 1425538, upload-time = "2026-09-28T05:20:49.074Z" }, + { url = "https://files.pythonhosted.org/packages/d0/b8/c5b4406e3a6591e51a42f85469351d1d824e0a54b84167aec9b2353759fe/hypothesis-6.168.3-cp310-abi3-musllinux_1_2_i686.whl", hash = "sha256:f8122cfdd0bc0ba843063effa22ac310bdebdb3a1319bf1e63f14baa119c72ab", size = 1377084, upload-time = "2026-09-28T05:20:06.618Z" }, + { url = "https://files.pythonhosted.org/packages/e0/01/0d84a8ea469d024c15f602799c0b8410fbe03d99fdb0370449b33c3c916f/hypothesis-6.168.3-cp310-abi3-musllinux_1_2_ppc64le.whl", hash = "sha256:4bedbb379eab34f792af7ee9a05aae04e9c08bbb52e0f90f5a2110d4fe4b2fbd", size = 1281162, upload-time = "2026-09-28T05:19:42.768Z" }, + { url = "https://files.pythonhosted.org/packages/22/b5/ea6435038de1a795f005cb603531e8ccc053febc50180f3ab55583c9c60e/hypothesis-6.168.3-cp310-abi3-musllinux_1_2_riscv64.whl", hash = "sha256:5a953115b9f5c95133ab2d04efffeec96e5658c3207923dca7285f7db3e6bbef", size = 1300433, upload-time = "2026-09-28T05:18:55.634Z" }, + { url = "https://files.pythonhosted.org/packages/6c/78/fa6c77d9f64b6d592e69e582d83cbce7d7e56897faa4762885a2123b0166/hypothesis-6.168.3-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:6173558e676ad25ed1e20507fa4024a0d816dd90f715f77006e5a28f19109026", size = 1336273, upload-time = "2026-09-28T05:19:08.273Z" }, + { url = "https://files.pythonhosted.org/packages/f1/56/4acd0d778bab818c9ea336fcba768bf43bc70db7f84cc373579298df4641/hypothesis-6.168.3-cp310-abi3-win32.whl", hash = "sha256:dc66390fb12d80585aa9222bf538ce8b7aa22cf5d118250647355a1c9e8f62f4", size = 678211, upload-time = "2026-09-28T05:19:23.355Z" }, + { url = "https://files.pythonhosted.org/packages/b0/db/0a02b146ad1c30f9716362f2e1a379dfd6b0f7be03ac1e22c9da24c9e2a9/hypothesis-6.168.3-cp310-abi3-win_amd64.whl", hash = "sha256:92325b276360fe86c5bf71a568c0d53a6d140b0de36dcf029f9164a17803bb24", size = 684906, upload-time = "2026-09-28T05:18:35.099Z" }, + { url = "https://files.pythonhosted.org/packages/a3/c0/958deaf726848f96f52250740bf39f13f476b068e22f73e2b358eaa07532/hypothesis-6.168.3-cp310-abi3-win_arm64.whl", hash = "sha256:3cf6f1eeaf41cd8d60cf1f88fde905ca1dd77c906929a507d6ac7f66f2ccba2a", size = 683292, upload-time = "2026-09-28T05:19:57.404Z" }, + { url = "https://files.pythonhosted.org/packages/f4/ab/443208c2988a24eaafbfbd6791b897ad9a8a1dd7f870d5b455d7d15a28ad/hypothesis-6.168.3-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:9029775dc2e25e3e8e596c4306926f0079158353631c7c52c285bbc5c8073c2b", size = 792239, upload-time = "2026-09-28T05:19:59.144Z" }, + { url = "https://files.pythonhosted.org/packages/cf/7b/619c1a76c52de2d3cfd68a2f9876c09464d63097db5bf86a28b62dc37bb1/hypothesis-6.168.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:0e1d91530cefdb9e0b6467c203eb509c61a11d70480a37db59cb53a2f9913102", size = 788113, upload-time = "2026-09-28T05:19:17.145Z" }, + { url = "https://files.pythonhosted.org/packages/ea/dd/33841e8833105f850214a486d83740ba52041892ca94e687a05829c0ce83/hypothesis-6.168.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0df00cbe8133aa220308d11fa28e3add996cf5102a39b279c1d711015fd9114b", size = 1124241, upload-time = "2026-09-28T05:18:37.589Z" }, + { url = "https://files.pythonhosted.org/packages/4b/43/c84a7900feced6a420e824ab61d316e4f59a6887d991bc143ecc294a09ed/hypothesis-6.168.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fd7f75a2e23288ee82ee965a952473d9c5447c2cbc1afc94be09d2402201774e", size = 1170406, upload-time = "2026-09-28T05:19:46.365Z" }, + { url = "https://files.pythonhosted.org/packages/47/5d/6e2a32b9c3020af7a06b00fe446a2c5155ae76ac468c0b68d7188e524002/hypothesis-6.168.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:bc2b1c37631f2231dd0d077225aa5908fc2bd34a4c3faf475053b0bc2eb24c95", size = 1300339, upload-time = "2026-09-28T05:20:31.968Z" }, + { url = "https://files.pythonhosted.org/packages/f9/78/19f3c9eb9a5c215b9fbde57be18ef7c1c78afa509b460d4e8f86026d741a/hypothesis-6.168.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:73960a58f6efc8cbc57d8ad0647955f7c5b25f3d562e3eaa57afa1c69894f7aa", size = 1336484, upload-time = "2026-09-28T05:19:02.841Z" }, + { url = "https://files.pythonhosted.org/packages/88/bb/d46c4519e989e022667705d8a56e83a09ad4ea50eae07ca4bb0f4708dd23/hypothesis-6.168.3-cp311-cp311-win_amd64.whl", hash = "sha256:3f1122223759acc0fe5301c1ae505d762ee61af91db7b191a791ccdbcd965462", size = 684646, upload-time = "2026-09-28T05:20:00.842Z" }, + { url = "https://files.pythonhosted.org/packages/7a/56/44a17266bcf1add5fba7c3df5c3920396a5e924d917fb0534a6f9e2b9b9a/hypothesis-6.168.3-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:bff12e036b67abc5ded682f724f4d7afaff5223190270a0763695f218c079068", size = 793313, upload-time = "2026-09-28T05:20:22.045Z" }, + { url = "https://files.pythonhosted.org/packages/d8/18/1a25b11e9133cb54c02ee6cf99a61296ad461aabc7aae3399e1d0ff1f095/hypothesis-6.168.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c73c6188056e6dc110260e39d141c69c3d02f23e3ba1d8610c7a8b6f2510ec96", size = 784855, upload-time = "2026-09-28T05:19:34.496Z" }, + { url = "https://files.pythonhosted.org/packages/8b/da/728d3210f0b0089337f37206a100d31ef546d1f99839e709f0a9ca443f8e/hypothesis-6.168.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bb1063cb794765097b8c0add598bd34a904f44dc15db81275dd1f0ed1ac567ed", size = 1123043, upload-time = "2026-09-28T05:19:05.468Z" }, + { url = "https://files.pythonhosted.org/packages/53/86/bfb9ec344a8b3ef2fa6f59bb3d30c5b3a7d86d594107670539c34ee53d1b/hypothesis-6.168.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9b2d47f5d9060b049039bef0b267e88480f6468f95ee394e514e84a81ccdc5f5", size = 1169121, upload-time = "2026-09-28T05:20:40.512Z" }, + { url = "https://files.pythonhosted.org/packages/3b/e0/5a76dbafbcaf8fff075f09377cddefa17289ef05dbf51878dde88385b966/hypothesis-6.168.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:8367f623a98cbf90f33fd2a43b100671b152b5975bc343a578290945f52f7018", size = 1298749, upload-time = "2026-09-28T05:19:32.883Z" }, + { url = "https://files.pythonhosted.org/packages/28/15/0e65af96b353f2c4bdc283c53ed0980e5ac5009afe97ef3b23c77b364664/hypothesis-6.168.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:fd81241f4cd76fb18d481e87b9688b30a0cb5c30841730513323ba1c7aba1837", size = 1335271, upload-time = "2026-09-28T05:20:54.005Z" }, + { url = "https://files.pythonhosted.org/packages/f5/c5/37eab2155664aa544df321f6d3940b89c6702d79a72fdc98d7b5a2286f8c/hypothesis-6.168.3-cp312-cp312-win_amd64.whl", hash = "sha256:377438de53afb94347d9845b7d90db5905c6d2a8d612108e9938e0f80503bb90", size = 682211, upload-time = "2026-09-28T05:18:51.206Z" }, + { url = "https://files.pythonhosted.org/packages/0c/a2/6787da846d929e52fc3344d803299c45782dbeac287528af08380e984bf8/hypothesis-6.168.3-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:1b230a850de63334c16654a34a2d547e0179d36b9071d4439b3e7237f6d077e7", size = 793254, upload-time = "2026-09-28T05:19:36.294Z" }, + { url = "https://files.pythonhosted.org/packages/89/ba/2893f5ca42501f4d562cba3229c8994c3a3e5fac66ef60c1e0e0b5220a5d/hypothesis-6.168.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:d63b0226cd3e0d8bdd97c3384b22a21934ed4d53246c1c93575dada616672499", size = 784699, upload-time = "2026-09-28T05:18:54.194Z" }, + { url = "https://files.pythonhosted.org/packages/b7/aa/7d7349daf75b71f6f35876f8de115e974c5c04d600e86df1b2779b0883ab/hypothesis-6.168.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0369f5df055f96e117ab12e5f249668ff144731ab5280bc7a205fdf81f990b89", size = 1123016, upload-time = "2026-09-28T05:20:36.372Z" }, + { url = "https://files.pythonhosted.org/packages/00/f0/7774e1ea072708ea46cb25c4aeee5f9978b6c271764809069e8a6789858e/hypothesis-6.168.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f076bcd0f77fdcdb7797826c879099573d03a02e228ebe649ea917081b962ac0", size = 1168989, upload-time = "2026-09-28T05:20:08.44Z" }, + { url = "https://files.pythonhosted.org/packages/a7/7d/113992abed9efbd7944e3a496a382da58152dce126fddf6419ff31a0a57d/hypothesis-6.168.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:b823ba1fcec8da730f29316d010b06d3f7e0c3828dcf91020e24c55e7d24652a", size = 1298626, upload-time = "2026-09-28T05:19:40.986Z" }, + { url = "https://files.pythonhosted.org/packages/d5/65/3659fa5e733027e5b37a27486e57f4053535e40853d23501c422bb275043/hypothesis-6.168.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:dd2849c269d674e4618590f3b48d443bd4c06b5aef3d8d869086c2e6d213d248", size = 1335184, upload-time = "2026-09-28T05:20:20.087Z" }, + { url = "https://files.pythonhosted.org/packages/b4/6c/35aab2221b5ea65125340f236e1a765a9e9f3b28d89a389ea0033fed29f7/hypothesis-6.168.3-cp313-cp313-win_amd64.whl", hash = "sha256:3ef7d26f5789e691401d5f87eafed9bd2763f0dbe47af6d6b66012a509404766", size = 682173, upload-time = "2026-09-28T05:19:12.762Z" }, + { url = "https://files.pythonhosted.org/packages/6e/79/27b0cb56ff5d2bc92458bf6fcebdb1f0dc01f57f043a178e9f9d74498169/hypothesis-6.168.3-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:e2d4c68729a13df9af4998d2652cfb5d541c5609b88c306880a5dfb284938ec2", size = 793287, upload-time = "2026-09-28T05:20:38.522Z" }, + { url = "https://files.pythonhosted.org/packages/e8/bd/5342f95c3bc36586777ef8cb8eba87ac7acf0184210327fb0e6d8654e295/hypothesis-6.168.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:b345f818083ec99966a43ca4f7b38feb62c6920ce28572bc2bde4948a8b7eaba", size = 784857, upload-time = "2026-09-28T05:20:42.609Z" }, + { url = "https://files.pythonhosted.org/packages/4a/5f/fc774241518a0588d362680a3084275058aab86d6bc02a2c61e1073142d0/hypothesis-6.168.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0608c610fc002978fc5de0f471770d8817e9455cb8649a47983c9f8bccfc1897", size = 1123330, upload-time = "2026-09-28T05:19:29.735Z" }, + { url = "https://files.pythonhosted.org/packages/b0/e6/131f16775a3dca5f4fe27f0d6ad9a9851600098a54a872d163f6ebf0b664/hypothesis-6.168.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9dcf6448b1ecc37f2b23f2d1b3ddfc9ff6b6910614c15a642dc82f419b96037b", size = 1169178, upload-time = "2026-09-28T05:19:53.436Z" }, + { url = "https://files.pythonhosted.org/packages/06/61/c9f5bff8b73321c9fd12f2d69666c6e4861b97b60f5f24fdd6ac293007fd/hypothesis-6.168.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ae4f9f094041dcce5119ebd7bab71062743ab02b6e654d056b370beda78c19e2", size = 1299127, upload-time = "2026-09-28T05:20:14.486Z" }, + { url = "https://files.pythonhosted.org/packages/e4/6d/d4618f8ab12dd76c4d58ea052252759aa2bf0c4e71f4b502ba5d577e0b9f/hypothesis-6.168.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:d479985fe73af97badfb72dc6d20c6a353e486a36f6d065f600026e0cf954a86", size = 1335390, upload-time = "2026-09-28T05:20:10.326Z" }, + { url = "https://files.pythonhosted.org/packages/95/b6/727161e17cc297df1aeea945de05c532033b66751625bec192bc5b5ff707/hypothesis-6.168.3-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:785e2c45f8c08e274b4bf1ccae97f1a4e09407e9a68e80790cfab1d17a4a45fa", size = 624291, upload-time = "2026-09-28T05:18:36.376Z" }, + { url = "https://files.pythonhosted.org/packages/77/23/2f9b506392a0b8712440bcb781abc5713be9ffac1303b6d10f3669050882/hypothesis-6.168.3-cp314-cp314-win_amd64.whl", hash = "sha256:320920b1e3dae8611eee8a03d063cf2187446f2a17c38cfb8a7fc1466f71eee2", size = 682064, upload-time = "2026-09-28T05:20:16.336Z" }, + { url = "https://files.pythonhosted.org/packages/50/93/efabfd95eb2b69c0c9fa1e1c83c8290aa2715d46baeb5a7764faf09c133a/hypothesis-6.168.3-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:35380baa981108a7f60c4eab71e46acd8d8f58440520346a1a6aba06dca7e074", size = 791875, upload-time = "2026-09-28T05:19:37.789Z" }, + { url = "https://files.pythonhosted.org/packages/1b/fc/2a0ada1623a9a33048bbf9f00a7c92513398c6b8865cba5efb854262ce30/hypothesis-6.168.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:f0aaaed00438fa6673d856aaee12a4a8afbde82a9f3c5ff487cacfb064239afe", size = 783412, upload-time = "2026-09-28T05:18:48.266Z" }, + { url = "https://files.pythonhosted.org/packages/41/31/73c615d37eeb12da0209555612c32ced628d860267c23cfd2691c6207aea/hypothesis-6.168.3-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f27e6df1576bf838e7f484d4ae5cba92114497ca30afb917056bf1ea33e95675", size = 1121662, upload-time = "2026-09-28T05:19:26.225Z" }, + { url = "https://files.pythonhosted.org/packages/92/54/1893344a3b8bbf83fa7c9bb7e96f6836580213854f46671cb749f7b4706c/hypothesis-6.168.3-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3bc85014577982ec6d2e266edc5cd6e7a7d3674c648791ca983c67a52f89a0c4", size = 1167761, upload-time = "2026-09-28T05:18:49.85Z" }, + { url = "https://files.pythonhosted.org/packages/26/97/a61d82968febd25a0f08ffbbfabfaeead66f68fc5fa73f3c9ece1c36fc8f/hypothesis-6.168.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:ccfc29505aa1cdcc254cb9cd701fd0811fef5480addd97d4127a00df023410f7", size = 1297309, upload-time = "2026-09-28T05:19:51.711Z" }, + { url = "https://files.pythonhosted.org/packages/bc/01/fe8e4cf6d39d02f4efadaa351427fa13722086cfc54a2da3579741c5177a/hypothesis-6.168.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:32d0699566aaa93f9e97a44705d7164386f1e91de78d277f53bada35e78bcc96", size = 1334260, upload-time = "2026-09-28T05:19:00.121Z" }, + { url = "https://files.pythonhosted.org/packages/39/6a/09177ebc62f4778f94379ecade6a51299d3d8c4f4b75ba636bf3a0202364/hypothesis-6.168.3-cp314-cp314t-win_amd64.whl", hash = "sha256:28d88fa174ecbd4ecbd7bb290f06d0db084a3971c3f511ae2830b65b5e25500f", size = 681992, upload-time = "2026-09-28T05:19:48.043Z" }, + { url = "https://files.pythonhosted.org/packages/f9/f6/890bf33d608cd63348d3146a3ca83362fbf09e589c5e5230a00c403070f4/hypothesis-6.168.3-cp315-abi3.abi3t-macosx_10_12_x86_64.whl", hash = "sha256:61f5782d807b1e6aa5c9beef1054cb2037e7d1add48a64972cd6ee447778781f", size = 791231, upload-time = "2026-09-28T05:18:43.998Z" }, + { url = "https://files.pythonhosted.org/packages/03/dd/fc36b204f8aa7437c676576d9437f0422de46aa8a729e6cd5bbb0224e759/hypothesis-6.168.3-cp315-abi3.abi3t-macosx_11_0_arm64.whl", hash = "sha256:7aacf3cf40c7ce8f9e4924d5b57bc0b068beafdfed2347bcf160a28b4cfbba7b", size = 783171, upload-time = "2026-09-28T05:19:20.353Z" }, + { url = "https://files.pythonhosted.org/packages/5c/d2/3cd087d577db67c404991d7723e64d7cd75570cdc82a0f7329aed6f2086c/hypothesis-6.168.3-cp315-abi3.abi3t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:01768a03a30dc54df7fe457c0b34016c84d598fa00d5965ededab93ba4eb3408", size = 1121152, upload-time = "2026-09-28T05:18:39.095Z" }, + { url = "https://files.pythonhosted.org/packages/42/6f/a05a68cc66e7a22701c50bf94fb9ddeb36f4f5d0de3cc130066709eda621/hypothesis-6.168.3-cp315-abi3.abi3t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:1a8a4ffc6c6e6e577f2bfbcfebf7cffbb310283ba2532c729570a0a752cebaaa", size = 1144069, upload-time = "2026-09-28T05:20:44.705Z" }, + { url = "https://files.pythonhosted.org/packages/4a/f4/fdd7a093fb2fb3a0ce24256c92ad5bf67936f4669bd06d5ceae4298150ec/hypothesis-6.168.3-cp315-abi3.abi3t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b987d73eba95183a7e59cca6d1925c588aa4307922d9852cc2b4d282a2ae4128", size = 1146692, upload-time = "2026-09-28T05:20:25.83Z" }, + { url = "https://files.pythonhosted.org/packages/f1/c8/6dbd4377e935505ae4fc8ee4c7b18c69994c4bbaca015447c470218bdbee/hypothesis-6.168.3-cp315-abi3.abi3t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d4569c39bd97d9573e946429ed676f3b55a7c8ed80920addd67d384a47d59b38", size = 1189480, upload-time = "2026-09-28T05:20:46.734Z" }, + { url = "https://files.pythonhosted.org/packages/ba/bf/ff288b496b690000d2686dcfa7f67855e4c5a6dddb464ed8e4880be83bb2/hypothesis-6.168.3-cp315-abi3.abi3t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6042b8707a4b25bbbfe20b110258fb7549a68951e5525608a8ce06091039e9fc", size = 1167109, upload-time = "2026-09-28T05:19:24.758Z" }, + { url = "https://files.pythonhosted.org/packages/d9/d1/3fee2bc29fc747fabbb27e174515592e390809ca465d3bbbabbcfa3235a8/hypothesis-6.168.3-cp315-abi3.abi3t-manylinux_2_31_riscv64.whl", hash = "sha256:f413629de94d38a7a2ad259697a6752526143cb49c2e2d7bdba19381c80693f6", size = 1126823, upload-time = "2026-09-28T05:18:52.636Z" }, + { url = "https://files.pythonhosted.org/packages/58/6a/585294392fa6a6d9719446a042a777ba98ecca265d9e48cbedc10c88df0f/hypothesis-6.168.3-cp315-abi3.abi3t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:f071737e4e775bebba07e319eb645a880d1e0186b4d24bad23255e849d86d483", size = 1155773, upload-time = "2026-09-28T05:20:51.268Z" }, + { url = "https://files.pythonhosted.org/packages/cd/4d/fa283ff79996debf1ff08593e01f8b773eb8211b19b3d6d5d491317a65bf/hypothesis-6.168.3-cp315-abi3.abi3t-musllinux_1_2_aarch64.whl", hash = "sha256:f59a3912858d0609c26054aa1c474847c797937f5e0e1c77f0d3f08032e50f09", size = 1296671, upload-time = "2026-09-28T05:18:46.937Z" }, + { url = "https://files.pythonhosted.org/packages/42/05/98f9c2f628da5afabb6c3e8df5d2d299d2d50bf306b14a6e26d3954c4951/hypothesis-6.168.3-cp315-abi3.abi3t-musllinux_1_2_armv7l.whl", hash = "sha256:f09c05a23a8025dd5cad07c2ed299a46778e72d49ff0dd5bf353bcc0f7dc1580", size = 1422001, upload-time = "2026-09-28T05:19:04.188Z" }, + { url = "https://files.pythonhosted.org/packages/b8/c9/f2109ade29a7ec284d55bca328d784743e8b13e321576fd34ee7e65f99af/hypothesis-6.168.3-cp315-abi3.abi3t-musllinux_1_2_i686.whl", hash = "sha256:44ace770bda3a0301739fc5a413c764de790c739df1f1a7218dd049f8594d9f5", size = 1374182, upload-time = "2026-09-28T05:20:27.764Z" }, + { url = "https://files.pythonhosted.org/packages/ce/6d/e05d5f72441564a3bebc71fa155deafd0fd3b015d6014ec8a00edf6e42bb/hypothesis-6.168.3-cp315-abi3.abi3t-musllinux_1_2_ppc64le.whl", hash = "sha256:03b131043608f94a2578a2a896a1a72092acb7079815eef5b8513b08447e0e62", size = 1278402, upload-time = "2026-09-28T05:20:56.332Z" }, + { url = "https://files.pythonhosted.org/packages/96/d7/6988a7f1f69c5c530687dce03a32c157e2d878e3a2e32af9269ce016b78a/hypothesis-6.168.3-cp315-abi3.abi3t-musllinux_1_2_riscv64.whl", hash = "sha256:e9784aca26eddfe99b03a0292320db742cc8a74200ef864fdce949f526f973cd", size = 1297770, upload-time = "2026-09-28T05:19:11.387Z" }, + { url = "https://files.pythonhosted.org/packages/a2/28/5bb82b60b836bd2329e1fe01ad94efc2b14dfa806f8e50ed14b795d78770/hypothesis-6.168.3-cp315-abi3.abi3t-musllinux_1_2_x86_64.whl", hash = "sha256:2b52ac363096232bebc2add117e9178d91f4248f4cdb919fd1026b5f86a4bb16", size = 1333977, upload-time = "2026-09-28T05:20:02.483Z" }, + { url = "https://files.pythonhosted.org/packages/8e/7d/d419841b8f65481ea1a50c4ba36f2670d48b8c7a51e4e8586089564cf7f6/hypothesis-6.168.3-cp315-abi3.abi3t-win32.whl", hash = "sha256:d28e3a6b511a74ce37df5274b51f36c2b274fea7365e00b16f0c81e22acd5957", size = 675394, upload-time = "2026-09-28T05:19:55.237Z" }, + { url = "https://files.pythonhosted.org/packages/d8/d2/1de6a2ad100e44817f2e9a8e8ba3eeaf4769621f4f87f2d4966c4971fcc4/hypothesis-6.168.3-cp315-abi3.abi3t-win_amd64.whl", hash = "sha256:7b9638789548361a57d984f56619ac694a914c328181d911271618409261ff4a", size = 681699, upload-time = "2026-09-28T05:19:09.957Z" }, + { url = "https://files.pythonhosted.org/packages/c0/79/be3370fd02734d6b1d950183ae9224580d19fa8d356b95348d60f1e3eeb7/hypothesis-6.168.3-cp315-abi3.abi3t-win_arm64.whl", hash = "sha256:65d78e4357ec48ed2c67825f06740ee3599be4cfe770a6092bed07108d679ac5", size = 679849, upload-time = "2026-09-28T05:19:06.884Z" }, + { url = "https://files.pythonhosted.org/packages/3f/0e/27960db1d45a94497e1681fb9d7b9140b44da4e655ba20f0d82f95d10230/hypothesis-6.168.3-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:101531b4ccf7fa12965a6b295d10b64c2f8a8fab61e1f9b18c55335d8fb02575", size = 793135, upload-time = "2026-09-28T05:19:14.056Z" }, + { url = "https://files.pythonhosted.org/packages/9a/cb/be08379286c1925fcd651b92ed835f470a83b859b5c484b3431da9d851f5/hypothesis-6.168.3-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:41e0120814de5c3a6b58d8cb27cb11b8873ab33fba130cd09855a27f5a12a1ca", size = 788995, upload-time = "2026-09-28T05:20:34.164Z" }, + { url = "https://files.pythonhosted.org/packages/38/7b/6d885d139b2ed76e2f4908cf10eae56acc73bf05cbef286357c4559c9a04/hypothesis-6.168.3-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9d120009d145697909f2f0c532f2d568558ddd6990707f8cba6576bfb9770696", size = 1124974, upload-time = "2026-09-28T05:19:49.903Z" }, + { url = "https://files.pythonhosted.org/packages/05/cc/b302ae809b48254830cae57801d0af0b66783df515b5dd56b9f21c8dfa86/hypothesis-6.168.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:818b3d09bba60ef90463e47a4bc87275dba1e8aeb184d3102888440ca7c7837d", size = 1171967, upload-time = "2026-09-28T05:20:12.295Z" }, + { url = "https://files.pythonhosted.org/packages/2c/ab/51031080a6600f5b07adf5f9dfa117345c2adda07a5c24bda523e70bd1e9/hypothesis-6.168.3-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:9e3c36eba80e089ecfa28ec08049723223cb41d3cfe4d9988169cf98440e402b", size = 685641, upload-time = "2026-09-28T05:19:44.609Z" }, +] + [[package]] name = "idna" version = "3.11" @@ -1661,6 +1749,7 @@ dependencies = [ [package.optional-dependencies] dev = [ + { name = "hypothesis" }, { name = "pytest" }, { name = "ruff" }, ] @@ -1670,6 +1759,7 @@ policyengine = [ [package.dev-dependencies] dev = [ + { name = "hypothesis" }, { name = "pytest" }, ] @@ -1677,6 +1767,7 @@ dev = [ requires-dist = [ { name = "cryptography", specifier = ">=46.0.3" }, { name = "httpx", specifier = ">=0.27.0" }, + { name = "hypothesis", marker = "extra == 'dev'", specifier = ">=6.100,<7" }, { name = "microplex", specifier = ">=0.1.0" }, { name = "numpy", specifier = ">=1.24.0" }, { name = "odfpy", specifier = ">=1.4.1" }, @@ -1697,7 +1788,10 @@ requires-dist = [ provides-extras = ["dev", "policyengine"] [package.metadata.requires-dev] -dev = [{ name = "pytest", specifier = ">=8.0.0,<9" }] +dev = [ + { name = "hypothesis", specifier = ">=6.100,<7" }, + { name = "pytest", specifier = ">=8.0.0,<9" }, +] [[package]] name = "policyengine-core" From 9c9313bf968115a6a8d7c21a6568f9e94159bec2 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 12:37:35 -0400 Subject: [PATCH 3/6] Make fold edits a ceremony and fold undo exact Answers the independent review of a803f082. - Any change to the entity-fold seed is an identity change and needs --allow-remint --remint-note, even when it plans no registry event: retargeting a fold's survivor moved observations between two existing lineages with no ceremony (three-entity regression added). - Undoing a fold now restores earlier same-dimension spelling merges. A row that matches nothing in its own slice rejoins a retired identity of its own entity whose names live on another slice's row, and those names move back off that row. Undoing all seven folds on the committed artifacts reproduces the pre-fold catalog exactly apart from the seed and registry digests; before this, the us.frb and us.census spellings revived as separate identities. The property test and an alias-bearing regression assert the exact round trip. - A folded row's own entity is validated before the fold replaces it. - The strict-JSON seed test checks duplicate keys, NaN and Infinity separately. - The docstring says what the fold guarantees about corrections: an inert fold never fails. Superseding a pre-versioning row is refused by the builder whatever the folds say (a pre-existing limitation #306 addresses); a test shows a correction superseding a versioned absorbed row, with either entity, regenerates with the registry unchanged. A second test appends new prints of a folded series under both entities with the registry unchanged. Co-Authored-By: Claude Opus 5.5 --- docs/catalog-curation-backlog.md | 23 +++- scripts/build_series_catalog.py | 92 +++++++++++++-- tests/test_build_series_catalog.py | 177 +++++++++++++++++++++++++++-- 3 files changed, 272 insertions(+), 20 deletions(-) diff --git a/docs/catalog-curation-backlog.md b/docs/catalog-curation-backlog.md index 2b7d65f1..6338b1bc 100644 --- a/docs/catalog-curation-backlog.md +++ b/docs/catalog-curation-backlog.md @@ -43,12 +43,25 @@ third concept, `bls.ces.nonfarm_payrolls.change`) and hand-chosen person roles, April and May). Fold them with a seed entry and a reviewed regeneration if a consumer ever needs one lineage. +Any edit to the seed is curation: adding, retargeting or removing a fold +moves observations between lineages, so the builder refuses it without +`--allow-remint --remint-note`, even when no registry event is planned. +Never delete the seed file while the committed catalog declares +`entity_folds_sha256`; the builder refuses that too. + To undo a fold, remove its entry from the seed's `folds` list and -regenerate: the absorbed identity revives with its original UUID. The -names the fold moved onto the survivor's `aliases` stay there as curated -memory; remove them by hand if they should go. Never delete the seed file -while the committed catalog declares `entity_folds_sha256`; the builder -refuses that, because it would split the lineages silently. +regenerate with the ceremony. The absorbed identity revives with its +original UUID, rows it had absorbed by earlier same-dimension merges (the +`us.frb` and `us.census` spellings above) rejoin it, and the names the fold +moved onto the survivor move back. Undoing all seven folds on the committed +artifacts reproduces the pre-fold catalog exactly, apart from the seed and +registry digests (seven `revived` lines, no other event). + +One limitation is older than the folds: the builder refuses a correction +that supersedes a row written before assertion versioning (every row of the +immutable prefix, including the seven hand-recorded May 2026 rows), while +the append gate accepts it. PolicyEngine/chronicle#306 addresses that. A +correction that supersedes a versioned absorbed row regenerates cleanly. ## Initial claims cadence metadata diff --git a/scripts/build_series_catalog.py b/scripts/build_series_catalog.py index 1dcce240..42271fcc 100644 --- a/scripts/build_series_catalog.py +++ b/scripts/build_series_catalog.py @@ -93,11 +93,17 @@ with the ``--remint-note``, and the survivor keeps its UUID. The catalog commits to the seed as ``entity_folds_sha256`` (absent when there is no seed). Once a committed catalog declares it, regenerating without the seed -is a hard error, because it would silently split the folded lineages again; -an emptied ``folds`` list is the reviewed way to undo a fold, and the -absorbed identities then revive with their original UUIDs. A fold that -matches no current row (its rows superseded, say) is inert, so a later -correction can never block regeneration; a fold must still name an +is a hard error, because it would silently split the folded lineages again. +Any change to the seed (a new fold, a retargeted survivor, a removed fold) +is an identity change: it needs ``--allow-remint --remint-note`` even when +it plans no registry event, because it moves observations between +lineages. Removing a fold undoes it: the absorbed identity revives with its +original UUID, and rows spelled by the names it had absorbed by earlier +same-dimension merges rejoin it (a row that matches nothing in its own +slice rejoins a retired identity of its own entity whose names now live on +another slice's row; no UUID crosses entities). A fold that matches no +current row is inert rather than an error, so a correction that supersedes +absorbed rows never makes the fold itself fail. A fold must name an absorbed identity the registry has bound and a survivor the committed catalog holds, so a mistyped fold is refused instead of ignored. @@ -732,7 +738,7 @@ def apply_entity_folds( return rows, Counter() applied: Counter = Counter() out: list[dict] = [] - for row in rows: + for index, row in enumerate(rows): slot = matcher.get( (_geo_key(row.get("geography")), _entity_key(row.get("entity"))) ) @@ -746,6 +752,13 @@ def apply_entity_folds( if fold is None: out.append(row) continue + # The fold replaces this entity, so validate it first: build_identities + # only ever sees the survivor's entity for this row. + problem = _dimension_problem( + row.get("entity"), ("name", "role"), "entity", ("name", "role") + ) + if problem: + raise SystemExit(f"observation row {index}: {problem}") folded = dict(row) folded["entity"] = dict(fold["survivor_entity"]) out.append(folded) @@ -965,6 +978,44 @@ def _index_names(self) -> None: if count > 1 or alias in canonical } + def returning_concept( + self, + key: tuple[str, str, str], + names: set[str], + registry: "UuidRegistry", + ) -> tuple[str, set[str], str] | None: + """The retired identity of ``key``'s own entity that its names rejoin. + + Used only when ``match`` found nothing in the row's own slice. If the + row's names are curated names of a committed row in ANOTHER entity + slice of the same geography, and the registry holds a retired + binding for that row's concept under the row's OWN entity, the row is + the spelling-merged part of that retired identity (an undone entity + fold) and rejoins it. The UUID stays in the row's own slice. + + Returns (concept, the linking names, the other row's uuid): the + builder moves the linking names back from that row onto the revived + identity, restoring the naming the fold had moved. + """ + _, geo_key, entity_key = key + hits: dict[str, tuple[set[str], str]] = {} + for row in self.rows: + if _geo_key(row.get("geography")) != geo_key: + continue + if _entity_key(row.get("entity")) == entity_key: + continue + linking = names & self._row_names(row) + if not linking: + continue + candidate = (row["concept"], geo_key, entity_key) + entry = registry.latest.get(candidate) + if entry is not None and not registry.is_live(candidate): + hits[row["concept"]] = (linking, row["uuid"]) + if len(hits) != 1: + return None + ((concept, (linking, source_uuid)),) = hits.items() + return concept, linking, source_uuid + def absorb(self, absorbed_key: tuple[str, str, str], survivor: dict) -> None: """Fold a committed row into ``survivor``'s naming memory. @@ -1756,12 +1807,27 @@ def build_catalog( # canonical concept (curation owns naming; observed spellings become # aliases). Buckets landing on the same canonical identity merge. canonical: dict[tuple[str, str, str], dict] = {} + # Names an undone fold moves back: onto the returning identity, and off + # the row (by uuid) that held them while the fold stood. + returned_names: dict[tuple[str, str, str], set[str]] = {} + released_names: dict[str, set[str]] = {} for key in sorted(identities): ident = identities[key] concept, geo_key, entity_key = key names = ident["concepts"] | {concept} prior = existing.match(key, names, ident["geography"], ident["entity"]) canon_concept = prior["concept"] if prior else concept + returning = ( + existing.returning_concept(key, names, registry) + if prior is None + else None + ) + if returning is not None: + canon_concept, linking, source_uuid = returning + returned_names.setdefault( + (canon_concept, geo_key, entity_key), set() + ).update(linking) + released_names.setdefault(source_uuid, set()).update(linking) canon_key = (canon_concept, geo_key, entity_key) bucket = canonical.setdefault( canon_key, @@ -2017,7 +2083,12 @@ def resolve_uuid( resolve_uuid(canon_key, prior, bucket["geography"], bucket["entity"]), canon_key, ) - curated_aliases = set(prior.get("aliases", [])) if prior else set() + curated_aliases = ( + set(prior.get("aliases", [])) - released_names.get(prior["uuid"], set()) + if prior + else set() + ) + curated_aliases |= returned_names.get(canon_key, set()) aliases = sorted((bucket["concepts"] | curated_aliases) - {concept}) all_suspects.update(bucket["suspects"]) for segment in bucket["stripped"]: @@ -2504,6 +2575,13 @@ def main(argv: list[str] | None = None) -> int: f"dropped {key}: uuid {row_uuid} would vanish from the catalog" for key, row_uuid in plan["dropped"] ] + if existing.entity_folds_sha256 != catalog.get("entity_folds_sha256"): + identity_changes.append( + "entity-fold seed changed: " + f"{existing.entity_folds_sha256 or 'none'} -> " + f"{catalog.get('entity_folds_sha256') or 'none'} (folds move " + "observations between lineages)" + ) if not existing.rows and registry.latest: # Without the prior catalog, curated naming and aliases are gone: a # renamed identity re-keys away from its registry binding and would diff --git a/tests/test_build_series_catalog.py b/tests/test_build_series_catalog.py index 0efa3863..251df3b8 100644 --- a/tests/test_build_series_catalog.py +++ b/tests/test_build_series_catalog.py @@ -2577,6 +2577,14 @@ def _uuid_for(rows: list[dict], entity: dict) -> str: return row["uuid"] +def _without_digests(catalog: dict) -> dict: + """A catalog minus the commitments an undo legitimately changes.""" + return { + k: v for k, v in catalog.items() + if k not in ("entity_folds_sha256", "uuid_registry_sha256") + } + + def _folded_repo(tmp_path: pathlib.Path, rows=None) -> tuple[list[str], str, str]: """A repo whose two drift lineages were folded; returns argv and the survivor and absorbed uuids.""" @@ -2657,8 +2665,11 @@ def test_emptied_entity_fold_revives_the_absorbed_uuid( ) -> None: argv, survivor, absorbed = _folded_repo(tmp_path) empty = _write_folds(tmp_path, []) - # Reviving is the generator's automatic, ungated event. - assert bsc.main(argv) == 0 + # Removing a fold moves observations between lineages: a ceremony. + registry_bytes = (tmp_path / "registry.jsonl").read_bytes() + assert bsc.main(argv) == 1 + assert (tmp_path / "registry.jsonl").read_bytes() == registry_bytes + assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 rows = _observed(tmp_path, "bls.cps.unemployment_rate") assert _uuid_for(rows, ECONOMY) == survivor assert _uuid_for(rows, HAND_ENTITY) == absorbed @@ -2730,6 +2741,145 @@ def test_entity_fold_reaches_rows_spelled_by_a_curated_alias( assert bsc.main(argv + ["--check"]) == 0 +def test_appends_after_a_fold_never_touch_the_registry( + tmp_path: pathlib.Path, +) -> None: + # The Thesis resolver regenerates the catalog on every append and refuses + # any registry change other than a first observation's mint. A later + # print of a folded series, carrying either entity, must regenerate with + # the registry byte-unchanged. + argv, survivor, absorbed = _folded_repo(tmp_path) + registry_bytes = (tmp_path / "registry.jsonl").read_bytes() + later = _drift_rows(hand_months=("2026-09",), economy_months=("2026-08",)) + with (tmp_path / "obs.jsonl").open("a", encoding="utf-8") as journal: + for row in later: + journal.write(json.dumps(row) + "\n") + assert bsc.main(argv) == 0 + assert (tmp_path / "registry.jsonl").read_bytes() == registry_bytes + (row,) = _observed(tmp_path, "bls.cps.unemployment_rate") + assert row["uuid"] == survivor and row["observation_count"] == 5 + assert row["last_observed_period"] == "2026-09" + catalog = json.loads((tmp_path / "catalog.json").read_text()) + assert absorbed not in {r["uuid"] for r in catalog["series"]} + assert bsc.main(argv + ["--check"]) == 0 + + +def test_undoing_a_fold_restores_earlier_spelling_merges( + tmp_path: pathlib.Path, +) -> None: + # The absorbed lineage had already absorbed a second spelling by a + # same-dimension curated merge. Removing the fold must revive exactly the + # absorbed identity, with that spelling back inside it, and must not + # revive the spelling's own long-retired identity. + sector = {"name": "institutional_sector", "role": "total_industrial_production"} + rows = [ + _row("fed.g17.ip.mom.may_2026", rid="fed.g17.ip.mom.may_2026.hand", + period=_fold_month("2026-05"), entity=dict(sector)), + _row("us.frb.ip.mom.2026_04", rid="us.frb.ip.mom.2026_04.hand", + period=_fold_month("2026-04"), entity=dict(sector)), + _row("fed.g17.ip.mom.2026-06", rid="fed.g17.ip.mom.2026-06.first_print", + period=_fold_month("2026-06"), source_concept="INDPRO"), + ] + argv = _repo(tmp_path, rows) + assert bsc.main(argv) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + spelled = next(r for r in catalog["series"] if r["concept"] == "us.frb.ip.mom") + hand = next( + r for r in catalog["series"] + if r["concept"] == "fed.g17.ip.mom" and r["entity"] == sector + ) + catalog["series"].remove(spelled) + hand["aliases"] = sorted({*hand["aliases"], "us.frb.ip.mom"}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + assert bsc.main(argv + ["--allow-remint", "--remint-note", "spelling"]) == 0 + prefold = json.loads((tmp_path / "catalog.json").read_text()) + _write_folds(tmp_path, [_fold(concept="fed.g17.ip.mom", absorbed_entity=sector)]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 + lines_before_undo = (tmp_path / "registry.jsonl").read_text().splitlines() + + _write_folds(tmp_path, []) + assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 + lines = (tmp_path / "registry.jsonl").read_text().splitlines() + events = [json.loads(line) for line in lines[len(lines_before_undo):]] + assert [(e.get("revived"), e["uuid"]) for e in events] == [(True, hand["uuid"])] + restored = _observed(tmp_path, "fed.g17.ip.mom") + (back,) = [r for r in restored if r["entity"] == sector] + assert back["uuid"] == hand["uuid"] and back["observation_count"] == 2 + assert "us.frb.ip.mom.{P}" in back["family_patterns"] + assert not _observed(tmp_path, "us.frb.ip.mom") + undone = json.loads((tmp_path / "catalog.json").read_text()) + assert undone["ambiguous_aliases"] == [] + assert _without_digests(undone) == _without_digests(prefold) + assert bsc.main(argv + ["--check"]) == 0 + + +def test_retargeting_a_fold_needs_the_ceremony(tmp_path: pathlib.Path) -> None: + # Moving a fold's survivor from one existing lineage to another plans no + # registry event, yet moves observations between UUIDs. + household = {"name": "household", "role": "aggregate"} + rows = _drift_rows() + [ + _row("bls.cps.unemployment_rate", rid="bls.cps.unemployment_rate.2026-08.hh", + period=_fold_month("2026-08"), entity=dict(household)), + ] + argv, survivor, _ = _folded_repo(tmp_path, rows) + household_uuid = _uuid_for(_observed(tmp_path, "bls.cps.unemployment_rate"), household) + catalog_bytes = (tmp_path / "catalog.json").read_bytes() + registry_bytes = (tmp_path / "registry.jsonl").read_bytes() + _write_folds(tmp_path, [_fold(survivor_entity=dict(household))]) + assert bsc.main(argv) == 1 + assert (tmp_path / "catalog.json").read_bytes() == catalog_bytes + assert (tmp_path / "registry.jsonl").read_bytes() == registry_bytes + assert bsc.main(argv + ["--check"]) == 1 + assert bsc.main(argv + ["--allow-remint", "--remint-note", "retarget"]) == 0 + rows_after = _observed(tmp_path, "bls.cps.unemployment_rate") + counts = {r["uuid"]: r["observation_count"] for r in rows_after} + assert counts == {survivor: 2, household_uuid: 2} + assert (tmp_path / "registry.jsonl").read_bytes() == registry_bytes + + +def test_a_folded_rows_own_entity_is_still_validated( + tmp_path: pathlib.Path, +) -> None: + rows = _drift_rows() + argv, _, _ = _folded_repo(tmp_path, rows) + rows[0]["entity"] = {**HAND_ENTITY, "bogus": "x"} + (tmp_path / "obs.jsonl").write_text( + "".join(json.dumps(r) + "\n" for r in rows), encoding="utf-8" + ) + with pytest.raises(SystemExit, match="entity.bogus is not an identity field"): + bsc.main(argv) + + +def test_a_correction_superseding_an_absorbed_row_regenerates( + tmp_path: pathlib.Path, +) -> None: + # A versioned absorbed row corrected by an appended superseding row, with + # its own entity or the survivor's, keeps one lineage and no registry + # event. (Superseding a pre-versioning row is refused by the builder + # whatever the folds say; that is a separate, pre-existing limitation.) + rows = _drift_rows() + rows[0]["assertionVersion"] = {"id": "av-test:hand-may", "supersedes": None} + argv, survivor, absorbed = _folded_repo(tmp_path, rows) + registry_bytes = (tmp_path / "registry.jsonl").read_bytes() + for entity, version in ((HAND_ENTITY, "av-test:fix-1"), (ECONOMY, "av-test:fix-2")): + correction = json.loads(json.dumps(rows[0])) + correction["value"] = 4.4 + correction["entity"] = dict(entity) + previous = "av-test:hand-may" if version.endswith("1") else "av-test:fix-1" + correction["assertionVersion"] = {"id": version, "supersedes": previous} + with (tmp_path / "obs.jsonl").open("a", encoding="utf-8") as journal: + journal.write(json.dumps(correction) + "\n") + assert bsc.main(argv) == 0 + (row,) = _observed(tmp_path, "bls.cps.unemployment_rate") + assert row["uuid"] == survivor and row["observation_count"] == 3 + assert (tmp_path / "registry.jsonl").read_bytes() == registry_bytes + assert bsc.main(argv + ["--check"]) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + assert absorbed not in {r["uuid"] for r in catalog["series"]} + + def test_entity_fold_naming_an_unbound_identity_is_refused( tmp_path: pathlib.Path, ) -> None: @@ -2791,14 +2941,22 @@ def test_entity_fold_seed_schema_is_closed( bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) -def test_entity_fold_seed_must_be_strict_json(tmp_path: pathlib.Path) -> None: +@pytest.mark.parametrize( + "text", + [ + '{"schemaVersion": "chronicle_entity_folds_v1", "folds": [], "folds": []}', + '{"schemaVersion": "chronicle_entity_folds_v1", "folds": [NaN]}', + '{"schemaVersion": "chronicle_entity_folds_v1", "folds": [Infinity]}', + ], + ids=["duplicate-key", "nan", "infinity"], +) +def test_entity_fold_seed_must_be_strict_json( + tmp_path: pathlib.Path, text: str +) -> None: argv = _repo(tmp_path, _drift_rows()) assert bsc.main(argv) == 0 (tmp_path / "seeds").mkdir() - (tmp_path / "seeds" / "entity_folds.json").write_text( - '{"schemaVersion": "chronicle_entity_folds_v1", "folds": [], ' - '"folds": [NaN]}', encoding="utf-8", - ) + (tmp_path / "seeds" / "entity_folds.json").write_text(text, encoding="utf-8") with pytest.raises(SystemExit, match="not strict JSON"): bsc.main(argv) @@ -2874,7 +3032,10 @@ def observed_total(catalog: dict) -> int: assert (tmp_path / "catalog.json").read_bytes() == snapshot _write_folds(tmp_path, []) - assert bsc.main(argv) == 0 + assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 restored = _observed(tmp_path, "bls.cps.unemployment_rate") assert {r["uuid"] for r in restored} == {survivor, absorbed} + # Undo is exact: the catalog is the pre-fold catalog again. + undone = json.loads((tmp_path / "catalog.json").read_text()) + assert _without_digests(undone) == _without_digests(before) assert bsc.main(argv + ["--check"]) == 0 From d3d23ff5e481465a82ac692b5ef450e90091be3a Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 14:23:29 -0400 Subject: [PATCH 4/6] Undo a fold only through an explicit undone marker Answers the independent review of 9c9313bf. - The rule that lets a row rejoin a retired identity through names held in another entity slice now applies only to folds marked "undone": true. At 9c9313bf it applied on every run, so an ordinary append of a new spelling could revive an unrelated retired identity without the ceremony (the review's append-only replay; now a regression test that fails on the old generator and passes here). - Folds are undone by the marker, never by deletion: removing an entry that git HEAD still holds is refused, because the entry is the record the builder needs to hand absorbed spellings back. - Documented limits: a curated alias no current row spells stays on the survivor after an undo (regression added), and the seed ratchet compares with the committed catalog header, which is trusted like every generated artifact. - Marking all seven committed folds undone still reproduces the pre-fold catalog exactly apart from the seed and registry digests. Co-Authored-By: Claude Opus 5.5 --- docs/catalog-curation-backlog.md | 31 ++++--- scripts/build_series_catalog.py | 137 +++++++++++++++++++++-------- tests/test_build_series_catalog.py | 108 +++++++++++++++++++++-- 3 files changed, 220 insertions(+), 56 deletions(-) diff --git a/docs/catalog-curation-backlog.md b/docs/catalog-curation-backlog.md index 6338b1bc..9b8cb3c9 100644 --- a/docs/catalog-curation-backlog.md +++ b/docs/catalog-curation-backlog.md @@ -43,19 +43,26 @@ third concept, `bls.ces.nonfarm_payrolls.change`) and hand-chosen person roles, April and May). Fold them with a seed entry and a reviewed regeneration if a consumer ever needs one lineage. -Any edit to the seed is curation: adding, retargeting or removing a fold +Any edit to the seed is curation: adding, retargeting or undoing a fold moves observations between lineages, so the builder refuses it without -`--allow-remint --remint-note`, even when no registry event is planned. -Never delete the seed file while the committed catalog declares -`entity_folds_sha256`; the builder refuses that too. - -To undo a fold, remove its entry from the seed's `folds` list and -regenerate with the ceremony. The absorbed identity revives with its -original UUID, rows it had absorbed by earlier same-dimension merges (the -`us.frb` and `us.census` spellings above) rejoin it, and the names the fold -moved onto the survivor move back. Undoing all seven folds on the committed -artifacts reproduces the pre-fold catalog exactly, apart from the seed and -registry digests (seven `revived` lines, no other event). +`--allow-remint --remint-note`, even when no registry event is planned. The +comparison is with the committed catalog's `entity_folds_sha256`, which, +like every generated artifact, is trusted not to be hand-edited. Never +delete the seed file while the committed catalog declares that digest; the +builder refuses that too. + +To undo a fold, mark its entry `"undone": true` and regenerate with the +ceremony; deleting the entry is refused while git HEAD still holds it. The +absorbed identity revives with its original UUID, rows it had absorbed by +earlier same-dimension merges (the `us.frb` and `us.census` spellings above) +rejoin it, and the names the fold moved onto the survivor move back. Only +an undone fold's absorbed identity can be rejoined this way, so an ordinary +append never revives a retired identity through a name held in another +slice. Marking all seven folds undone on the committed artifacts reproduces +the pre-fold catalog exactly, apart from the seed and registry digests +(seven `revived` lines, no other event). A curated alias that no current +row spells stays on the survivor after an undo; move it back by hand if it +matters. One limitation is older than the folds: the builder refuses a correction that supersedes a row written before assertion versioning (every row of the diff --git a/scripts/build_series_catalog.py b/scripts/build_series_catalog.py index 42271fcc..ab9ed8d4 100644 --- a/scripts/build_series_catalog.py +++ b/scripts/build_series_catalog.py @@ -94,14 +94,18 @@ commits to the seed as ``entity_folds_sha256`` (absent when there is no seed). Once a committed catalog declares it, regenerating without the seed is a hard error, because it would silently split the folded lineages again. -Any change to the seed (a new fold, a retargeted survivor, a removed fold) +Any change to the seed (a new fold, a retargeted survivor, an undone fold) is an identity change: it needs ``--allow-remint --remint-note`` even when it plans no registry event, because it moves observations between -lineages. Removing a fold undoes it: the absorbed identity revives with its -original UUID, and rows spelled by the names it had absorbed by earlier -same-dimension merges rejoin it (a row that matches nothing in its own -slice rejoins a retired identity of its own entity whose names now live on -another slice's row; no UUID crosses entities). A fold that matches no +lineages. (The comparison is with the committed catalog's +``entity_folds_sha256``; like every generated artifact, that header is +trusted not to be hand-edited.) Undo a fold by marking it ``undone: true``; +deleting the entry is refused while git HEAD still holds it. An undone fold +stops folding, its absorbed identity revives with its original UUID, rows +spelled by the names it had absorbed by earlier same-dimension merges rejoin +it, and those names move back off the survivor. Only an undone fold's +absorbed identity can be rejoined this way, and no UUID crosses entities. +Curated aliases that no current row spells stay on the survivor. A fold that current row is inert rather than an error, so a correction that supersedes absorbed rows never makes the fold itself fail. A fold must name an absorbed identity the registry has bound and a survivor the committed @@ -642,10 +646,15 @@ def load_entity_folds(path: pathlib.Path | None) -> tuple[list[dict], bytes | No where = f"entity folds {path}: fold {index}" if not isinstance(fold, dict): raise SystemExit(f"{where} must be an object") - if set(fold) != set(ENTITY_FOLD_FIELDS): + if not set(ENTITY_FOLD_FIELDS) <= set(fold) or ( + set(fold) - set(ENTITY_FOLD_FIELDS) - {"undone"} + ): raise SystemExit( f"{where} must have exactly the fields {list(ENTITY_FOLD_FIELDS)}" + " (plus an optional undone: true)" ) + if "undone" in fold and fold["undone"] is not True: + raise SystemExit(f"{where}: undone must be true when present") concept = fold["concept"] if not isinstance(concept, str) or not concept: raise SystemExit(f"{where}: concept must be a nonempty string") @@ -677,8 +686,9 @@ def load_entity_folds(path: pathlib.Path | None) -> tuple[list[dict], bytes | No if absorbed_key in seen: raise SystemExit(f"{where} repeats the fold of {absorbed_key}") seen.add(absorbed_key) - absorbed_keys.add(absorbed_key) - survivor_keys.add(survivor_key) + if not fold.get("undone"): + absorbed_keys.add(absorbed_key) + survivor_keys.add(survivor_key) chained = absorbed_keys & survivor_keys if chained: raise SystemExit( @@ -688,21 +698,39 @@ def load_entity_folds(path: pathlib.Path | None) -> tuple[list[dict], bytes | No return folds, raw +def entity_fold_key(fold: dict) -> tuple[str, str, str]: + """The absorbed identity a fold names: its key in a seed.""" + return ( + fold["concept"], + _geo_key(fold["geography"]), + _entity_key(fold["absorbed_entity"]), + ) + + def prepare_entity_folds( folds: list[dict], existing: "ExistingCatalog", registry: "UuidRegistry" -) -> dict[tuple[str, str], dict[str, dict]]: +) -> tuple[ + dict[tuple[str, str], dict[str, dict]], + dict[tuple[str, str], list[tuple[str, tuple[str, str, str]]]], +]: """Validate folds against committed state and move naming memory. - Returns the row matcher: (geo_key, absorbed entity_key) -> concept - spelling -> fold. The spellings are the fold concept plus every curated - name of the survivor, which after the first fold include the absorbed - row's names, so alias-spelled absorbed rows fold too. + Returns the row matcher for active folds: (geo_key, absorbed entity_key) + -> concept spelling -> fold. The spellings are the fold concept plus every + curated name of the survivor, which after the first fold include the + absorbed row's names, so alias-spelled absorbed rows fold too. + + Also returns the return index for folds marked ``undone``: (geo_key, + absorbed entity_key) -> [(fold concept, survivor key)]. Only those + entries let a row rejoin a retired identity through names held in + another entity slice; nothing else does. """ matcher: dict[tuple[str, str], dict[str, dict]] = {} + returns: dict[tuple[str, str], list[tuple[str, tuple[str, str, str]]]] = {} for fold in folds: concept = fold["concept"] geo_key = _geo_key(fold["geography"]) - absorbed_key = (concept, geo_key, _entity_key(fold["absorbed_entity"])) + absorbed_key = entity_fold_key(fold) survivor_key = (concept, geo_key, _entity_key(fold["survivor_entity"])) survivor = existing.by_identity.get(survivor_key) if survivor is None or survivor.get("status") != "observed": @@ -716,13 +744,18 @@ def prepare_entity_folds( "the absorbed identity — check the concept, geography and " "entity spelling" ) + if fold.get("undone"): + returns.setdefault((geo_key, absorbed_key[2]), []).append( + (concept, survivor_key) + ) + continue if absorbed_key in existing.by_identity: existing.absorb(absorbed_key, survivor) names = {concept, survivor["concept"], *survivor.get("aliases", [])} slot = matcher.setdefault((geo_key, absorbed_key[2]), {}) for name in names: slot[name] = fold - return matcher + return matcher, returns def apply_entity_folds( @@ -983,34 +1016,33 @@ def returning_concept( key: tuple[str, str, str], names: set[str], registry: "UuidRegistry", + returns: dict[tuple[str, str], list[tuple[str, tuple[str, str, str]]]], ) -> tuple[str, set[str], str] | None: - """The retired identity of ``key``'s own entity that its names rejoin. - - Used only when ``match`` found nothing in the row's own slice. If the - row's names are curated names of a committed row in ANOTHER entity - slice of the same geography, and the registry holds a retired - binding for that row's concept under the row's OWN entity, the row is - the spelling-merged part of that retired identity (an undone entity - fold) and rejoins it. The UUID stays in the row's own slice. - - Returns (concept, the linking names, the other row's uuid): the - builder moves the linking names back from that row onto the revived - identity, restoring the naming the fold had moved. + """The identity an undone fold hands back to a row of its own entity. + + Used only when ``match`` found nothing in the row's own slice, and + only for folds marked ``undone`` (``returns``). If the row's names are + curated names of that fold's survivor, and the registry holds the + fold's absorbed identity retired, the row is part of that identity + (directly, or through a spelling it had absorbed by an earlier + same-dimension merge) and rejoins it. The UUID stays in the row's own + slice. Returns (concept, the linking names, the survivor's uuid): the + builder moves the linking names back from the survivor. """ _, geo_key, entity_key = key hits: dict[str, tuple[set[str], str]] = {} - for row in self.rows: - if _geo_key(row.get("geography")) != geo_key: - continue - if _entity_key(row.get("entity")) == entity_key: + for concept, survivor_key in returns.get((geo_key, entity_key), []): + survivor = self.by_identity.get(survivor_key) + if survivor is None: continue - linking = names & self._row_names(row) + linking = names & self._row_names(survivor) if not linking: continue - candidate = (row["concept"], geo_key, entity_key) - entry = registry.latest.get(candidate) - if entry is not None and not registry.is_live(candidate): - hits[row["concept"]] = (linking, row["uuid"]) + candidate = (concept, geo_key, entity_key) + if registry.latest.get(candidate) is not None and not registry.is_live( + candidate + ): + hits[concept] = (linking, survivor["uuid"]) if len(hits) != 1: return None ((concept, (linking, source_uuid)),) = hits.items() @@ -1797,7 +1829,7 @@ def build_catalog( "the seed would split the folded lineages again. To undo a fold, " "remove it from the seed's folds list; never delete the file." ) - fold_matcher = prepare_entity_folds(folds, existing, registry) + fold_matcher, fold_returns = prepare_entity_folds(folds, existing, registry) identity_rows, folds_applied = apply_entity_folds(current_rows, fold_matcher) identities = build_identities(identity_rows) @@ -1818,7 +1850,7 @@ def build_catalog( prior = existing.match(key, names, ident["geography"], ident["entity"]) canon_concept = prior["concept"] if prior else concept returning = ( - existing.returning_concept(key, names, registry) + existing.returning_concept(key, names, registry, fold_returns) if prior is None else None ) @@ -2460,6 +2492,32 @@ def append_only_problem(base: bytes, current: bytes) -> str | None: ) +def _check_entity_folds_vs_head(path: pathlib.Path) -> None: + """Refuse a seed that drops a fold its committed HEAD version holds. + + Undo a fold by marking it ``undone: true``; deleting the entry would drop + the record the builder needs to hand absorbed spellings back. + """ + head = git_head_bytes(path) + if head is None: + return + try: + head_folds = json.loads(head.decode("utf-8")).get("folds") or [] + head_keys = {entity_fold_key(f) for f in head_folds} + except (UnicodeDecodeError, ValueError, AttributeError, KeyError, TypeError): + return # the committed seed is malformed; the loader reports that + current_keys: set[tuple[str, str, str]] = set() + if path.exists(): + current = json.loads(path.read_text(encoding="utf-8")) + current_keys = {entity_fold_key(f) for f in current.get("folds") or []} + dropped = sorted(head_keys - current_keys) + if dropped: + raise SystemExit( + f"entity folds {path}: {dropped} are folds at HEAD but missing " + "now — undo a fold by marking it undone: true, never by deleting it" + ) + + def _check_registry_vs_head(registry: UuidRegistry) -> None: head = git_head_bytes(registry.path) if head is None: @@ -2560,6 +2618,7 @@ def main(argv: list[str] | None = None) -> int: entity_folds = args.entity_folds or ( args.catalog.parent / "seeds" / "entity_folds.json" ) + _check_entity_folds_vs_head(entity_folds) catalog, plan = build_catalog( args.observations, args.docket, existing, registry, entity_folds ) diff --git a/tests/test_build_series_catalog.py b/tests/test_build_series_catalog.py index 251df3b8..f9c81c08 100644 --- a/tests/test_build_series_catalog.py +++ b/tests/test_build_series_catalog.py @@ -2660,11 +2660,11 @@ def test_entity_fold_seed_cannot_silently_vanish(tmp_path: pathlib.Path) -> None bsc.main(argv + ["--check"]) -def test_emptied_entity_fold_revives_the_absorbed_uuid( +def test_an_undone_fold_revives_the_absorbed_uuid( tmp_path: pathlib.Path, ) -> None: argv, survivor, absorbed = _folded_repo(tmp_path) - empty = _write_folds(tmp_path, []) + undone = _write_folds(tmp_path, [{**_fold(), "undone": True}]) # Removing a fold moves observations between lineages: a ceremony. registry_bytes = (tmp_path / "registry.jsonl").read_bytes() assert bsc.main(argv) == 1 @@ -2678,7 +2678,7 @@ def test_emptied_entity_fold_revives_the_absorbed_uuid( ) assert revive["revived"] is True and revive["uuid"] == absorbed catalog = json.loads((tmp_path / "catalog.json").read_text()) - assert catalog["entity_folds_sha256"] == bsc.hashlib.sha256(empty).hexdigest() + assert catalog["entity_folds_sha256"] == bsc.hashlib.sha256(undone).hexdigest() assert bsc.main(argv + ["--check"]) == 0 @@ -2799,7 +2799,10 @@ def test_undoing_a_fold_restores_earlier_spelling_merges( assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 lines_before_undo = (tmp_path / "registry.jsonl").read_text().splitlines() - _write_folds(tmp_path, []) + _write_folds( + tmp_path, + [{**_fold(concept="fed.g17.ip.mom", absorbed_entity=sector), "undone": True}], + ) assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 lines = (tmp_path / "registry.jsonl").read_text().splitlines() events = [json.loads(line) for line in lines[len(lines_before_undo):]] @@ -2880,6 +2883,99 @@ def test_a_correction_superseding_an_absorbed_row_regenerates( assert absorbed not in {r["uuid"] for r in catalog["series"]} +def test_retired_identities_never_capture_rows_without_an_undone_fold( + tmp_path: pathlib.Path, +) -> None: + # The review's append-only replay: a household lineage retired by an + # ordinary curated correction, a curated alias held only on the economy + # row, then a new household row spelled by that alias. With no fold + # undone, the row must mint its own identity, never revive the retired + # one. + household = {"name": "household", "role": "aggregate"} + rows = [ + _row("a.one", rid="a.one.2026-05", period=_fold_month("2026-05"), + entity=dict(household)), + _row("a.one", rid="a.one.2026-06", period=_fold_month("2026-06")), + ] + argv = _repo(tmp_path, rows) + assert bsc.main(argv) == 0 + household_uuid = _uuid_for(_observed(tmp_path, "a.one"), household) + # Retire the household lineage: its only row leaves the journal. + (tmp_path / "obs.jsonl").write_text(json.dumps(rows[1]) + "\n", encoding="utf-8") + assert bsc.main(argv + [ + "--allow-remint", "--remint-note", + "household lineage corrected away by a curated correction", + ]) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + (economy,) = [r for r in catalog["series"] if r["concept"] == "a.one"] + economy["aliases"] = sorted({*economy["aliases"], "b.one"}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + registry_lines = (tmp_path / "registry.jsonl").read_text().splitlines() + with (tmp_path / "obs.jsonl").open("a", encoding="utf-8") as journal: + journal.write(json.dumps(_row( + "b.one", rid="b.one.2026-07", period=_fold_month("2026-07"), + entity=dict(household), + )) + "\n") + assert bsc.main(argv) == 0 + events = [ + json.loads(line) + for line in (tmp_path / "registry.jsonl").read_text().splitlines()[ + len(registry_lines): + ] + ] + assert [(e["concept"], "revived" in e) for e in events] == [("b.one", False)] + catalog = json.loads((tmp_path / "catalog.json").read_text()) + assert household_uuid not in {r["uuid"] for r in catalog["series"]} + + +def test_a_fold_cannot_be_deleted_while_head_holds_it( + tmp_path: pathlib.Path, +) -> None: + import subprocess + + argv, _, _ = _folded_repo(tmp_path) + for command in ( + ["git", "init", "-q"], + ["git", "add", "-A"], + ["git", "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "f"], + ): + subprocess.run(command, cwd=tmp_path, check=True) + _write_folds(tmp_path, []) + with pytest.raises(SystemExit, match="mark it undone|marking it undone"): + bsc.main(argv + ["--allow-remint", "--remint-note", "delete"]) + _write_folds(tmp_path, [{**_fold(), "undone": True}]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 + + +def test_unobserved_curated_aliases_stay_on_the_survivor_after_undo( + tmp_path: pathlib.Path, +) -> None: + # Documented limitation: names move back on undo only when a current row + # spells them; a curated alias nobody spells stays on the survivor. + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + hand = next( + r for r in catalog["series"] + if r["concept"] == "bls.cps.unemployment_rate" and r["entity"] == HAND_ENTITY + ) + hand["aliases"] = sorted({*hand["aliases"], "labor.market.unemployment_rate"}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + _write_folds(tmp_path, [_fold()]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 + _write_folds(tmp_path, [{**_fold(), "undone": True}]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 + rows = _observed(tmp_path, "bls.cps.unemployment_rate") + by_entity = {r["entity"]["name"]: r for r in rows} + assert "labor.market.unemployment_rate" in by_entity["economy"]["aliases"] + assert "labor.market.unemployment_rate" not in by_entity["person"]["aliases"] + assert bsc.main(argv + ["--check"]) == 0 + + def test_entity_fold_naming_an_unbound_identity_is_refused( tmp_path: pathlib.Path, ) -> None: @@ -2912,6 +3008,8 @@ def test_entity_fold_without_a_committed_survivor_is_refused( ([_fold()], {"comment": 3}, "comment must be a string"), ([{k: v for k, v in _fold().items() if k != "note"}], {}, "exactly the fields"), ([{**_fold(), "extra": 1}], {}, "exactly the fields"), + ([{**_fold(), "undone": False}], {}, "undone must be true"), + ([{**_fold(), "undone": "yes"}], {}, "undone must be true"), ([_fold(note=" ")], {}, "note must be a nonempty string"), ([_fold(survivor_entity=dict(HAND_ENTITY))], {}, "into itself"), ([_fold(), _fold()], {}, "repeats the fold"), @@ -3031,7 +3129,7 @@ def observed_total(catalog: dict) -> int: assert bsc.main(argv) == 0 assert (tmp_path / "catalog.json").read_bytes() == snapshot - _write_folds(tmp_path, []) + _write_folds(tmp_path, [{**_fold(), "undone": True}]) assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 restored = _observed(tmp_path, "bls.cps.unemployment_rate") assert {r["uuid"] for r in restored} == {survivor, absorbed} From 38716eeaaf97ea35e262a675a74232d7cd70aa97 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 14:47:29 -0400 Subject: [PATCH 5/6] Declare each fold's absorbed names and match only those Answers the independent review of d3d23ff5. - Each fold now declares absorbed_names, the absorbed row's concept and aliases, checked for equality against that row while it is committed. Folding matches only those spellings; at d3d23ff5 the matcher used every survivor alias, so a new absorbed-entity row spelled by a survivor-only alias was silently captured (regression added). Replaying the fold from the pre-fold state with the new seed reproduces the committed catalog and registry byte for byte; an incomplete absorbed_names is refused. - Undo moves exactly the declared names back, so curated aliases no row spells now round-trip too (the regression asserts the exact pre-fold catalog). - The seed comment and the missing-seed error say to mark a fold undone, not to remove it; the docstring sentence that lost words is whole again; the round-4 regression retires its lineage by an appended superseding correction instead of rewriting the journal. - Regenerated with the ceremony for the new seed digest; the registry is unchanged. Co-Authored-By: Claude Opus 5.5 --- docs/catalog-curation-backlog.md | 27 ++++--- ledger/seeds/entity_folds.json | 33 ++++++++- ledger/series_catalog.json | 2 +- scripts/build_series_catalog.py | 103 +++++++++++++++++--------- tests/test_build_series_catalog.py | 111 +++++++++++++++++++++++++---- 5 files changed, 216 insertions(+), 60 deletions(-) diff --git a/docs/catalog-curation-backlog.md b/docs/catalog-curation-backlog.md index 9b8cb3c9..ff41073f 100644 --- a/docs/catalog-curation-backlog.md +++ b/docs/catalog-curation-backlog.md @@ -51,18 +51,23 @@ like every generated artifact, is trusted not to be hand-edited. Never delete the seed file while the committed catalog declares that digest; the builder refuses that too. +Each fold declares `absorbed_names`: the absorbed row's concept and +aliases, which the builder checks for equality against that row while it is +still committed. Folding matches only those spellings, so a spelling that +only the survivor holds never pulls a row of the absorbed entity across. + To undo a fold, mark its entry `"undone": true` and regenerate with the -ceremony; deleting the entry is refused while git HEAD still holds it. The -absorbed identity revives with its original UUID, rows it had absorbed by -earlier same-dimension merges (the `us.frb` and `us.census` spellings above) -rejoin it, and the names the fold moved onto the survivor move back. Only -an undone fold's absorbed identity can be rejoined this way, so an ordinary -append never revives a retired identity through a name held in another -slice. Marking all seven folds undone on the committed artifacts reproduces -the pre-fold catalog exactly, apart from the seed and registry digests -(seven `revived` lines, no other event). A curated alias that no current -row spells stays on the survivor after an undo; move it back by hand if it -matters. +ceremony; deleting the entry is refused while git HEAD still holds it, and +in a tree without git history it must not be done at all, because the entry +is the record the builder uses to hand names back. The absorbed identity +revives with its original UUID, rows it had absorbed by earlier +same-dimension merges (the `us.frb` and `us.census` spellings above) rejoin +it, and its `absorbed_names` move back off the survivor, curated aliases no +row spells included. Only an undone fold's absorbed identity can be +rejoined this way, so an ordinary append never revives a retired identity +through a name held in another slice. Marking all seven folds undone on the +committed artifacts reproduces the pre-fold catalog exactly, apart from the +seed and registry digests (seven `revived` lines, no other event). One limitation is older than the folds: the builder refuses a correction that supersedes a row written before assertion versioning (every row of the diff --git a/ledger/seeds/entity_folds.json b/ledger/seeds/entity_folds.json index eb3d1757..f7f1566b 100644 --- a/ledger/seeds/entity_folds.json +++ b/ledger/seeds/entity_folds.json @@ -1,6 +1,6 @@ { "schemaVersion": "chronicle_entity_folds_v1", - "comment": "Curated cross-entity folds for scripts/build_series_catalog.py. Each fold reads every current observation of the concept and geography that carries absorbed_entity as carrying survivor_entity when the catalog groups identities; the observation file is never changed. Undo a fold by removing it from this list, never by deleting the file. The seven folds below are the entity-drift families in docs/catalog-curation-backlog.md, folded into their economy/aggregate lineages by Max's ruling d353 (2026-09-27).", + "comment": "Curated cross-entity folds for scripts/build_series_catalog.py. Each fold reads every current observation of the concept and geography that carries absorbed_entity, and is spelled by one of absorbed_names (the absorbed row's concept and aliases when the fold was made), as carrying survivor_entity when the catalog groups identities; the observation file is never changed. Undo a fold by adding \"undone\": true to its entry, never by deleting the entry or the file. The seven folds below are the entity-drift families in docs/catalog-curation-backlog.md, folded into their economy/aggregate lineages by Max's ruling d353 (2026-09-27).", "folds": [ { "concept": "bls.cpi.u.core_mom", @@ -17,6 +17,10 @@ "name": "economy", "role": "aggregate" }, + "absorbed_names": [ + "bls.cpi.u.core_mom", + "bls.cpi.u.core_mom.may_2026" + ], "note": "Hand-recorded ledger line 15 carries household/cpi_u_less_food_energy; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." }, { @@ -34,6 +38,10 @@ "name": "economy", "role": "aggregate" }, + "absorbed_names": [ + "bls.cpi.u.headline_mom", + "bls.cpi.u.headline_mom.may_2026" + ], "note": "Hand-recorded ledger line 14 carries household/cpi_u_all_items; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." }, { @@ -51,6 +59,9 @@ "name": "economy", "role": "aggregate" }, + "absorbed_names": [ + "bls.cps.unemployment_rate" + ], "note": "Hand-recorded ledger line 2 carries person/civilian_labor_force; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." }, { @@ -68,6 +79,10 @@ "name": "economy", "role": "aggregate" }, + "absorbed_names": [ + "bls.import_price_index.all_imports_mom", + "bls.import_price_index.all_imports_mom.may_2026" + ], "note": "Hand-recorded its May 2026 print carries household/all_imports; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." }, { @@ -85,6 +100,12 @@ "name": "economy", "role": "aggregate" }, + "absorbed_names": [ + "census.housing_starts.saar", + "census.housing_starts.saar.may_2026", + "us.census.housing_starts.total_saar", + "us.census.housing_starts.total_saar.2026_05" + ], "note": "Hand-recorded its May 2026 prints carries dwelling/housing_start; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." }, { @@ -102,6 +123,10 @@ "name": "economy", "role": "aggregate" }, + "absorbed_names": [ + "fed.g17.capacity_utilization.total_industry", + "fed.g17.capacity_utilization.total_industry.may_2026" + ], "note": "Hand-recorded its May 2026 print carries institutional_sector/total_industry_capacity; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." }, { @@ -119,6 +144,12 @@ "name": "economy", "role": "aggregate" }, + "absorbed_names": [ + "fed.g17.industrial_production.total_index_mom", + "fed.g17.industrial_production.total_index_mom.may_2026", + "us.frb.industrial_production.total.mom_sa", + "us.frb.industrial_production.total.mom_sa.2026_05" + ], "note": "Hand-recorded its May 2026 prints carries institutional_sector/total_industrial_production; every resolver print of the series carries economy/aggregate, the default entity resolve_pending.generic_fact writes. One series, so the hand-recorded lineage joins the resolver lineage (d353)." } ] diff --git a/ledger/series_catalog.json b/ledger/series_catalog.json index 23ae9523..de51f991 100644 --- a/ledger/series_catalog.json +++ b/ledger/series_catalog.json @@ -5,7 +5,7 @@ "observation_rows": 233, "current_assertion_rows": 233, "docket_seed_sha256": "5914192517350e0166045afd9064a515ea312acbea1844d9cb594cc9f525dbb9", - "entity_folds_sha256": "442739aba771eadf57984ed968391f702f5b826c8b98ba4cae1e04cc1587e572", + "entity_folds_sha256": "f7496541139308e97c65c8681dd9f44829d46df25eede0d4e639203049667b58", "uuid_registry_sha256": "272d8fd6b2e82151d781d8a9bc69f0f7abaf934a837279c47d2f534683443f31", "suspect_segments": [ "LNU02374597" diff --git a/scripts/build_series_catalog.py b/scripts/build_series_catalog.py index ab9ed8d4..9286ceb0 100644 --- a/scripts/build_series_catalog.py +++ b/scripts/build_series_catalog.py @@ -103,12 +103,15 @@ deleting the entry is refused while git HEAD still holds it. An undone fold stops folding, its absorbed identity revives with its original UUID, rows spelled by the names it had absorbed by earlier same-dimension merges rejoin -it, and those names move back off the survivor. Only an undone fold's -absorbed identity can be rejoined this way, and no UUID crosses entities. -Curated aliases that no current row spells stay on the survivor. A fold that -current row is inert rather than an error, so a correction that supersedes -absorbed rows never makes the fold itself fail. A fold must name an -absorbed identity the registry has bound and a survivor the committed +it, and the fold's ``absorbed_names`` move back off the survivor. Only an +undone fold's absorbed identity can be rejoined this way, and no UUID +crosses entities. Each fold declares ``absorbed_names``, the absorbed row's +concept and aliases, checked for equality against that row while it is +committed: folding matches only those spellings, so a spelling only the +survivor holds never pulls an absorbed-entity row across. A fold that +matches no current row is inert rather than an error, so a correction that +supersedes absorbed rows never makes the fold itself fail. A fold must name +an absorbed identity the registry has bound and a survivor the committed catalog holds, so a mistyped fold is refused instead of ignored. Inputs are pinned: the observation JSONL (``observations_sha256``), the @@ -147,7 +150,8 @@ ENTITY_FOLDS = ROOT / "ledger" / "seeds" / "entity_folds.json" ENTITY_FOLDS_SCHEMA = "chronicle_entity_folds_v1" ENTITY_FOLD_FIELDS = ( - "concept", "geography", "absorbed_entity", "survivor_entity", "note", + "concept", "geography", "absorbed_entity", "survivor_entity", + "absorbed_names", "note", ) GENERATOR_VERSION = 3 @@ -678,6 +682,23 @@ def load_entity_folds(path: pathlib.Path | None) -> tuple[list[dict], bytes | No raise SystemExit(f"{where}: {problem or side + ' is required'}") if not _usable_note(fold["note"]): raise SystemExit(f"{where}: note must be a nonempty string") + names = fold["absorbed_names"] + if ( + not isinstance(names, list) + or not names + or not all(isinstance(n, str) and n for n in names) + or names != sorted(set(names)) + ): + raise SystemExit( + f"{where}: absorbed_names must be a sorted list of distinct " + "nonempty strings" + ) + if concept not in names: + raise SystemExit(f"{where}: absorbed_names must include the concept") + for name in names: + for problem in (_reserved_segment_problem(name), _cosmetic_problem(name)): + if problem: + raise SystemExit(f"{where}: absorbed name {problem}") geo_key = _geo_key(fold["geography"]) absorbed_key = (concept, geo_key, _entity_key(fold["absorbed_entity"])) survivor_key = (concept, geo_key, _entity_key(fold["survivor_entity"])) @@ -711,22 +732,25 @@ def prepare_entity_folds( folds: list[dict], existing: "ExistingCatalog", registry: "UuidRegistry" ) -> tuple[ dict[tuple[str, str], dict[str, dict]], - dict[tuple[str, str], list[tuple[str, tuple[str, str, str]]]], + dict[tuple[str, str], list[tuple[str, tuple[str, str, str], set[str]]]], ]: """Validate folds against committed state and move naming memory. Returns the row matcher for active folds: (geo_key, absorbed entity_key) - -> concept spelling -> fold. The spellings are the fold concept plus every - curated name of the survivor, which after the first fold include the - absorbed row's names, so alias-spelled absorbed rows fold too. + -> concept spelling -> fold. The spellings are exactly the fold's declared + ``absorbed_names`` (checked against the absorbed row while it is still + committed), so alias-spelled absorbed rows fold too, and a spelling only + the survivor holds never pulls an absorbed-entity row across. Also returns the return index for folds marked ``undone``: (geo_key, - absorbed entity_key) -> [(fold concept, survivor key)]. Only those - entries let a row rejoin a retired identity through names held in - another entity slice; nothing else does. + absorbed entity_key) -> [(fold concept, survivor key, absorbed names)]. + Only those entries let a row rejoin a retired identity through names held + in another entity slice; nothing else does. """ matcher: dict[tuple[str, str], dict[str, dict]] = {} - returns: dict[tuple[str, str], list[tuple[str, tuple[str, str, str]]]] = {} + returns: dict[ + tuple[str, str], list[tuple[str, tuple[str, str, str], set[str]]] + ] = {} for fold in folds: concept = fold["concept"] geo_key = _geo_key(fold["geography"]) @@ -744,16 +768,24 @@ def prepare_entity_folds( "the absorbed identity — check the concept, geography and " "entity spelling" ) + declared = set(fold["absorbed_names"]) if fold.get("undone"): returns.setdefault((geo_key, absorbed_key[2]), []).append( - (concept, survivor_key) + (concept, survivor_key, declared) ) continue - if absorbed_key in existing.by_identity: + absorbed = existing.by_identity.get(absorbed_key) + if absorbed is not None: + held = {absorbed["concept"], *absorbed.get("aliases", [])} + if declared != held: + raise SystemExit( + f"entity fold {absorbed_key}: absorbed_names must be " + f"exactly the absorbed row's names {sorted(held)}, got " + f"{sorted(declared)}" + ) existing.absorb(absorbed_key, survivor) - names = {concept, survivor["concept"], *survivor.get("aliases", [])} slot = matcher.setdefault((geo_key, absorbed_key[2]), {}) - for name in names: + for name in declared: slot[name] = fold return matcher, returns @@ -1016,37 +1048,38 @@ def returning_concept( key: tuple[str, str, str], names: set[str], registry: "UuidRegistry", - returns: dict[tuple[str, str], list[tuple[str, tuple[str, str, str]]]], + returns: dict[ + tuple[str, str], list[tuple[str, tuple[str, str, str], set[str]]] + ], ) -> tuple[str, set[str], str] | None: """The identity an undone fold hands back to a row of its own entity. Used only when ``match`` found nothing in the row's own slice, and - only for folds marked ``undone`` (``returns``). If the row's names are - curated names of that fold's survivor, and the registry holds the - fold's absorbed identity retired, the row is part of that identity - (directly, or through a spelling it had absorbed by an earlier - same-dimension merge) and rejoins it. The UUID stays in the row's own - slice. Returns (concept, the linking names, the survivor's uuid): the - builder moves the linking names back from the survivor. + only for folds marked ``undone`` (``returns``). If one of the row's + names is among the fold's declared ``absorbed_names`` and the + registry holds the fold's absorbed identity retired, the row rejoins + it (directly, or through a spelling it had absorbed by an earlier + same-dimension merge). The UUID stays in the row's own slice. Returns + (concept, the declared names, the survivor's uuid): the builder moves + the declared names back from the survivor onto the revived identity. """ _, geo_key, entity_key = key hits: dict[str, tuple[set[str], str]] = {} - for concept, survivor_key in returns.get((geo_key, entity_key), []): + for concept, survivor_key, declared in returns.get((geo_key, entity_key), []): + if not names & declared: + continue survivor = self.by_identity.get(survivor_key) if survivor is None: continue - linking = names & self._row_names(survivor) - if not linking: - continue candidate = (concept, geo_key, entity_key) if registry.latest.get(candidate) is not None and not registry.is_live( candidate ): - hits[concept] = (linking, survivor["uuid"]) + hits[concept] = (set(declared), survivor["uuid"]) if len(hits) != 1: return None - ((concept, (linking, source_uuid)),) = hits.items() - return concept, linking, source_uuid + ((concept, (declared, source_uuid)),) = hits.items() + return concept, declared, source_uuid def absorb(self, absorbed_key: tuple[str, str, str], survivor: dict) -> None: """Fold a committed row into ``survivor``'s naming memory. @@ -1827,7 +1860,7 @@ def build_catalog( f"entity-fold seed missing: {entity_folds_path} — the committed " "catalog declares entity_folds_sha256, and regenerating without " "the seed would split the folded lineages again. To undo a fold, " - "remove it from the seed's folds list; never delete the file." + "mark it undone: true in the seed; never delete the file." ) fold_matcher, fold_returns = prepare_entity_folds(folds, existing, registry) identity_rows, folds_applied = apply_entity_folds(current_rows, fold_matcher) diff --git a/tests/test_build_series_catalog.py b/tests/test_build_series_catalog.py index f9c81c08..f111bc19 100644 --- a/tests/test_build_series_catalog.py +++ b/tests/test_build_series_catalog.py @@ -2552,9 +2552,19 @@ def _fold(**overrides) -> dict: "note": FOLD_NOTE, } fold.update(overrides) + fold.setdefault("absorbed_names", [fold["concept"]]) return fold +# The hand lineage of the industrial-production fixtures after its curated +# same-dimension merge: its concept, its observed spelling, the merged +# spelling and that spelling's observed form. +IP_ABSORBED_NAMES = [ + "fed.g17.ip.mom", "fed.g17.ip.mom.may_2026", + "us.frb.ip.mom", "us.frb.ip.mom.2026_04", +] + + def _write_folds(tmp_path: pathlib.Path, folds: list, **doc_overrides) -> bytes: doc = {"schemaVersion": bsc.ENTITY_FOLDS_SCHEMA, "folds": folds} doc.update(doc_overrides) @@ -2732,7 +2742,10 @@ def test_entity_fold_reaches_rows_spelled_by_a_curated_alias( assert bsc.main(argv + ["--allow-remint", "--remint-note", "spelling"]) == 0 economy = _uuid_for(_observed(tmp_path, "fed.g17.ip.mom"), ECONOMY) - _write_folds(tmp_path, [_fold(concept="fed.g17.ip.mom", absorbed_entity=sector)]) + _write_folds(tmp_path, [_fold( + concept="fed.g17.ip.mom", absorbed_entity=sector, + absorbed_names=IP_ABSORBED_NAMES, + )]) assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 (row,) = _observed(tmp_path, "fed.g17.ip.mom") assert row["uuid"] == economy and row["observation_count"] == 3 @@ -2795,13 +2808,19 @@ def test_undoing_a_fold_restores_earlier_spelling_merges( ) assert bsc.main(argv + ["--allow-remint", "--remint-note", "spelling"]) == 0 prefold = json.loads((tmp_path / "catalog.json").read_text()) - _write_folds(tmp_path, [_fold(concept="fed.g17.ip.mom", absorbed_entity=sector)]) + _write_folds(tmp_path, [_fold( + concept="fed.g17.ip.mom", absorbed_entity=sector, + absorbed_names=IP_ABSORBED_NAMES, + )]) assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 lines_before_undo = (tmp_path / "registry.jsonl").read_text().splitlines() _write_folds( tmp_path, - [{**_fold(concept="fed.g17.ip.mom", absorbed_entity=sector), "undone": True}], + [{**_fold( + concept="fed.g17.ip.mom", absorbed_entity=sector, + absorbed_names=IP_ABSORBED_NAMES, + ), "undone": True}], ) assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 lines = (tmp_path / "registry.jsonl").read_text().splitlines() @@ -2897,11 +2916,17 @@ def test_retired_identities_never_capture_rows_without_an_undone_fold( entity=dict(household)), _row("a.one", rid="a.one.2026-06", period=_fold_month("2026-06")), ] + rows[0]["assertionVersion"] = {"id": "av-test:a-may", "supersedes": None} argv = _repo(tmp_path, rows) assert bsc.main(argv) == 0 household_uuid = _uuid_for(_observed(tmp_path, "a.one"), household) - # Retire the household lineage: its only row leaves the journal. - (tmp_path / "obs.jsonl").write_text(json.dumps(rows[1]) + "\n", encoding="utf-8") + # Retire the household lineage by an appended correction that moves its + # only row to the economy entity; the journal stays append-only. + correction = json.loads(json.dumps(rows[0])) + correction["entity"] = {"name": "economy", "role": "aggregate"} + correction["assertionVersion"] = {"id": "av-test:a-may-fix", "supersedes": "av-test:a-may"} + with (tmp_path / "obs.jsonl").open("a", encoding="utf-8") as journal: + journal.write(json.dumps(correction) + "\n") assert bsc.main(argv + [ "--allow-remint", "--remint-note", "household lineage corrected away by a curated correction", @@ -2949,11 +2974,11 @@ def test_a_fold_cannot_be_deleted_while_head_holds_it( assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 -def test_unobserved_curated_aliases_stay_on_the_survivor_after_undo( +def test_unobserved_curated_aliases_round_trip_through_undo( tmp_path: pathlib.Path, ) -> None: - # Documented limitation: names move back on undo only when a current row - # spells them; a curated alias nobody spells stays on the survivor. + # absorbed_names records every name of the absorbed lineage, so a curated + # alias no row spells moves to the survivor and back again. argv = _repo(tmp_path, _drift_rows()) assert bsc.main(argv) == 0 catalog = json.loads((tmp_path / "catalog.json").read_text()) @@ -2965,17 +2990,75 @@ def test_unobserved_curated_aliases_stay_on_the_survivor_after_undo( (tmp_path / "catalog.json").write_text( json.dumps(catalog, indent=2) + "\n", encoding="utf-8" ) - _write_folds(tmp_path, [_fold()]) + prefold = json.loads((tmp_path / "catalog.json").read_text()) + names = ["bls.cps.unemployment_rate", "labor.market.unemployment_rate"] + _write_folds(tmp_path, [_fold(absorbed_names=names)]) assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 - _write_folds(tmp_path, [{**_fold(), "undone": True}]) + (folded,) = _observed(tmp_path, "bls.cps.unemployment_rate") + assert "labor.market.unemployment_rate" in folded["aliases"] + _write_folds(tmp_path, [{**_fold(absorbed_names=names), "undone": True}]) assert bsc.main(argv + ["--allow-remint", "--remint-note", "undo"]) == 0 rows = _observed(tmp_path, "bls.cps.unemployment_rate") by_entity = {r["entity"]["name"]: r for r in rows} - assert "labor.market.unemployment_rate" in by_entity["economy"]["aliases"] - assert "labor.market.unemployment_rate" not in by_entity["person"]["aliases"] + assert "labor.market.unemployment_rate" not in by_entity["economy"]["aliases"] + assert "labor.market.unemployment_rate" in by_entity["person"]["aliases"] + undone = json.loads((tmp_path / "catalog.json").read_text()) + assert _without_digests(undone) == _without_digests(prefold) assert bsc.main(argv + ["--check"]) == 0 +def test_a_fold_never_captures_a_spelling_only_the_survivor_holds( + tmp_path: pathlib.Path, +) -> None: + # The round-5 review's replay: b.one is curated on the economy survivor + # alone; a new person row spelled b.one is a new identity, not part of + # the absorbed lineage. + argv, survivor, _ = _folded_repo(tmp_path) + catalog = json.loads((tmp_path / "catalog.json").read_text()) + (economy,) = [ + r for r in catalog["series"] if r["concept"] == "bls.cps.unemployment_rate" + ] + economy["aliases"] = sorted({*economy["aliases"], "b.one"}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + registry_lines = (tmp_path / "registry.jsonl").read_text().splitlines() + with (tmp_path / "obs.jsonl").open("a", encoding="utf-8") as journal: + journal.write(json.dumps(_row( + "b.one", rid="b.one.2026-08", period=_fold_month("2026-08"), + entity=dict(HAND_ENTITY), + )) + "\n") + assert bsc.main(argv) == 0 + (row,) = _observed(tmp_path, "bls.cps.unemployment_rate") + assert row["uuid"] == survivor and row["observation_count"] == 3 + events = [ + json.loads(line) + for line in (tmp_path / "registry.jsonl").read_text().splitlines()[ + len(registry_lines): + ] + ] + assert [(e["concept"], e["entity"]) for e in events] == [("b.one", HAND_ENTITY)] + + +def test_a_fold_must_declare_exactly_the_absorbed_names( + tmp_path: pathlib.Path, +) -> None: + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + hand = next( + r for r in catalog["series"] + if r["concept"] == "bls.cps.unemployment_rate" and r["entity"] == HAND_ENTITY + ) + hand["aliases"] = ["labor.market.unemployment_rate"] + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + _write_folds(tmp_path, [_fold()]) + with pytest.raises(SystemExit, match="absorbed_names must be exactly"): + bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) + + def test_entity_fold_naming_an_unbound_identity_is_refused( tmp_path: pathlib.Path, ) -> None: @@ -3009,6 +3092,10 @@ def test_entity_fold_without_a_committed_survivor_is_refused( ([{k: v for k, v in _fold().items() if k != "note"}], {}, "exactly the fields"), ([{**_fold(), "extra": 1}], {}, "exactly the fields"), ([{**_fold(), "undone": False}], {}, "undone must be true"), + ([_fold(absorbed_names=[])], {}, "absorbed_names must be a sorted list"), + ([_fold(absorbed_names=["z.one", "bls.cps.unemployment_rate"])], {}, + "absorbed_names must be a sorted list"), + ([_fold(absorbed_names=["a.other"])], {}, "must include the concept"), ([{**_fold(), "undone": "yes"}], {}, "undone must be true"), ([_fold(note=" ")], {}, "note must be a nonempty string"), ([_fold(survivor_entity=dict(HAND_ENTITY))], {}, "into itself"), From 0e1dc63b0dbf09a980793c0f846bf970caadc631 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 12 Oct 2026 15:15:50 -0400 Subject: [PATCH 6/6] Refuse inconsistent ownership of a fold's absorbed names Answers the minors of the approving review of 38716eea. - At fold time, an absorbed name already held by a row in the survivor's slice is refused: shared ownership made the undo inexact. - While a fold stands, the survivor must hold every absorbed name alone; a hand edit that drops one from the survivor or gives it to another series is refused instead of routing folded rows there. - The docstring's field list names absorbed_names and the undone marker, and the property test's description says the fold is marked undone. The committed catalog, a fresh fold from d7e45bc5 and a full marked undo all reproduce as before. Co-Authored-By: Claude Opus 5.5 --- scripts/build_series_catalog.py | 41 ++++++++++++++++++--- tests/test_build_series_catalog.py | 57 +++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/scripts/build_series_catalog.py b/scripts/build_series_catalog.py index 9286ceb0..bbac7214 100644 --- a/scripts/build_series_catalog.py +++ b/scripts/build_series_catalog.py @@ -85,10 +85,11 @@ ``economy/aggregate``). Alias inheritance never crosses an entity slice, so regeneration would restore the split. The seed at ``ledger/seeds/entity_folds.json`` (``chronicle_entity_folds_v1``) lists -folds as (concept, geography, absorbed_entity, survivor_entity, note). -Before identities are grouped, every current row of that concept and -geography carrying the absorbed entity is read as carrying the survivor -entity; the observation file itself is never changed. The absorbed row's +folds as (concept, geography, absorbed_entity, survivor_entity, +absorbed_names, note), optionally marked ``undone``. Before identities are +grouped, every current row of that concept and geography carrying the +absorbed entity and spelled by one of the absorbed names is read as carrying +the survivor entity; the observation file itself is never changed. The absorbed row's curated names join the survivor's ``aliases``, its live binding is retired with the ``--remint-note``, and the survivor keeps its UUID. The catalog commits to the seed as ``entity_folds_sha256`` (absent when there is no @@ -775,6 +776,8 @@ def prepare_entity_folds( ) continue absorbed = existing.by_identity.get(absorbed_key) + survivor_slice = existing.by_dim.get((geo_key, survivor_key[2]), []) + moved = declared - {concept} if absorbed is not None: held = {absorbed["concept"], *absorbed.get("aliases", [])} if declared != held: @@ -783,7 +786,37 @@ def prepare_entity_folds( f"exactly the absorbed row's names {sorted(held)}, got " f"{sorted(declared)}" ) + # Shared ownership would make the undo inexact: the builder could + # not tell which of the survivor's names were its own. + shared = sorted( + name + for row in survivor_slice + for name in moved & {row["concept"], *row.get("aliases", [])} + ) + if shared: + raise SystemExit( + f"entity fold {absorbed_key}: {shared} already belong to " + "a row in the survivor's slice; resolve that ownership " + "before folding" + ) existing.absorb(absorbed_key, survivor) + else: + # While a fold stands, the survivor alone holds the moved names; + # a hand edit that gives one to another series would route folded + # rows to that series. + missing = sorted(moved - set(survivor.get("aliases", []))) + elsewhere = sorted( + name + for row in survivor_slice + if row is not survivor + for name in moved & {row["concept"], *row.get("aliases", [])} + ) + if missing or elsewhere: + raise SystemExit( + f"entity fold {absorbed_key}: the survivor must hold every " + f"absorbed name alone; missing {missing}, held elsewhere " + f"{elsewhere}" + ) slot = matcher.setdefault((geo_key, absorbed_key[2]), {}) for name in declared: slot[name] = fold diff --git a/tests/test_build_series_catalog.py b/tests/test_build_series_catalog.py index f111bc19..67bf4790 100644 --- a/tests/test_build_series_catalog.py +++ b/tests/test_build_series_catalog.py @@ -3040,6 +3040,61 @@ def test_a_fold_never_captures_a_spelling_only_the_survivor_holds( assert [(e["concept"], e["entity"]) for e in events] == [("b.one", HAND_ENTITY)] +def test_a_fold_refuses_names_already_held_in_the_survivor_slice( + tmp_path: pathlib.Path, +) -> None: + # A name on both lineages makes undo inexact; resolve it before folding. + argv = _repo(tmp_path, _drift_rows()) + assert bsc.main(argv) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + for row in catalog["series"]: + if row["concept"] == "bls.cps.unemployment_rate": + row["aliases"] = sorted({*row["aliases"], "labor.market.unemployment_rate"}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + names = ["bls.cps.unemployment_rate", "labor.market.unemployment_rate"] + _write_folds(tmp_path, [_fold(absorbed_names=names)]) + with pytest.raises(SystemExit, match="already belong to a row in the survivor"): + bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) + + +@pytest.mark.parametrize("edit", ["drop", "move"]) +def test_a_standing_fold_refuses_inconsistent_spelling_ownership( + tmp_path: pathlib.Path, edit: str +) -> None: + # The round-6 review's replay: after the fold, a hand edit takes an + # absorbed name off the survivor (and, for "move", gives it to another + # economy series). Folded rows must not follow it. + argv = _repo(tmp_path, _drift_rows() + [ + _row("other.series", rid="other.series.2026-06", period=_fold_month("2026-06")), + ]) + assert bsc.main(argv) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + hand = next( + r for r in catalog["series"] + if r["concept"] == "bls.cps.unemployment_rate" and r["entity"] == HAND_ENTITY + ) + hand["aliases"] = sorted({*hand["aliases"], "labor.market.unemployment_rate"}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + names = ["bls.cps.unemployment_rate", "labor.market.unemployment_rate"] + _write_folds(tmp_path, [_fold(absorbed_names=names)]) + assert bsc.main(argv + ["--allow-remint", "--remint-note", FOLD_NOTE]) == 0 + catalog = json.loads((tmp_path / "catalog.json").read_text()) + for row in catalog["series"]: + if row["concept"] == "bls.cps.unemployment_rate": + row["aliases"] = [a for a in row["aliases"] if a != names[1]] + if edit == "move" and row["concept"] == "other.series": + row["aliases"] = sorted({*row["aliases"], names[1]}) + (tmp_path / "catalog.json").write_text( + json.dumps(catalog, indent=2) + "\n", encoding="utf-8" + ) + with pytest.raises(SystemExit, match="must hold every absorbed name alone"): + bsc.main(argv) + + def test_a_fold_must_declare_exactly_the_absorbed_names( tmp_path: pathlib.Path, ) -> None: @@ -3175,7 +3230,7 @@ def test_entity_fold_invariants_hold_for_any_split( """For every split of one series across two entities (months may overlap): the fold conserves observations, mints nothing, keeps the survivor's UUID, retires exactly the absorbed one, is byte-idempotent, - and an emptied fold revives exactly the absorbed UUID.""" + and marking the fold undone revives exactly the absorbed UUID.""" tmp_path = tmp_path_factory.mktemp("fold") rows = _drift_rows(hand_months=sorted(hand), economy_months=sorted(economy)) argv = _repo(tmp_path, rows)