--- title: "ADR 0018: GitLab API retries only idempotent requests" --- * Status: accepted * Code: [`pkg/provider/gitlab/gitlab.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/gitlab/gitlab.go) (`clientOptions`, `gitlabRetryPolicy`, `gitlabRetryBackoff`, `gitlabRetryRequestOption`) ## Context The go-gitlab client retries by default. PAC can opt in to its own retry behaviour with `EnableAPIRetry`, bounded by `APIRetryMaxAttempts` and `APIRetryMaxWaitSeconds`. When a network failure leaves no response, the retry policy has no status line or request to inspect. ## Decision * With the setting off, `clientOptions` adds nothing but the base URL, so the go-gitlab defaults stay in force and existing behaviour is unchanged. * With the setting on, only `GET`, `HEAD` and `OPTIONS` are retried after network or server errors. A mutation may already have been applied by the server, so retrying could duplicate it. * The request method is stored in the request context by `gitlabRetryRequestOption`, so the policy can classify a request even when there is no response. If a call passes `gitlab.WithContext`, the upstream client does not copy that key; the method is then unknown, the request counts as non-idempotent and is not retried. * A `429` is retried regardless of method, but not when the server asks for a wait longer than the configured maximum. * The rate limit headers (`Retry-After`, `RateLimit-Reset`) are used only on a `429` response, because GitLab sets `RateLimit-Reset` on ordinary responses too. Other transient failures use a short linear backoff with jitter capped at the maximum wait. ## Consequences * Failed `POST`/`PUT`/`DELETE` calls are never retried on 5xx or connection errors, even when they would have been safe. * Code that passes `gitlab.WithContext` silently loses retries for network failures.