All jobs

Cancel Superseded Runs with Concurrency Groups and Job Timeouts in GitHub Actions

Yes. An agent reads every workflow in your repo, adds a concurrency group that cancels outdated PR runs and a timeout on each job, and proves the workflows pass.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts by reading every workflow, because the right concurrency key is different for a pull request check and a deploy. In a repository like actions/typescript-action there are five under .github/workflows: ci.yml with a test-typescript job that runs npm ci, npm run format:check, npm run lint and npm run ci-test, and a test-action job that runs the action itself with uses: ./; check-dist.yml, which rebuilds dist/ with npm run bundle and fails if git diff shows the checked-in bundle is stale; linter.yml, which runs super-linter/super-linter/slim@v8 over the whole tree; codeql-analysis.yml, which also runs on a weekly schedule; and licensed.yml, whose pull_request and push triggers are commented out so it runs only on workflow_dispatch. The first four trigger on pull_request and push to main, all five set permissions, and none sets concurrency or timeout-minutes, so every push to a pull request branch starts a fresh set of four runs while the previous four keep going to completion, and a hung step runs until GitHub's six-hour default.

It then decides the key per workflow rather than pasting one block. For the three check workflows, ci.yml, check-dist.yml and linter.yml, the group is ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} with cancel-in-progress: true: on a pull request every push cancels the run for the previous commit, and on main the ref keeps each branch's runs separate. For codeql-analysis.yml the same key is used but cancellation is left on only for pull requests, with cancel-in-progress: ${{ github.event_name == 'pull_request' }}, because a cancelled CodeQL run on main or on the weekly schedule leaves no analysis uploaded for that commit. licensed.yml gets a timeout but no concurrency block, since a manually dispatched run has nothing to supersede. The agent reads .github/dependabot.yml too, which opens weekly grouped pull requests for npm and github-actions, and notes that those branches get the same cancellation, which is where most of the saved minutes come from.

Timeouts come from what the jobs actually take. The agent runs the repository's own steps in its sandbox on the Node from .node-version, 24.4.0: npm ci, the format check, the lint, npm run ci-test under Jest with --experimental-vm-modules, and npm run bundle through Rollup, and times each. It then sets timeout-minutes on every job to a round number comfortably above the slowest observed step, with a higher value for the super-linter job, which downloads a large image, and for CodeQL. Each value goes in with a short comment naming the step it is sized for, so the next person who sees a timeout failure knows whether the job got slower or the limit was tight.

The proof is the workflows running on the pull request. Before pushing, the agent validates every edited file with actionlint, which catches a misspelt context in the concurrency expression and a timeout-minutes placed at the wrong level. It pushes, opens the pull request, then pushes a second, empty commit and reads the run list to show the first commit's in-progress runs were cancelled and the second's completed, quoting the run ids and their conclusions in the description. check-dist.yml passes unchanged because the pull request touches no source, which the agent calls out as the sign that nothing outside .github/workflows was altered.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add concurrency groups and job timeouts to every workflow in this repository. Read every file under .github/workflows and .github/dependabot.yml first, and note which workflows are checks and which upload results that should not be lost. Add a concurrency block to each workflow keyed on the workflow name and the pull request number or ref, with cancel-in-progress true for check workflows and conditional on pull requests for any workflow that uploads analysis results. Run the repository's own steps in the sandbox on the Node version in .node-version, time them, and set timeout-minutes on every job with a comment naming the step it is sized for. Validate every edited workflow with actionlint, open a pull request, push a second commit to it, and show in the description that the first commit's runs were cancelled and the second's passed, with run ids.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that changes only the five files under .github/workflows: a concurrency block near the top of the four that run on pull requests and a timeout-minutes line on every job, with a one-line comment beside every timeout. Nothing under src/, dist/ or package.json changes, so check-dist.yml passes on the pull request without a rebuild.

The description has a table of workflows with their concurrency key, whether cancellation applies on main, and each job's timeout with the measured step time it was sized from; the actionlint output; and the list of runs for the two commits with the first set shown as cancelled and the second as completed. The transcript at GET /o/{org}/sessions/{id}/messages keeps the timings and the run queries.

Before merging, a reviewer reads the CodeQL block to confirm cancellation is limited to pull requests, and glances at the timeout values against the measured times. The next pull request with two quick pushes in a row then shows the effect directly: one set of checks for the latest commit rather than two.

Run it on every terminal hand-off

A maintainer watching the Actions tab fill with runs for commits nobody cares about anymore starts this from the terminal with this body and the repository in resources, then goes back to the review they were doing. The run reads the real workflows and times the real steps, so the keys and the timeouts fit this repository rather than a template.

Send a request_id, a UUID, with the body so a retried start returns the run it already began. When the turn ends, GET /o/{org}/sessions/{id} names the pull request, and the same body sent for each repository you maintain applies the same policy everywhere, each in its own sandbox with its own pull request.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The change is a few lines per workflow, but the two decisions in it are easy to get wrong from memory: which key separates pull requests from main, and which workflows must not be cancelled because a cancelled run leaves no uploaded result. Picking timeouts without measuring produces either limits that never fire or limits that fail the first slow runner. The agent reads each workflow, measures each job, and writes the reasoning next to the number.

The proof is the one that matters, a cancelled run and a completed one on the pull request itself, with ids a reviewer can click. Running it on Rush gives the job its own sandbox with the repository's Node version, keeps the timings and actionlint output in the transcript, and makes the same policy a matter of sending the same body for the next repository.

Frequently asked questions

Will a push to main cancel a run that was uploading a result?

Only where cancellation is safe. For the check workflows the key on github.ref means pushes to main cancel the previous main run, which is what most teams want. For codeql-analysis.yml the cancel-in-progress expression is true only on pull requests, so a main analysis always completes and uploads, and the description explains that distinction.

How are the timeout values chosen?

By running the jobs. The agent executes npm ci, the format check, the lint, the Jest suite and the Rollup bundle in its sandbox on the Node version from .node-version and records each duration, then sets a round number with headroom above the slowest, higher for the super-linter and CodeQL jobs whose cost is mostly download. Each value has a comment naming the step it was sized for.

Does it touch the Dependabot pull requests?

Indirectly. .github/dependabot.yml opens grouped weekly pull requests, and each of those branches now gets the same cancellation when Dependabot rebases it, which is where a lot of the wasted minutes were going. The configuration file itself is not changed.

What does actionlint catch here?

The two mistakes this change invites: a context name misspelt inside the ${{ }} concurrency expression, which GitHub would evaluate to an empty string and silently put every run in one group, and a timeout-minutes placed on a step or at the workflow level instead of on the job. The agent runs it on every edited file before pushing and quotes the clean result.

More GitHub Actions jobs

More jobs like this: Hand off a long task

Keep reading