From c032cffaeb95df5d244009a29bda1ba749385be2 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:13:57 +0000 Subject: [PATCH 1/4] #7 WL5: stall-sweep check test, red against an empty check --- catalog/stall-sweep/check.sh | 2 ++ catalog/stall-sweep/test.sh | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 catalog/stall-sweep/check.sh create mode 100644 catalog/stall-sweep/test.sh diff --git a/catalog/stall-sweep/check.sh b/catalog/stall-sweep/check.sh new file mode 100644 index 0000000..039e4d0 --- /dev/null +++ b/catalog/stall-sweep/check.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exit 0 diff --git a/catalog/stall-sweep/test.sh b/catalog/stall-sweep/test.sh new file mode 100644 index 0000000..86b9408 --- /dev/null +++ b/catalog/stall-sweep/test.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# Runs stall-sweep's check against a stand-in `gh` that prints synthetic +# pull requests, and checks what the check prints. Needs sh, sed, date and +# python3. Run from anywhere: sh catalog/stall-sweep/test.sh +set -u +here=$(cd "$(dirname "$0")" && pwd) +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +mkdir "$work/bin" +cat > "$work/bin/gh" <<'GH' +#!/bin/sh +[ -f "$FIXTURE" ] || { echo "gh: could not reach GitHub" >&2; exit 1; } +cat "$FIXTURE" +GH +chmod +x "$work/bin/gh" +# The check as an adapter applies it: params replaced by their values. +sed -e 's|{{repo}}|example-org/example-repo|g' -e 's|{{idle_minutes}}|60|g' \ + "$here/check.sh" > "$work/check.sh" + +ago() { date -u -d "-$1 minutes" +%Y-%m-%dT%H:%M:%SZ; } +fail=0 +# run +run() { + out=$(cd "$work" && FIXTURE="$2" PATH="$work/bin:$PATH" sh ./check.sh 2>/dev/null) + code=$? + if [ "$code" != "$3" ] || [ "$out" != "$4" ]; then + printf 'FAIL %s\n exit %s, want %s\n got: %s\n want: %s\n' "$1" "$code" "$3" "$out" "$4" + fail=1 + else + echo "ok $1" + fi +} + +# catches: a quiet wake that still prints, so an agent starts for nothing. +echo '[]' > "$work/none.json" +run "no open pull requests: quiet" "$work/none.json" 0 "" + +# catches: waking on work that moved recently, or on a draft nobody waits for. +cat > "$work/fresh.json" < "$work/stalled.json" < Date: Mon, 16 Nov 2026 00:14:54 +0000 Subject: [PATCH 2/4] #7 WL5: catalog: the stall-sweep loop, its check and its test (green) --- catalog/stall-sweep.md | 30 ++++++++++++++++++++ catalog/stall-sweep/check.sh | 53 +++++++++++++++++++++++++++++++++++- catalog/stall-sweep/test.sh | 3 +- 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 catalog/stall-sweep.md diff --git a/catalog/stall-sweep.md b/catalog/stall-sweep.md new file mode 100644 index 0000000..f5f12a9 --- /dev/null +++ b/catalog/stall-sweep.md @@ -0,0 +1,30 @@ +--- +id: "stall-sweep" +name: "Stall sweep" +trigger: {"cron": "20 * * * *", "timezone": "UTC"} +check: {"run": "stall-sweep/check.sh", "timeout": 60} +thread: "same" +secrets: [] +priority: 2 +params: {"repo": "example-org/example-repo", "idle_minutes": 60} +--- +Stall sweep for {{repo}}. The check below lists each open pull request that +has had no progress for {{idle_minutes}} minutes or more, with why it looks +stalled. + +For each line: + +1. Read the pull request, its checks and its comments, and confirm the + reason. If it moved since the check ran, skip it. +2. Name who owns the next step, by the repository's own rules: its builder + for a conflict, failing checks or requested changes; its reviewer, or + whoever starts reviews, when it waits for a review; whoever merges when it + is approved and green; whoever runs CI when its checks never finished. +3. Tell that owner, once, in one short comment on the pull request or a + message to them: what is waiting, for how long, and why. + +Do not merge, review, push or rerun anything yourself unless the +repository's rules make that your job. Your comment counts as progress, so +the next sweep stays quiet about that pull request until it is idle again. +Reply with one line per pull request: its number, the reason and who you +told. diff --git a/catalog/stall-sweep/check.sh b/catalog/stall-sweep/check.sh index 039e4d0..f33abd4 100644 --- a/catalog/stall-sweep/check.sh +++ b/catalog/stall-sweep/check.sh @@ -1,2 +1,53 @@ #!/bin/sh -exit 0 +# stall-sweep's check: prints one line per open pull request in {{repo}} +# that has had no progress for {{idle_minutes}} minutes or more, with why it +# looks stalled. Prints nothing when nothing is stalled, so no agent starts. +# Any update counts as progress: a push, a comment, a review or a label. +# A failed GitHub read fails the run (exit 2) rather than looking quiet. +set -u +prs=$(timeout 40 gh pr list -R "{{repo}}" --state open --limit 200 \ + --json number,isDraft,updatedAt,mergeable,reviewDecision,statusCheckRollup) || { + echo "stall-sweep: could not list pull requests in {{repo}}" >&2 + exit 2 +} +printf '%s' "$prs" | python3 -I -c ' +import datetime, json, sys +idle_limit = int(sys.argv[1]) +now = datetime.datetime.now(datetime.timezone.utc) +bad = ("FAILURE", "ERROR", "TIMED_OUT", "CANCELLED", "ACTION_REQUIRED", "STARTUP_FAILURE") +for p in sorted(json.load(sys.stdin), key=lambda p: p["number"]): + if p["isDraft"]: + continue + updated = datetime.datetime.fromisoformat(p["updatedAt"].replace("Z", "+00:00")) + idle = int((now - updated).total_seconds() // 60) + if idle < idle_limit: + continue + failing, running = [], False + for c in p.get("statusCheckRollup") or []: + if c.get("__typename") == "StatusContext": + state, name = c.get("state"), c.get("context") + if state in bad: + failing.append(name) + elif state in ("PENDING", "EXPECTED"): + running = True + elif c.get("status") != "COMPLETED": + running = True + elif c.get("conclusion") in bad: + failing.append(c.get("name")) + why = [] + if p.get("mergeable") == "CONFLICTING": + why.append("conflicts with its base") + if failing: + why.append("failing checks: " + ", ".join(failing)) + elif running: + why.append("checks not finished") + if not why: + decision = p.get("reviewDecision") + if decision == "APPROVED": + why.append("approved and green, not merged") + elif decision == "CHANGES_REQUESTED": + why.append("changes requested, no new push") + else: + why.append("green, waiting for a review") + print("#%d idle %d min: %s" % (p["number"], idle, "; ".join(why))) +' "{{idle_minutes}}" || exit 2 diff --git a/catalog/stall-sweep/test.sh b/catalog/stall-sweep/test.sh index 86b9408..b89605a 100644 --- a/catalog/stall-sweep/test.sh +++ b/catalog/stall-sweep/test.sh @@ -17,7 +17,8 @@ chmod +x "$work/bin/gh" sed -e 's|{{repo}}|example-org/example-repo|g' -e 's|{{idle_minutes}}|60|g' \ "$here/check.sh" > "$work/check.sh" -ago() { date -u -d "-$1 minutes" +%Y-%m-%dT%H:%M:%SZ; } +# Half a minute past each whole minute, so a slow run cannot change the count. +ago() { date -u -d "-$(( $1 * 60 + 30 )) seconds" +%Y-%m-%dT%H:%M:%SZ; } fail=0 # run run() { From 62ed9033b397de9b58724796eecfd618221eacaf Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:26:38 +0000 Subject: [PATCH 3/4] #7 WL5: R2: red: a capped pull request list hides a stalled one --- catalog/stall-sweep/test.sh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/catalog/stall-sweep/test.sh b/catalog/stall-sweep/test.sh index b89605a..e4e1a8c 100644 --- a/catalog/stall-sweep/test.sh +++ b/catalog/stall-sweep/test.sh @@ -9,8 +9,13 @@ trap 'rm -rf "$work"' EXIT mkdir "$work/bin" cat > "$work/bin/gh" <<'GH' #!/bin/sh +# Like gh pr list: returns at most --limit pull requests (default 30), newest first. [ -f "$FIXTURE" ] || { echo "gh: could not reach GitHub" >&2; exit 1; } -cat "$FIXTURE" +limit=30 +while [ $# -gt 0 ]; do [ "$1" = "--limit" ] && limit=$2; shift; done +python3 -I -c 'import json, sys +prs = sorted(json.load(open(sys.argv[1])), key=lambda p: -p["number"]) +print(json.dumps(prs[:int(sys.argv[2])]))' "$FIXTURE" "$limit" GH chmod +x "$work/bin/gh" # The check as an adapter applies it: params replaced by their values. @@ -63,6 +68,27 @@ run "stalled pull requests: one line each, with why" "$work/stalled.json" 0 "#12 #15 idle 70 min: green, waiting for a review #16 idle 200 min: changes requested, no new push" +# many : open pull requests, #2 upward fresh, #1 stalled. +many() { + python3 -I -c 'import json, sys +fresh, old = sys.argv[2], sys.argv[3] +prs = [{"number": n, "isDraft": False, "updatedAt": fresh, "mergeable": "MERGEABLE", + "reviewDecision": "", "statusCheckRollup": []} for n in range(2, int(sys.argv[1]) + 1)] +prs.append({"number": 1, "isDraft": False, "updatedAt": old, "mergeable": "CONFLICTING", + "reviewDecision": "", "statusCheckRollup": []}) +print(json.dumps(prs))' "$2" "$(ago 10)" "$(ago 1440)" > "$1" +} + +# catches: a capped read that drops the oldest pull request, so a stalled one +# behind many fresh ones is never seen and the wake looks quiet. +many "$work/many.json" 201 +run "201 open, the oldest stalled: reported" "$work/many.json" 0 "#1 idle 1440 min: conflicts with its base" + +# catches: a repository with more open pull requests than the check can read +# looking quiet instead of failing the run. +many "$work/toomany.json" 1001 +run "1001 open: the run fails, nothing printed" "$work/toomany.json" 2 "" + # catches: an unreachable GitHub read as "nothing is due", hiding every stall. run "gh fails: the run fails, nothing printed" "none" 2 "" From 1a168c99101e3cc7c34a5bc53472c9687fb4f3b4 Mon Sep 17 00:00:00 2001 From: jparker2006 <85816763+jparker2006@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:26:42 +0000 Subject: [PATCH 4/4] #7 WL5: R2: read every open pull request or fail the run (green) --- catalog/stall-sweep/check.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/catalog/stall-sweep/check.sh b/catalog/stall-sweep/check.sh index f33abd4..0a996bf 100644 --- a/catalog/stall-sweep/check.sh +++ b/catalog/stall-sweep/check.sh @@ -3,9 +3,10 @@ # that has had no progress for {{idle_minutes}} minutes or more, with why it # looks stalled. Prints nothing when nothing is stalled, so no agent starts. # Any update counts as progress: a push, a comment, a review or a label. -# A failed GitHub read fails the run (exit 2) rather than looking quiet. +# A read that fails, or that cannot list every open pull request (more than +# 1000), fails the run (exit 2) rather than looking quiet. set -u -prs=$(timeout 40 gh pr list -R "{{repo}}" --state open --limit 200 \ +prs=$(timeout 40 gh pr list -R "{{repo}}" --state open --limit 1001 \ --json number,isDraft,updatedAt,mergeable,reviewDecision,statusCheckRollup) || { echo "stall-sweep: could not list pull requests in {{repo}}" >&2 exit 2 @@ -14,8 +15,12 @@ printf '%s' "$prs" | python3 -I -c ' import datetime, json, sys idle_limit = int(sys.argv[1]) now = datetime.datetime.now(datetime.timezone.utc) +prs = json.load(sys.stdin) +if len(prs) > 1000: + sys.stderr.write("stall-sweep: more than 1000 open pull requests; cannot read them all\n") + sys.exit(2) bad = ("FAILURE", "ERROR", "TIMED_OUT", "CANCELLED", "ACTION_REQUIRED", "STARTUP_FAILURE") -for p in sorted(json.load(sys.stdin), key=lambda p: p["number"]): +for p in sorted(prs, key=lambda p: p["number"]): if p["isDraft"]: continue updated = datetime.datetime.fromisoformat(p["updatedAt"].replace("Z", "+00:00"))