refactor(regeneration): inject selectors so each owns its kind-specific logic
Summary
Refactors the post-merge selective-regeneration selectors so the merge follow-up no longer reaches
into kind-specific details. Addresses the review feedback that typing the orchestrator against a
specific pair of selectors "defeats the purpose" of the shared DefinitionSelectorBase, and the
follow-up that selection and output capture were two concerns bundled onto a single selector.
Jira: IFC-2916 (internal, under IFC-2704)
Origin: https://github.com/opsmill/infrahub/pull/9924#discussion_r3597524020
Change
Each selector now owns only its kind's selection — loading definitions, narrowing to affected
members, building the run request, and consolidating its own requests. It no longer carries its
cascade role or knows how its output is captured.
A CascadeParticipant[RequestT] composes a selector with its place in the cascade and is the single
surface the follow-up drives — it delegates to its selector rather than exposing it:
CascadeSourcecarries aCascadeSourceOutputFactorythat builds aCascadeSourceOutputfrom
the requests the selector chose, so the source's writes are captured without the selector handling
that.CascadeTerminalcarries none — nothing downstream re-reads what it produces.
The RegenerationPlanner builds the plan and the dispatcher runs it by cascade role: sources run to completion. The dispatcher holds no kind-specific logic and its failure fallbacks are generic too.
Behavior is unchanged: same selective dispatch, same generator→artifact cascade, same per-generator
failure isolation and safe fallbacks.
How tested
- Unit: the participant entry mapping (a source forwards its requests to its output factory and
carries the built capture; a terminal carries none);build_plantags each entry and shares the
modified-kind computation;reselect_from_cascade_outputexcludes the sources and escalates
repository-wide;terminal_full_regenerationscovers every terminal and excludes sources;
GeneratorOutputFactoryderives the capture scope from a generator's runs;GeneratorSelector
tags its blanket regeneration as merge-sourced;ArtifactSelectorconsolidates per definition; the
planner routes consolidation to each owning participant; the dispatcher submits what the planner
returns and falls back to blanket terminal regeneration on failure. - Component: the real-graph selection flow drives the rebuilt dispatcher end-to-end.
Housekeeping changelog fragment added (backend-only refactor; no schema, config, event, CLI, docs, or
frontend changes).
How to review
core/merge/selective_regen/participant.py—CascadeParticipant/CascadeSource/
CascadeTerminal: the composition,to_entry, and the façade (load/plan/
consolidated_entry/full_regeneration) that keeps the selector private.core/merge/selective_regen/definition_selector/base.py— the per-selector contract: selection
(workflow,load_definitions,select,consolidate) plus the blanket
full_regeneration_workflow/full_regeneration_parameters.core/merge/selective_regen/generator_output.py—GeneratorOutputFactory(the cascade-output
builder) and the tracking-group capturer; production impls inherit theirProtocolexplicitly.core/merge/selective_regen/orchestrator.py— theRegenerationPlannerprotocol, the injected
participants, andbuild_plan/reselect_from_cascade_output/consolidate_submissions/
terminal_full_regenerations.core/merge/regeneration_dispatcher.py— role-based dispatch and the generic terminal fallback,
free of kind-specific logic.core/branch/tasks.py— the wiring (the capturer is composed into the generator source).
Flow
merge committed
▼
dispatch() ──(feature off · no diff summary · summary load fails · selection fails)──▶ FULL REGEN (every kind)
▼
build_plan() per participant: load → select → plan entry
CascadeSource (generators) carry an output capture · CascadeTerminal (artifacts) don't
▼
run the sources (generators) [awaited, so their writes have landed]
├─ a source run fails ─────────────────────────────────────▶ regenerate every TERMINAL (never re-run sources)
▼
capture each source's own writes → reselect the terminals that read them
├─ capture or reselect fails ──────────────────────────────▶ regenerate every TERMINAL
▼
submit terminals + reselected [fire-and-forget, deduped per workflow, only after capture]
🤖 Generated with Claude Code