@@ -143,15 +143,43 @@ jobs:
143143 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
144144 REF_NAME : ${{ github.ref_name }}
145145 run : |
146+ # The search is only a coarse server-side filter. GitHub discards the brackets and
147+ # matches the remaining words as a phrase anywhere in the title, so this query also
148+ # returns PRs that merely mention the link checker rather than ones the checker
149+ # opened. Trusting its count lets an unrelated open PR suppress dispatch for as long
150+ # as it stays open, and it fails silently: the probe still scans, still sees the
151+ # changed links, and just declines to act. jq re-checks the real prefix so only a
152+ # PR the checker actually opened counts.
153+ #
154+ # The limit has to leave room for the whole coarse result set: this is a correctness
155+ # guard, and a prefixed PR truncated out of the window would look like "none open"
156+ # and dispatch a duplicate. gh pages through the API, so the value is a ceiling on
157+ # how many PRs we are willing to inspect, not a per-request cap.
146158 OPEN_PR_COUNT=$(gh pr list --state open --search '"[link-checker]" in:title' \
147- --limit 1 --json number --jq 'length')
159+ --limit 500 --json title \
160+ --jq '[.[] | select(.title | startswith("[link-checker] "))] | length')
148161
149162 if [ "$OPEN_PR_COUNT" -gt 0 ]; then
150163 echo "An HTTP link checker pull request is already open; skipping dispatch."
151164 echo "An HTTP link checker pull request is already open, so no new agent run was dispatched." >> "$GITHUB_STEP_SUMMARY"
152165 exit 0
153166 fi
154167
168+ # An agent run that has started but not yet opened its PR is invisible to the check
169+ # above, so look for one directly before adding a second. Scope it to the ref we
170+ # would dispatch on: a manual run on another branch is unrelated work, and letting
171+ # it count here would silently hold up the scheduled dispatch. The limit is generous
172+ # for the same reason as above — a burst of completed runs must not push the one
173+ # in-flight run out of the window and make it look idle.
174+ IN_FLIGHT=$(gh run list --workflow http-link-checker.lock.yml --branch "$REF_NAME" \
175+ --limit 200 --json status --jq '[.[] | select(.status != "completed")] | length')
176+
177+ if [ "$IN_FLIGHT" -gt 0 ]; then
178+ echo "An agentic HTTP link checker run is already in flight; skipping dispatch."
179+ echo "An agentic HTTP link checker run is already in flight, so no new agent run was dispatched." >> "$GITHUB_STEP_SUMMARY"
180+ exit 0
181+ fi
182+
155183 gh workflow run http-link-checker.lock.yml --ref "$REF_NAME"
156184 echo "Dispatched the agentic HTTP link checker." >> "$GITHUB_STEP_SUMMARY"
157185 shell : bash
0 commit comments