fix(ci): serialize Gradle cache mounts with sharing=locked (repair post-merge API build) #1001

Merged
chris merged 1 commit from fix/gradle-cache-lock into main 2026-10-03 12:00:18 +02:00
Owner

Problem

Post-merge run 3528 for PR #1000 failed at Build API image: gradle :apps:api:dependencies died with "Timeout waiting to connect to the Gradle daemon" + FileLockContentionHandler exceptions. Deploy API was skipped, so the API still runs the pre-merge image.

Root cause (timeline-proven):

  • apps/api/Dockerfile and apps/worker-media/Dockerfile share cache id memories-gradle-cache as their entire GRADLE_USER_HOME (daemon registry + file locks).
  • The root build.gradle.kts change in #1000 invalidated both images' gradle layers at once → both jobs launched Gradle 0.3s apart (09:41:45.9 / 09:41:46.2) in separate network namespaces on one shared daemon registry → API timed out, media worker won.

Fix

Add sharing=locked to all four Gradle cache mounts: BuildKit serializes every step using that cache id across all builds on the daemon, so exactly one Gradle process owns GRADLE_USER_HOME at a time, while dependency caching stays shared (no cache duplication).

Verification

  • Parallel docker build of both images via docker:28-cli + BuildKit (the CI execution path) with the fixed Dockerfiles: both exit 0 (gradle dependencies + bootJar executed for each).
  • Scope of this PR (apps/api/**, apps/worker-media/**) re-triggers exactly the failed jobs on merge: Build API image → Deploy API (+ media worker rebuild/redeploy).
## Problem Post-merge run 3528 for PR #1000 failed at **Build API image**: `gradle :apps:api:dependencies` died with *"Timeout waiting to connect to the Gradle daemon"* + `FileLockContentionHandler` exceptions. **Deploy API was skipped**, so the API still runs the pre-merge image. Root cause (timeline-proven): - `apps/api/Dockerfile` and `apps/worker-media/Dockerfile` share cache id `memories-gradle-cache` as their **entire `GRADLE_USER_HOME`** (daemon registry + file locks). - The root `build.gradle.kts` change in #1000 invalidated both images' gradle layers at once → both jobs launched Gradle **0.3s apart** (09:41:45.9 / 09:41:46.2) in separate network namespaces on one shared daemon registry → API timed out, media worker won. ## Fix Add `sharing=locked` to all four Gradle cache mounts: BuildKit serializes every step using that cache id across all builds on the daemon, so exactly one Gradle process owns `GRADLE_USER_HOME` at a time, while dependency caching stays shared (no cache duplication). ## Verification - Parallel `docker build` of **both** images via `docker:28-cli` + BuildKit (the CI execution path) with the fixed Dockerfiles: **both exit 0** (gradle `dependencies` + `bootJar` executed for each). - Scope of this PR (`apps/api/**`, `apps/worker-media/**`) re-triggers exactly the failed jobs on merge: **Build API image → Deploy API** (+ media worker rebuild/redeploy).
fix(ci): serialize Gradle cache mounts with sharing=locked
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 1m36s
fa1b605d05
Run 3528 'Build API image' failed with 'Timeout waiting to connect to
the Gradle daemon' + FileLockContentionHandler errors: apps/api and
apps/worker-media Dockerfiles share cache id memories-gradle-cache as
their whole GRADLE_USER_HOME (daemon registry + file locks), and a
root build.gradle.kts change invalidates both images' gradle layers at
once — the two jobs then ran Gradle 0.3s apart in separate network
namespaces on one shared daemon registry (media won, API timed out).

sharing=locked makes BuildKit serialize all steps using that cache id
across builds on the daemon, so only one Gradle process owns
GRADLE_USER_HOME at a time while dependency caching stays shared.
chris merged commit ccd7866fa7 into main 2026-10-03 12:00:18 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1001
No description provided.