# Deterministic GitLab Dynamic Child Pipelines for Polyglot Monorepos

> Engineering Guide by Wake ([wakeci.dev](https://wakeci.dev/)) · Updated November 22, 2026

**Direct answer:** Static `rules:changes` path filters silently miss transitive dependencies across Python, Rust, TypeScript, Go, and Nix packages. Replacing static YAML with a 15-line GitLab `trigger:include:artifact` parent pipeline that resolves your real dependency graph cut our self-hosted GitLab CE UI merge request from **2m 59s to 30s (7.1x less runner compute)** while keeping the full suite mandatory on default branches and tags.

## Why GitLab `rules:changes` Fails in Monorepos

- **Transitive dependency blind spots:** Editing `libs/proto/schema.py` breaks `services/api` and `services/worker` even though no file under `services/` changed. Hand-maintained path lists drift until teams give up and run every job on every push.
- **Coding agents amplify the waste:** When Claude Code or Cursor pushes 5-10 iterative fix commits per MR, re-running cold Nix, Rust, and integration test stages for a 2-line UI tweak saturates self-hosted runner fleets.
- **Late-stage failure feedback:** Running `lint` in the final stage forces developers to wait for full build and integration suites just to learn a formatting error failed at minute 2:49.

## How GitLab Dynamic Child Pipelines Work

GitLab natively supports generating a child pipeline YAML artifact at runtime and running it via `trigger:include:artifact`, keeping all existing runners, Docker images, and caches intact:

```yaml
stages: [plan, run]

wake-plan:
  stage: plan
  image: ghcr.io/strange-metal/wake:latest
  script:
    - wake plan --ci-file .wake-pipeline.yml --post-comment --out wake-generated-ci.yml
  artifacts:
    paths:
      - wake-generated-ci.yml

wake-child:
  stage: run
  trigger:
    include:
      - artifact: wake-generated-ci.yml
        job: wake-plan
    strategy: depend
```

`wake plan` scans `pyproject.toml`, `package.json`, `Cargo.toml`, `go.mod`, `flake.nix`, `callPackage`, and optional `.wake.yml` edges, computes the exact transitive reverse-dependency closure of changed files, promotes linters to parallel stage 0, injects explicit `needs:` DAG edges, and writes `wake-generated-ci.yml`.

## Three Self-Hosted GitLab Runner Pitfalls

1. **Never trust `CI_COMMIT_BEFORE_SHA` on feature branches:** First pushes set it to 40 zeroes; force-pushes after rebase point to unreachable commits. Always force-fetch `origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME` (or `CI_DEFAULT_BRANCH`) and diff against `git merge-base`.
2. **Docker executor cached `.git` volumes go stale:** Explicitly run `git fetch --no-tags --depth=50 origin +refs/heads/$TARGET:refs/remotes/origin/$TARGET` inside the planner job.
3. **Keep a deterministic full-suite safety net:** Edits to root lockfiles, shared CI templates, default branches (`develop`/`main`), and release tags must bypass pruning and execute 100% of jobs.

## Measured Results on Self-Hosted GitLab CE

| Scenario | Jobs Run | Wall-Clock | Compute | Result |
|---|---:|---:|---:|---|
| Static YAML (cold cache) | 9 / 9 | 2m 59s | 4m 32s | Failed at 2:49 on formatting |
| Static YAML (warm cache) | 9 / 9 | 1m 23s | 2m 40s | UI edit rebuilt backend + Nix |
| Wake stage-0 fast-fail | 1 / 9 | 21s | 21s | **4.0x faster feedback** |
| Wake dynamic child pipeline (UI MR) | 3 / 9 | 30s | 38.3s | **7.1x less compute** |

---

- HTML version: https://wakeci.dev/guides/gitlab-dynamic-child-pipelines
- Live X-Ray flamegraph: https://wakeci.dev/demo/xray-baseline.html
- Contact for a 15-minute zero-egress X-Ray audit: chris@wakeci.dev
