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::Default declares timeout as an entry, and Entry::Job marks it inherit: true, so Inheritable#inherit! already copies the default into the job's entries[:timeout].
  • Job#parsed_timeout used the attributes-generated has_timeout?/timeout, which only read the job's own raw config hash, so the inherited entry was never used. retry and tags read their composed entries, which is why they work from default:.
  • The fix reads timeout_value from the composed entry only when the job has no timeout of its own. Jobs that set timeout (directly, through extends, or through !reference) keep the existing code path unchanged.
  • The flag is checked only in that inherited case, so pipelines without default:timeout never evaluate it. The production caller (Gitlab::Ci::Config#jobs) already wraps root.jobs_value in FeatureFlags.with_actor(project).
  • inherit:default: false and inherit:default: [list] are respected, because inheritance goes through Processable#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

  1. Merge with the flag off. No behavior change.
  2. On GitLab.com, enable it for a test project, then gitlab-org/gitlab, then roll out by percentage of projects, watching job_execution_timeout failures.
  3. When stable, remove the flag. gitlab_com_derisk flags 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 flag ci_default_timeout_inheritance removed.") and removal of the flag note.
    • A Changelog: fixed entry that calls out the behavior change for self-managed upgrades.
    • Simplifying parsed_timeout to read only the composed entry.

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

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

  1. Create a project with this .gitlab-ci.yml:

    default:
      timeout: 2m
    
    uses_default:
      script: echo hi
    
    own_timeout:
      timeout: 5m
      script: echo hi
  2. Run a pipeline. The job page for uses_default shows the project timeout, which is the current behavior.

  3. In the Rails console, run Feature.enable(:ci_default_timeout_inheritance, Project.find_by_full_path('<path>')).

  4. Run another pipeline. uses_default now shows a 2-minute timeout, and own_timeout still 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.

Edited by Adam Mulvany

Merge request reports

Loading
Loading