Skip to content

[q] fix(spec-enforcer): recover round-robin state from PRs when cache is empty #28072

@github-actions

Description

@github-actions

Q Workflow Optimization Report

Issue Found

Workflow: Package Specification Enforcer (spec-enforcer)

Run Analyzed: #24831118139 (run #10)

Problem: The agent's own log confirmed: "Since this is a new cache (just initialized), I need to do a round-robin selection." — despite this being run #10, the cache-memory was empty, causing the round-robin to restart from the beginning (processing actionpins and cli again instead of continuing from where a previous run left off).

The root cause: when cache-memory is empty (due to cache eviction, a first-time run, or any other reason), Phase 0 simply creates an empty directory with no rotation.json. Phase 1 then has no rotation state to read, so the agent silently restarts from index 0.

Change Made

File: .github/workflows/spec-enforcer.md

Added a step 3 to Phase 0 "Initialize or Load":

  • When rotation.json is missing, the agent now searches for the most recently merged PR with the pkg-specifications label
  • It parses the "Next packages in rotation" line from the PR body (which is written by every spec-enforcer run)
  • Uses this to reconstruct last_packages and last_index so the round-robin continues from where it left off
  • Falls back to starting at index -1 (beginning) only if no previous PR is found

This makes the round-robin state self-healing: even if cache is lost, the workflow recovers the correct starting point from its own PR history.

Expected Improvements

  • Round-robin no longer silently restarts from package actionpins every time cache is evicted
  • Consistent package coverage across runs — each package gets enforced in order before cycling back
  • No changes to Phase 1–5 logic; minimal, surgical fix

Validation

Compiled successfully with no errors or warnings:

  • spec-enforcer.mdspec-enforcer.lock.yml (prompt imported at runtime via {{#runtime-import}})

References


Warning

Protected Files — Push Permission Denied

This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.

Protected files

The push was rejected because GitHub Actions does not have workflows permission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.

Create the pull request manually
# Download the patch from the workflow run
gh run download 24834376768 -n agent -D /tmp/agent-24834376768

# Create a new branch
git checkout -b q/fix-spec-enforcer-round-robin-459d45b1e13946aa main

# Apply the patch (--3way handles cross-repo patches)
git am --3way /tmp/agent-24834376768/aw-q-fix-spec-enforcer-round-robin.patch

# Push the branch and create the pull request
git push origin q/fix-spec-enforcer-round-robin-459d45b1e13946aa
gh pr create --title '[q] fix(spec-enforcer): recover round-robin state from PRs when cache is empty' --base main --head q/fix-spec-enforcer-round-robin-459d45b1e13946aa --repo github/gh-aw

🎩 Equipped by Q · ● 4.9M ·

  • expires on Apr 25, 2026, 12:24 PM UTC

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions