Skip to content

The agent that grows with you

fix(release): abandon force-cancels the attempt's in-progress runs

ethernet59dc1ad5ff15
diff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.py
index 4461c60b491..8acafee1f13 100644
--- a/scripts/releases/entrypoint.py
+++ b/scripts/releases/entrypoint.py
@@ -376,25 +376,40 @@ def publish(version: str, *, repository: str, dispatch, inspect=None, head_versi
return {"requested": tag, "version": version, "repository": repository}
-def abandon(version: str, *, repo: Path, remote: str, repository: str, delete, inspect=None) -> dict:
+def _in_progress_runs(inspect, repository: str, tag: str) -> list[dict]:
+ """Release runs of ``tag`` that have not completed, as ``gh run list`` rows."""
+ rows = json.loads(inspect([
+ "gh", "run", "list", "--repo", repository, "--workflow", WORKFLOW,
+ "--branch", tag, "--json", "databaseId,url,status", "--limit", "100",
+ ]) or "[]")
+ return [row for row in rows if row["status"] != "completed"]
+
+
+def abandon(version: str, *, repo: Path, remote: str, repository: str, execute, inspect=None) -> dict:
"""Clear the outstanding attempt of ``version``. The attempt ref stays; the marker is the record.
- The draft goes first: a cleared attempt with a live draft could still be
- published by hand, while a draftless outstanding attempt is just abandoned
- again. This reads every outstanding attempt, not the one-attempt view, so
- it still clears one when a concurrent cut left two.
+ Its in-progress runs are cancelled and its draft deleted before the marker
+ exists: a live run can autopublish the draft, a cleared attempt with a live
+ draft could still be published by hand, and once the marker is written
+ there is no outstanding attempt left to retry the cleanup against. This
+ reads every outstanding attempt, not the one-attempt view, so it still
+ clears one when a concurrent cut left two.
"""
_refresh_claims(repo, remote)
matching = [found for found in _outstanding_attempts(repo, remote) if found[0] == version]
if len(matching) != 1:
raise ReleaseRefused(f"stable {version} has no outstanding attempt to abandon")
_version, attempt, tag = matching[0]
+ cancelled: list[str] = []
if inspect is not None:
draft = _release_view(tag, repository, inspect)
+ if draft is not None and draft.get("isDraft") is not True:
+ raise ReleaseRefused(f"{tag} is published and cannot be abandoned")
+ for run in _in_progress_runs(inspect, repository, tag):
+ execute(["gh", "run", "cancel", str(run["databaseId"]), "--repo", repository, "--force"])
+ cancelled.append(run["url"])
if draft is not None:
- if draft.get("isDraft") is not True:
- raise ReleaseRefused(f"{tag} is published and cannot be abandoned")
- delete(["gh", "release", "delete", tag, "--repo", repository, "--yes"])
+ execute(["gh", "release", "delete", tag, "--repo", repository, "--yes"])
marker = marker_ref(version, attempt)
message = json.dumps({"schema": 1, "version": version, "attempt": attempt, "attemptRef": tag},
sort_keys=True, separators=(",", ":"))
@@ -403,7 +418,8 @@ def abandon(version: str, *, repo: Path, remote: str, repository: str, delete, i
_git(repo, "push", remote, f"refs/tags/{marker}")
except subprocess.CalledProcessError as error:
raise _claim_collision(repo, remote, marker, error) from error
- return {"version": version, "tag": tag, "marker": marker, "repository": repository}
+ return {"version": version, "tag": tag, "marker": marker, "repository": repository,
+ "cancelled": cancelled}
def next_steps(result: dict, *, bold: bool = False) -> str:
@@ -505,6 +521,7 @@ def abandon_steps(result: dict) -> str:
_version, attempt = parse_attempt_ref(tag)
return "\n".join([
f"Cleared {tag}. The marker {result['marker']} records it.",
+ *(f"Cancelled {url}" for url in result.get("cancelled", [])),
f"v{version} is not spent. The next cut is rc.{attempt + 1}-v{version}.",
])
@@ -527,6 +544,6 @@ def cmd_publish(args) -> None:
def cmd_abandon(args) -> None:
repo, remote, repository = _command_repository(args)
result = abandon(args.version, repo=repo, remote=remote, repository=repository,
- delete=lambda command: _execute(repo, command),
+ execute=lambda command: _execute(repo, command),
inspect=lambda command: _inspect(repo, command))
print(abandon_steps(result))
diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.py
index ffb9fe072f2..cc651d789d8 100644
--- a/tests/scripts/test_release_entrypoint.py
+++ b/tests/scripts/test_release_entrypoint.py
@@ -512,16 +512,19 @@ def test_publish_preflight_finds_the_draft_on_the_outstanding_attempt(source):
repo=source, remote="origin")
-def _abandon(repo, version, *, draft=None, calls=None):
+def _abandon(repo, version, *, draft=None, runs=(), calls=None):
from scripts.releases.entrypoint import ReleaseRefused, abandon
def inspect(command):
+ if command[1] == "run":
+ assert command[command.index("--branch") + 1] == f"rc.1-v{version}"
+ return json.dumps(list(runs))
if draft is None or command[3] != draft["tagName"]:
raise ReleaseRefused("release not found")
return json.dumps(draft)
return abandon(version, repo=repo, remote="origin", repository="example/hermes-agent",
- delete=(calls if calls is not None else []).append, inspect=inspect)
+ execute=(calls if calls is not None else []).append, inspect=inspect)
def test_abandon_of_a_draft_deletes_it_writes_the_marker_and_frees_the_version(source):
@@ -532,7 +535,8 @@ def test_abandon_of_a_draft_deletes_it_writes_the_marker_and_frees_the_version(s
draft={"tagName": "rc.1-v0.21.5", "isDraft": True, "isPrerelease": False})
assert result == {"version": "0.21.5", "tag": "rc.1-v0.21.5",
- "marker": "abandoned-rc.1-v0.21.5", "repository": "example/hermes-agent"}
+ "marker": "abandoned-rc.1-v0.21.5", "repository": "example/hermes-agent",
+ "cancelled": []}
assert calls == [["gh", "release", "delete", "rc.1-v0.21.5", "--repo", "example/hermes-agent", "--yes"]]
remote = git(source, "ls-remote", "origin", "refs/tags/*")
assert "refs/tags/abandoned-rc.1-v0.21.5" in remote
@@ -544,6 +548,41 @@ def test_abandon_of_a_draft_deletes_it_writes_the_marker_and_frees_the_version(s
assert _release(source, _advance(source, "fix"))["tag"] == "rc.2-v0.21.5"
+def test_abandon_force_cancels_in_progress_runs_before_the_draft_and_the_marker(source):
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ calls = []
+ runs = [{"databaseId": 11, "url": "https://example.test/runs/11", "status": "in_progress"},
+ {"databaseId": 12, "url": "https://example.test/runs/12", "status": "completed"},
+ {"databaseId": 13, "url": "https://example.test/runs/13", "status": "queued"}]
+
+ result = _abandon(source, "0.21.5", calls=calls, runs=runs,
+ draft={"tagName": "rc.1-v0.21.5", "isDraft": True, "isPrerelease": False})
+
+ assert calls == [
+ ["gh", "run", "cancel", "11", "--repo", "example/hermes-agent", "--force"],
+ ["gh", "run", "cancel", "13", "--repo", "example/hermes-agent", "--force"],
+ ["gh", "release", "delete", "rc.1-v0.21.5", "--repo", "example/hermes-agent", "--yes"],
+ ]
+ assert result["cancelled"] == ["https://example.test/runs/11", "https://example.test/runs/13"]
+ assert "abandoned-rc.1-v0.21.5" in git(source, "ls-remote", "origin", "refs/tags/*")
+
+
+def test_abandon_that_cannot_cancel_a_run_writes_no_marker_so_it_can_be_retried(source):
+ from scripts.releases.entrypoint import ReleaseRefused, abandon
+
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ run = {"databaseId": 11, "url": "https://example.test/runs/11", "status": "in_progress"}
+
+ def refuse(_command):
+ raise ReleaseRefused("HTTP 403")
+
+ with pytest.raises(ReleaseRefused, match="HTTP 403"):
+ abandon("0.21.5", repo=source, remote="origin", repository="example/hermes-agent",
+ execute=refuse, inspect=lambda command: json.dumps([run]) if command[1] == "run"
+ else (_ for _ in ()).throw(ReleaseRefused("release not found")))
+ assert "abandoned-rc" not in git(source, "ls-remote", "origin", "refs/tags/*")
+
+
def test_abandon_of_a_draftless_burned_attempt_writes_the_marker(source):
_claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
calls = []
@@ -568,9 +607,12 @@ def test_abandon_refuses_a_release_that_was_published(source):
from scripts.releases.entrypoint import ReleaseRefused
_claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ calls = []
with pytest.raises(ReleaseRefused, match="published and cannot be abandoned"):
- _abandon(source, "0.21.5",
+ _abandon(source, "0.21.5", calls=calls,
+ runs=[{"databaseId": 11, "url": "https://example.test/runs/11", "status": "in_progress"}],
draft={"tagName": "rc.1-v0.21.5", "isDraft": False, "isPrerelease": False})
+ assert calls == []
assert "abandoned-rc" not in git(source, "ls-remote", "origin", "refs/tags/*")
diff --git a/website/docs/developer-guide/stable-releases.md b/website/docs/developer-guide/stable-releases.md
index cfc33d4b23f..2114708b392 100644
--- a/website/docs/developer-guide/stable-releases.md
+++ b/website/docs/developer-guide/stable-releases.md
@@ -159,7 +159,8 @@ python scripts/release.py abandon --version 0.21.5 --remote origin
`publish` performs a synchronous supersession preflight, then dispatches the same
ordered controller used by automatic recovery. It refuses a known burned version
-below a newer published release. `abandon` deletes the draft when one exists,
+below a newer published release. `abandon` force-cancels the attempt's
+in-progress `Stable Release` runs, deletes the draft when one exists,
writes an `abandoned-rc.<N>-vX.Y.Z` marker ref, and keeps the attempt ref. The
marker is the record of abandonment; the attempt ref is never deleted. The
version is not spent, so the next cut is `rc.<N+1>-vX.Y.Z`.