@@ -357,19 +357,18 @@ def family_prefixes(family: str) -> set[str]:
357357 return {identity (member )[:16 ] for member in {family , * key_families (family )}}
358358
359359
360- def offered_images (
361- items : list [dict ], families : dict [tuple , dict [str , Family ]]
362- ) -> dict [str , set [str ]]:
363- """Return the image keys ``choose`` builds candidate IDs from under each family prefix."""
364- offered : dict [str , set [str ]] = {}
365- for item in items :
366- if item ["source-status" ] != "baseline" :
367- continue
368- image = identity (observation_key (item ["source" ])[- 1 ])[:16 ]
369- for family in families .get (observation_key (item ["source" ]), {}):
370- for prefix in family_prefixes (family ):
371- offered .setdefault (prefix , set ()).add (image )
372- return offered
360+ def master_images (root : Path ) -> dict [str , str ]:
361+ """Return the normalized image of each master config key at ``root``, by single-key family."""
362+ from infx .config import project_root
363+ from infx .matrix .validation import load_config_files
364+
365+ root = project_root (root )
366+ images = {}
367+ for path in sorted ((root / "configs" ).glob ("*-master.yaml" )):
368+ source = path .relative_to (root ).as_posix ()
369+ for key , entry in load_config_files ([str (path )], validate = False ).items ():
370+ images [f"{ source } :{ key } " ] = normalized_image (entry ["image" ])
371+ return images
373372
374373
375374def hold (
@@ -748,17 +747,22 @@ def __init__(
748747 ) -> None :
749748 """Start from ``headroom`` of clusters of ``size`` nodes, with ``backoff`` clusters.
750749
751- ``backlog`` counts the open finished Klaud PRs of each master config.
750+ ``backlog`` counts the finished and running Klaud candidates of each master config.
752751 """
753752 self .headroom , self .size , self .backoff = dict (headroom ), size , backoff
754- self .backlogged = { group for group , n in backlog . items () if n >= FINISHED_BACKLOG_CAP }
753+ self .backlog = Counter ( backlog )
755754 self .backed_off : set [str ] = set ()
756755
756+ @property
757+ def backlogged (self ) -> set [str ]:
758+ """The master configs with FINISHED_BACKLOG_CAP finished or running Klaud candidates."""
759+ return {group for group , n in self .backlog .items () if n >= FINISHED_BACKLOG_CAP }
760+
757761 def blocker (self , candidate : dict ) -> str | None :
758762 """Return why the wave cannot take ``candidate`` now, or None.
759763
760- That is "backlog" while its master config has FINISHED_BACKLOG_CAP finished PRs awaiting
761- review, then "backoff" or "capacity".
764+ That is "backlog" while its master config has FINISHED_BACKLOG_CAP Klaud candidates
765+ running or awaiting review, then "backoff" or "capacity".
762766 """
763767 clusters = candidate ["clusters" ]
764768 if config_group (candidate ["family" ]) in self .backlogged :
@@ -770,10 +774,11 @@ def blocker(self, candidate: dict) -> str | None:
770774 return None
771775
772776 def take (self , candidate : dict ) -> None :
773- """Reserve ``candidate``'s full sweep on each target cluster for the rest of the wave."""
777+ """Reserve ``candidate``'s full sweep and a backlog place for the rest of the wave."""
774778 for cluster in candidate ["clusters" ]:
775779 self .headroom [cluster ] -= min (candidate ["sweep-node-demand" ], self .size [cluster ])
776780 self .backed_off .update (self .backoff .intersection (candidate ["clusters" ]))
781+ self .backlog [config_group (candidate ["family" ])] += 1
777782
778783
779784def klaud_pulls (pulls : list [dict ]) -> list [dict ]:
@@ -790,12 +795,12 @@ def plan(
790795 are ordered toward idle clusters, cooled down by ``cooldown_hours`` and the recent-outcome
791796 holds, held while a maintainer recently closed their family's PR unless it was requeued,
792797 and capped at REVIEW_PER_SLOT per free slot plus REVIEW_MARGIN, at most
793- ``review_batch_size``. Candidates of master configs with FINISHED_BACKLOG_CAP finished PRs
794- awaiting review go last. Only open Klaud PRs are indexed. CLUSTER_STATE gives ``select``
795- the claimed families' committed demand, the clusters under infrastructure backoff and the
796- finished PRs of each master config, and gives ``regenerate-producers`` this plan's headroom
797- and cluster sizes. Stale finished PRs whose family the feed now offers on another image are
798- first closed for requeue, which frees their families from the next wave on .
798+ ``review_batch_size``. Candidates of master configs with FINISHED_BACKLOG_CAP Klaud
799+ candidates running or awaiting review go last. Only open Klaud PRs are indexed.
800+ CLUSTER_STATE gives ``select`` the claimed families' committed demand, the clusters under
801+ infrastructure backoff and the finished and claimed candidates of each master config, and
802+ gives ``regenerate-producers`` this plan's headroom and cluster sizes. Stale finished PRs
803+ that main superseded are first closed for requeue and left out of the index .
799804 """
800805 from . import claims
801806 from .finished import finished , requeue_superseded
@@ -822,12 +827,10 @@ def plan(
822827 blocked = {candidate .family for owner in owners for candidate in owner .candidates }
823828 families = live_families (root )
824829 now = datetime .now (UTC )
825- requeue_superseded (
826- repository ,
827- [pr for page in pulls for pr in page ],
828- offered_images (items , families ),
829- owners ,
830- now ,
830+ superseded = set (
831+ requeue_superseded (
832+ repository , [pr for page in pulls for pr in page ], master_images (root ), owners , now
833+ )
831834 )
832835 capacity = fetch_capacity (policy ) or Capacity (idle = {}, queued = {}, size = {})
833836 committed = committed_demand (blocked , families , capacity .size )
@@ -872,6 +875,7 @@ def plan(
872875 "finished" : finished (repository , pr ) is not None ,
873876 }
874877 for pr in klaud_pulls ([pr for page in pulls for pr in page ])
878+ if pr ["number" ] not in superseded
875879 ]
876880 if candidates :
877881 for pr in open_prs :
@@ -894,12 +898,19 @@ def plan(
894898 }
895899 )
896900 pr ["files-complete" ] = sum (len (page ) for page in pages ) < 3000
901+ awaiting = {pr ["branch" ].removeprefix ("klaud/auto-" ) for pr in open_prs if pr ["finished" ]}
897902 backlog = Counter (
898903 group
899904 for pr in open_prs
900905 if pr ["finished" ]
901906 for group in {config_group (name ) for name in pr .get ("files" , [])} - {None }
902907 )
908+ backlog .update (
909+ config_group (candidate .family )
910+ for owner in owners
911+ for candidate in owner .candidates
912+ if candidate .id not in awaiting
913+ )
903914 wave = WaveCapacity ({}, {}, set (), backlog )
904915 candidates = sorted (candidates , key = lambda candidate : wave .blocker (candidate ) == "backlog" )
905916 candidates = candidates [: min (review_batch_size , REVIEW_PER_SLOT * free_slots + REVIEW_MARGIN )]
@@ -1392,7 +1403,8 @@ def select(
13921403 the cap, and writes their context, ownership.json and selection.json under ``directory``.
13931404 Those sessions are the larger of ``active_sessions``, counted by recovery before the
13941405 review, and the ``running_sessions`` counted now. Selection stops if they are unreadable.
1395- Candidates whose master config has FINISHED_BACKLOG_CAP finished PRs awaiting review wait.
1406+ Candidates whose master config has FINISHED_BACKLOG_CAP Klaud candidates running or awaiting
1407+ review, counting those this wave takes, wait.
13961408 """
13971409 from . import claims , validation
13981410 from .reporting import (
@@ -1596,7 +1608,7 @@ def select(
15961608 summary += (
15971609 f" { len (backlog_deferred )} reviewed candidates wait because"
15981610 f" { ', ' .join (sorted (wave .backlogged ))} already have { FINISHED_BACKLOG_CAP } or more"
1599- " finished Klaud PRs awaiting review."
1611+ " Klaud candidates running or awaiting review."
16001612 )
16011613 if baseline_deferred :
16021614 summary += f" { len (baseline_deferred )} candidates lacked a verifiable full baseline: " + (
0 commit comments