From b72d7b45a632a4bebf6f860eb32d18fb5d853738 Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Sat, 28 Nov 2026 19:21:46 +0100 Subject: [PATCH] fix(typed_actions): refuse actions.rerun outside the 30-day window without sending the POST Ursache: Der POST auf actions/runs//rerun eines >30 Tage alten Laufs liefert HTTP 403; transport.py behandelt jeden 403 ohne Rate-Header als persistenten, host-weiten policy HOLD. Fix: exec_rerun liest den Lauf ohnehin und lehnt bei created_at > 30 Tage lokal ab, ohne Request. Transport und alle anderen 403-Pfade bleiben unveraendert fail-closed. Test: test_rerun_outside_30_day_window_is_refused_without_a_request; tests/test_typed_actions.py und tests/test_coordination.py (148 passed). Ticket: T-20261127-325831929 Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01THB2EzGbmyMB2S1P43LDZb --- CHANGELOG.md | 4 ++++ src/githubbot_core/typed_actions.py | 11 +++++++++++ tests/test_typed_actions.py | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b6887..3b4e28a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Format: [Keep a Changelog](https://keepachangelog.com/de/1.1.0/), [Semantic Vers ## [Unreleased] +### Behoben / Fixed + +- `actions.rerun`: Ein Lauf außerhalb des 30-Tage-Rerun-Fensters von GitHub wird lokal abgelehnt, ohne den POST zu senden. Der sonst folgende HTTP 403 setzte einen persistenten host-weiten `policy_hold` und blockierte alle koordinierten Schreibaktionen / a run older than 30 days is refused locally without sending the POST; its 403 used to set a persistent host-wide policy HOLD. Jeder andere 403 bleibt unverändert fail-closed (Ticket T-20261127-325831929). + ## [0.2.2] - 2026-11-22 ### Behoben / Fixed diff --git a/src/githubbot_core/typed_actions.py b/src/githubbot_core/typed_actions.py index 92a466a..bd78974 100644 --- a/src/githubbot_core/typed_actions.py +++ b/src/githubbot_core/typed_actions.py @@ -12,6 +12,7 @@ import re import os +from datetime import datetime, timedelta, timezone import subprocess import sys import tempfile @@ -534,6 +535,16 @@ def exec_rerun(transport, params: dict, config: dict): return None, "run comes from a fork; fork runs are never re-run or approved by the bot" if run.get("status") != "completed": return None, f"run is {run.get('status')!r}, not completed" + # GitHub re-runs only up to 30 days after the initial run (docs.github.com, "Re-run + # workflows and jobs"). Sending the POST anyway earns a 403, which the transport must + # treat as a host-wide policy HOLD, so refuse locally and never send it. A missing or + # unreadable timestamp changes nothing: the request goes out as before. + try: + started = datetime.fromisoformat(str(run.get("created_at")).replace("Z", "+00:00")) + if datetime.now(timezone.utc) - started > timedelta(days=30): + return None, "run is outside the 30-day re-run window; not re-run" + except ValueError: + pass _, error = transport.request("POST", f"repos/{repo}/actions/runs/{run_id}/rerun", None) return (None, error) if error else ({"readback": {"rerun": run_id}}, None) diff --git a/tests/test_typed_actions.py b/tests/test_typed_actions.py index 41a3d13..2765945 100644 --- a/tests/test_typed_actions.py +++ b/tests/test_typed_actions.py @@ -368,6 +368,30 @@ def test_rerun_refuses_fork_runs_other_heads_and_running_runs(): assert transport.writes == [("POST", f"repos/{REPO}/actions/runs/5/rerun", None)] +def test_rerun_outside_30_day_window_is_refused_without_a_request(): + # GitHub only allows a re-run up to 30 days after the initial run; the POST + # would answer 403, which the transport treats as a host-wide policy HOLD. + from datetime import datetime, timedelta, timezone + + def run(age_days): + stamp = (datetime.now(timezone.utc) - timedelta(days=age_days)).strftime("%Y-%m-%dT%H:%M:%SZ") + return { + "head_sha": SHA, + "status": "completed", + "head_repository": {"full_name": REPO}, + "created_at": stamp, + } + + action = Action("actions.rerun", {"repo": REPO, "run_id": 5, "sha": SHA}) + transport = Transport({f"repos/{REPO}/actions/runs/5": run(46)}) + receipt = actions.apply([action], transport, config())["receipts"][0] + assert receipt["status"] == "failed" and "30-day" in receipt["detail"] + assert transport.writes == [] + transport = Transport({f"repos/{REPO}/actions/runs/5": run(29)}) + assert actions.apply([action], transport, config())["receipts"][0]["status"] == "applied" + assert transport.writes == [("POST", f"repos/{REPO}/actions/runs/5/rerun", None)] + + def test_dispatch_needs_an_active_workflow(): action = Action("actions.dispatch", {"repo": REPO, "workflow": "ci.yml", "ref": "bot/fix"}) transport = Transport({f"repos/{REPO}/actions/workflows/ci.yml": {"state": "disabled_manually"}})