Apply timeout from default section to jobs
What does this MR do and why?
default:timeout in .gitlab-ci.yml passes validation but has no effect: jobs fall back to the project timeout. This MR makes jobs inherit it, behind the default-off gitlab_com_derisk flag ci_default_timeout_inheritance (actor: project).
Root cause and approach
Entry::Defaultdeclarestimeoutas an entry, andEntry::Jobmarks itinherit: true, soInheritable#inherit!already copies the default into the job'sentries[:timeout].Job#parsed_timeoutused theattributes-generatedhas_timeout?/timeout, which only read the job's own raw config hash, so the inherited entry was never used.retryandtagsread their composed entries, which is why they work fromdefault:.- The fix reads
timeout_valuefrom the composed entry only when the job has no timeout of its own. Jobs that settimeout(directly, throughextends, or through!reference) keep the existing code path unchanged. - The flag is checked only in that inherited case, so pipelines without
default:timeoutnever evaluate it. The production caller (Gitlab::Ci::Config#jobs) already wrapsroot.jobs_valueinFeatureFlags.with_actor(project). inherit:default: falseandinherit:default: [list]are respected, because inheritance goes throughProcessable#overwrite_entry.
Why a feature flag
Existing pipelines that already set default:timeout have had it ignored. Once this is enabled, those jobs are enforced, and a default shorter than a job's real runtime starts timing jobs out. The flag lets us enable it per project on GitLab.com first.
This includes our own pipelines: .gitlab-ci.yml and several child-pipeline templates set default: timeout: 90m with the comment "Default job timeout doesn't work". Enabling the flag for gitlab-org/gitlab enforces that intended 90-minute default, so the rollout issue covers it as an explicit step.
Rollout and docs plan
Tracked in the rollout issue: #637618
- Merge with the flag off. No behavior change.
- On GitLab.com, enable it for a test project, then
gitlab-org/gitlab, then roll out by percentage of projects, watchingjob_execution_timeoutfailures. - When stable, remove the flag.
gitlab_com_deriskflags can't be enabled by default and are short-lived, so self-managed instances get the behavior when the flag is removed. The removal MR carries:- A history entry in
doc/ci/yaml/_index.md("Generally available in GitLab X.Y. Feature flagci_default_timeout_inheritanceremoved.") and removal of the flag note. - A
Changelog: fixedentry that calls out the behavior change for self-managed upgrades. - Simplifying
parsed_timeoutto read only the composed entry.
- A history entry in
Docs in this MR (as agreed in !266852 (comment 4165307508)): default:timeout was never listed in the reference, so it's documented as a new feature behind a flag. doc/ci/yaml/_index.md adds timeout to the default keyword list, a history entry and flag note on default, and replaces the "not supported in default" note from !230251 (merged).
/cc @lyspin @marcel.amirault for awareness: this replaces the documented limitation with a fix once the flag is removed.
References
- Issue: #213634 (closed)
- Where the bug started: !19847 (merged) (GitLab 12.6, commit 1e7fe975) added
timeouttodefault:, but the job kept reading it from its own raw config throughhas_timeout?/timeout.default:timeouthas never had an effect. Details: !266852 (comment 4147892697) - Rollout issue: #637618
- Product guidance ("we should fix it or remove the field"): #213634 (comment 2664938855)
- Why this differs from the
default:artifactsdeep-merge question (timeouthas no sub-keys, so this is a straightforward bug): #404563 (comment 2848613640) - Docs that documented the limitation: !230251 (merged), !143712 (merged)
Screenshots or screen recordings
Not applicable, no UI change. Results from a real runner on a development instance (timeout/timeout_source on Ci::Build):
| Flag | Job relying on default: timeout: 2m |
Job with timeout: 5m |
|---|---|---|
| Off (before) | 3600 s, project_timeout_source |
300 s, job_timeout_source |
| On (after) | 120 s, job_timeout_source |
300 s, job_timeout_source |
With the flag on, a sleep 200 job failed with job_execution_timeout after about 120 s.
How to set up and validate locally
-
Create a project with this
.gitlab-ci.yml:default: timeout: 2m uses_default: script: echo hi own_timeout: timeout: 5m script: echo hi -
Run a pipeline. The job page for
uses_defaultshows the project timeout, which is the current behavior. -
In the Rails console, run
Feature.enable(:ci_default_timeout_inheritance, Project.find_by_full_path('<path>')). -
Run another pipeline.
uses_defaultnow shows a 2-minute timeout, andown_timeoutstill shows 5 minutes.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.