---
title: "Put time limits on jobs that can hang"
description: "Set job timeouts from normal run history so stalled checks release runners and produce a failure that can be investigated."
url: https://starsling.dev/ci-playbooks/techniques/bound-job-runtime
canonicalUrl: https://starsling.dev/ci-playbooks/techniques/bound-job-runtime
---

# Put time limits on jobs that can hang

Set job timeouts from normal run history so stalled checks release runners and produce a failure that can be investigated.

## How to choose an approach

Compare the examples by repository setup, prerequisites, and risks before adopting one. Each company implemented this in its own environment; measure each change against your own baseline.

- **[Anthropic](https://starsling.dev/ci-playbooks/anthropic#flaky-job-timeouts)**: Use it when A non-matrix integration job has timed-out runs near the 360-minute default and at least three successful runs to measure. Check before adopting: A timed-out required check still blocks the merge, so the hanging tests get fixed by name.
- **[Mastra](https://starsling.dev/ci-playbooks/mastra#bounded-jobs)**: Use it when A database, checkout or external service occasionally hangs beyond useful execution time. Check before adopting: A timeout caps the runner minutes a hung job can burn. Leave room for normal tails and diagnostics.
- **[Shopify](https://starsling.dev/ci-playbooks/shopify#bound-hung-tests)**: Use it when A job with no timeout-minutes can stall and hold a runner until the platform default. Check before adopting: Set the ceiling from the job's real duration with headroom for cold setup.
- **[Spotify](https://starsling.dev/ci-playbooks/spotify#job-timeouts)**: Use it when A job sometimes hangs and runs until the platform's default limit, six hours on GitHub-hosted runners. Check before adopting: Set each timeout well above the longest healthy run so slow runs still finish; the passing iOS run on this change took 6m34s against a 45-minute cap.

## Apply this technique

````text
Evaluate and apply this CI technique to my repository: Put time limits on jobs that can hang.

Set job timeouts from normal run history so stalled checks release runners and produce a failure that can be investigated.

Read the technique and its source-backed company examples: https://starsling.dev/ci-playbooks/techniques/bound-job-runtime.md

Inspect this repository’s CI workflows, build and test commands, dependencies, and recent run timings. Identify where this technique applies and explain the expected benefit using this repository’s evidence.
Measure a baseline from recent comparable runs: elapsed time, queue time, runner minutes and failures where available. If data is unavailable, say what cannot be measured.
Compare relevant company approaches, checking prerequisites, platform differences and tradeoffs. Rank applicable options by evidence, fit and measurable opportunity; do not present company results as predictions for this repo.
Recommend the smallest safe change, show what checks and fallback paths remain, and ASK ME WHICH CHANGE TO APPROVE BEFORE EDITING ANY FILES.
Only after approval, work on a new feature branch, make one reversible change, and open a reviewable pull request. Never merge or push to a default or protected branch.
Keep required checks, test coverage, deployment and release behavior intact. Validate the change and compare equivalent runs where possible; report limitations and what should be monitored after merge.
````

## How companies used this technique

Read what each company changed and follow the original sources.

### Anthropic: Bound flaky job runtime

Anthropic describes running tests that were already flaky or failing across the board. As a StarSling pattern for GitHub Actions, a timeout set from successful run history stops a hanging job from holding a runner for six hours.

Evidence: StarSling pattern for GitHub Actions

Use it when: A non-matrix integration job has timed-out runs near the 360-minute default and at least three successful runs to measure.

Before applying it: A timed-out required check still blocks the merge, so the hanging tests get fixed by name.

[Read more in the Anthropic playbook](https://starsling.dev/ci-playbooks/anthropic#flaky-job-timeouts)

[Primary source](https://claude.com/resources/articles/agentic-coding-is-straining-ci-heres-how-we-scaled-test-impact-analysis-at-anthropic)

### Mastra: Bound integration jobs that can hang

Mastra added explicit timeouts to integration and change-detection jobs, then broadened timeout coverage. Later checkout timeouts were lengthened, showing why the bound needs observed tail data.

Evidence: Source PR/commit evidence

The combined store workflow keeps its job timeouts in test-combined-stores.yml. ([Source](https://github.com/mastra-ai/mastra/blob/f92e947a448a47515acf14df1eddc5fd5c36f424/.github/workflows/test-combined-stores.yml))

Use it when: A database, checkout or external service occasionally hangs beyond useful execution time.

Before applying it: A timeout caps the runner minutes a hung job can burn. Leave room for normal tails and diagnostics.

[Read more in the Mastra playbook](https://starsling.dev/ci-playbooks/mastra#bounded-jobs)

[Primary source](https://github.com/mastra-ai/mastra/pull/14098)

### Shopify: Bound a test job that can hang

After tests looped indefinitely during development, Job Iteration added a five-minute timeout to a build matrix that normally runs in under a minute. A hung leg now stops at five minutes; the platform default is 360.

Evidence: Source PR/commit evidence

Merged 2026-06-04; the timeout is on the default branch. ([Source](https://github.com/Shopify/job-iteration/pull/717))

Use it when: A job with no timeout-minutes can stall and hold a runner until the platform default.

Before applying it: Set the ceiling from the job's real duration with headroom for cold setup.

[Read more in the Shopify playbook](https://starsling.dev/ci-playbooks/shopify#bound-hung-tests)

[Primary source](https://github.com/Shopify/job-iteration/pull/717)

### Spotify: Cap hung test jobs with timeouts

The confidence-sdk-flutter iOS test job could hang on the simulator and run for six hours. The change adds a 45-minute job timeout and a 30-minute timeout on the integration test step, boots the selected simulator before the tests and removes the blocking simctl bootstatus wait.

Evidence: Source PR/commit evidence

Use it when: A job sometimes hangs and runs until the platform's default limit, six hours on GitHub-hosted runners.

Before applying it: Set each timeout well above the longest healthy run so slow runs still finish; the passing iOS run on this change took 6m34s against a 45-minute cap.

[Read more in the Spotify playbook](https://starsling.dev/ci-playbooks/spotify#job-timeouts)

[Primary source](https://github.com/spotify/confidence-sdk-flutter/pull/72)

## CI optimization is continuous work.

Apply this technique yourself, or use StarSling Runners for faster GitHub Actions and optional agent-driven optimization PRs, which teams on eligible paid plans can turn on.

[Get self-improving CI](https://starsling.dev/products/runners)

## Related techniques

### [Bound agent execution and retries](https://starsling.dev/ci-playbooks/techniques/bounded-agent-execution)

Set explicit time, turn, or retry budgets so an agent that cannot finish returns control rather than consuming unbounded CI capacity.

3 implementations · 3 companies (DoorDash, Spotify, Stripe)

### [Cancel superseded pull request runs](https://starsling.dev/ci-playbooks/techniques/cancel-superseded-runs)

Free runner capacity by canceling validation that a newer commit has replaced. Keep required main-branch and release runs intact.

4 implementations · 4 companies (Anthropic, Mastra, Stripe, Uber)

### [Package once, and build full installers after merge](https://starsling.dev/ci-playbooks/techniques/package-once)

Drop the build step that packaging repeats, and build the unpacked app pull requests test.

1 implementation · 1 company (DoorDash)

## Company Playbooks

### [Anthropic](https://starsling.dev/ci-playbooks/anthropic)

Run only affected tests

### [DoorDash](https://starsling.dev/ci-playbooks/doordash)

Run build and test in parallel, sharded across CI agents

### [Linear](https://starsling.dev/ci-playbooks/linear)

Benchmark the same job on faster hardware

### [Mastra](https://starsling.dev/ci-playbooks/mastra)

StarSling runners for the slowest test workflow

### [OpenAI](https://starsling.dev/ci-playbooks/openai)

Rank CI fixes by the minutes they save

### [Ramp](https://starsling.dev/ci-playbooks/ramp)

Move a CPU-bound test suite to a faster CPU

### [Shopify](https://starsling.dev/ci-playbooks/shopify)

Let an agent iterate against one CI metric

### [Spotify](https://starsling.dev/ci-playbooks/spotify)

Build arm64 on native arm64 runners

### [Stripe](https://starsling.dev/ci-playbooks/stripe)

Run only the tests a change can reach

### [Uber](https://starsling.dev/ci-playbooks/uber)

Build the merge-queue speculations most likely to be needed

## Related guides

Implementation guides for this technique.

### [Bound runner jobs with timeouts](https://starsling.dev/best-practices/github-actions/bound-job-timeouts)

Set job and step timeouts using expected durations and failure behavior.

### [Right-size GitHub Actions runners](https://starsling.dev/best-practices/github-actions/right-size-runners)

Match runner resources to the workload and compare equivalent runs.
