# 4.4 Retries and Timeouts

_Pekit / Pekit TRM / Steps_

> How pekit runs a step's attempts under #[retry], what makes a step flaky, how #[timeout] spans the attempts, and what a step's failure does to the steps and targets after it.

GCSL applies `#[retry]` and `#[timeout]` to an ordinary call itself. For a
step's own call, pekit applies them instead, since the step's body runs as
a unit of its own on pekit's schedule.

## 4.4.1 Attempts

A step's first attempt is attempt 0. When an attempt fails, by its code's
own failure, and the step's `#[retry(n)]` allows another, the step runs
again from its start, in a new sandbox staged afresh as
`step-<token>-<node>-<attempt>` under the cache's scratch directory. Nothing
of the failed attempt carries over: not its files, not its `/tmp`, and
not its programs' writes.

A program that can't start because its file is open for writing isn't an
attempt. GCSL starts it again for about a second, whatever the step's
`#[retry]`. A newly written file can stay open for moments in a process forked
meanwhile, and a program that didn't start did nothing.

A step that passes on an attempt after the first is *flaky*. It is
recorded as any step that succeeds, and the build warns:

```text
warning: step `NAME` passed only when it was run again: it is flaky
```

`pekit test` reports a test whose step was flaky as `flaky`.

## 4.4.2 Timeouts

A step's `#[timeout(limit)]` is a deadline for all its attempts together,
from the start of its first attempt. The time the pool spends staging each
attempt's sandbox doesn't count: the deadline moves on by that time. When
the deadline passes, the running program is stopped, and the step fails
with "the step timed out", at the program it was running. A step that
fails once its deadline has passed isn't retried, whatever its `#[retry]`
allows.

## 4.4.3 What a failure reaches

A step that fails after its attempts fails every step that needs its
result, without running them, with the same failure. A target whose value
needs the failed step fails with that failure, reported where the target's
code, or the library code it called, made the step. Other targets of the
same build carry on, and the command exits with status 1 once every target
has finished or failed.
