Skip to content

refactor(operator-trend): collapse persistence builders onto a parametrized base (T3-2 phase 6)#82

Merged
saagpatel merged 1 commit into
mainfrom
refactor/operator-trend-collapse-persistence
Jun 20, 2026
Merged

refactor(operator-trend): collapse persistence builders onto a parametrized base (T3-2 phase 6)#82
saagpatel merged 1 commit into
mainfrom
refactor/operator-trend-collapse-persistence

Conversation

@saagpatel

Copy link
Copy Markdown
Owner

What

The rebuild and rererestore persistence builders in operator_trend_closure_forecast_reset_controls were ~190-line hand-clones of one algorithm. This extracts a single _persistence_for_target_base + 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.

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:

  1. Differential test — before touching the file, ran the real rebuild and rererestore builders vs. the base+spec over the net's full corpus → byte-identical for both tiers.
  2. Composer golden byte-identical — the phase-4 net (test(operator-trend): characterize reset-reentry dict-composers (T3-2 phase 4) #79) pins all 44 composers' outputs; after the collapse the golden regenerates unchanged. A correct collapse changes no output, and this one doesn't.
  3. Full suite green2539 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 rerererestore delegation wrapper (which injects the rererestore builder as a callable), __all__, and every other caller are untouched. Only the two bodies now route through the shared base.

Design

_PersistenceTierSpec (a NamedTuple) carries the ~17 tier-specific literals; the base reads them. Tier-neutral naming (settled_values/settling_values rather than rebuilt/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; mypy on edited source clean
  • Composer golden byte-identical to main; full suite green

…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 saagpatel merged commit ab2076e into main Jun 20, 2026
3 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant