From 14207d404cb1ac9048a7b9bfa1a9afe1222d286b Mon Sep 17 00:00:00 2001 From: Adam Wright <668955+adamjohnwright@users.noreply.github.com> Date: Fri, 16 Oct 2026 10:56:09 -0400 Subject: [PATCH] Clear every derived structure cache per pathway (deltasignal specs/065 amendment 1) The variant leaf-set, matching-leaf, hand-off leaf and set-chooser memos and the variant_keys memo are built from getters that return empty outside the current pathway's prefetch, and survived into the next pathway of a build. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/reaction_generator.py | 9 +++++++++ tests/test_variant_emission.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/reaction_generator.py b/src/reaction_generator.py index c3e8e78..f04ed9f 100755 --- a/src/reaction_generator.py +++ b/src/reaction_generator.py @@ -787,6 +787,15 @@ def prime_entity_caches(reaction_connections: pd.DataFrame) -> None: # would make the network depend on build order (deltasignal specs/065). from src.variant_emission import _sig_cache _sig_cache.clear() + # So are the structure memos built from those getters (specs/065 + # amendment 1); caches filled by their own direct query hold database + # truth and are kept. + import src.logic_network_generator as lng + for c in (lng._variant_leafsets_cache, lng._matching_leaves_cache, + lng._handoff_leaf_cache, lng._sets_chosen_cache): + c.clear() + from src import variant_keys + variant_keys.reset_caches() clear_prefetch_cache() reaction_ids = reaction_ids_from_connections(reaction_connections) if not reaction_ids: diff --git a/tests/test_variant_emission.py b/tests/test_variant_emission.py index a79f869..38bf8bb 100644 --- a/tests/test_variant_emission.py +++ b/tests/test_variant_emission.py @@ -251,3 +251,19 @@ def test_priming_a_pathway_clears_set_member_signatures(monkeypatch): ve._sig_cache[("M1", True)] = ("stale",) rg.prime_entity_caches(None) assert ve._sig_cache == {} + + +def test_priming_a_pathway_clears_derived_structure_caches(monkeypatch): + # specs/065 amendment 1: every memo computed from the prefetch-limited + # getters is per pathway. + import src.reaction_generator as rg + import src.logic_network_generator as lng + monkeypatch.setattr(rg, "reaction_ids_from_connections", lambda rc: ["R1"]) + monkeypatch.setattr(rg, "prefetch_entity_data", lambda ids: None) + caches = (lng._variant_leafsets_cache, lng._matching_leaves_cache, + lng._handoff_leaf_cache, lng._sets_chosen_cache, + vk._memo, vk._variants_cache, vk._struct) + for c in caches: + c["stale"] = None + rg.prime_entity_caches(None) + assert all("stale" not in c for c in caches)