In September a dev deploy of one of my side projects took 29 minutes, and a deploy of a commit that changed nothing updated all 11 of its CloudFormation stacks and rebuilt both of its Docker images. The pipeline had been built the way I build most things now, one feature at a time with Claude writing most of the code, and each piece of it had been correct when it was added.
I started muda to find out where those minutes went. It began as an audit script and a written standard inside that project, and it is now a standalone tool at muda.tools: a Go binary that reads a repository's GitHub Actions history, plus a set of agent skills that walk a coding agent through measuring, diagnosing, fixing and verifying. This post covers the project the standard came from: what the measurements showed, what changed, and why a pipeline built this way ends up like this. A second post covers the first pipeline muda ran on that it had never seen.
The first pipeline
The side project is an AWS CDK app with eleven stacks and two Lambda container images, plus two smaller repositories with the same shape. Its deploy workflow re-ran the full pytest suite, built both images inside cdk deploy under QEMU on x86 runners, and deployed every stack one after another.
I didn't have a firm idea of where the time went, so I measured each job and step from the run logs before changing anything. I profiled the test suite in an arm64 Linux container with 2 CPUs and one process. It took 246 seconds, and three of its 2,325 tests took 64 seconds each, where the next slowest took 6.4:

All three tests built the same thing: the project's default lineup portfolio, its most expensive computation, from identical inputs. Two of them were in the builder's test file. One checks the portfolio's fingerprint against a reference value, and the other checks how its lineups serialize. They now share one pytest fixture declared with scope="module", so the portfolio is built once per test file and both tests read the same result. The third test builds the portfolio through the dispatch path the API uses, which is different code, so it still builds its own.
The suite also runs in parallel now. pytest-xdist splits the tests across worker processes, and with four workers the two remaining 64-second builds run on different workers at the same time instead of one after the other.
In CI the numbers are larger, because the CI runner was slower than the container I profiled in. The pytest step took 504 seconds there, one process on a 2-vCPU runner. After the fixture change, with four workers and the job moved to an 8-vCPU runner, it took 142 seconds.
The deploy logs showed every stack updating on every deploy, including deploys whose commits changed no infrastructure. CDK's version reporting writes an AWS::CDK::Metadata resource into each template, that resource embedded the Node version, and none of the workflows pinned Node. The fix pinned Node and Python through .nvmrc and .python-version, so every workflow reads one version from a file, and set "versionReporting": false in cdk.json. Nothing stops a later change from turning it back on, so the repository also has a composite action, .github/actions/cdk-synth-gate/action.yml, that PR CI and both deploy workflows run right after cdk synth. One of its steps rejects any template that still carries the resource:
shopt -s nullglob
templates=(infra/cdk.out/*.template.json)
if [ ${#templates[@]} -eq 0 ]; then
echo "::error::No synth templates found"
exit 1
fi
set +e
MATCHES=$(grep -l '"AWS::CDK::Metadata"' "${templates[@]}")
rc=$?
set -e
[ $rc -ge 2 ] && exit $rc
[ -n "$MATCHES" ] && exit 1
The step has three outcomes, and only one of them passes:
- No templates.
cdk synthwrites one.template.jsonper stack intocdk.out. If synth wrote nothing, a search for the resource would find nothing and pass, so the step counts the templates first and fails on zero.shopt -s nullglobis what makes that count work: without it, a pattern that matches no files stays in the array as the literal stringinfra/cdk.out/*.template.json, and the array has one entry instead of none. - A read error.
grep -lprints the files that contain the resource and exits 0 if it found one, 1 if it found none, and 2 if it couldn't read a file. The step turns offset -earound the call so a 1 doesn't stop the script, then fails on 2 or higher. The usual shortcut,grep ... || true, treats an unreadable file the same as a clean one. - A match. Any template that still contains
AWS::CDK::Metadatafails the step.
A redeploy of the same commit then updated 2 stacks instead of 11, and cdk deploy went from 866 seconds to 64.
Building images once
Building the images inside cdk deploy caused several wastes at once: the builds ran under emulation, they had no layer cache, and dev and prod each built the same image separately. Adding a layer cache to the existing build would have made repeat builds faster, but every deploy would still have built under emulation, and dev and prod would still each have built the same image. The change moved the build out of the deploy entirely:
- A native arm64 job builds exactly the images the CDK asset manifest describes and pushes them under the manifest's own tag, with a layer cache in a separate, mutable repository. The build uses BuildKit, Docker's build engine and the backend behind
docker buildx, which can export its layer cache to a registry and read it back on the next build. - Pull requests run the same build read-only, as a required check, so CI builds what the deploy ships.
- The deploy asserts every image is already present and never builds one.
- Production copies dev's image by digest at the registry level and then checks that each running Lambda runs that digest.
Three details have to be right for this to work:
- Single-manifest images. A registry stores an image as a manifest that lists its layers. When buildx runs a builder in its own container, which the registry cache requires, it attaches a provenance attestation (a record of how the image was built) by default. To push the image and the attestation together it wraps both in an OCI image index, a manifest that points at other manifests. Lambda deploys only a single image manifest, so the first deploy with the new build failed. The build now passes
--provenance=false --sbom=falseand pushes withoci-mediatypes=false, the prod copy usesdocker buildx imagetools create --prefer-index=falseso the registry copy keeps the single manifest, and both steps read the pushed manifest's media type back and fail if it isn't a single image manifest. - A separate cache repository. CDK pushes images to its bootstrap repository in ECR, which has immutable tags: once a tag is written, it always names the same image. BuildKit's registry cache works the other way. Each build overwrites the same cache tag, one per image, so the first cache write to the image repository succeeded and every later one was refused. The cache now lives in its own ECR repository with mutable tags. Builds after a merge read and write it with
--cache-to type=registry,ref=<repo>:buildcache-<image>,mode=max, and pull request builds only read it, so an unmerged change can't put layers in the cache. - One hash in every stage. Dev and prod only produce the same image hash if the test that compares them replays the steps CI runs before synth, such as rewriting registry hosts in
uv.lock.
The Dockerfile changed too, because a cache only helps when the layers that change often come after the ones that don't. A first build stage runs uv export --frozen against the committed lock and splits the result into third-party packages from PyPI and the project's own wheels from its private registry. The split fails the build unless the two lists are disjoint and together equal the export. The runtime stage then installs in three layers:
# 1. Third-party closure, exactly as locked
COPY --from=lockgen /thirdparty.txt /thirdparty.txt
RUN --mount=type=secret,id=ca_token,env=CA_TOKEN \
pip install --no-cache-dir -r /thirdparty.txt
# 2. Our own wheels, no resolution
COPY --from=lockgen /firstparty.txt /firstparty.txt
RUN --mount=type=secret,id=ca_token,env=CA_TOKEN \
pip install --no-cache-dir --no-deps \
-r /firstparty.txt
# 3. Local source, last
COPY packages/api/pyproject.toml /build/
COPY packages/api/src /build/src
RUN pip install --no-cache-dir --no-deps /build
The registry token used to be a build ARG, which made it part of the cache key and the CDK asset hash, so every token rotation invalidated the cache and changed the image's identity. As a BuildKit secret mount (RUN --mount=type=secret) it exists only for the duration of each RUN and appears in no layer, cache key or hash. A code change now rebuilds only the last layer, and a bump of one of the project's own packages rebuilds the last two.
In the deploy job, one step reads the synthesized asset manifests and fails, naming the missing tag, if any image isn't already in the registry. It runs before cdk deploy, so the deploy can never fall back to building an image itself.
After this change cdk deploy on dev took 12 seconds with all 11 stacks unchanged, and production stopped building images:

Skipping checks CI already ran
After every merge, the deploy workflow re-ran every PR check on a tree CI had just passed. In 30 to 40 sampled merges per repository, the squash-merge tree was always the tree PR CI had tested. PR CI now uploads an artifact named for the tree and the target branch once every check passes, and the deploy skips its copy of those checks only when it finds that artifact from this repository's CI workflow, on a pull_request event, with a successful conclusion, unexpired. If the lookup fails, every check runs.
The lookup is a composite action, tested-tree, and the first job of each deploy workflow runs it right after checkout. It computes the commit's tree hash with git rev-parse 'HEAD^{tree}', asks the GitHub API for an artifact with the matching name, and then checks the workflow run that uploaded it. That is all one bash step, and every way the step can fail to prove the tree (an API error, no artifact, the wrong workflow or event, a failed or expired run) calls the same function. It sets the job output tested to false, leaves a visible warning, and exits 0, so the deploy carries on down the full-checks path instead of failing:
not_tested() {
echo "::warning::tested-tree lookup failed: $1"
echo "tested=false" >> "$GITHUB_OUTPUT"
exit 0
}
The record is keyed on the tree and the target branch, not the commit, because CI configuration can differ by base: one of the repositories synthesizes the prod stage for pull requests into main, so a record from a pull request into dev can't justify skipping a prod check.
The skip also changes how the jobs after it are gated. GitHub Actions skips a job when any job it needs was skipped, so the jobs downstream of the checks need an explicit condition. !cancelled() alone would also let them run after a failed check, so the condition names every check and accepts a skip only when the lookup proved the tree:
build-images:
needs: [tested-tree, lint, audit, cdk-synth]
if: >-
!cancelled()
&& needs.tested-tree.result == 'success'
&& (needs.lint.result == 'success'
|| (needs.lint.result == 'skipped'
&& needs.tested-tree.outputs.tested == 'true'))
The same pair of clauses repeats for audit and cdk-synth.
Checks that CI never performs for the deploy target still always run: the prod-stage synth, and a read-only resolve of every first-party dependency against the production registry.

Together with building images once, that took the main app's dev deploy from 28.9 minutes to 3m27s:

How the pipeline got this way
None of this was designed as one piece. The API image's Dockerfile shows how it accumulated. It became a container image because the dependency closure passed Lambda's 250 MB zip limit, then gained a sibling workspace package, then a streaming adapter. After a library's major release broke cold starts, because the image resolved dependencies from the live index while CI tested the lock, it moved to installing from the lock. To reach uv.lock, its build context moved up to the repository root. Each change fixed a real failure and passed CI, and along the way the shared lock ended up in the context of both images, so every bump of one of the project's own packages rebuilt both.
When Claude makes a change like that, it works from the task, the files it reads and the result of the checks. The checks say whether the change is correct. None of them report how long the next deploy takes, and the deploy runs after the pull request merges, outside the loop the agent works in. A deploy that gets a minute slower fails nothing, so nothing in that loop pushes back on it.
Many of the wastes were also tool defaults. cdk deploy builds a DockerImageAsset itself unless something else already pushed it, CDK reports versions unless told not to, and floating runner images and toolchain versions are what most examples use. Code that follows the documented, idiomatic path reproduces those defaults, and each one costs little on a single deploy.
The changes also added more than they removed. The deploy workflow carried a copy of every PR check. A trap explained in a comment on one stack was never applied to a sibling stack written later. Removing a step means knowing what it protects, which needs the whole pipeline in view, and a single change rarely has that view. The checks were also narrower than they looked: CI never built an image and never ran the infrastructure tests, so a green pull request said nothing about whether the images would build.
The waste doesn't show up in any one diff, so muda starts from the run history of the whole pipeline instead of from reviewing changes.
The standard
Each of these became a general rule plus the project's instance of it, with no project facts in the general part. By the end there were ten waste classes, named for what they look like in a pipeline (an unchanged deploy that still updates stacks, an unpinned toolchain, emulated builds, uncached work, serial work that could run in parallel, checks run twice on the same tree, and so on), and ten recipes, each a known fix for one or more of them. Because the general part held no project facts, the standard could move out of the project and into its own repository, where it became muda's waste classes and recipes. The next post runs that version on a pipeline it had never seen. muda is at muda.tools.