From 3333f337c9eb9354d1db1bcb1763fe5d9329790b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 21:46:44 +0000 Subject: [PATCH] fix(ci_status): Heart's publish run no longer reports itself as CI in progress The Heart Health workflow observes its own repository while running, so its own still-running run was always the newest `Heart Health` run: ci_status:PyAutoHeart and PyAutoHeart:ci read "in_progress" on every publish, a finding no repair could clear. Inside GitHub Actions, when the observed repo is the observer's own repository (GITHUB_REPOSITORY), the run whose id is GITHUB_RUN_ID is set aside and the previous run of that workflow is the evidence. Every other in-progress run still reads as in progress. normalize_runs keeps run ids. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016nhQ8RkwYK9RzapmsQRGCj --- heart/checks/ci_status.py | 22 ++++++++++++++++++++- tests/test_ci_status.py | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/heart/checks/ci_status.py b/heart/checks/ci_status.py index 593020be..382bcc88 100644 --- a/heart/checks/ci_status.py +++ b/heart/checks/ci_status.py @@ -226,11 +226,28 @@ def normalize_runs(payload: Any, branch: str = "main") -> list[dict[str, Any]]: "url": run.get("url") or run.get("html_url") or "", "event": run.get("event") or "", "headBranch": head_branch or "", + "id": str(run.get("databaseId") or run.get("id") or ""), } ) return runs +def observer_run_id(name: str) -> str: + """The id of the Actions run doing this observation, when it observes itself. + + Heart publishes from a workflow in its own repository, so a tick there + lists that very run — still ``in_progress`` — as the newest run of its + workflow. Read as evidence it is a permanent self-made "CI in progress" + that no repair can clear. Only the observer's own run is set aside; every + other in-progress run still reads as in progress. + """ + run_id = os.environ.get("GITHUB_RUN_ID", "") + repo = os.environ.get("GITHUB_REPOSITORY", "").rsplit("/", 1)[-1] + if run_id and repo and repo.lower() == (name or "").lower(): + return run_id + return "" + + def latest_per_workflow(runs: list[dict[str, Any]]) -> dict[str, dict[str, Any]]: """Collapse ``gh run list`` output to the newest run of each workflow on main. @@ -336,7 +353,10 @@ def build_sidecar( fetched itself from one an agent handed it. """ required = required_for(group, config_path) - latest = latest_per_workflow(normalize_runs(runs)) + own_run = observer_run_id(name) + observed = [r for r in normalize_runs(runs) + if not (own_run and r.get("id") == own_run)] + latest = latest_per_workflow(observed) workflows = {wf: _wf_entry(run, head_sha) for wf, run in latest.items()} if error: diff --git a/tests/test_ci_status.py b/tests/test_ci_status.py index 54dbf753..0a712c28 100644 --- a/tests/test_ci_status.py +++ b/tests/test_ci_status.py @@ -479,3 +479,43 @@ def test_stale_drop_point_keeps_the_original_error(self, tmp_path, monkeypatch): assert sidecar["status"] == "unavailable" assert "gh: command not found" in sidecar["error"] assert "stale" in sidecar["error"] + + +# --- the observer's own run (Heart publishing from its own repository) ----- + +def _own_runs(): + previous = dict(_run("Heart Health", "success", created="2026-06-29T00:00:00Z"), databaseId=1) + own = dict(_run("Heart Health", "", status="in_progress", created="2026-06-29T01:00:00Z"), + databaseId=2) + return [previous, own] + + +def test_observer_skips_its_own_in_progress_run(tmp_path, monkeypatch): + monkeypatch.setenv("GITHUB_RUN_ID", "2") + monkeypatch.setenv("GITHUB_REPOSITORY", "SomeOrg/PyAutoHeart") + side = ci.build_sidecar("PyAutoHeart", "organs", _own_runs(), HEAD, "T", + config_path=_cfg(tmp_path)) + assert side["workflows"]["Heart Health"]["status"] == "completed" + assert side["workflows"]["Heart Health"]["conclusion"] == "success" + assert side["conclusion"] == "success" + + +def test_another_repos_in_progress_run_still_reads_in_progress(tmp_path, monkeypatch): + monkeypatch.setenv("GITHUB_RUN_ID", "2") + monkeypatch.setenv("GITHUB_REPOSITORY", "SomeOrg/PyAutoHeart") + side = ci.build_sidecar("PyAutoFit", "organs", _own_runs(), HEAD, "T", + config_path=_cfg(tmp_path)) + assert side["workflows"]["Heart Health"]["status"] == "in_progress" + + +def test_outside_actions_every_run_is_evidence(tmp_path, monkeypatch): + monkeypatch.delenv("GITHUB_RUN_ID", raising=False) + monkeypatch.delenv("GITHUB_REPOSITORY", raising=False) + side = ci.build_sidecar("PyAutoHeart", "organs", _own_runs(), HEAD, "T", + config_path=_cfg(tmp_path)) + assert side["workflows"]["Heart Health"]["status"] == "in_progress" + + +def test_normalize_runs_keeps_the_run_id(): + assert ci.normalize_runs([dict(_run("Tests", "success"), databaseId=7)])[0]["id"] == "7" + assert ci.normalize_runs({"workflow_runs": [dict(_rest_run("Tests", "success"), id=9)]})[0]["id"] == "9"