6666INFRA_COOLDOWN_DAYS = 7
6767LONG_HOLD_HOURS = 72
6868LONG_HOLD_OUTCOMES = frozenset ({"already-updated" , "duplicate" , "route-mismatch" })
69+ REPEAT_HOLD_OUTCOMES = frozenset ({"failed" , "incompatible" , "inconclusive" })
6970PAUSED_WEIGHTS = frozenset (ASSET_REASONS )
7071UNDATED_IMAGE_HOLD_DAYS = 7
7172DATED_TAG = re .compile (r"(?<!\d)20\d\d(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])(?!\d)" )
@@ -371,19 +372,24 @@ def offered_images(
371372 return offered
372373
373374
374- def hold (label : str | None , phase : str | None , cooldown_hours : int ) -> timedelta :
375+ def hold (
376+ label : str | None , phase : str | None , previous : str | None , cooldown_hours : int
377+ ) -> timedelta :
375378 """Return how long outcome ``label``, recorded in ``phase``, keeps its candidate out of plans.
376379
377- Infrastructure outcomes (INFRA_OUTCOMES) hold for INFRA_COOLDOWN_DAYS. Outcomes a retry soon
378- would repeat (LONG_HOLD_OUTCOMES, infrastructure faults in INFRA_REASONS, incompatible at
379- resolve) hold for LONG_HOLD_HOURS, others for ``cooldown_hours``.
380+ ``previous`` is the label of the candidate's session before it. Infrastructure outcomes
381+ (INFRA_OUTCOMES) hold for INFRA_COOLDOWN_DAYS. Outcomes a retry soon would repeat
382+ (LONG_HOLD_OUTCOMES, infrastructure faults in INFRA_REASONS, incompatible at resolve, and a
383+ REPEAT_HOLD_OUTCOMES outcome following another) hold for LONG_HOLD_HOURS, others for
384+ ``cooldown_hours``.
380385 """
381386 if label in INFRA_OUTCOMES :
382387 return timedelta (days = INFRA_COOLDOWN_DAYS )
383388 if (
384389 label in LONG_HOLD_OUTCOMES
385390 or label in INFRA_REASONS
386391 or (label == "incompatible" and phase == "resolve" )
392+ or (label in REPEAT_HOLD_OUTCOMES and previous in REPEAT_HOLD_OUTCOMES )
387393 ):
388394 return timedelta (hours = max (cooldown_hours , LONG_HOLD_HOURS ))
389395 return timedelta (hours = cooldown_hours )
@@ -392,11 +398,13 @@ def hold(label: str | None, phase: str | None, cooldown_hours: int) -> timedelta
392398def recent_candidate_outcomes (repository : str , cooldown_hours : int ) -> History :
393399 """Return the recent outcomes that still hold candidates, families, weights, images or clusters.
394400
395- Each candidate's newest session artifact counts and holds the candidate for ``hold``. While
396- held, missing weights and route mismatches (PAUSED_WEIGHTS) pause their (model, precision,
397- hardware) key, and a cluster time limit (LIMIT_REASONS) holds the branch prefixes of the
398- candidate's curve and of its keys whatever its image. An already-updated outcome holds its
399- image from its newest time, and INFRA_BACKOFF_OUTCOMES infrastructure failures within
401+ Each candidate's newest session artifact counts and holds the candidate for ``hold``, given
402+ the finished outcome of its previous attempt (the newest finished session of an earlier
403+ planner run) when the newest one is in REPEAT_HOLD_OUTCOMES. While held, missing weights and
404+ route mismatches (PAUSED_WEIGHTS) pause their (model, precision, hardware) key, and a cluster
405+ time limit (LIMIT_REASONS) holds the branch prefixes of the candidate's curve and of its keys
406+ whatever its image. An already-updated outcome holds its image from its newest time, and
407+ INFRA_BACKOFF_OUTCOMES infrastructure failures within
400408 INFRA_BACKOFF_HOURS back off a target cluster. A wave's baseline deferral for a
401409 BASELINE_HOLD_REASONS reason holds the candidate for LONG_HOLD_HOURS unless a session of it
402410 started after that wave. Only scheduled auto-sweeps and Klaud Cold's resume runs hold
@@ -442,7 +450,7 @@ def artifacts(run_id: int) -> list[dict]:
442450 listings = dict (zip (ordered , pool .map (artifacts , ordered ), strict = True ))
443451 except (OSError , ValueError , KeyError , TypeError , subprocess .SubprocessError ) as error :
444452 raise ReadError ("candidate-history-unavailable" ) from error
445- latest : dict [str , tuple [dict , int ]] = {}
453+ sessions : dict [str , dict [ int , tuple [dict , int ] ]] = {}
446454 for run_id in ordered :
447455 for artifact in listings [run_id ]:
448456 try :
@@ -455,37 +463,60 @@ def artifacts(run_id: int) -> list[dict]:
455463 or utc (artifact ["created_at" ]) < window
456464 ):
457465 continue
458- if match [1 ] not in latest or artifact ["id" ] > latest [match [1 ]][0 ]["id" ]:
459- latest [match [1 ]] = (artifact , run_id )
466+ sessions .setdefault (match [1 ], {})[artifact ["id" ]] = (artifact , run_id )
460467 except (AttributeError , KeyError , TypeError , ValueError ):
461468 continue
469+ ranked = {
470+ candidate : [found [artifact_id ] for artifact_id in sorted (found , reverse = True )]
471+ for candidate , found in sessions .items ()
472+ }
473+ latest = {candidate : found [0 ] for candidate , found in ranked .items ()}
462474 deferring = [
463475 (created , run_id )
464476 for created , run_id in dated
465477 if plans [run_id ] == run_id and now - created < timedelta (hours = LONG_HOLD_HOURS )
466478 ]
467- outcomes = pool .map (lambda pair : recorded_outcome (repository , pair [0 ]), latest .values ())
479+ pending = pool .map (lambda pair : recorded_outcome (repository , pair [0 ]), latest .values ())
468480 records = dict (
469481 zip (
470482 [run_id for _ , run_id in deferring ],
471483 pool .map (lambda pair : plan_record (repository , listings [pair [1 ]]), deferring ),
472484 strict = True ,
473485 )
474486 )
487+ outcomes = dict (zip (latest , pending , strict = True ))
488+
489+ def previous_outcome (candidate : str ) -> str | None :
490+ attempts = {plans [ranked [candidate ][0 ][1 ]]}
491+ for artifact , run_id in ranked [candidate ][1 :]:
492+ if plans [run_id ] in attempts :
493+ continue
494+ attempts .add (plans [run_id ])
495+ label = recorded_outcome (repository , artifact )[0 ]
496+ if label not in {None , "no-outcome" }:
497+ return label
498+ return None
499+
500+ repeats = [
501+ candidate
502+ for candidate , (label , _ ) in outcomes .items ()
503+ if label in REPEAT_HOLD_OUTCOMES and len (ranked [candidate ]) > 1
504+ ]
505+ previous = dict (zip (repeats , pool .map (previous_outcome , repeats ), strict = True ))
475506 result : dict [str , str | None ] = {}
476507 held_images : dict [str , datetime ] = {}
477508 held_families : set [str ] = set ()
478509 planned_labels : dict [int , dict [str , str ]] = {}
479510 for (candidate , (artifact , run_id )), (label , phase ) in zip (
480- latest .items (), outcomes , strict = True
511+ latest .items (), outcomes . values () , strict = True
481512 ):
482513 created = utc (artifact ["created_at" ])
483514 if label == "already-updated" :
484515 image = candidate .split ("-" , 1 )[1 ]
485516 held_images [image ] = max (held_images .get (image , created ), created )
486517 if label in INFRA_REASONS and now - created < timedelta (hours = INFRA_BACKOFF_HOURS ):
487518 planned_labels .setdefault (plans [run_id ], {})[candidate ] = label
488- if now - created >= hold (label , phase , cooldown_hours ):
519+ if now - created >= hold (label , phase , previous . get ( candidate ), cooldown_hours ):
489520 continue
490521 result [candidate ] = label
491522 if label in LIMIT_REASONS :
0 commit comments