@@ -1778,7 +1778,7 @@ def accepted_continuity_supersession(
17781778
17791779def classify_implicit_plan_authority (
17801780 client : PublicClient ,
1781- ) -> tuple [dict [str , Any ], list [str ]]:
1781+ ) -> tuple [dict [str , Any ], list [dict [ str , Any ] ]]:
17821782 authorities : list [dict [str , Any ]] = []
17831783 tags = list_release_plan_tags (client )
17841784 for tag in tags :
@@ -1906,45 +1906,57 @@ def classify_implicit_plan_authority(
19061906 f"latest release plan { selected ['tag' ]} is superseded and cannot be recovered" ,
19071907 "plan-discovery" ,
19081908 )
1909- return selected , tags
1909+ return selected , authorities
19101910
19111911
19121912def implicit_plan_authority_converged (
19131913 client : PublicClient ,
1914- tags : list [str ],
1915- selected : dict [str , Any ],
1914+ authority_snapshot : list [dict [str , Any ]],
19161915) -> bool :
1917- if set (list_release_plan_tags (client )) != set (tags ):
1918- return False
1919- if resolve_tag (client , CONTROL_REPOSITORY , selected ["tag" ]) != selected ["commit" ]:
1920- return False
1921- lifecycle , successor = direct_plan_lifecycle (
1922- client ,
1923- selected ["tag" ],
1924- selected ["commit" ],
1925- selected ["plan" ],
1926- selected ["preparation" ],
1927- )
1928- return lifecycle == selected ["lifecycle" ] and successor == selected ["successor" ]
1916+ _selected , current_snapshot = classify_implicit_plan_authority (client )
1917+ return current_snapshot == authority_snapshot
19291918
19301919
19311920def select_implicit_plan_authority (client : PublicClient ) -> dict [str , Any ]:
19321921 for _attempt in range (IMPLICIT_AUTHORITY_MAX_ATTEMPTS ):
1933- selected , tags = classify_implicit_plan_authority (client )
1934- if implicit_plan_authority_converged (client , tags , selected ):
1935- return selected
1922+ selected , authority_snapshot = classify_implicit_plan_authority (client )
1923+ if implicit_plan_authority_converged (client , authority_snapshot ):
1924+ return { ** selected , "authority_snapshot" : authority_snapshot }
19361925 raise RecoveryError (
1937- "release plan registry or selected lifecycle authority did not converge "
1926+ "release plan registry or lifecycle authority did not converge "
19381927 f"after { IMPLICIT_AUTHORITY_MAX_ATTEMPTS } attempts" ,
19391928 "plan-discovery" ,
19401929 )
19411930
19421931
1932+ def revalidate_implicit_plan_authority (
1933+ client : PublicClient ,
1934+ implicit_authority : dict [str , Any ],
1935+ ) -> None :
1936+ authority_snapshot = implicit_authority .get ("authority_snapshot" )
1937+ if not isinstance (authority_snapshot , list ) or not implicit_plan_authority_converged (
1938+ client ,
1939+ authority_snapshot ,
1940+ ):
1941+ raise RecoveryError (
1942+ "implicit release plan authority changed during component preflight; "
1943+ "refusing a stale recovery action" ,
1944+ "plan-discovery" ,
1945+ )
1946+
1947+
19431948def discover_plan (
19441949 client : PublicClient , requested_tag : str | None , component_name : str
1945- ) -> tuple [str , str , dict [str , Any ], dict [str , Any ] | None ]:
1950+ ) -> tuple [
1951+ str ,
1952+ str ,
1953+ dict [str , Any ],
1954+ dict [str , Any ] | None ,
1955+ dict [str , Any ] | None ,
1956+ ]:
19461957 if component_name not in COMPONENTS :
19471958 raise RecoveryError (f"unknown release component: { component_name } " , "plan-discovery" )
1959+ implicit_authority = None
19481960 if requested_tag :
19491961 tag = requested_tag
19501962 if not tag .startswith (PLAN_TAG_PREFIX ):
@@ -1961,6 +1973,7 @@ def discover_plan(
19611973 plan , preparation = read_plan_authority (client , tag , commit )
19621974 else :
19631975 selected = select_implicit_plan_authority (client )
1976+ implicit_authority = selected
19641977 tag = selected ["tag" ]
19651978 commit = selected ["commit" ]
19661979 plan = selected ["plan" ]
@@ -1981,7 +1994,7 @@ def discover_plan(
19811994 "only completed legacy releases may recover without it" ,
19821995 "plan-discovery" ,
19831996 ) from error
1984- return tag , commit , plan , preparation
1997+ return tag , commit , plan , preparation , implicit_authority
19851998
19861999
19872000def load_recovery_workflow_authority (
@@ -2588,6 +2601,7 @@ def resolve_component(
25882601 record_commit : str ,
25892602 plan : dict [str , Any ],
25902603 preparation : dict [str , Any ] | None ,
2604+ implicit_authority : dict [str , Any ] | None = None ,
25912605) -> tuple [dict [str , Any ], dict [str , str ]]:
25922606 if component_name not in COMPONENTS :
25932607 raise RecoveryError (f"unknown release component: { component_name } " )
@@ -2640,6 +2654,8 @@ def resolve_component(
26402654 identity ["commit" ],
26412655 )
26422656 action = "publish"
2657+ if implicit_authority is not None :
2658+ revalidate_implicit_plan_authority (client , implicit_authority )
26432659 state = base_state (component_name , tag , plan )
26442660 state .update (
26452661 {
@@ -2757,12 +2773,18 @@ def main() -> int:
27572773 record_commit : str | None = None
27582774 plan : dict [str , Any ] | None = None
27592775 try :
2760- tag , record_commit , plan , preparation = discover_plan (client , args .plan_tag , args .component )
2776+ tag , record_commit , plan , preparation , implicit_authority = discover_plan (
2777+ client ,
2778+ args .plan_tag ,
2779+ args .component ,
2780+ )
27612781 args .plan_output .write_bytes (canonical_json (plan ))
27622782 if preparation is not None :
27632783 args .preparation_output .write_bytes (canonical_json (preparation ))
27642784 continuity_pause = scheduled_continuity_pause (client , plan ) if args .plan_tag is None else None
27652785 if continuity_pause is not None :
2786+ assert implicit_authority is not None
2787+ revalidate_implicit_plan_authority (client , implicit_authority )
27662788 paused = base_state (args .component , tag , plan )
27672789 paused .update (
27682790 {
@@ -2794,6 +2816,7 @@ def main() -> int:
27942816 record_commit ,
27952817 plan ,
27962818 preparation ,
2819+ implicit_authority ,
27972820 )
27982821 args .evidence .write_bytes (canonical_json (state ))
27992822 write_output (args .github_output , outputs )
0 commit comments