CI fails on an untouched branch. How do you debug it?
Question
Commit a91f3c2 passed CI yesterday. Today the exact same commit fails npm test with TypeError: parser.parseV2 is not a function. No one touched the branch. Here is the workflow:
jobs:
test:
runs-on: ubuntu-latest
container: node:20-alpine
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: node_modules
key: deps-v1
- run: npm install
- run: npm test- Which five moving parts in this workflow can break an untouched commit overnight?
- How do you isolate the exact culprit first?
- How do you fix the workflow so builds stay deterministic?
Show hints (3)
- "SPOT FLOATING VERSIONS"
Check every line that resolves a mutable tag at runtime:
ubuntu-latest,node:20-alpine,@v4, andnpm install. - "INSPECT CACHE KEY"
key: deps-v1never changes whenpackage-lock.jsonchanges, and cachingnode_modulesdirectly can mix binaries from an older Node build. - "DIFF YESTERDAY VS TODAY"
Compare the resolved runner image, container digest, cache hit status, and installed package versions between yesterday's passing log and today's failing log.
Show checked explanation
Code stayed fixed, so an unpinned external input moved overnight: ubuntu-latest, mutable node:20-alpine, tag-pinned @v4 actions, a static deps-v1 node_modules cache, or npm install resolving newer transitive packages. Diff yesterday's green log against today's red log, reproduce in the exact container, then pin digests, SHAs, lockfile cache keys, and npm ci.
Broken and fixed GitHub Actions YAML structure, 64-hex image digest and 40-hex commit SHA formats, lockfile cache key, and npm ci command replacement were checked on CPython 3.12.10; runner, cache, and npm ci semantics were checked against GitHub Actions and npm documentation. Checked by an editor other than the author.
Walkthrough
When an untouched commit breaks overnight, stop staring at application code and ask what changed in the build environment. Diff yesterday's passing CI log against today's failing log on four lines: runner image version, pulled container digest (sha256), cache hit/miss, and installed package versions (npm ls). Then pull the exact container digest locally and run the failing test to reproduce cleanly.
This 12-line workflow hides five separate moving parts:
| Moving part | Why it breaks overnight | Deterministic fix |
|---|---|---|
ubuntu-latest | GitHub rotates runner OS releases silently | Pin an explicit OS (ubuntu-24.04) |
node:20-alpine | Mutable tag updates Node and Alpine packages | Pin the immutable @sha256:... digest |
actions/*@v4 | Mutable major tag can shift or be compromised | Pin a full 40-char commit SHA (# v4) |
key: deps-v1 on node_modules | Restores stale modules across lockfile or Node updates | Cache ~/.npm keyed by hashFiles('package-lock.json') |
npm install | Drifts when lockfile is missing, unlocked, or out of sync; keeps stale node_modules | Use npm ci for clean, exact lockfile installs |
In this TypeError: parser.parseV2 is not a function failure, suspect stale cached node_modules from deps-v1 or npm install resolving a newer package when the lockfile is missing, unlocked, or out of sync. In npm v7+, npm install respects an in-sync lockfile, yet still keeps stale node_modules and rewrites the lockfile on drift. npm ci wipes node_modules, installs exact lockfile versions, and fails fast on any mismatch.
Here is the hardened, repeatable job:
jobs:
test:
runs-on: ubuntu-24.04
container: node@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
- run: npm ci
- run: npm testPair SHA pinning with automated update PRs (like Dependabot) so security updates still land cleanly through normal CI checks instead of breaking main at random.
Common mistakes
- Clicking 'Re-run jobs' three times and assuming the test is flaky. If an unpinned dependency or base image broke, retries waste time and mask supply-chain drift.
- Using
npm installin CI instead ofnpm ci.npm installcan silently upgrade unlocked ranges and ignore stale files sitting inside cachednode_modules. - Caching
node_moduleswith a fixed key likedeps-v1. Native addons compiled under one Node version break when the container updates. - Deleting the lockfile to make CI pass. That discards reproducible versions and pushes an untested dependency tree to production.
Follow-up questions
- "Why pin third-party GitHub Actions to a 40-character commit SHA instead of @v4?" Git tags like
@v4are mutable pointers. An upstream maintainer or attacker who gains repo access can move@v4to new commits with access to your CI secrets. A full commit SHA is immutable. - "What if the failure still happens after pinning dependencies, images, and caches?" Check time-dependent inputs: an expired TLS certificate or test token, a hardcoded date in a unit test, an external API mock or rate limit, or runner clock/timezone assumptions.
What a strong answer covers
Identifies all five unpinned inputs (ubuntu-latest, mutable image tag, @v4 action tags, static node_modules cache, and npm install). Starts by diffing yesterday's passing log against today's failing log, reproduces locally, and pins digests, commit SHAs, lockfile cache keys, and npm ci.
Open in interactive practice deck →