Skip to content

Commit 3fc1289

Browse files
authored
upstreaming: recover controller post-commit steps (#5012)
1 parent 62c9ae0 commit 3fc1289

5 files changed

Lines changed: 119 additions & 21 deletions

File tree

‎.github/workflows/upstreaming-controller.yml‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,23 +282,8 @@ jobs:
282282
GH_TOKEN: ${{ steps.ledger-token.outputs.token }}
283283
run: |
284284
set -euo pipefail
285-
retry_api() {
286-
local attempt delay=1
287-
for attempt in 1 2 3 4; do
288-
if gh api "$@"; then return 0; fi
289-
[ "$attempt" -eq 4 ] && return 1
290-
sleep "$delay"
291-
delay=$((delay * 2))
292-
done
293-
}
294-
jq -r '.commands[] | select(.result == "accepted") | .comment | select(type == "number")' \
295-
report.json | sort -nu | while read -r comment; do
296-
reactions=$(retry_api "/repos/$GITHUB_REPOSITORY/issues/comments/$comment/reactions?per_page=100")
297-
jq -e 'any(.[]; .content == "+1" and .user.login == "riseproject-dev[bot]")' \
298-
<<<"$reactions" >/dev/null || \
299-
retry_api -X POST "/repos/$GITHUB_REPOSITORY/issues/comments/$comment/reactions" \
300-
-f content='+1' >/dev/null
301-
done
285+
uv run --no-project --with-requirements upstreaming/requirements.txt \
286+
python -m upstreaming.command_reactions --out command-reactions/receipts.json
302287
303288
- name: Append concise lifecycle entries to tracking issues
304289
if: steps.policy.outputs.read_only == 'false'
@@ -329,6 +314,7 @@ jobs:
329314
path: |
330315
status-ledger/receipts.json
331316
command-feedback/receipts.json
317+
command-reactions/receipts.json
332318
if-no-files-found: ignore
333319
retention-days: 30
334320

‎SESSIONLOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@
4040
- 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.
4141
- 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.
4242
- 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.
43+
- Fixed command-completion reaction handling for controller ticks with no commands so post-commit bookkeeping cannot block dispatcher recovery and continuation.
44+
- 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.

‎upstreaming/command_reactions.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: 2026 The RISE Project
2+
# SPDX-License-Identifier: MIT
3+
"""Idempotently mark durably accepted commands complete with ``+1``."""
4+
from __future__ import annotations
5+
6+
import json
7+
import os
8+
from pathlib import Path
9+
import time
10+
11+
from .status_ledger import Api, LedgerError
12+
13+
14+
def _retry(call, attempts: int = 4):
15+
delay = 1
16+
for attempt in range(attempts):
17+
try:
18+
return call()
19+
except (LedgerError, OSError):
20+
if attempt + 1 == attempts:
21+
raise
22+
time.sleep(delay)
23+
delay *= 2
24+
25+
26+
def publish(root: Path, token: str) -> list[dict]:
27+
api = Api(token)
28+
results = []
29+
paths = sorted((root / "upstreaming-state/commands").glob("*.json"))[-512:]
30+
for path in paths:
31+
receipt = json.loads(path.read_text())
32+
if receipt.get("result") != "accepted":
33+
continue
34+
comment_id = int(receipt["comment_id"])
35+
endpoint = f"/repos/riseproject-dev/python-wheels/issues/comments/{comment_id}/reactions"
36+
reactions = _retry(lambda: api.request("GET", endpoint + "?per_page=100"))
37+
if any(item.get("content") == "+1" and (item.get("user") or {}).get("login") == "riseproject-dev[bot]"
38+
for item in reactions):
39+
results.append({"command_id": receipt["command_id"], "comment_id": comment_id, "status": "existing"})
40+
continue
41+
created = _retry(lambda: api.request("POST", endpoint, {"content": "+1"}))
42+
if created.get("content") != "+1" or (created.get("user") or {}).get("login") != "riseproject-dev[bot]":
43+
raise LedgerError("command completion reaction readback or App author mismatch")
44+
results.append({"command_id": receipt["command_id"], "comment_id": comment_id, "status": "created"})
45+
return results
46+
47+
48+
if __name__ == "__main__":
49+
import argparse
50+
parser = argparse.ArgumentParser(description=__doc__)
51+
parser.add_argument("--root", type=Path, default=Path.cwd())
52+
parser.add_argument("--out", type=Path, required=True)
53+
args = parser.parse_args()
54+
result = publish(args.root, os.environ.get("GH_TOKEN", ""))
55+
args.out.parent.mkdir(parents=True, exist_ok=True)
56+
args.out.write_text(json.dumps(result, indent=2))
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: 2026 The RISE Project
2+
# SPDX-License-Identifier: MIT
3+
"""Accepted command completion reactions are durable and self-healing."""
4+
import json
5+
from pathlib import Path
6+
import tempfile
7+
import unittest
8+
from unittest.mock import patch
9+
10+
from upstreaming import command_reactions
11+
12+
13+
class FakeApi:
14+
def __init__(self, existing=False):
15+
self.existing = existing
16+
self.posts = []
17+
18+
def request(self, method, path, body=None):
19+
if method == "GET":
20+
return ([{"content": "+1", "user": {"login": "riseproject-dev[bot]"}}]
21+
if self.existing else [])
22+
self.posts.append((path, body))
23+
return {"content": "+1", "user": {"login": "riseproject-dev[bot]"}}
24+
25+
26+
class TestCommandReactions(unittest.TestCase):
27+
def root(self, td):
28+
root = Path(td)
29+
directory = root / "upstreaming-state/commands"
30+
directory.mkdir(parents=True)
31+
accepted = {"command_id": "comment-7", "comment_id": 7, "result": "accepted"}
32+
rejected = {"command_id": "comment-8", "comment_id": 8, "result": "rejected"}
33+
(directory / "comment-7.json").write_text(json.dumps(accepted))
34+
(directory / "comment-8.json").write_text(json.dumps(rejected))
35+
return root
36+
37+
def test_backfills_accepted_receipts_and_ignores_rejections(self):
38+
with tempfile.TemporaryDirectory() as td:
39+
api = FakeApi()
40+
with patch("upstreaming.command_reactions.Api", return_value=api):
41+
result = command_reactions.publish(self.root(td), "token")
42+
self.assertEqual(result, [{"command_id": "comment-7", "comment_id": 7, "status": "created"}])
43+
self.assertEqual(api.posts[0][1], {"content": "+1"})
44+
self.assertIn("/issues/comments/7/reactions", api.posts[0][0])
45+
46+
def test_existing_app_completion_is_idempotent(self):
47+
with tempfile.TemporaryDirectory() as td:
48+
api = FakeApi(existing=True)
49+
with patch("upstreaming.command_reactions.Api", return_value=api):
50+
result = command_reactions.publish(self.root(td), "token")
51+
self.assertEqual(result[0]["status"], "existing")
52+
self.assertEqual(api.posts, [])
53+
54+
55+
if __name__ == "__main__":
56+
unittest.main()

‎upstreaming/tests/test_workflow_contracts.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@ def test_command_acknowledgement_is_fast_idempotent_and_not_serialized(self):
198198
complete = next(step for step in reconcile["steps"]
199199
if step.get("name") == "Mark accepted commands complete")
200200
self.assertEqual(complete["if"], "steps.policy.outputs.read_only == 'false'")
201-
self.assertIn('.commands[] | select(.result == "accepted")', complete["run"])
202-
self.assertIn("-f content='+1'", complete["run"])
203-
self.assertIn('riseproject-dev[bot]', complete["run"])
204-
self.assertIn("for attempt in 1 2 3 4", complete["run"])
201+
self.assertIn("upstreaming.command_reactions", complete["run"])
202+
self.assertIn("command-reactions/receipts.json", complete["run"])
205203
publish_index = next(i for i, step in enumerate(reconcile["steps"])
206204
if step.get("name") == "Publish one validated state-only commit on main")
207205
complete_index = reconcile["steps"].index(complete)

0 commit comments

Comments
 (0)