An open source, non-profit web search engine
Bound the retries, and let a run answer rather than only commit
Daoud Clarke2f0de72af9ca
diff --git a/.github/claude/coordinate.md b/.github/claude/coordinate.mdindex da8a60a..cc01b95 100644--- a/.github/claude/coordinate.md+++ b/.github/claude/coordinate.md@@ -8,6 +8,11 @@ branch and stop there. A review step then reads what you committed in a fresh cofixes what it finds, and a finalise step pushes the branch and opens or updates the pullrequest. So: **never `git push`, and never run `gh pr create`.**+Committing is not the only thing you can do, though, and it is often not the useful one.+Answering a question, saying what you could not work out, recording what you learnt on the+issue and filing what you found but should not fix here are all first-class outcomes —+section 2 lists them alongside the ones that write code.+The prompt carries:- `ISSUE_NUMBER` — `$N` below.@@ -57,19 +62,59 @@ growing this pull request past its budget.**Fix the failing checks.** `gh pr checkout $PULL_REQUEST`, reproduce the failure locally,fix the cause, commit. Never make a check pass by weakening or deleting the test that-caught the problem.+caught the problem. If the failure is not the branch's — a flake, or something broken in+the environment — say so on the pull request with the evidence and commit nothing, rather+than committing a change that pretends to fix it.**Rebase onto main.** The branch conflicts. `gh pr checkout $PULL_REQUEST`, then`git rebase origin/main`, resolve, re-run both gates. Say in your final message that thebranch was rebased, so the finalise step force-pushes rather than failing on a non-fast-forward.+**Answer the question, and commit nothing.** The feedback asks about the change rather+than asking for a change to it: why it was done this way, whether something was+considered, what a test actually covers. Work the answer out from the code — not from what+the pull request body claims — and post it on the thread it was asked on:++```+gh pr comment $PULL_REQUEST --body "..."+gh api repos/$REPOSITORY/pulls/comments/<comment-id>/replies -f body="..." # inline thread+```++Say what you looked at, so the reviewer can check the answer rather than take it. If+working it out shows the reviewer was right, make the change instead: an articulate+explanation of a mistake is worth nothing.+**Ask, and commit nothing.** The issue or the feedback is too ambiguous to act on withoutguessing. Post the specific questions that block you with `gh issue comment $N` (or`gh pr comment $PULL_REQUEST`), and stop. Guessing wastes a review; a question does not.+Two things can go with any of the above, and neither is an action on its own:++**Record what you found out, on the issue.** `gh issue comment $N` when the run turned up+something the next run or a human needs and the pull request is the wrong place for it: a+plan section that cannot be built as written, a constraint the issue does not mention, a+failure you could not reproduce. These runs have no memory between them, so the thread is+the only place a finding survives. Correct the issue's own description only when a+maintainer asked you to (`gh issue edit $N`), and never rewrite what someone else wrote —+saying in a comment that the description is out of date is honest; quietly replacing it is+not.++**File a follow-up issue.** Something real turned up that this issue is not about: a bug+you noticed while reading the code, a request from a reviewer that belongs to a different+change. Search for it first with `gh issue list --search "<terms>" --state all`, then+`gh issue create`: say what you saw, where, and how you noticed it, and link this issue+and the pull request. Leave it unlabelled. An issue reaches these queues only when+someone with write access labels it, and an automation that could label its own would be+feeding itself. At most one per run, and never for a style preference, for something a+plan section already covers, or for anything you could simply have fixed here.+Committing nothing is a valid outcome. The review and finalise steps are skipped when the-run leaves no new commit, and the item stays queued for whenever the answer arrives.+run leaves no new commit, and on a pull request the workflow then comments to say the run+changed nothing — which is also what stops the same red checks or the same unanswered+review selecting this pull request on every trigger from here to eternity. Nothing else+happens until a new commit lands or someone says something new, so whatever you post+before you stop is all a human has to go on: make it specific.## 3. Both gates must pass before you stop@@ -90,10 +135,17 @@ Your final message is what the finalise step writes the pull request body from.action you took and why, what changed, what you deliberately did not do, and the actualresults of the two gates.+If you committed nothing, no later step runs and nobody reads that message. Everything a+human needs has to be in what you posted on the issue or the pull request before you+stopped.+## Rules- Never `git push`. Never `gh pr create`. The finalise step does both.-- Do not merge anything, do not close the issue, do not change labels.+- Do not merge anything, and do not close the issue — the pull request closes it, by+ saying `Closes #$N` when it finishes the last section of the plan.+- Do not add or remove labels, on this issue or on one you file. Labels are how a human+ says what the automation may pick up, and `claude: stuck` is the workflow's own.- One action per run, and one pull request open per issue at a time.- At most about 500 added lines including tests, excluding `uv.lock`, `devdata/`,`front-end/` build output and `docs/plans/`.diff --git a/.github/claude/finalise-pull-request.md b/.github/claude/finalise-pull-request.mdindex c19c6fa..76f84bf 100644--- a/.github/claude/finalise-pull-request.md+++ b/.github/claude/finalise-pull-request.md@@ -6,7 +6,18 @@ are the only step that is allowed to push.`ISSUE_NUMBER` is in the prompt; `$N` below means that number.-## 1. Verify before you publish+## 1. Read what the earlier steps reported++Each step of this pipeline is a fresh session, so the only thing you know about the two+before you is what they wrote down. `BUILD_SUMMARY` and `REVIEW_SUMMARY` in the prompt are+the paths of their final messages — the build step's, and the review step's. Read both.++That is what the body describes, and it is the only honest source for it. An empty file+means that step left no final message; write that it reported nothing rather than+inventing what it might have found. Their claims about the gates are theirs, not yours:+section 2 is where you measure that for yourself.++## 2. Verify before you publishNothing on this branch has been checked since the last commit landed, so check it:@@ -19,7 +30,7 @@ Both must pass. If either fails, **push nothing** — say exactly what fails inmessage and stop. A pull request that does not build blocks every later part of the issue,and a branch that was never pushed costs nothing to redo.-## 2. Check the size budget+## 3. Check the size budget```git diff --numstat origin/main...HEAD@@ -29,7 +40,7 @@ Sum the added lines, ignoring `uv.lock`, `poetry.lock`, `devdata/`, `front-end/`output and `docs/plans/`. Over 500 is a problem to report in the body, not to fix byrewriting the change at this stage — say so plainly so the reviewer can decide.-## 3. Check the plan bookkeeping+## 4. Check the plan bookkeepingIf `docs/plans/issue-$N-*.md` exists, the build step should have either appended ` (Done)`to exactly one section heading, or `git rm`-ed the file when it built the last section. If@@ -38,7 +49,7 @@ it — otherwise the next run rebuilds the same section.A plan branch (`claude/issue-$N-plan`) adds the plan file and changes nothing else.-## 4. Push+## 5. Push```git push -u origin $(git branch --show-current)@@ -47,7 +58,7 @@ git push -u origin $(git branch --show-current)If the build step said it rebased the branch, use `--force-with-lease` instead — a rebasecannot fast-forward. Otherwise never force-push.-## 5. Open or update the pull request+## 6. Open or update the pull request```gh pr list --head "$(git branch --show-current)" --state open --json numberdiff --git a/.github/scripts/record-claude-run.sh b/.github/scripts/record-claude-run.shindex 2f01b3b..deb1ea7 100755--- a/.github/scripts/record-claude-run.sh+++ b/.github/scripts/record-claude-run.sh@@ -1,12 +1,18 @@#!/usr/bin/env bash#-# Append one Claude step's outcome and its result message to $CLAUDE_RUN_LOG.+# Append one Claude step's outcome and its result message to $CLAUDE_RUN_LOG, and leave+# its final message where a later step can read it.## claude-code-action writes every step's messages to the same path under $RUNNER_TEMP and# overwrites it, so a step's result has to be copied out before the next step runs. The# log this builds is what tells a step that never reached the model from one where Claude# ran and genuinely failed; see classify-claude-run.sh.#+# The final message is copied out for a second reason. Each step is a fresh session that+# can see nothing of the one before it, and the finalise step is asked to write a pull+# request body describing what the build and the review did — which it can only do if it+# is handed what they said. Its prompt points at these files.+## $OUTCOME and $EXECUTION_FILE come from the step being recorded, as# steps.<id>.outcome and steps.<id>.outputs.execution_file.@@ -14,6 +20,7 @@ set -euo pipefailstep="$1"log="${CLAUDE_RUN_LOG:?}"+summary_dir="${CLAUDE_SUMMARY_DIR:?}"# A step that was skipped, or one that died before Claude produced anything, leaves no# execution file. An empty result is how the classifier sees "nothing to go on".@@ -25,3 +32,8 @@ fijq -nc --arg step "$step" --arg outcome "$OUTCOME" --argjson result "$result" \'{step: $step, outcome: $outcome, result: $result}' | tee -a "$log"++# An empty file rather than a missing one: the step that reads it should see that this+# step reported nothing, not have to guess whether the path is right.+mkdir -p "$summary_dir"+jq -r '.result // ""' <<<"$result" >"$summary_dir/$step.md"diff --git a/.github/scripts/report-no-change.sh b/.github/scripts/report-no-change.shnew file mode 100755index 0000000..bc9e4d2--- /dev/null+++ b/.github/scripts/report-no-change.sh@@ -0,0 +1,33 @@+#!/usr/bin/env bash+#+# Say on the pull request that this run changed nothing, and why it was woken.+#+# The comment is load-bearing rather than courtesy. The selector's queues are pure+# functions of repository state, so a run that ends without committing leaves exactly the+# state that selected it: the same red checks, the same unanswered review. Without a record+# that the automation has already had its turn at this commit, the item would be selected+# again on the next trigger and on every scheduled run after that, at three Opus steps a+# time, for as long as the reason stood.+#+# So this is what bounds the retries: select-claude-work.sh stops counting failing checks+# and conflicts once a report is newer than the last commit, and counts feedback only from+# after it. A new commit, or a human replying, is what starts the pull request moving+# again.+#+# The marker string has to stay in step with the one select-claude-work.sh looks for.++set -euo pipefail++pull_request="${PULL_REQUEST:?}"+reason="${REASON:?}"+readonly marker='<!-- claude-run: no change -->'++gh pr comment "$pull_request" --body "This run looked at the pull request and left the+branch as it found it.++It was woken because: $reason.++It will not try again by itself at this commit — pushing a commit here, or replying, is+what wakes it.++$marker"diff --git a/.github/scripts/select-claude-work.sh b/.github/scripts/select-claude-work.shindex f8dec31..a5a6ad3 100755--- a/.github/scripts/select-claude-work.sh+++ b/.github/scripts/select-claude-work.sh@@ -21,6 +21,10 @@# such an issue is no longer simply skipped — an unanswered review is the most valuable# thing the automation can pick up, because it is what a human is waiting on.#+# Pull requests from forks are not the automation's to work on and are ignored throughout,+# branch name notwithstanding: a fork's branch is code nobody here has reviewed, and the+# workflow could not check it out with a working token even if it wanted to.+## The one label the automation writes is "claude: stuck", added by the workflow when a run# fails for a reason that is not a usage limit. Items on a stuck issue are skipped so a# broken item cannot burn the budget on every scheduled run; a human removes the label, or@@ -42,47 +46,82 @@ readonly max_items="${CLAUDE_MAX_ITEMS:-3}"readonly only_issue="${CLAUDE_ONLY_ISSUE:-}"open_issues=$(gh issue list --state open --limit 200 --json number,title,labels)-open_branches=$(gh pr list --state open --limit 200 --json headRefName --jq '.[].headRefName')+open_pull_requests=$(gh pr list --state open --limit 200 \+ --json number,headRefName,isCrossRepository \+ --jq '[.[] | select(.isCrossRepository | not)]')++# What a run that changed nothing leaves behind, so that it is not asked the same question+# on the next trigger and every scheduled run after it. Written by+# .github/scripts/report-no-change.sh — the two strings have to stay in step.+readonly no_change_marker='<!-- claude-run: no change -->'-# What needs answering on one open pull request, if anything. Feedback counts only from an-# OWNER, MEMBER or COLLABORATOR — a drive-by comment on a public repository must not be-# able to steer a run — and only when it is newer than the last commit on the branch, which-# is what "already addressed" means here. A review carrying inline comments and no body-# still arrives as a review with a submittedAt, so inline-only feedback is caught too.+# What needs answering on one open pull request, if anything.+#+# Feedback counts only from an OWNER, MEMBER or COLLABORATOR — a drive-by comment on a+# public repository must not be able to steer a run — and only when it is newer than the+# last commit on the branch, which is what "already addressed" means here. A review+# carrying inline comments and no body still arrives as a review with a timestamp, so+# inline-only feedback is caught too.+#+# The last thing a run said about the current commit bounds the retries. A run that ends+# without committing changes nothing the queues are derived from, so failing checks it+# could not fix, or a question it could not answer without guessing, would select this+# pull request again on every trigger for as long as they stood. Once it has reported on a+# commit, the mechanical reasons stop counting for that commit and only something said+# after the report counts as feedback — a new commit, or a human replying, is what starts+# it again.+#+# Comments and reviews come from the REST API rather than from `gh pr view`, which is the+# only one of the two that says whether an author is a bot: GraphQL gives a Bot actor a+# login without the "[bot]" suffix, so a suffix test against gh's projection silently+# matches nothing and the automation reads its own comments as a maintainer's.## Asked per pull request rather than across the list: `gh pr list --json commits` walks# every author of every commit of every open pull request, which exceeds GitHub's GraphQL# node limit on a repository this size.readonly reason_filter='def is_maintainer:- (.authorAssociation | . == "OWNER" or . == "MEMBER" or . == "COLLABORATOR")- and (.author.login | endswith("[bot]") | not);--{ last_commit: (.commits | last | .committedDate),- feedback: ([ (.reviews[] | select(is_maintainer) | .submittedAt),- (.comments[] | select(is_maintainer) | .createdAt) ] | max),- failing: [ .statusCheckRollup[] | select(.conclusion == "FAILURE") | .name ],- conflicting: (.mergeable == "CONFLICTING") }-| [ (if .feedback != null and .feedback > .last_commit+ (.author_association | . == "OWNER" or . == "MEMBER" or . == "COLLABORATOR")+ and (.user.type != "Bot");++($state.commits | last | .committedDate) as $last_commit+| ([ $comments[]+ | select(.user.type == "Bot")+ | select(.body | contains($marker))+ | .created_at ] | max) as $reported+| ([ ($reviews[] | select(is_maintainer) | .submitted_at),+ ($comments[] | select(is_maintainer) | .created_at) ] | max) as $feedback+| ($reported != null and $reported > $last_commit) as $already_reported+| [ (if $feedback != null and $feedback > $last_commit+ and ($reported == null or $feedback > $reported)then "unanswered feedback" else empty end),- (if (.failing | length) > 0- then "failing checks: " + (.failing | join(", ")) else empty end),- (if .conflicting then "conflicts with main" else empty end) ]+ (if $already_reported then empty+ else ([ $state.statusCheckRollup[] | select(.conclusion == "FAILURE") | .name ]+ | if length > 0 then "failing checks: " + join(", ") else empty end)+ end),+ (if $state.mergeable == "CONFLICTING" and ($already_reported | not)+ then "conflicts with main" else empty end) ]| join("; ")'-reason_to_respond() {- gh pr view "$1" --json mergeable,statusCheckRollup,reviews,comments,commits \- --jq "$reason_filter"+# `gh api --paginate` prints one JSON document per page, which jq -s puts back together.+whole_of() {+ gh api "$1" --paginate | jq -s 'add // []'}-pull_request_for() {- gh pr list --state open --limit 200 --json number,headRefName \- --jq ".[] | select(.headRefName | startswith(\"claude/issue-$1-\")) | .number" | head -1+reason_to_respond() {+ local state comments reviews+ state=$(gh pr view "$1" --json mergeable,statusCheckRollup,commits)+ comments=$(whole_of "repos/{owner}/{repo}/issues/$1/comments")+ reviews=$(whole_of "repos/{owner}/{repo}/pulls/$1/reviews")+ jq -nr --argjson state "$state" --argjson comments "$comments" \+ --argjson reviews "$reviews" --arg marker "$no_change_marker" "$reason_filter"}-has_open_pull_request() {- grep -qE "^claude/issue-$1-" <<<"$open_branches"+pull_request_for() {+ jq -r --arg prefix "claude/issue-$1-" \+ 'map(select(.headRefName | startswith($prefix))) | first | .number // empty' \+ <<<"$open_pull_requests"}plan_file_for() {@@ -141,8 +180,9 @@ while IFS=$'\t' read -r number title labels; do'{issue: $issue, title: $title, kind: $kind, pr: $pr, reason: $reason}')"}- if has_open_pull_request "$number"; then- pull_request=$(pull_request_for "$number")+ pull_request=$(pull_request_for "$number")++ if [[ -n $pull_request ]]; thenreason=$(reason_to_respond "$pull_request")if [[ -n $reason ]]; thenrespond_items+=("$(emit respond "$pull_request" "$reason")")diff --git a/.github/workflows/claude-issues.yml b/.github/workflows/claude-issues.ymlindex 2728072..5ac21cc 100644--- a/.github/workflows/claude-issues.yml+++ b/.github/workflows/claude-issues.yml@@ -3,11 +3,13 @@ name: Claude issue automation# Turns triaged issues into pull requests, and keeps the pull requests it opened moving.## A run picks up one issue and decides what it needs — write a plan, build the next part,-# answer a review, fix red checks, rebase, or ask a question — then builds it, reviews it-# in a fresh context, and opens or updates the pull request. The three Claude steps below-# are that pipeline; .github/scripts/select-claude-work.sh decides what to point it at and-# .github/claude/*.md is what each step is told. See docs/plans/README.md for the plan-# format the queues are derived from.+# answer a review, fix red checks, rebase, answer a question, ask one, or file what it+# found and should not fix here — then builds it, reviews it in a fresh context, and opens+# or updates the pull request. Changing no code is a normal outcome, and one a run says out+# loud rather than ending in silence. The three Claude steps below are that pipeline;+# .github/scripts/select-claude-work.sh decides what to point it at and .github/claude/*.md+# is what each step is told. See docs/plans/README.md for the plan format the queues are+# derived from.## Only one claude/issue-<N>-* pull request is ever open per issue. It no longer blocks the# issue, though: while it is open the only thing the automation may do to that issue is@@ -82,19 +84,28 @@ jobs:# access must never be able to start a run on a public repository, so a comment or# review only counts from an OWNER, MEMBER or COLLABORATOR, and never from a bot —# which is also what stops the automation waking itself with its own comments.+ #+ # A pull request from a fork is out of scope for the same reason, and for a practical+ # one: GitHub gives a fork's pull_request event no secrets and a read-only token+ # whatever the permissions block above says, so CLAUDE_CODE_OAUTH_TOKEN would be+ # empty, every Claude step would fail and the classifier's label write would 403.if: >-(github.event_name != 'issues' || github.event.action != 'labeled'|| github.event.label.name == 'ready to plan'|| github.event.label.name == 'ready to code')- && (github.event_name != 'pull_request' || github.event.pull_request.merged)+ && (github.event_name != 'pull_request'+ || (github.event.pull_request.merged+ && github.event.pull_request.head.repo.full_name == github.repository))&& (github.event_name != 'issue_comment'|| (contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)&& !endsWith(github.event.comment.user.login, '[bot]')))&& (github.event_name != 'pull_request_review'|| (startsWith(github.event.pull_request.head.ref, 'claude/')+ && github.event.pull_request.head.repo.full_name == github.repository&& contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.review.author_association)))&& (github.event_name != 'pull_request_review_comment'|| (startsWith(github.event.pull_request.head.ref, 'claude/')+ && github.event.pull_request.head.repo.full_name == github.repository&& contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)))&& (github.event_name != 'workflow_run'|| (github.event.workflow_run.conclusion == 'failure'@@ -111,6 +122,8 @@ jobs:steps:- name: Check out repositoryuses: actions/checkout@v4+ with:+ ref: ${{ github.event_name == 'pull_request' && 'main' || github.ref }}# Read-only listing, so the default workflow token is enough here.- name: Select the work to act onid: select@@ -153,25 +166,30 @@ jobs:- 5432:5432env:- CLAUDE_RUN_LOG: ${{ github.workspace }}/claude-runs.jsonl+ # Outside the checkout, both of these. The review and finalise steps run git with an+ # unrestricted Bash tool and are asked to commit; a file sitting untracked in the+ # working tree is one `git add -A` away from being part of the pull request.+ CLAUDE_RUN_LOG: ${{ runner.temp }}/claude-runs.jsonl+ CLAUDE_SUMMARY_DIR: ${{ runner.temp }}/claude-summariesISSUE_NUMBER: ${{ matrix.item.issue }}steps:- # Full history: every step diffs the branch against main.+ # Full history: every step diffs the branch against main, and the step below+ # compares HEAD against the branch's own remote tip.+ #+ # The ref is pinned because `pull_request` hands github.ref as refs/pull/<n>/merge:+ # a ref GitHub stops guaranteeing once the pull request closes, and a snapshot of a+ # merge that is not main even when it does resolve. Every other trigger here already+ # resolves to the default branch, and workflow_dispatch keeps the branch it was+ # dispatched on so this pipeline can be tested from one.- name: Check out repositoryuses: actions/checkout@v4with:+ ref: ${{ github.event_name == 'pull_request' && 'main' || github.ref }}fetch-depth: 0- name: Set up the projectuses: ./.github/actions/setup-project- # What "the build committed something" is measured against. Taken before the first- # step rather than derived from the branch, because a run answering review feedback- # checks out a branch that already has commits on it.- - name: Note the starting commit- id: start- run: echo "sha=$(git rev-parse HEAD)" >>"$GITHUB_OUTPUT"-# No github_token input on any Claude step: the action then authenticates as the# Claude GitHub App, which sets GH_TOKEN and the git credentials for Claude and,# unlike the workflow token, lets CI run on the pull requests it pushes.@@ -217,16 +235,31 @@ jobs:# Derived from git state rather than from anything a step has to remember to set, so# a rerun is as harmless as the selector's queues are. A run that committed nothing —- # it asked a question, or found the work already done — skips the rest of the job.+ # it asked a question, answered one, or found the work already done — skips the rest+ # of the job.+ #+ # Measured against the branch's own published tip rather than against the commit this+ # job checked out. A `respond` run starts with `gh pr checkout`, which moves HEAD to+ # commits that are already pushed and already reviewed: comparing against where the+ # job started would call every one of those runs a build.- name: Did the run commit anything?id: builtrun: |- if [[ $(git rev-parse HEAD) != "${{ steps.start.outputs.sha }}" \- && $(git branch --show-current) == claude/* ]]; then- echo "built=true" >>"$GITHUB_OUTPUT"- else+ branch=$(git branch --show-current)+ if [[ $branch != claude/* ]]; thenecho "built=false" >>"$GITHUB_OUTPUT"- echo "::notice::No new commit on a claude/* branch; nothing to review or push."+ echo "::notice::Not on a claude/* branch; nothing to review or push."+ exit 0+ fi+ published="origin/$branch"+ if ! git rev-parse --verify --quiet "$published" >/dev/null; then+ published=origin/main+ fi+ if [[ $(git rev-parse HEAD) == $(git rev-parse "$published") ]]; then+ echo "built=false" >>"$GITHUB_OUTPUT"+ echo "::notice::$branch is unchanged from $published; nothing to review or push."+ else+ echo "built=true" >>"$GITHUB_OUTPUT"fi# A fresh context is the whole point: this step has no memory of the reasoning that@@ -263,9 +296,18 @@ jobs:# The only step allowed to push. It re-runs both gates first, so the pull request# body describes the code as it stands after the review rather than before it.+ #+ # The review step is continue-on-error, so a review that ran out of turns part-way+ # through a fix ends red having left the branch mid-change. Publishing that is the+ # "opens a pull request nobody reviewed" failure the review step exists to prevent,+ # so its outcome gates this step exactly as the build's does. When review is skipped+ # this step is skipped too: both are guarded on the same build.- name: Open or update the pull requestid: finalise- if: steps.built.outputs.built == 'true' && steps.coordinate.outcome == 'success'+ if: >-+ steps.built.outputs.built == 'true'+ && steps.coordinate.outcome == 'success'+ && steps.review.outcome == 'success'uses: anthropics/claude-code-action@v1continue-on-error: trueenv:@@ -281,6 +323,8 @@ jobs:ISSUE_NUMBER: ${{ matrix.item.issue }}ISSUE_TITLE: ${{ matrix.item.title }}REPOSITORY: ${{ github.repository }}+ BUILD_SUMMARY: ${{ runner.temp }}/claude-summaries/coordinate.md+ REVIEW_SUMMARY: ${{ runner.temp }}/claude-summaries/review.mdclaude_args: |--model claude-opus-5--max-turns 30@@ -297,9 +341,25 @@ jobs:uses: actions/upload-artifact@v4with:name: claude-run-${{ matrix.item.issue }}- path: claude-runs.jsonl+ path: ${{ runner.temp }}/claude-runs.jsonlif-no-files-found: ignore+ # A run that changes nothing leaves the repository exactly as the selector found+ # it, so the same red checks or the same unanswered review would select this pull+ # request again on the next trigger, and on every scheduled run after that, at three+ # Opus steps a time. This comment is the record that stops it; select-claude-work.sh+ # reads it as "this commit has already had its turn".+ - name: Say on the pull request that nothing changed+ if: >-+ matrix.item.kind == 'respond'+ && steps.coordinate.outcome == 'success'+ && steps.built.outputs.built != 'true'+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ PULL_REQUEST: ${{ matrix.item.pr }}+ REASON: ${{ matrix.item.reason }}+ run: .github/scripts/report-no-change.sh+- name: Report how the run endedif: always()env:diff --git a/test/test_claude_automation_workflow.py b/test/test_claude_automation_workflow.pyindex 43e3a98..ff0c304 100644--- a/test/test_claude_automation_workflow.py+++ b/test/test_claude_automation_workflow.py@@ -15,6 +15,8 @@ import yamlREPOSITORY_ROOT = Path(__file__).resolve().parent.parentWORKFLOW_PATH = REPOSITORY_ROOT / ".github/workflows/claude-issues.yml"+SELECTOR_PATH = REPOSITORY_ROOT / ".github/scripts/select-claude-work.sh"+REPORTER_PATH = REPOSITORY_ROOT / ".github/scripts/report-no-change.sh"CLAUDE_ACTION = "anthropics/claude-code-action@v1"# yaml.safe_load reads the `on:` key as the boolean True, per YAML 1.1.@@ -69,6 +71,35 @@ def test_review_and_finalise_run_only_on_a_successful_build(claude_steps: list[dassert "steps.coordinate.outcome == 'success'" in guard, step["id"]+def test_nothing_is_published_over_a_review_that_did_not_finish(claude_steps: list[dict]) -> None:+ """The review step is continue-on-error, so one that ran out of turns half-way through+ a fix ends red having left the branch mid-change. Pushing that is exactly the pull+ request nobody reviewed."""+ assert "steps.review.outcome == 'success'" in claude_steps[2]["if"]+++def test_a_build_is_measured_against_the_branch_not_against_the_checkout(+ work_steps: list[dict],+) -> None:+ """A respond run starts with `gh pr checkout`, which moves HEAD to commits that are+ already pushed: measured against where the job started, every one of those runs would+ count as a build and be reviewed and pushed again."""+ built = next(step for step in work_steps if step.get("id") == "built")+ assert "origin/$branch" in built["run"]+ assert "steps.start" not in built["run"]+++def test_the_finalise_step_is_told_what_the_earlier_steps_reported(claude_steps: list[dict]) -> None:+ """It writes the pull request body from them, and each step is a fresh session that can+ see nothing of the last one."""+ prompt = claude_steps[2]["with"]["prompt"]+ assert "BUILD_SUMMARY" in prompt+ assert "REVIEW_SUMMARY" in prompt+ instructions = (REPOSITORY_ROOT / ".github/claude/finalise-pull-request.md").read_text()+ assert "BUILD_SUMMARY" in instructions+ assert "REVIEW_SUMMARY" in instructions++def test_every_claude_step_is_recorded_so_a_failure_can_be_classified(work_steps: list[dict],) -> None:@@ -130,6 +161,73 @@ def test_comment_and_review_triggers_require_write_access(workflow: dict) -> Nonassert '"OWNER","MEMBER","COLLABORATOR"' in clause.split("&& (github.event_name")[0]+def test_nothing_the_runs_write_lands_inside_the_checkout(workflow: dict) -> None:+ """The review and finalise steps run git with an unrestricted Bash tool and are asked+ to commit; an untracked file in the working tree is one `git add -A` from the diff."""+ for name, value in workflow["jobs"]["work"]["env"].items():+ if name.startswith("CLAUDE_") and "/" in value:+ assert value.startswith("${{ runner.temp }}"), name+++def test_no_checkout_lands_on_the_pull_request_merge_ref(workflow: dict) -> None:+ """`pull_request` hands github.ref as refs/pull/<n>/merge, which GitHub stops+ guaranteeing once the pull request closes — and which is not main even when it+ resolves."""+ checkouts = [+ step+ for job in workflow["jobs"].values()+ for step in job["steps"]+ if str(step.get("uses", "")).startswith("actions/checkout")+ ]+ assert checkouts+ for checkout in checkouts:+ assert "github.event_name == 'pull_request'" in checkout["with"]["ref"]+++def test_only_pull_requests_from_this_repository_start_a_run(workflow: dict) -> None:+ """A fork's pull_request event gets no secrets and a read-only token whatever the+ permissions block says, so every step of the run would fail in public."""+ guard = workflow["jobs"]["select"]["if"]+ for event in ("pull_request", "pull_request_review", "pull_request_review_comment"):+ clause = guard.split(f"github.event_name != '{event}'")[1].split("&& (github.event_name")[0]+ assert "head.repo.full_name == github.repository" in clause, event+++def test_a_run_that_changes_nothing_says_so_on_the_pull_request(work_steps: list[dict]) -> None:+ """It is the only record such a run leaves. Without it the same red checks select the+ same pull request on every trigger and every scheduled run, for as long as they are+ red."""+ reporter = next(+ step for step in work_steps if step.get("run", "").startswith(".github/scripts/report-no-change.sh")+ )+ guard = reporter["if"]+ assert "matrix.item.kind == 'respond'" in guard+ assert "steps.built.outputs.built != 'true'" in guard+++def test_the_selector_looks_for_the_marker_the_reporter_writes() -> None:+ """Two files, one string: if they drift apart the retries stop being bounded and+ nothing says so."""+ marker = "<!-- claude-run: no change -->"+ assert marker in REPORTER_PATH.read_text()+ assert marker in SELECTOR_PATH.read_text()+++def test_feedback_is_read_from_an_api_that_identifies_bots() -> None:+ """gh's GraphQL projection gives a Bot author a login without the "[bot]" suffix, so a+ suffix test there matches nothing and the automation reads its own comments as a+ maintainer's. REST says user.type."""+ selector = SELECTOR_PATH.read_text()+ assert '.user.type != "Bot"' in selector+ assert 'endswith("[bot]")' not in selector+++def test_forks_are_not_the_automations_to_work_on() -> None:+ """A fork's branch may be named claude/issue-N-anything, and is code nobody here has+ reviewed."""+ assert "isCrossRepository" in SELECTOR_PATH.read_text()++def test_referenced_scripts_are_executable(work_steps: list[dict], workflow: dict) -> None:steps = work_steps + workflow["jobs"]["select"]["steps"]scripts = {step["run"].split()[0] for step in steps if step.get("run", "").startswith(".github/")}