refactor(operator-trend): collapse persistence builders onto a parametrized base (T3-2 phase 6)#82
Merged
Conversation
…trized base (T3-2 phase 6) The rebuild and rererestore persistence builders were ~190-line hand-clones of one algorithm -- proven identical by the phase-4 composer golden, the floor fix (#80), and a differential test over the net's corpus. Extract a single _persistence_for_target_base plus a _PersistenceTierSpec carrying the per-tier literals (status keys, status tokens, reason prose, output keys); both public builders become thin wrappers that pass their spec. Public signatures are unchanged, so the apply-chain wiring, the rerererestore delegation wrapper (which injects the rererestore builder), and all other callers are untouched. Net -121 lines (265 insertions, 386 deletions). The composer golden is byte-identical -- a correct collapse changes no output -- and the full suite (2539 passed) is green. Correctness is demonstrated, not assumed.
saagpatel
added a commit
that referenced
this pull request
Jun 20, 2026
… base (T3-2 phase 6b) (#83) Second structural collapse, same pattern as the persistence base (#82): the rebuild and rererestore churn builders are one algorithm differing only in the per-event freshness/reset keys, reason prose, and output keys. Extract _churn_for_target_base + a _ChurnTierSpec; both public builders become thin wrappers passing their spec. Public signatures unchanged -> apply-chain wiring, the rerererestore delegation wrapper, and all callers untouched. Net -40 lines. Verified: differential test (real builders vs base+spec over the net corpus, byte-identical both tiers) + composer golden byte-identical to main + full suite (2539 passed). ruff + mypy clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
rebuildandrererestorepersistence builders inoperator_trend_closure_forecast_reset_controlswere ~190-line hand-clones of one algorithm. This extracts a single_persistence_for_target_base+ a_PersistenceTierSpeccarrying the per-tier literals (status keys, status tokens, reason prose, output keys); both public builders become thin wrappers that pass their spec.The first structural collapse of the T3-2 fractal. −121 net lines (one family, two tiers).
Why this is safe to claim
Correctness here is demonstrated, not assumed — three independent proofs:
rebuildandrererestorebuilders vs. the base+spec over the net's full corpus → byte-identical for both tiers.2539 passed, 2 skipped.This was only possible because the prep landed first: the floor fix (#80) and freshness fix (#81) removed the real behavioral divergences, leaving clean clones the net could prove equivalent.
What's preserved
Public function signatures are unchanged, so the apply-chain wiring, the
rerererestoredelegation wrapper (which injects therererestorebuilder as a callable),__all__, and every other caller are untouched. Only the two bodies now route through the shared base.Design
_PersistenceTierSpec(aNamedTuple) carries the ~17 tier-specific literals; the base reads them. Tier-neutral naming (settled_values/settling_valuesrather thanrebuilt/rebuilding) so the abstraction reads cleanly across tiers. The same pattern extends to the remaining clean families (churn, refresh_recovery, hotspots) in follow-ups.Verification
ruff check src/ tests/clean;mypyon edited source cleanmain; full suite green