From 8ca8eb7445a511bed18c49b460d5730c22bd3d54 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Fri, 20 Nov 2026 22:41:39 +0100 Subject: [PATCH] upstreaming: recover controller post-commit steps --- .github/workflows/upstreaming-controller.yml | 20 ++----- SESSIONLOG.md | 2 + upstreaming/command_reactions.py | 56 ++++++++++++++++++++ upstreaming/tests/test_command_reactions.py | 56 ++++++++++++++++++++ upstreaming/tests/test_workflow_contracts.py | 6 +-- 5 files changed, 119 insertions(+), 21 deletions(-) create mode 100644 upstreaming/command_reactions.py create mode 100644 upstreaming/tests/test_command_reactions.py diff --git a/.github/workflows/upstreaming-controller.yml b/.github/workflows/upstreaming-controller.yml index d0a795beffa..5ede8c5a608 100644 --- a/.github/workflows/upstreaming-controller.yml +++ b/.github/workflows/upstreaming-controller.yml @@ -282,23 +282,8 @@ jobs: GH_TOKEN: ${{ steps.ledger-token.outputs.token }} run: | set -euo pipefail - retry_api() { - local attempt delay=1 - for attempt in 1 2 3 4; do - if gh api "$@"; then return 0; fi - [ "$attempt" -eq 4 ] && return 1 - sleep "$delay" - delay=$((delay * 2)) - done - } - jq -r '.commands[] | select(.result == "accepted") | .comment | select(type == "number")' \ - report.json | sort -nu | while read -r comment; do - reactions=$(retry_api "/repos/$GITHUB_REPOSITORY/issues/comments/$comment/reactions?per_page=100") - jq -e 'any(.[]; .content == "+1" and .user.login == "riseproject-dev[bot]")' \ - <<<"$reactions" >/dev/null || \ - retry_api -X POST "/repos/$GITHUB_REPOSITORY/issues/comments/$comment/reactions" \ - -f content='+1' >/dev/null - done + uv run --no-project --with-requirements upstreaming/requirements.txt \ + python -m upstreaming.command_reactions --out command-reactions/receipts.json - name: Append concise lifecycle entries to tracking issues if: steps.policy.outputs.read_only == 'false' @@ -329,6 +314,7 @@ jobs: path: | status-ledger/receipts.json command-feedback/receipts.json + command-reactions/receipts.json if-no-files-found: ignore retention-days: 30 diff --git a/SESSIONLOG.md b/SESSIONLOG.md index 84e00c549a3..9206fd388bf 100644 --- a/SESSIONLOG.md +++ b/SESSIONLOG.md @@ -40,3 +40,5 @@ - Diagnosed dispatcher failures as queue payload-limit violations from embedding complete dossier research in Work, then added a bounded projection preserving IDs, exact paths, response contracts, path coverage, dependency findings and risks plus a pre-staging byte-budget guard. - Kept the complete dossier as committed evidence and added an immutable exact-ref path/raw URL/SHA-256 reference; trusted worker setup now fetches and verifies it into `/tmp/gh-aw/agent/dossier.json` for mandatory worker reading while the queue carries only a bounded projection. - Restored worker-facing wording that names the complete authoritative record as “the latest verified dossier,” while describing bounded `data` only as its queue-safe index. +- Fixed command-completion reaction handling for controller ticks with no commands so post-commit bookkeeping cannot block dispatcher recovery and continuation. +- Replaced report-only command completion reactions with a durable accepted-receipt scanner so failed post-commit ticks are backfilled idempotently, including the accepted py-webrtcvad resume command. diff --git a/upstreaming/command_reactions.py b/upstreaming/command_reactions.py new file mode 100644 index 00000000000..de818737e48 --- /dev/null +++ b/upstreaming/command_reactions.py @@ -0,0 +1,56 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +"""Idempotently mark durably accepted commands complete with ``+1``.""" +from __future__ import annotations + +import json +import os +from pathlib import Path +import time + +from .status_ledger import Api, LedgerError + + +def _retry(call, attempts: int = 4): + delay = 1 + for attempt in range(attempts): + try: + return call() + except (LedgerError, OSError): + if attempt + 1 == attempts: + raise + time.sleep(delay) + delay *= 2 + + +def publish(root: Path, token: str) -> list[dict]: + api = Api(token) + results = [] + paths = sorted((root / "upstreaming-state/commands").glob("*.json"))[-512:] + for path in paths: + receipt = json.loads(path.read_text()) + if receipt.get("result") != "accepted": + continue + comment_id = int(receipt["comment_id"]) + endpoint = f"/repos/riseproject-dev/python-wheels/issues/comments/{comment_id}/reactions" + reactions = _retry(lambda: api.request("GET", endpoint + "?per_page=100")) + if any(item.get("content") == "+1" and (item.get("user") or {}).get("login") == "riseproject-dev[bot]" + for item in reactions): + results.append({"command_id": receipt["command_id"], "comment_id": comment_id, "status": "existing"}) + continue + created = _retry(lambda: api.request("POST", endpoint, {"content": "+1"})) + if created.get("content") != "+1" or (created.get("user") or {}).get("login") != "riseproject-dev[bot]": + raise LedgerError("command completion reaction readback or App author mismatch") + results.append({"command_id": receipt["command_id"], "comment_id": comment_id, "status": "created"}) + return results + + +if __name__ == "__main__": + import argparse + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--root", type=Path, default=Path.cwd()) + parser.add_argument("--out", type=Path, required=True) + args = parser.parse_args() + result = publish(args.root, os.environ.get("GH_TOKEN", "")) + args.out.parent.mkdir(parents=True, exist_ok=True) + args.out.write_text(json.dumps(result, indent=2)) diff --git a/upstreaming/tests/test_command_reactions.py b/upstreaming/tests/test_command_reactions.py new file mode 100644 index 00000000000..3f5b8e076a6 --- /dev/null +++ b/upstreaming/tests/test_command_reactions.py @@ -0,0 +1,56 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +"""Accepted command completion reactions are durable and self-healing.""" +import json +from pathlib import Path +import tempfile +import unittest +from unittest.mock import patch + +from upstreaming import command_reactions + + +class FakeApi: + def __init__(self, existing=False): + self.existing = existing + self.posts = [] + + def request(self, method, path, body=None): + if method == "GET": + return ([{"content": "+1", "user": {"login": "riseproject-dev[bot]"}}] + if self.existing else []) + self.posts.append((path, body)) + return {"content": "+1", "user": {"login": "riseproject-dev[bot]"}} + + +class TestCommandReactions(unittest.TestCase): + def root(self, td): + root = Path(td) + directory = root / "upstreaming-state/commands" + directory.mkdir(parents=True) + accepted = {"command_id": "comment-7", "comment_id": 7, "result": "accepted"} + rejected = {"command_id": "comment-8", "comment_id": 8, "result": "rejected"} + (directory / "comment-7.json").write_text(json.dumps(accepted)) + (directory / "comment-8.json").write_text(json.dumps(rejected)) + return root + + def test_backfills_accepted_receipts_and_ignores_rejections(self): + with tempfile.TemporaryDirectory() as td: + api = FakeApi() + with patch("upstreaming.command_reactions.Api", return_value=api): + result = command_reactions.publish(self.root(td), "token") + self.assertEqual(result, [{"command_id": "comment-7", "comment_id": 7, "status": "created"}]) + self.assertEqual(api.posts[0][1], {"content": "+1"}) + self.assertIn("/issues/comments/7/reactions", api.posts[0][0]) + + def test_existing_app_completion_is_idempotent(self): + with tempfile.TemporaryDirectory() as td: + api = FakeApi(existing=True) + with patch("upstreaming.command_reactions.Api", return_value=api): + result = command_reactions.publish(self.root(td), "token") + self.assertEqual(result[0]["status"], "existing") + self.assertEqual(api.posts, []) + + +if __name__ == "__main__": + unittest.main() diff --git a/upstreaming/tests/test_workflow_contracts.py b/upstreaming/tests/test_workflow_contracts.py index 00c72dfbf8a..4abf29b34e0 100644 --- a/upstreaming/tests/test_workflow_contracts.py +++ b/upstreaming/tests/test_workflow_contracts.py @@ -198,10 +198,8 @@ def test_command_acknowledgement_is_fast_idempotent_and_not_serialized(self): complete = next(step for step in reconcile["steps"] if step.get("name") == "Mark accepted commands complete") self.assertEqual(complete["if"], "steps.policy.outputs.read_only == 'false'") - self.assertIn('.commands[] | select(.result == "accepted")', complete["run"]) - self.assertIn("-f content='+1'", complete["run"]) - self.assertIn('riseproject-dev[bot]', complete["run"]) - self.assertIn("for attempt in 1 2 3 4", complete["run"]) + self.assertIn("upstreaming.command_reactions", complete["run"]) + self.assertIn("command-reactions/receipts.json", complete["run"]) publish_index = next(i for i, step in enumerate(reconcile["steps"]) if step.get("name") == "Publish one validated state-only commit on main") complete_index = reconcile["steps"].index(complete)