Skip to main content
A timeout set far above a test’s passing runtime wastes CI time. When the test breaks, it waits out the timeout instead of failing fast, often once per retry. A coding agent such as Cursor or Claude Code can bring these timeouts down when it knows how long the test takes to pass, whether its failures hit the timeout, and where the timeout is set. Trunk provides the first two, and the agent finds the third in your repository. The agent makes only two kinds of change: it lowers a timeout to fit the test’s passing runtime, or it finds out why the test is slow.

1. Configure a timeout inflation monitor

The timeout inflation monitor flags a test when its failures take far longer than its passes, which means its failures are waiting out a timeout. Create one in the test collection’s monitor settings and use the preview panel to see which tests it would flag before you save. Give it a label such as timeout-inflated, so the tests it flags are easy to list. These values suit this recipe. Adjust each one by what the right-hand column says it depends on.

2. Find the tests to tighten

Start the agent in one of two ways: The monitor only flags a test whose failures wait out its timeout. To also find slow tests that haven’t failed yet, call GET /v2/tests with sort=durationP95, period=7d and include=metrics, and have the agent compare each test’s runtime with its configured timeout.

3. Gather context

The P95 duration on the test covers failing runs too, so a test that keeps waiting out its timeout pushes its own P95 up. Have the agent use passing runs only.
Where frameworks set timeouts:
  • Jest and Vitest: the timeout argument to it or test, jest.setTimeout, vi.setConfig, and testTimeout in the config.
  • Playwright: test.setTimeout, test.slow(), and timeout and expect.timeout in playwright.config. The timeout applies to each retry.
  • pytest: @pytest.mark.timeout and timeout in the pytest config.
  • Go: go test -timeout and context.WithTimeout inside tests.
  • JUnit: @Timeout.
  • CI jobs: timeout-minutes and its equivalents.

4. Propose tighter values or find the cause

Lower the timeout when the test’s passing durations are steady. Set it to twice the passing P95, at least 1.25 times the slowest pass in the window, and no lower than the framework’s default for that kind of test. Round up to a round number. Propose a change only when the current timeout is at least three times the new value.
  • Use the slowest CI job: if the test is slow only on one runner type, the timeout must fit that one.
  • Change a shared timeout only when every test it covers fits the new value. Otherwise, give the test a timeout of its own.
Find the cause of the slowness instead when the passing durations are spread wide (P99 far above P50), are rising over the window, or are slow for what the test checks. Have the agent look for fixed sleeps, polling with long intervals, real network calls, retries with backoff, and expensive setup that runs once per test. A timeout fitted to a test like this is too loose for its fast runs and too tight for its slow ones. Have the agent open one pull request per suite or config file. In the description, list each test with its current timeout, passing P95 and slowest pass, failing P50, and proposed timeout. Estimate the CI time saved as the old timeout minus the new one, times the number of failures in the window.

5. Track

  • Link the pull request’s ticket with POST /v2/tests/{testId}/ticket, or create one with POST /v2/tests/{testId}/create-ticket.
  • After the pull request merges, the monitor resolves the test once its failures fall under the resolution ratio, and removes the label.
  • If a test starts timing out on healthy runs, the new timeout is too tight. Raise it to fit the slowest pass, or find the cause of the slowness as in step 4.