Backtestshugorun-20261009-153657#15261

Issue #15261 Merged fix PR #15262 Run 9 Oct 2026 · run-20261009-153657 gohugoio/hugo

github: Fix workflow for stale issues

Worse

The merged fix was judged better than our patch.

In this judgment, Patch B = our agent, Patch A = the merged fix.

The failure comes from input validation inside dessant/lock-threads v6.0.0: it rejects any github-token longer than 100 characters, and GitHub's tokens now exceed that. Patch A pins the action to a newer patch release (v6.0.2) by commit SHA and changes nothing else. A patch release published after the breakage is the natural place for the upstream fix that relaxes this validation, so A addresses the root cause in the dependency. It keeps the existing, well-exercised behavior: pagination limits, rate-limit handling, filtering, and the configured labels and comments. The diff alone can't prove v6.0.2 contains the fix, which leaves some uncertainty, but the change is minimal, low-risk and easy to review.

Patch B replaces the action with a 75-line custom bash script, a sparse checkout step and a Go test in the root `main` package. The script appears functional, but it re-implements an established action and brings new risks:
- The search API caps results at 1000, which matters on the first 21-day run.
- Comment, label and lock run as separate non-atomic calls, so a mid-loop failure under `set -e` leaves items commented or labeled but unlocked.
- Rate-limit handling is a fixed sleep.
- The script now needs ongoing maintenance in the Hugo repo.

B's test does exercise the script against a stubbed `gh`, but most of it checks B's own replacement logic rather than the original bug. It also puts a CI-workflow test into the main Go test suite, which is unrelated churn. Under the scope criterion, B's broader redesign adds risk and obscures what is a one-line dependency bump. A is the better fix: correct at the root, minimal and consistent with how the workflow already pins actions.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

27m 54s

Wall-clock time in the container

Full test suite

No new failures

63 passed · 2 skipped · 65 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

190vs 2 merged

Changed lines, ours vs merged

The workflow began failing on 26 May 2026:

<https://github.com/gohugoio/hugo/actions/runs/26486945788>

"github-token" length must be less than or equal to 100 characters long

The two patches

