Skip to content

The agent that grows with you

feat(release): discover attempt refs and abandon markers

etherneta6e16f093409
diff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.py
index 9698cc332c1..8117fc6d5a4 100644
--- a/scripts/releases/entrypoint.py
+++ b/scripts/releases/entrypoint.py
@@ -15,8 +15,8 @@ import time
from pathlib import Path
from scripts.releases.versioning import (
- SEED, attempt_ref, derive_next_version, marker_ref, next_attempt, parse_attempt_ref,
- parse_marker_ref,
+ SEED, attempt_ref, derive_next_version, marker_ref, next_attempt,
+ outstanding_attempts, parse_attempt_ref, parse_marker_ref,
)
WORKFLOW = "stable-release.yml"
@@ -75,21 +75,19 @@ def _claim_collision(repo: Path, remote: str, tag: str, error: Exception) -> Rel
def _outstanding_attempts(repo: Path, remote: str) -> list[tuple[str, int, str]]:
- """Attempts with no abandon marker whose version has no final tag on ``remote``."""
- refs = _claims(repo)
- cleared = {parsed for parsed in map(parse_marker_ref, refs) if parsed}
+ """Attempts with no abandon marker whose version has no final tag on ``remote``.
+
+ The predicate is the shared one in ``versioning``; this wrapper only owns
+ the remote lookup of the final tags.
+ """
published: dict[str, bool] = {}
- outstanding = []
- for ref in refs:
- parsed = parse_attempt_ref(ref)
- if parsed is None or parsed in cleared:
- continue
- version, attempt = parsed
+
+ def is_published(version: str) -> bool:
if version not in published:
published[version] = bool(_git(repo, "ls-remote", remote, f"refs/tags/v{version}"))
- if not published[version]:
- outstanding.append((version, attempt, ref))
- return outstanding
+ return published[version]
+
+ return outstanding_attempts(_claims(repo), is_published)
def _outstanding_attempt(repo: Path, remote: str) -> tuple[str, int, str] | None:
diff --git a/scripts/releases/sequencer.py b/scripts/releases/sequencer.py
index bc8aca407ee..766c770f3a0 100644
--- a/scripts/releases/sequencer.py
+++ b/scripts/releases/sequencer.py
@@ -16,9 +16,11 @@ import time
from datetime import datetime, timedelta, timezone
from pathlib import Path
-from hermes_cli.update_channel import STABLE_TAG_RE
+from scripts.releases.versioning import (
+ marker_ref, outstanding_attempts, parse_attempt_ref, parse_marker_ref,
+ version_from_tag,
+)
-CLAIM_TAG_RE = re.compile(r"^(v(?:0|[1-9]\d{0,2})\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))-rc$")
SHA256 = re.compile(r"[a-f0-9]{64}")
DOCKER_DIGEST = re.compile(r"sha256:[a-f0-9]{64}")
MAX_ATTEMPTS = 3
@@ -190,12 +192,21 @@ def classify_final_release(tag: str, claim_tag: str, release: dict | None) -> tu
def _remote_tags(run=output) -> dict[str, dict[str, str]]:
+ """Every remote receipt tag, attempt ref, and abandon marker ref.
+
+ Three listings, because a fetch or ls-remote glob is filtered here by the
+ ref parsers, not widened.
+ """
refs: dict[str, dict[str, str]] = {}
- for line in run(["git", "ls-remote", "--tags", "origin", "refs/tags/v*"]).splitlines():
+ for line in run([
+ "git", "ls-remote", "--tags", "origin",
+ "refs/tags/v*", "refs/tags/rc.*", "refs/tags/abandoned-rc.*",
+ ]).splitlines():
sha, ref = line.split()
peeled = ref.endswith("^{}")
tag = ref.removeprefix("refs/tags/").removesuffix("^{}")
- if STABLE_TAG_RE.fullmatch(tag) or CLAIM_TAG_RE.fullmatch(tag):
+ if (version_from_tag(tag) or parse_attempt_ref(tag)
+ or parse_marker_ref(tag)):
refs.setdefault(tag, {})["commit" if peeled else "object"] = sha
return refs
@@ -217,25 +228,33 @@ def discover(repository: str, run=output) -> list[dict]:
"""Derive every stable claim state from remote refs and GitHub objects."""
from scripts.releases.stable import tagger_epoch
- run(["git", "fetch", "origin", "+refs/tags/v*:refs/tags/v*"])
+ run([
+ "git", "fetch", "origin", "+refs/tags/v*:refs/tags/v*",
+ "+refs/tags/rc.*:refs/tags/rc.*",
+ "+refs/tags/abandoned-rc.*:refs/tags/abandoned-rc.*",
+ ])
refs = _remote_tags(run)
+ outstanding = outstanding_attempts(list(refs), lambda v: f"v{v}" in refs)
+ if len(outstanding) > 1:
+ named = ", ".join(ref for *_rest, ref in outstanding)
+ raise ValueError(f"more than one outstanding attempt ({named})")
releases = _release_rows(repository, run)
workflow_runs = _workflow_runs(repository, run)
records = []
for claim_tag, claim_ref in refs.items():
- match = CLAIM_TAG_RE.fullmatch(claim_tag)
- if match is None:
+ parsed = parse_attempt_ref(claim_tag)
+ if parsed is None:
continue
+ version, attempt = parsed
if set(claim_ref) != {"object", "commit"}:
raise ValueError(f"{claim_tag} must be an annotated remote tag")
- tag = match.group(1)
- version = tag[1:]
+ tag = f"v{version}"
commit = claim_ref["commit"]
claim = _tag_message(claim_tag, claim_ref["object"], run)
claim_epoch = claim.get("claimEpoch")
expected_claim = {
- "schema": 1, "version": version, "commit": commit,
+ "schema": 1, "version": version, "attempt": attempt, "commit": commit,
"autopublish": claim["autopublish"], "claimEpoch": claim_epoch,
}
if (claim != expected_claim or not isinstance(claim["autopublish"], bool)
@@ -260,7 +279,7 @@ def discover(repository: str, run=output) -> list[dict]:
raise ValueError(f"{tag} points at a different commit than {claim_tag}")
final = _tag_message(tag, final_ref["object"], run)
expected_final = {
- "schema": 1, "version": version, "commit": commit,
+ "schema": 1, "version": version, "attempt": attempt, "commit": commit,
"claimTag": claim_tag, "claimTagObject": claim_ref["object"],
"autopublish": claim["autopublish"],
"claimEpoch": claim_epoch,
@@ -277,6 +296,9 @@ def discover(repository: str, run=output) -> list[dict]:
state, needs_retarget = "burned", False
else:
state, needs_retarget = classify_final_release(tag, claim_tag, release)
+ elif marker_ref(version, attempt) in refs:
+ # The attempt was abandoned and its version has no final tag.
+ state, retry = "burned", None
else:
if release is not None and (release.get("tag_name") != claim_tag
or release.get("draft") is not True
@@ -292,6 +314,7 @@ def discover(repository: str, run=output) -> list[dict]:
records.append({
"version": version,
+ "attempt": attempt,
"state": state,
"autopublish": claim["autopublish"],
"claim_tag": claim_tag,
diff --git a/scripts/releases/versioning.py b/scripts/releases/versioning.py
index d03f987c78f..f486d79fb79 100644
--- a/scripts/releases/versioning.py
+++ b/scripts/releases/versioning.py
@@ -132,3 +132,27 @@ def next_attempt(version: str, refs: list[str]) -> int:
attempts = [parsed[1] for parsed in map(parse_attempt_ref, refs)
if parsed and parsed[0] == version]
return max(attempts, default=0) + 1
+
+
+def outstanding_attempts(refs: list[str], is_published) -> list[tuple[str, int, str]]:
+ """The one definition of an outstanding attempt.
+
+ An attempt ref is outstanding when its abandon marker ref does not exist
+ and its version has no final tag. ``is_published(version)`` answers whether
+ the final tag ``v{version}`` exists, so callers keep their own remote
+ lookup. Both the release entrypoint and the sequencer refuse more than one
+ of these, across all versions.
+ """
+ cleared = {parsed for parsed in map(parse_marker_ref, refs) if parsed}
+ published: dict[str, bool] = {}
+ outstanding: list[tuple[str, int, str]] = []
+ for ref in refs:
+ parsed = parse_attempt_ref(ref)
+ if parsed is None or parsed in cleared:
+ continue
+ version, attempt = parsed
+ if version not in published:
+ published[version] = bool(is_published(version))
+ if not published[version]:
+ outstanding.append((version, attempt, ref))
+ return outstanding
diff --git a/tests/scripts/test_release_sequencer.py b/tests/scripts/test_release_sequencer.py
index 87d8d71f51b..6203e4e7e27 100644
--- a/tests/scripts/test_release_sequencer.py
+++ b/tests/scripts/test_release_sequencer.py
@@ -183,6 +183,98 @@ def test_an_unpublished_claim_below_the_head_is_refused():
plan(_claims(("0.21.4", "green", True)), head="0.21.5")
+def _claim_message(version, attempt, commit, *, autopublish=False,
+ epoch=1_790_000_000):
+ return {"schema": 1, "version": version, "attempt": attempt, "commit": commit,
+ "autopublish": autopublish, "claimEpoch": epoch}
+
+
+def _final_message(version, attempt, commit, *, release_id, epoch=1_790_000_000):
+ claim_tag = f"rc.{attempt}-v{version}"
+ return {
+ "schema": 1, "version": version, "attempt": attempt, "commit": commit,
+ "autopublish": False, "claimEpoch": epoch, "claimTag": claim_tag,
+ "claimTagObject": "1" * 40, "releaseId": release_id,
+ "candidateManifestSha256": "a" * 64, "dockerManifestDigest": "sha256:" + "b" * 64,
+ }
+
+
+def _discover_run(tags, releases=(), workflow_runs=()):
+ def run(argv):
+ if argv[:2] == ["git", "fetch"]:
+ return ""
+ if argv[:3] == ["git", "ls-remote", "--tags"]:
+ return "\n".join(
+ f"{sha}\trefs/tags/{tag}\n{commit}\trefs/tags/{tag}^{{}}"
+ for tag, (sha, commit, _message) in tags.items()
+ )
+ if argv[:2] == ["git", "rev-parse"]:
+ return tags[argv[-1].removeprefix("refs/tags/")][0]
+ if argv[:3] == ["git", "cat-file", "-t"]:
+ return "tag"
+ if argv[:3] == ["git", "cat-file", "-p"]:
+ message = next(m for s, _c, m in tags.values() if s == argv[3])
+ return f"tagger Fixture <[email protected]> {message['claimEpoch']} +0000\n"
+ if argv[:3] == ["git", "tag", "-l"]:
+ return json.dumps(tags[argv[3]][2])
+ if argv[:4] == ["gh", "api", "--paginate", "--slurp"]:
+ if "/releases?" in argv[-1]:
+ return json.dumps([list(releases)])
+ return json.dumps([{"workflow_runs": list(workflow_runs)}])
+ raise AssertionError(argv)
+
+ return run
+
+
+def test_discover_reads_an_attempt_ref_and_keeps_the_version():
+ from scripts.releases.sequencer import discover
+
+ commit = "a" * 40
+ tags = {
+ "rc.2-v0.21.5": ("1" * 40, commit, _claim_message("0.21.5", 2, commit)),
+ "v0.21.5": ("2" * 40, commit,
+ _final_message("0.21.5", 2, commit, release_id=7)),
+ }
+ releases = [{
+ "id": 7, "tag_name": "v0.21.5", "draft": False, "prerelease": False,
+ "published_at": "2026-09-22T01:00:00Z",
+ }]
+ records = discover("example/project", _discover_run(tags, releases=releases))
+ assert records[0]["version"] == "0.21.5"
+ assert records[0]["claim_tag"] == "rc.2-v0.21.5"
+ assert records[0]["state"] == "published"
+
+
+def test_a_marker_ref_clears_the_attempt():
+ from scripts.releases.sequencer import discover
+
+ commit = "a" * 40
+ tags = {
+ "rc.1-v0.21.5": ("1" * 40, commit, _claim_message("0.21.5", 1, commit)),
+ "abandoned-rc.1-v0.21.5": ("2" * 40, commit, {}),
+ }
+ failed = {
+ "id": 42, "status": "completed", "conclusion": "failure",
+ "run_attempt": 1, "updated_at": "2026-09-22T01:14:59Z",
+ "head_branch": "rc.1-v0.21.5", "head_sha": commit,
+ }
+ records = discover("example/project",
+ _discover_run(tags, workflow_runs=[failed]))
+ assert records[0]["state"] == "burned"
+
+
+def test_two_outstanding_attempts_are_refused_across_versions():
+ from scripts.releases.sequencer import discover
+
+ commit = "a" * 40
+ tags = {
+ "rc.1-v0.21.5": ("1" * 40, commit, _claim_message("0.21.5", 1, commit)),
+ "rc.1-v0.22.0": ("2" * 40, commit, _claim_message("0.22.0", 1, commit)),
+ }
+ with pytest.raises(ValueError, match="more than one outstanding attempt"):
+ discover("example/project", _discover_run(tags))
+
+
def test_reconcile_discovers_custody_flips_then_advances_oldest_first():
from scripts.releases.sequencer import reconcile
@@ -190,10 +282,10 @@ def test_reconcile_discovers_custody_flips_then_advances_oldest_first():
tags = {}
releases = []
for index, version in enumerate(("0.21.5", "0.21.6"), start=1):
- claim_tag, tag = f"v{version}-rc", f"v{version}"
+ claim_tag, tag = f"rc.1-v{version}", f"v{version}"
claim_object, final_object = str(index) * 40, str(index + 2) * 40
claim = {
- "schema": 1, "version": version, "commit": commit,
+ "schema": 1, "version": version, "attempt": 1, "commit": commit,
"autopublish": False, "claimEpoch": 1_790_000_000 + index,
}
final = {
diff --git a/tests/scripts/test_release_version_from_ref.py b/tests/scripts/test_release_version_from_ref.py
index a07ad7a7fc5..d2d8c5a08b0 100644
--- a/tests/scripts/test_release_version_from_ref.py
+++ b/tests/scripts/test_release_version_from_ref.py
@@ -108,3 +108,16 @@ def test_canary_base_comes_from_the_validated_protected_stable_head():
assert published_stable_version(
"example/hermes-agent", base_url="https://assets.example", reader_type=Reader,
) == "0.21.7"
+
+
+def test_outstanding_attempts_is_the_one_shared_predicate():
+ from scripts.releases.versioning import outstanding_attempts
+
+ refs = ["rc.1-v0.21.5", "abandoned-rc.1-v0.21.5", "rc.2-v0.21.5",
+ "rc.1-v0.21.6", "v0.21.5", "rc.1-v0.21.7"]
+ published = {"0.21.6", "0.21.7"}
+
+ def is_published(version):
+ return version in published
+
+ assert outstanding_attempts(refs, is_published) == [("0.21.5", 2, "rc.2-v0.21.5")]