Skip to content

Commit 833fa29

Browse files
committed
Revalidate release-plan authority before implicit recovery acts
1 parent 72c3fa9 commit 833fa29

2 files changed

Lines changed: 138 additions & 24 deletions

File tree

‎scripts/ci/component-release-recovery.py‎

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ def accepted_continuity_supersession(
17781778

17791779
def 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

19121912
def 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

19311920
def 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+
19431948
def 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

19872000
def 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)

‎scripts/ci/test-component-release-recovery.py‎

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def test_updated_older_release_cannot_override_newer_immutable_plan(self) -> Non
594594
mock.patch.object(
595595
self.recovery,
596596
"read_plan_authority",
597-
side_effect=[(older, None), (newer, None)],
597+
side_effect=[(older, None), (newer, None), (older, None), (newer, None)],
598598
),
599599
mock.patch.object(
600600
self.recovery,
@@ -603,6 +603,7 @@ def test_updated_older_release_cannot_override_newer_immutable_plan(self) -> Non
603603
("completed", None),
604604
("completed", None),
605605
("completed", None),
606+
("completed", None),
606607
],
607608
),
608609
mock.patch.object(
@@ -701,6 +702,96 @@ def lifecycle(
701702
self.assertEqual("actionable", selected["lifecycle"])
702703
self.assertEqual(4, registry_reads)
703704

705+
def test_convergence_rechecks_nonselected_lifecycle_authority(self) -> None:
706+
older = {"tag": "release-plan/older", "lifecycle": "completed"}
707+
changed_older = {**older, "lifecycle": "superseded"}
708+
latest = {"tag": "release-plan/latest", "lifecycle": "actionable"}
709+
current_snapshot = [changed_older, latest]
710+
711+
with mock.patch.object(
712+
self.recovery,
713+
"classify_implicit_plan_authority",
714+
side_effect=[
715+
(latest, [older, latest]),
716+
(latest, current_snapshot),
717+
(latest, current_snapshot),
718+
(latest, current_snapshot),
719+
],
720+
) as classify:
721+
selected = self.recovery.select_implicit_plan_authority(mock.Mock())
722+
723+
self.assertEqual(4, classify.call_count)
724+
self.assertEqual(current_snapshot, selected["authority_snapshot"])
725+
726+
def test_final_implicit_boundary_rejects_stale_publish_but_manual_recovery_does_not(self) -> None:
727+
candidate = lifecycle_plan(self.recovery)
728+
candidate_preparation = {
729+
"components": {
730+
"workflow": {
731+
"release_notes": {
732+
"release_date": "2026-07-23",
733+
"sha256": "c" * 64,
734+
"source": {},
735+
}
736+
}
737+
}
738+
}
739+
component = self.recovery.COMPONENTS["workflow"]
740+
publication_preflight = mock.Mock(
741+
side_effect=self.recovery.NotFound("not published")
742+
)
743+
implicit_authority = {
744+
"authority_snapshot": [
745+
{"tag": "release-plan/older", "lifecycle": "actionable"}
746+
]
747+
}
748+
current_snapshot = [
749+
{"tag": "release-plan/older", "lifecycle": "superseded"},
750+
{"tag": "release-plan/successor", "lifecycle": "actionable"},
751+
]
752+
753+
with (
754+
mock.patch.object(self.recovery, "verify_plan_authority", return_value=({}, {})),
755+
mock.patch.object(self.recovery, "validate_release_preparation"),
756+
mock.patch.object(self.recovery, "resolve_tag", return_value=None),
757+
mock.patch.object(
758+
self.recovery,
759+
"classify_implicit_plan_authority",
760+
return_value=(current_snapshot[-1], current_snapshot),
761+
) as classify,
762+
mock.patch.dict(
763+
self.recovery.VERIFIERS,
764+
{component.distribution: publication_preflight},
765+
),
766+
):
767+
with self.assertRaisesRegex(
768+
self.recovery.RecoveryError,
769+
"refusing a stale recovery action",
770+
):
771+
self.recovery.resolve_component(
772+
mock.Mock(),
773+
"workflow",
774+
"release-plan/older",
775+
"a" * 40,
776+
candidate,
777+
candidate_preparation,
778+
implicit_authority,
779+
)
780+
781+
state, outputs = self.recovery.resolve_component(
782+
mock.Mock(),
783+
"workflow",
784+
"release-plan/older",
785+
"a" * 40,
786+
candidate,
787+
candidate_preparation,
788+
)
789+
790+
self.assertEqual("publish", outputs["action"])
791+
self.assertEqual("publication", state["phase"])
792+
self.assertEqual(1, classify.call_count)
793+
self.assertEqual(2, publication_preflight.call_count)
794+
704795
def test_interrupted_plan_rejects_multiple_continuity_successors(self) -> None:
705796
interrupted = lifecycle_plan(self.recovery)
706797
interrupted["plan"] = "interrupted-plan"

0 commit comments

Comments
 (0)