Our patch+185 −5
.github/scripts/lock-threads.shnew file mode 100755index 000000000..e2a53be68@@ -0,0 +1,75 @@+#!/usr/bin/env bash+#+# Locks closed issues and pull requests that have had no recent activity.+#+# This replaces dessant/lock-threads, which rejects GitHub tokens longer+# than 100 characters (GitHub's tokens now exceed that).+#+# Requires the gh CLI with GH_TOKEN set. Configured via environment:+#+#   GITHUB_REPOSITORY    owner/repo (set by GitHub Actions)+#   ISSUE_INACTIVE_DAYS  lock issues not updated in this many days (default 365)+#   PR_INACTIVE_DAYS     lock PRs not updated in this many days (default 365)+#   ISSUE_LABELS         comma-separated labels to add to locked issues+#   ISSUE_COMMENT        comment to post on locked issues+#   PR_COMMENT           comment to post on locked PRs+#   LOCK_REASON          lock reason (default resolved)+#   LOCK_DELAY           seconds to wait between items, to stay under+#                        GitHub's secondary rate limits (default 3)++set -euo pipefail++: "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY must be set}"++ISSUE_INACTIVE_DAYS="${ISSUE_INACTIVE_DAYS:-365}"+PR_INACTIVE_DAYS="${PR_INACTIVE_DAYS:-365}"+ISSUE_LABELS="${ISSUE_LABELS:-}"+ISSUE_COMMENT="${ISSUE_COMMENT:-}"+PR_COMMENT="${PR_COMMENT:-}"+LOCK_REASON="${LOCK_REASON:-resolved}"+LOCK_DELAY="${LOCK_DELAY:-3}"++# lock_threads TYPE INACTIVE_DAYS LABELS COMMENT+lock_threads() {+	local type="$1" days="$2" labels="$3" comment="$4"+	local cutoff query numbers number label+	local -a label_list=()++	if [[ ! "$days" =~ ^[0-9]+$ ]]; then+		echo "invalid inactive days for $type: $days" >&2+		return 1+	fi++	# GNU date, falling back to BSD date (macOS).+	cutoff="$(date -u -d "-${days} days" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null ||+		date -u -v-"${days}"d +%Y-%m-%dT%H:%M:%SZ)"+	query="repo:${GITHUB_REPOSITORY} is:${type} is:closed is:unlocked updated:<${cutoff}"++	# Collect all results before mutating anything; locking an item updates+	# it and would otherwise shift the search pages under us.+	numbers="$(gh api -X GET search/issues -f q="$query" -f per_page=100 --paginate --jq '.items[].number')"++	if [[ -n "$labels" ]]; then+		IFS=',' read -r -a label_list <<<"$labels"+	fi++	for number in $numbers; do+		echo "Locking ${type} #${number}"+		if [[ -n "$comment" ]]; then+			gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${number}/comments" -f body="$comment" >/dev/null+		fi+		# The ${arr[@]+...} form avoids an unbound variable error on bash < 4.4.+		for label in ${label_list[@]+"${label_list[@]}"}; do+			label="${label#"${label%%[![:space:]]*}"}"+			label="${label%"${label##*[![:space:]]}"}"+			if [[ -n "$label" ]]; then+				gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${number}/labels" -f "labels[]=${label}" >/dev/null+			fi+		done+		gh api -X PUT "repos/${GITHUB_REPOSITORY}/issues/${number}/lock" -f lock_reason="$LOCK_REASON" >/dev/null+		sleep "$LOCK_DELAY"+	done+}++lock_threads issue "$ISSUE_INACTIVE_DAYS" "$ISSUE_LABELS" "$ISSUE_COMMENT"+lock_threads pr "$PR_INACTIVE_DAYS" "" "$PR_COMMENT".github/workflows/stale.ymlindex 89dbdde7d..b818b4cbc 100644@@ -8,19 +8,27 @@ permissions: jobs:   stale:     permissions:+      contents: read       issues: write       pull-requests: write     runs-on: ubuntu-latest     steps:-      - uses: dessant/lock-threads@f5f995c727ac99a91dec92781a8e34e7c839a65e # v6.0.0+      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2         with:-          issue-inactive-days: 21-          add-issue-labels: 'Outdated'-          issue-comment: >+          persist-credentials: false+          sparse-checkout: .github/scripts+      - name: Lock closed issues and PRs+        run: bash .github/scripts/lock-threads.sh+        env:+          GH_TOKEN: ${{ github.token }}+          ISSUE_INACTIVE_DAYS: 21+          PR_INACTIVE_DAYS: 365+          ISSUE_LABELS: 'Outdated'+          ISSUE_COMMENT: >             This issue has been automatically locked since there             has not been any recent activity after it was closed.             Please open a new issue for related bugs.-          pr-comment: >+          PR_COMMENT: >             This pull request has been automatically locked since there             has not been any recent activity after it was closed.             Please open a new issue for related bugs.github_workflows_test.gonew file mode 100644index 000000000..635e6ea59@@ -0,0 +1,97 @@+// Copyright 2026 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package main++import (+	"os"+	"os/exec"+	"path/filepath"+	"runtime"+	"strings"+	"testing"++	qt "github.com/frankban/quicktest"+)++const ghStub = `#!/usr/bin/env bash+printf '%s\n' "$*" >> "$GH_STUB_LOG"+case "$*" in+  *search/issues*is:issue*) printf '1\n2\n' ;;+  *search/issues*is:pr*) printf '3\n' ;;+esac+`++// The stale workflow must lock threads without an action that rejects+// GitHub tokens longer than 100 characters.+func TestStaleWorkflowLockThreads(t *testing.T) {+	if runtime.GOOS == "windows" {+		t.Skip("requires bash")+	}+	bash, err := exec.LookPath("bash")+	if err != nil {+		t.Skip("requires bash")+	}++	c := qt.New(t)++	workflow, err := os.ReadFile(filepath.Join(".github", "workflows", "stale.yml"))+	c.Assert(err, qt.IsNil)+	c.Assert(string(workflow), qt.Not(qt.Contains), "dessant/lock-threads")+	c.Assert(string(workflow), qt.Contains, "bash .github/scripts/lock-threads.sh")++	dir := t.TempDir()+	c.Assert(os.WriteFile(filepath.Join(dir, "gh"), []byte(ghStub), 0o755), qt.IsNil)+	logFile := filepath.Join(dir, "gh.log")++	cmd := exec.Command(bash, filepath.Join(".github", "scripts", "lock-threads.sh"))+	cmd.Env = append(os.Environ(),+		"PATH="+dir+string(os.PathListSeparator)+os.Getenv("PATH"),+		"GH_STUB_LOG="+logFile,+		"GH_TOKEN="+strings.Repeat("x", 200),+		"GITHUB_REPOSITORY=gohugoio/hugo",+		"ISSUE_INACTIVE_DAYS=21",+		"PR_INACTIVE_DAYS=365",+		"ISSUE_LABELS=Outdated",+		"ISSUE_COMMENT=Issue locked.",+		"PR_COMMENT=PR locked.",+		"LOCK_REASON=",+		"LOCK_DELAY=0",+	)+	out, err := cmd.CombinedOutput()+	c.Assert(err, qt.IsNil, qt.Commentf("%s", out))+	c.Assert(string(out), qt.Contains, "Locking issue #1")+	c.Assert(string(out), qt.Contains, "Locking issue #2")+	c.Assert(string(out), qt.Contains, "Locking pr #3")++	b, err := os.ReadFile(logFile)+	c.Assert(err, qt.IsNil)+	calls := strings.Split(strings.TrimSpace(string(b)), "\n")++	c.Assert(calls[0], qt.Contains, "q=repo:gohugoio/hugo is:issue is:closed is:unlocked updated:<")+	c.Assert(len(calls), qt.Equals, 10)+	c.Assert(calls[7], qt.Contains, "q=repo:gohugoio/hugo is:pr is:closed is:unlocked updated:<")++	c.Assert(calls, qt.DeepEquals, []string{+		calls[0],+		"api -X POST repos/gohugoio/hugo/issues/1/comments -f body=Issue locked.",+		"api -X POST repos/gohugoio/hugo/issues/1/labels -f labels[]=Outdated",+		"api -X PUT repos/gohugoio/hugo/issues/1/lock -f lock_reason=resolved",+		"api -X POST repos/gohugoio/hugo/issues/2/comments -f body=Issue locked.",+		"api -X POST repos/gohugoio/hugo/issues/2/labels -f labels[]=Outdated",+		"api -X PUT repos/gohugoio/hugo/issues/2/lock -f lock_reason=resolved",+		calls[7],+		"api -X POST repos/gohugoio/hugo/issues/3/comments -f body=PR locked.",+		"api -X PUT repos/gohugoio/hugo/issues/3/lock -f lock_reason=resolved",+	})+} 
Merged fix · PR #15262+1 −1
.github/workflows/stale.ymlindex 89dbdde7d..73e31f024 100644@@ -12,7 +12,7 @@ jobs:       pull-requests: write     runs-on: ubuntu-latest     steps:-      - uses: dessant/lock-threads@f5f995c727ac99a91dec92781a8e34e7c839a65e # v6.0.0+      - uses: dessant/lock-threads@89ae32b08ed1a541efecbab17912962a5e38981c # v6.0.2         with:           issue-inactive-days: 21           add-issue-labels: 'Outdated'