debug-ci-pipeline-failure
Skill9 starsChanged 5 months agoApache-2.0View on GitHub
Debugs a red CI job to root cause instead of blind-rerunning — reproduce locally in the SAME image (`act -j <job>`, `gitlab-runner exec`, `circleci local execute`, or `docker run` the exact pinned digest), read the full log + the real exit code (124=timeout, 137=OOM/SIGKILL, 143=SIGTERM, 139=segfault), then classify into flaky / env-drift / poisoned-or-stale cache / resource-OOM / missing-secret / timeout / test-ordering / network, and confirm with a targeted experiment — diff local-vs-CTRL env (`printenv | sort`, tool `--version`, lockfile hash), run clean (no cache, `--no-cache`/clear key) vs cached, isolate ONE matrix leg, bisect with `git bisect run`, re-run with debug logging (`ACTIONS_STEP_DEBUG=true`, `CI_DEBUG_TRACE=true`, `set -x`) or open an interactive runner (`tmate`/`debug with SSH`/`--privileged` shell) — and fix the cause (pin the digest, scope the cache key, raise the limit, randomize then fix test order) not the symptom.
- Reads credentials
- Installs packages
In this repository147 other files it gives its agents.
- second-brain/AGENTS.mdAGENTS.md
- second-brain/CLAUDE.mdCLAUDE.md
- agent-tool-mcp-builderSkill
- api-design-reviewSkill
- async-concurrency-correctnessSkill
- audit-accessibility-wcagSkill
- audit-license-complianceSkill
- audit-technical-seoSkill
- auth-jwt-sessionSkill
- author-codemodSkill
- brainstorm-designSkill
- build-audit-loggingSkill
- build-cdc-streaming-pipelineSkill
- build-cli-toolSkill
- build-data-tableSkill
- build-etl-pipelineSkill
- build-form-validationSkill
- build-native-mobile-uiSkill
- build-office-docsSkill
- build-offline-first-syncSkill
- build-react-componentSkill
- build-realtime-channelSkill
- build-spreadsheetSkill
- build-vector-searchSkill
- caching-strategySkill
- cicd-pipeline-authorSkill
- cloud-cost-optimizeSkill
- code-commentsSkill
- code-reviewSkill
- compose-local-dev-stackSkill
- configure-bundler-buildSkill
- configure-dns-tlsSkill
- configure-reverse-proxy-lbSkill
- configure-security-headers-cspSkill
- contract-testingSkill
- datetime-timezone-correctnessSkill
- db-migration-safetySkill
- debug-flaky-testsSkill
- debug-frontend-browserSkill
- debug-root-causeSkill
- defend-llm-prompt-injectionSkill
- deliver-webhooksSkill
- dependency-upgradeSkill
- deploy-releaseSkill
- design-api-paginationSkill
- design-authorization-modelSkill
- design-backup-dr-recoverySkill
- design-event-sourcing-cqrsSkill
- design-multi-tenancySkill
- design-protobuf-grpc-serviceSkill
- design-relational-schemaSkill
- design-search-index-infraSkill
- design-state-machineSkill
- design-token-systemSkill
- diff-table-paritySkill
- distributed-locks-leasesSkill
- dockerfile-optimizeSkill
- encrypt-sensitive-dataSkill
- error-messageSkill
- estimate-workSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 85
If clean is green and cached is red → the cache is the cause: the key is too coarse (not keyed on lockfile hash) or restores across …
- Distinctive: line 132
Matrix restored: if you isolated a leg, the full matrix is back and all legs pass.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to Use
Reach for this skill when a CI job is failing and you need to find out WHY before touching anything:
- "It's green locally but red on CI" / "passes on my machine, fails on the runner"
- "The job got killed — exit 137 / OOM / 'Process completed with exit code 137'"
- "It only fails sometimes — re-running makes it go green" (don't stop there — classify it)
- "One matrix leg (py3.12 / arm64 / windows) fails, the rest pass"
- "Nothing in my diff touches this — it broke on its own" (env/cache/upstream drift)
- "The job hangs and gets cancelled after N minutes" (timeout vs deadlock)
- "I keep hitting Re-run and hoping" — STOP, reproduce and root-cause instead
NOT this skill:
- Authoring the pipeline YAML, stages, caching strategy, runners from scratch → cicd-pipeline-author (this skill debugs the pipeline it produced)
- Fixing the nondeterministic test itself (shared state, time/random, async races, order-dependence) once you've confirmed flakiness is the cause → debug-flaky-tests (this skill decides whether it's a flaky test vs env/cache/limit, then hands off)
- General "why does this code crash" root-causing unrelated to CI → debug-root-cause (this skill is CI-runner-specific: images, caches, runners, matrices)
- Choosing/pinning the toolchain & language versions as a deliverable → pin-toolchain-versions (this skill detects version drift as a cause and tells you to pin)
- Designing the cache key/layers/TTL as a strategy → caching-strategy (this skill invalidates a poisoned cache to confirm it's the cause)
- Debugging a failing K8s pod/job workload (not a CI runner) → k8s-debug-workload
- A missing secret that's really a vault/rotation/scoping problem → secrets-management (this skill detects "secret empty on CI" as a class; that one fixes how secrets are stored/injected)
- Standing up a reproducible local dev container to match CI → compose-local-dev-stack / setup-devcontainer-env
- A production incident/postmortem (not a build) → incident-response-sre
Steps
Read the log top-to-bottom and grab the REAL exit code before theorizing. The first red line is rarely the cause — scroll up to the first error, and check the process exit code, which names the failure class:
Exit code Means Likely cause 1/2generic failure / misuse real test/build error — read the actual assertion 124command timed out ( timeoutwrapper)step exceeded its time budget 137128+9= SIGKILLOOM-killed (almost always memory limit) or job cancelled 139128+11= SIGSEGVnative segfault (bad binary/arch mismatch) 143128+15= SIGTERMtimeout/cancel signalled gracefully 125docker run failed image/entrypoint problem, not your code In GitHub Actions add
--rerun-failed-jobsonly AFTER you know why. Download the raw log (gh run view <id> --log-failed, GitLab "Complete Raw") — the web UI truncates and folds groups.Reproduce locally in the SAME image, not your laptop. "Green on my machine" proves nothing if your machine isn't the runner. Run the actual job in its actual container:
CI Local reproduce GitHub Actions act -j <job> --container-architecture linux/amd64(use the runner image:-P ubuntu-latest=catthehacker/ubuntu:act-latest)GitLab CI gitlab-runner exec docker <job>orglab ci run; pull the exactimage:CircleCI circleci local execute --job <job>any docker run --rm -it <image>@<digest>then run the steps by handPin the image by digest (
@sha256:…), not a moving tag —ubuntu-latest/node:20drift between your pull and the runner's. If it reproduces in the container but not on your host, the delta IS the bug (next step).- Diff the environment — env-drift is the #1 silent cause. Inside the reproduced container vs your host, compare:
Classic drifts: tool tag floated (printenv | sort > /tmp/ci.env # capture on CI (add `printenv|sort` as a debug step) <tool> --version # node/python/go/java/gcc — exact patch sha256sum package-lock.json poetry.lock go.sum # lockfile parity uname -m && cat /etc/os-release # arch (arm64 vs amd64!) + distro locale && echo $TZ # LANG/LC_ALL/TZ change sort & date testsactions/setup-node@v4with no exact version),npm civsnpm install(lockfile ignored),$PATHordering picks a different binary,TZ/LANGunset on the runner breaks date/sort tests, CI setsCI=truewhich flips test behavior. Fix = pin (digest + lockfile + exact tool version) → pin-toolchain-versions. Classify the failure — match symptom to cause, then run ONE experiment to confirm. Don't guess and re-run; prove it:
Class Tell-tale Confirm by Flaky test passes on re-run, no code change, intermittent re-run the SAME commit 10×; randomize order → debug-flaky-tests Env/version drift green local, red CI; broke with no relevant diff the env diff in step 3 Poisoned/stale cache broke after a dep bump or cache-key collision; "works in clean checkout" run with cache disabled (step 5) Resource / OOM exit 137, "Killed", slow then dead raise mem / lower parallelism; watch RSS Missing/empty secret only on fork PRs, only on protected branches, ***blankecho "len=${#SECRET}"(never the value)Timeout / deadlock exit 124/143, "cancelled after Nm" run with timeout+ thread dump on hangTest-ordering fails only in CI's shard/order, passes in isolation run that ONE test alone; then full suite Network/flaky registry ETIMEDOUT/ECONNRESET/429 to npm/pypi/ghcrretry; check it's not a hard dep on a live service Run clean-vs-cached to convict the cache. A poisoned or stale cache makes "works in a fresh checkout, fails in CI" — because CI restored a bad layer. Force a clean run and compare:
- GitHub Actions: bump the cache
key(e.g.-v2), orgh cache delete <key>, or setactions/cacheto a key that won't hit. Re-run withACTIONS_STEP_DEBUG=true. - GitLab:
CACHE_DISABLE=true/ clear via "Clear runner caches"; or changecache:key. - Docker layer cache:
docker build --no-cache --pull; suspect a stale base layer if aRUN apt-get/pip installsilently uses old pins. - Package managers:
npm ci(notinstall),pip install --no-cache-dir,go clean -cache.
If clean is green and cached is red → the cache is the cause: the key is too coarse (not keyed on lockfile hash) or restores across incompatible refs → caching-strategy to re-scope the key. If BOTH fail, the cache is innocent — move on.
- GitHub Actions: bump the cache
- Isolate ONE matrix leg. A matrix-only failure (only
windows-latest, onlypy3.12, onlyarm64) is a portability bug, not a flake. Temporarily pin the matrix to the failing leg (include:just that combo) so you iterate on one red job, not 12. Common per-leg causes: path separators / line endings (CRLF) on Windows, glibc vs musl (alpine) for native deps, arch-specific wheels/binaries on arm64, a stdlib behavior that changed in the new language minor. Fix the portability issue, then restore the full matrix. Crank up debug logging and
set -x. The default log hides what ran. Turn on tracing:CI Debug switch GitHub Actions secrets/vars ACTIONS_STEP_DEBUG=trueandACTIONS_RUNNER_DEBUG=trueGitLab CI variables: CI_DEBUG_TRACE: "true"(⚠ leaks env — protected branch only)shell steps add set -euxo pipefailto see every command + fail-fast on the real lineany echo printenv|sort,df -h,free -m,nproc, tool--versionas a debug stepset -x+pipefailalone fixes a whole class of "silent failure" where an early command in a pipe failed but the exit code was masked by the last one.- Drop into an interactive runner when logs aren't enough. For "I can't reproduce it locally and the log is opaque," open a live shell ON the runner:
- GitHub Actions:
mxschmitt/action-tmate@v3step (gates on failure) → SSH into the live runner mid-job; ortmatein a manualworkflow_dispatch. - GitLab: interactive web terminal /
gitlab-runner --debug; CircleCI: "Rerun job with SSH". - Inside: re-run the failing command by hand, inspect
/tmp, check mounted caches,catthe generated config,ps/topfor the OOM,dmesg | tailfor the kill. Tear it down — don't leave a runner pinned.
- GitHub Actions:
- Convict resource/OOM with real numbers. Exit 137 + "Killed" = the kernel OOM-killer. Don't just
continue-on-error— measure: GitHub-hosted runners are ~7 GB / 2 cores; self-hosted/container jobs have a--memorycgroup limit. Add/usr/bin/time -v <cmd>(Max RSS), orwhile true; do free -m; sleep 5; done &to watch growth. Fixes: lower test parallelism (-j2,--maxWorkers=2,pytest -n2), raise the container/runner memory limit, split the job, or fix the actual leak. Node OOM specifically →NODE_OPTIONS=--max-old-space-size=4096. - Fix the ROOT CAUSE, then re-run to confirm — never ship a blind re-run as the fix. A green re-run on a flaky/poisoned/under-provisioned job is a false negative that WILL recur. The closing move per class: pin the digest+lockfile+tool version (drift), re-scope or invalidate the cache key (cache), raise the limit or cut parallelism (OOM), randomize-then-pin test order / fix the shared state (ordering/flake → debug-flaky-tests), add a retry-with-backoff ONLY for genuinely external network calls (and nothing else). Then re-run the SAME commit ≥3× to prove it's deterministically green. Quarantining a flaky test (skip + tracking issue) is acceptable as a stopgap to unblock the pipeline — but it's a TODO, not the fix.
Common Errors
- Hitting "Re-run job" until it's green and calling it fixed. That's hiding a flaky/OOM/cache bug; it recurs and erodes trust in CI. Fix: classify (step 4) and fix the cause; re-run only to confirm.
- "It passes on my machine" as proof. Your laptop isn't the runner (arch, tool version, env, cache). Fix: reproduce in the exact image/digest (step 2).
- Reading only the last red line. The real error is usually higher; the last line is often a downstream symptom. Fix: read top-down, find the FIRST error + the exit code.
- Treating exit 137 as a code bug. It's OOM/kill, not your assertion. Fix: measure RSS, raise mem or cut parallelism (step 9).
- Floating tags (
node:20,ubuntu-latest,@v4minor). They drift between your pull and CI's → "broke with no diff." Fix: pin by digest + lockfile + exact version (pin-toolchain-versions). npm install/ non-ciinstalls in CI. Ignores the lockfile → different deps than local. Fix:npm ci,poetry install --no-update,--frozen-lockfile.- Blaming the test when it's the cache. Stale restored layer fails a clean build. Fix: clean-vs-cached run (step 5) before touching the test.
- Debugging the whole matrix at once. 12 red legs hide which is the real bug. Fix: isolate the one failing leg (step 6).
CI_DEBUG_TRACE/printing secrets to debug. Leaks credentials into logs. Fix: trace on protected branches only; print${#SECRET}length, never the value.- No
pipefail, so a failed mid-pipe command exits 0. Silent green on a broken step. Fix:set -euo pipefailin every shell step. - Empty secret on fork PRs read as a code bug. Secrets aren't exposed to forks/
pull_requestfrom forks by design. Fix: recognize the class, usepull_request_targetcarefully or a label gate, not a value hunt. - Adding broad retries to mask flakiness. Retrying a deterministic bug just burns minutes. Fix: retry ONLY external network I/O; fix logic/ordering/resource causes.
Verify
- Reproduced in-image: the failure reproduces with
act/gitlab-runner exec/docker run @digest(or you've proven via env-diff exactly what the runner has that you don't) — not just observed in the web UI. - Classified, not guessed: you can name the class (flaky / env-drift / cache / OOM / secret / timeout / ordering / network) AND state the experiment that confirmed it (clean-vs-cached, isolated test, RSS measurement, env diff).
- Exit code accounted for: you read the real exit code and it's consistent with the diagnosis (137→OOM, 124/143→timeout, 1/2→real error).
- Root cause fix, not a re-run: the diff pins/invalidates/scopes/limits the actual cause; there's no bare "Re-run" or blanket
continue-on-errorstanding in for a fix. - Determinism proven: the SAME commit is re-run ≥3× (and for a flake, ≥10×) and is green every time — not green once after N reds.
- No new leak: debug tracing is off (or gated to protected branches), no secret value was printed, and interactive runners were torn down.
- Matrix restored: if you isolated a leg, the full matrix is back and all legs pass.
Done = the failure was reproduced in the runner's actual image, classified into one named cause confirmed by a targeted experiment (env diff / clean-vs-cached / isolated test / RSS), and fixed at the root (pin, cache-key, limit, order) — proven by the same commit going green ≥3× with no blind re-run, no masking, and no leaked secrets.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

