From 1ba1ed19ea212ad2a5e0dc58826470b568ed9df4 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Wed, 25 Nov 2026 21:25:46 -0800 Subject: [PATCH 01/10] ADFA-6958: Run the CI checks in their own job, alongside the APK build Step 3 of the ADFA-6953 plan. The Universal APK job ran four checks (apiCheck, the plugin-api and sqlite-debugger unit tests, and spotlessCheck with the :common compile) one after another before the assemble, about 123 s on a normal stage build. They now run in a new job, "Run checks (API, unit tests, Spotless)", on a second runner at the same time as the build, so they are off the critical path. The build job still publishes nothing unless the checks pass: a new step before the Google Cloud login waits for the checks job (GitHub API, filter=latest so "Re-run failed jobs" sees the newest attempt) and fails if it did not succeed. "Build Universal APK", the only status check that stage's branch protection requires, therefore still fails on a failed check, and branch protection needs no change. The steps moved unchanged, with the same comments and error hint. The checks job sets up the workspace the same way (checkout, flox, google-services.json and its cleanup, INCLUDE_LLAMA_ASSETS=false). Runner use over 2026-11-19..26: jobs waited a median 2 s for a runner, 5 of 885 waited over a minute, and all six runners were busy 0.1% of the busy time, so the second runner per push should not cause queueing. The sqlite-debugger README names the job its tests now run in. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 129 +++++++++++++++++++++----- subprojects/sqlite-debugger/README.md | 2 +- 2 files changed, 105 insertions(+), 26 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index ed07b819d8..c056e939b1 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -133,10 +133,14 @@ jobs: echo "Jira ticket $JIRA_TICKET exists" - build_apk: - name: Build Universal APK + # The checks run here, on a second runner at the same time as build_apk, instead of before the + # assemble (ADFA-6958). build_apk publishes nothing until this job has passed (its step "Wait + # for the checks to pass"), so "Build Universal APK", the check branch protection requires, + # still fails when a check fails. + checks: + name: Run checks (API, unit tests, Spotless) runs-on: self-hosted - timeout-minutes: 60 + timeout-minutes: 30 needs: [ check_changes, validate_branch ] if: needs.check_changes.outputs.must_build == 'true' env: @@ -144,35 +148,13 @@ jobs: steps: - - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.12.1 - with: - access_token: ${{ github.token }} - - name: Checkout PR branch uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 0 - - name: Validate branch name length - run: | - BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} - BRANCH_LENGTH=${#BRANCH_NAME} - echo "Branch name: $BRANCH_NAME" - echo "Branch name length: $BRANCH_LENGTH characters" - - if [ $BRANCH_LENGTH -gt 80 ]; then - echo "ERROR: Branch name exceeds the 80 character limit ($BRANCH_LENGTH characters)" - echo "This causes Google Cloud authentication to fail due to subject mapping limits." - echo "Please rename your branch to 80 characters or fewer and try again." - exit 1 - fi - - echo "Branch name length is valid ($BRANCH_LENGTH ≤ 80 characters)" - - name: Check if Nix is installed - id: check_nix run: | if command -v nix >/dev/null 2>&1; then echo "nix is installed" @@ -228,6 +210,72 @@ jobs: exit "$status" fi + - name: Cleanup google-services.json + if: always() + run: | + rm -f app/google-services.json + echo "google-services.json cleaned up successfully" + + build_apk: + name: Build Universal APK + runs-on: self-hosted + timeout-minutes: 60 + needs: [ check_changes, validate_branch ] + if: needs.check_changes.outputs.must_build == 'true' + env: + INCLUDE_LLAMA_ASSETS: "false" + + steps: + + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.12.1 + with: + access_token: ${{ github.token }} + + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + fetch-depth: 0 + + - name: Validate branch name length + run: | + BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + BRANCH_LENGTH=${#BRANCH_NAME} + echo "Branch name: $BRANCH_NAME" + echo "Branch name length: $BRANCH_LENGTH characters" + + if [ $BRANCH_LENGTH -gt 80 ]; then + echo "ERROR: Branch name exceeds the 80 character limit ($BRANCH_LENGTH characters)" + echo "This causes Google Cloud authentication to fail due to subject mapping limits." + echo "Please rename your branch to 80 characters or fewer and try again." + exit 1 + fi + + echo "Branch name length is valid ($BRANCH_LENGTH ≤ 80 characters)" + + - name: Check if Nix is installed + id: check_nix + run: | + if command -v nix >/dev/null 2>&1; then + echo "nix is installed" + echo "nix_installed=true" >> $GITHUB_ENV + else + echo "nix is not installed" + echo "nix_installed=false" >> $GITHUB_ENV + fi + + - name: Install Flox + if: env.nix_installed == 'false' + uses: flox/install-flox-action@v2 + + - name: Create google-services.json + env: + GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }} + run: | + echo "$GOOGLE_SERVICES_JSON" > app/google-services.json + echo "google-services.json created successfully" + - name: Install advancecomp (advzip, used by recompressApk) run: | command -v advzip || { sudo apt-get update && sudo apt-get install -y advancecomp; } @@ -336,6 +384,37 @@ jobs: echo "JIRA_TITLE=$JIRA_TITLE" >> $GITHUB_OUTPUT echo "JIRA_URL=$JIRA_URL" >> $GITHUB_OUTPUT + # Publish nothing until the checks job has passed. It started with this job and is much + # shorter, so this normally returns at once. filter=latest: after "Re-run failed jobs", the + # checks job's newest attempt counts, not the failed one. + - name: Wait for the checks to pass + env: + CHECKS_JOB: Run checks (API, unit tests, Spotless) + GH_TOKEN: ${{ github.token }} + run: | + url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100" + deadline=$((SECONDS + 30 * 60)) + while :; do + state=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \ + | jq -r --arg name "$CHECKS_JOB" '.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)"') || state="" + case "$state" in + "completed success") + echo "The checks passed." + exit 0 + ;; + completed\ *) + echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }', so nothing was published. Its log shows which check failed." + exit 1 + ;; + esac + if [ "$SECONDS" -ge "$deadline" ]; then + echo "::error::Gave up after 30 minutes waiting for the job '$CHECKS_JOB' (last state: '${state:-not found}'), so nothing was published." + exit 1 + fi + echo "Job '$CHECKS_JOB': ${state:-not found yet}; checking again in 15 s" + sleep 15 + done + - name: Authenticate to Google Cloud via Workload Identity uses: google-github-actions/auth@v2 with: diff --git a/subprojects/sqlite-debugger/README.md b/subprojects/sqlite-debugger/README.md index 236123db27..17ae166606 100644 --- a/subprojects/sqlite-debugger/README.md +++ b/subprojects/sqlite-debugger/README.md @@ -52,7 +52,7 @@ The layout of `sqlitedbg_event_record` lives in `sqlitedbg.h`. The JNI layer han - **JNI test:** when a JDK is on PATH, `test.sh` also builds `libsqlitedbg.so` as it ships (no `SQLITE_CORE`) against a requery-like `libsqlite3x.so` and runs `src/test/jni/JniQueryTest.java` through `NativeBridge`: paging, the total-bytes budget, per-cell truncation, bound types, one statement per call, the deadline, refused writes and transactions, and the rollback of a transaction left open. It uses Java stubs of `NativeBridge` and `DebugEngineException` instead of the Kotlin, so a JDK is all it needs; `test.sh` checks the native names match `NativeBridge.kt`. Otherwise it is skipped with a message. CI runs `test.sh` in `.github/workflows/test-sqlite-debugger.yml` for changes under this module. - **JVM tests:** `flox activate -d flox/local -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest`. They cover `EventDecoder`, `McpProtocol`, `McpHttp`, `DatabaseTools` (with `FakeDebugEngine`) and `EndpointBroadcast`, its announce receiver included. -`.github/workflows/test-sqlite-debugger.yml` runs `test.sh` (the C and JNI tests) on pull requests that touch the module or the SQLite headers. The JVM tests run in `.github/workflows/debug.yml`, in the step "Run sqlite-debugger unit tests" beside the `:plugin-api` one. +`.github/workflows/test-sqlite-debugger.yml` runs `test.sh` (the C and JNI tests) on pull requests that touch the module or the SQLite headers. The JVM tests run in `.github/workflows/debug.yml`, in the job "Run checks (API, unit tests, Spotless)", step "Run sqlite-debugger unit tests", beside the `:plugin-api` one. ## Not done yet From af5ccb218bbfd49d3e09e897d25ca977ab8fd5d2 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Wed, 25 Nov 2026 21:37:20 -0800 Subject: [PATCH 02/10] ADFA-6958: Cap the checks job at two workers; harden the wait step From the independent review of the first commit: - The six runners are three per machine (01/03/05 on one, 02/04/06 on the other, from the job logs), so the checks job often shares a machine with a build job. Over 2026-11-19..26, "Build Universal APK" jobs that shared their machine with another Gradle-heavy job for at least half their run took a median 1047 s, against 638 s with no neighbour (83 and 119 jobs). The machines have 30 cores (Gradle uses 30 worker leases), and a full build uses all of them. --max-workers=2 keeps the checks to two cores; they are off the critical path. - curl gets --max-time 30, so a hung API call cannot stall the wait. - The wait's limit is 40 minutes instead of 30. It counts from the wait step, so it must also cover the checks job waiting for a runner. - The failure message says to use "Re-run failed jobs": re-running only the checks job leaves "Build Universal APK" failed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index c056e939b1..18eb30ae2d 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -137,6 +137,8 @@ jobs: # assemble (ADFA-6958). build_apk publishes nothing until this job has passed (its step "Wait # for the checks to pass"), so "Build Universal APK", the check branch protection requires, # still fails when a check fails. + # Each machine hosts three runners, so this job often shares one with a build job. --max-workers=2 + # keeps it to two of the machine's cores; it is off the critical path, so its own time matters less. checks: name: Run checks (API, unit tests, Spotless) runs-on: self-hosted @@ -177,21 +179,21 @@ jobs: - name: Verify plugin-api binary compatibility run: | - flox activate -d flox/base -- ./gradlew :plugin-api:apiCheck --no-daemon + flox activate -d flox/base -- ./gradlew :plugin-api:apiCheck --no-daemon --max-workers=2 # testDebugUnitTest, not testV8DebugUnitTest: :plugin-api declares no product flavors, so the # v8 task every other module has does not exist here. Named as its own step rather than left # to jacocoAggregateReport, which is not on the PR path at all. - name: Run plugin-api unit tests run: | - flox activate -d flox/base -- ./gradlew :plugin-api:testDebugUnitTest --no-daemon + flox activate -d flox/base -- ./gradlew :plugin-api:testDebugUnitTest --no-daemon --max-workers=2 # The SQLite debugger's Kotlin tests (EventDecoder, McpProtocol, McpHttp, DatabaseTools). Its own # workflow, test-sqlite-debugger.yml, runs only test.sh (the C and JNI tests) on ubuntu-latest. Like # :plugin-api it has no product flavors, so the task is testDebugUnitTest. - name: Run sqlite-debugger unit tests run: | - flox activate -d flox/base -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest --no-daemon + flox activate -d flox/base -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest --no-daemon --max-workers=2 # Combined with a compile task on purpose: spotlessCheck alone never pulls a # source-tree-writing task into the graph, so the implicit-dependency failure ADFA-5244 fixed @@ -202,7 +204,7 @@ jobs: # Two tasks, so two possible causes: the message must not name one of them. Blaming # Spotless for a compile error is the exact misdiagnosis this step exists to catch. set +e - flox activate -d flox/base -- ./gradlew :common:compileV8DebugKotlin spotlessCheck --no-daemon + flox activate -d flox/base -- ./gradlew :common:compileV8DebugKotlin spotlessCheck --no-daemon --max-workers=2 status=$? set -e if [ "$status" -ne 0 ]; then @@ -386,16 +388,17 @@ jobs: # Publish nothing until the checks job has passed. It started with this job and is much # shorter, so this normally returns at once. filter=latest: after "Re-run failed jobs", the - # checks job's newest attempt counts, not the failed one. + # checks job's newest attempt counts, not the failed one. The 40-minute limit counts from + # here, so it also covers the checks job waiting for a runner; past it, nothing is published. - name: Wait for the checks to pass env: CHECKS_JOB: Run checks (API, unit tests, Spotless) GH_TOKEN: ${{ github.token }} run: | url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100" - deadline=$((SECONDS + 30 * 60)) + deadline=$((SECONDS + 40 * 60)) while :; do - state=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \ + state=$(curl -fsS --max-time 30 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \ | jq -r --arg name "$CHECKS_JOB" '.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)"') || state="" case "$state" in "completed success") @@ -403,12 +406,12 @@ jobs: exit 0 ;; completed\ *) - echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }', so nothing was published. Its log shows which check failed." + echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }', so nothing was published. Its log shows which check failed. To retry, use \"Re-run failed jobs\": re-running only one of the two jobs leaves this one failed." exit 1 ;; esac if [ "$SECONDS" -ge "$deadline" ]; then - echo "::error::Gave up after 30 minutes waiting for the job '$CHECKS_JOB' (last state: '${state:-not found}'), so nothing was published." + echo "::error::Gave up after 40 minutes waiting for the job '$CHECKS_JOB' (last state: '${state:-not found}'), so nothing was published." exit 1 fi echo "Job '$CHECKS_JOB': ${state:-not found yet}; checking again in 15 s" From 5e5751cc776540bda04398150fde501c9a9bc4ba Mon Sep 17 00:00:00 2001 From: David Schachter Date: Wed, 25 Nov 2026 21:42:57 -0800 Subject: [PATCH 03/10] ADFA-6958: Give up waiting for the checks before the job times out From the re-review: on 87 recent green builds the wait step would start after a median 705 s, p90 1236 s and max 1554 s. A fixed 40-minute wait on top of that could run into the build job's 60-minute timeout, which shows a generic cancellation instead of the error. If the checks passed at the last moment, the timeout could also stop the job after the App Tester upload but before the Jira and Slack steps. The job now records its start time in its first step, and the wait gives up 5 minutes before the 60-minute timeout, leaving time for the publish steps. The timeout itself is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 18eb30ae2d..fac2e25cd5 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -221,6 +221,7 @@ jobs: build_apk: name: Build Universal APK runs-on: self-hosted + # "Wait for the checks to pass" gives up 5 minutes before this timeout; change both together. timeout-minutes: 60 needs: [ check_changes, validate_branch ] if: needs.check_changes.outputs.must_build == 'true' @@ -229,6 +230,10 @@ jobs: steps: + # For "Wait for the checks to pass", which must give up before this job's timeout. + - name: Record the job start time + run: echo "JOB_STARTED_AT=$(date +%s)" >> "$GITHUB_ENV" + - name: Cancel previous runs uses: styfle/cancel-workflow-action@0.12.1 with: @@ -388,15 +393,16 @@ jobs: # Publish nothing until the checks job has passed. It started with this job and is much # shorter, so this normally returns at once. filter=latest: after "Re-run failed jobs", the - # checks job's newest attempt counts, not the failed one. The 40-minute limit counts from - # here, so it also covers the checks job waiting for a runner; past it, nothing is published. + # checks job's newest attempt counts, not the failed one. It gives up 5 minutes before this + # job's 60-minute timeout, which leaves time for the publish steps: a timeout during them + # could upload to App Tester without the Jira and Slack steps. - name: Wait for the checks to pass env: CHECKS_JOB: Run checks (API, unit tests, Spotless) GH_TOKEN: ${{ github.token }} run: | url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100" - deadline=$((SECONDS + 40 * 60)) + deadline=$((JOB_STARTED_AT + (60 - 5) * 60)) while :; do state=$(curl -fsS --max-time 30 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \ | jq -r --arg name "$CHECKS_JOB" '.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)"') || state="" @@ -410,8 +416,8 @@ jobs: exit 1 ;; esac - if [ "$SECONDS" -ge "$deadline" ]; then - echo "::error::Gave up after 40 minutes waiting for the job '$CHECKS_JOB' (last state: '${state:-not found}'), so nothing was published." + if [ "$(date +%s)" -ge "$deadline" ]; then + echo "::error::Gave up waiting for the job '$CHECKS_JOB' 5 minutes before this job's timeout (last state: '${state:-not found}'), so nothing was published." exit 1 fi echo "Job '$CHECKS_JOB': ${state:-not found yet}; checking again in 15 s" From 448ce9461b224e64321dac1d753e189e1c72c712 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Wed, 25 Nov 2026 22:11:20 -0800 Subject: [PATCH 04/10] ADFA-6958: Check the wait deadline before accepting success From CodeRabbit: if the assemble itself ran past the 55-minute mark and the checks had already passed, the wait step accepted success at once, so publishing could start without the 5-minute reserve the step exists to keep, and the job's timeout could fall between the App Tester upload and the Jira and Slack steps. The step now checks the deadline after each poll and before accepting success. A failed check still reports as a failed check at any time. Tested locally against real runs: success in time, success too late, failure in time and too late, not found in time and too late. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index fac2e25cd5..5991b66b4b 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -407,19 +407,21 @@ jobs: state=$(curl -fsS --max-time 30 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \ | jq -r --arg name "$CHECKS_JOB" '.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)"') || state="" case "$state" in - "completed success") - echo "The checks passed." - exit 0 - ;; + "completed success") ;; completed\ *) echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }', so nothing was published. Its log shows which check failed. To retry, use \"Re-run failed jobs\": re-running only one of the two jobs leaves this one failed." exit 1 ;; esac + # Before accepting success too: a build that gets here late must not start publishing. if [ "$(date +%s)" -ge "$deadline" ]; then - echo "::error::Gave up waiting for the job '$CHECKS_JOB' 5 minutes before this job's timeout (last state: '${state:-not found}'), so nothing was published." + echo "::error::Too close to this job's timeout to publish safely (job '$CHECKS_JOB': '${state:-not found}'), so nothing was published." exit 1 fi + if [ "$state" = "completed success" ]; then + echo "The checks passed." + exit 0 + fi echo "Job '$CHECKS_JOB': ${state:-not found yet}; checking again in 15 s" sleep 15 done From 62fb3d5a7a9df25af39f137047f765bec353009f Mon Sep 17 00:00:00 2001 From: David Schachter Date: Thu, 26 Nov 2026 11:16:14 -0800 Subject: [PATCH 05/10] ADFA-6958: Cap the checks job's heap gradle.properties lets Gradle and the Kotlin daemon each grow to 8 GB of heap, and three runners share a machine with 30 GB and no swap. From 2026-10-31 to 2026-11-26, four jobs lost a Gradle or Kotlin process partway through, each while other Gradle builds ran on the same machine, with no OutOfMemoryError logged (ADFA-7325). The checks job adds a second Gradle job per push, so give its four Gradle calls 3 GB for Gradle and 2 GB for the Kotlin daemon. The value replaces the gradle.properties line, so it repeats that line's other flags. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 5991b66b4b..3a902bcec8 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -147,6 +147,14 @@ jobs: if: needs.check_changes.outputs.must_build == 'true' env: INCLUDE_LLAMA_ASSETS: "false" + # Passed as -Dorg.gradle.jvmargs, which replaces that line in gradle.properties, so it repeats + # the line's other flags. These checks need far less heap than the APK build's 8 GB each for + # Gradle and Kotlin, and three runners share a machine with 30 GB and no swap, where Gradle + # and Kotlin processes have been killed when builds overlapped (ADFA-7325). + CHECKS_JVMARGS: >- + -Xmx3g -Dkotlin.daemon.jvm.options=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError + --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.io=ALL-UNNAMED steps: @@ -179,21 +187,21 @@ jobs: - name: Verify plugin-api binary compatibility run: | - flox activate -d flox/base -- ./gradlew :plugin-api:apiCheck --no-daemon --max-workers=2 + flox activate -d flox/base -- ./gradlew :plugin-api:apiCheck --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS" # testDebugUnitTest, not testV8DebugUnitTest: :plugin-api declares no product flavors, so the # v8 task every other module has does not exist here. Named as its own step rather than left # to jacocoAggregateReport, which is not on the PR path at all. - name: Run plugin-api unit tests run: | - flox activate -d flox/base -- ./gradlew :plugin-api:testDebugUnitTest --no-daemon --max-workers=2 + flox activate -d flox/base -- ./gradlew :plugin-api:testDebugUnitTest --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS" # The SQLite debugger's Kotlin tests (EventDecoder, McpProtocol, McpHttp, DatabaseTools). Its own # workflow, test-sqlite-debugger.yml, runs only test.sh (the C and JNI tests) on ubuntu-latest. Like # :plugin-api it has no product flavors, so the task is testDebugUnitTest. - name: Run sqlite-debugger unit tests run: | - flox activate -d flox/base -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest --no-daemon --max-workers=2 + flox activate -d flox/base -- ./gradlew :subprojects:sqlite-debugger:testDebugUnitTest --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS" # Combined with a compile task on purpose: spotlessCheck alone never pulls a # source-tree-writing task into the graph, so the implicit-dependency failure ADFA-5244 fixed @@ -204,7 +212,7 @@ jobs: # Two tasks, so two possible causes: the message must not name one of them. Blaming # Spotless for a compile error is the exact misdiagnosis this step exists to catch. set +e - flox activate -d flox/base -- ./gradlew :common:compileV8DebugKotlin spotlessCheck --no-daemon --max-workers=2 + flox activate -d flox/base -- ./gradlew :common:compileV8DebugKotlin spotlessCheck --no-daemon --max-workers=2 "-Dorg.gradle.jvmargs=$CHECKS_JVMARGS" status=$? set -e if [ "$status" -ne 0 ]; then From 18f735df4767f56494eaa9f8882d0751b480a575 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Thu, 26 Nov 2026 11:39:16 -0800 Subject: [PATCH 06/10] ADFA-6958: Say where to raise the checks job's heap, and point at the jvmargs copies Independent review of 62fb3d5a7: only runner 02's machine was measured, so say so; Gradle's and Kotlin's out-of-memory messages point at gradle.properties, which CHECKS_JVMARGS overrides, so say to raise the limit there; and gradle.properties now names the workflows that replace its org.gradle.jvmargs line, so a new flag reaches them too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 6 ++++-- gradle.properties | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 3a902bcec8..d7894cf2fd 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -149,8 +149,10 @@ jobs: INCLUDE_LLAMA_ASSETS: "false" # Passed as -Dorg.gradle.jvmargs, which replaces that line in gradle.properties, so it repeats # the line's other flags. These checks need far less heap than the APK build's 8 GB each for - # Gradle and Kotlin, and three runners share a machine with 30 GB and no swap, where Gradle - # and Kotlin processes have been killed when builds overlapped (ADFA-7325). + # Gradle and Kotlin. Three runners share each machine (the one measured has 30 GB and no + # swap), and Gradle and Kotlin processes have been killed there when builds overlapped + # (ADFA-7325). If a check runs out of memory, raise the limit here: Gradle's and Kotlin's + # messages point at gradle.properties, which this value overrides. CHECKS_JVMARGS: >- -Xmx3g -Dkotlin.daemon.jvm.options=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED diff --git a/gradle.properties b/gradle.properties index 21c60ef2b9..febcc0c598 100755 --- a/gradle.properties +++ b/gradle.properties @@ -18,6 +18,9 @@ android.nonTransitiveRClass=false android.useAndroidX=true org.gradle.caching=true org.gradle.configureondemand=true +# Workflows that pass -Dorg.gradle.jvmargs replace this whole line, not just the heap size: +# CHECKS_JVMARGS in .github/workflows/debug.yml, release.yml and generate_assets.yml. A flag +# added here must be added there too. org.gradle.jvmargs=-Xmx8192M -Dkotlin.daemon.jvm.options\="-Xmx8192M" -XX\:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.lang\=ALL-UNNAMED --add-opens java.base/java.util\=ALL-UNNAMED --add-opens java.base/java.io\=ALL-UNNAMED org.gradle.parallel=true org.gradle.vfs.watch=true From fed757c9df2e52c67635d6511d3354e3d4e2711d Mon Sep 17 00:00:00 2001 From: David Schachter Date: Thu, 26 Nov 2026 11:44:54 -0800 Subject: [PATCH 07/10] ADFA-6958: Say which out-of-memory hint overrides CHECKS_JVMARGS Re-review of 18f735df4: Kotlin's message points at kotlin.daemon.jvmargs, which KGP applies after kotlin.daemon.jvm.options, so setting it in gradle.properties would override this job's 2 GB, and the build's 8 GB. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index d7894cf2fd..581e0c3c25 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -151,8 +151,9 @@ jobs: # the line's other flags. These checks need far less heap than the APK build's 8 GB each for # Gradle and Kotlin. Three runners share each machine (the one measured has 30 GB and no # swap), and Gradle and Kotlin processes have been killed there when builds overlapped - # (ADFA-7325). If a check runs out of memory, raise the limit here: Gradle's and Kotlin's - # messages point at gradle.properties, which this value overrides. + # (ADFA-7325). If a check runs out of memory, raise the limit here. Gradle's message points + # at org.gradle.jvmargs in gradle.properties, which this value overrides; Kotlin's points at + # kotlin.daemon.jvmargs, which would override this value in every job. CHECKS_JVMARGS: >- -Xmx3g -Dkotlin.daemon.jvm.options=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED From 32a0631f5b94a344765f851c4163544ef878a70d Mon Sep 17 00:00:00 2001 From: David Schachter Date: Mon, 30 Nov 2026 13:07:23 -0800 Subject: [PATCH 08/10] ADFA-6958: Stop the APK build when a check fails Hal's review: a failed check must signal the assemble to abort, so the self-hosted runners are not held for the rest of a ten-minute build that cannot be published. The "Assemble Universal APK" step now runs Gradle in the background and polls the checks job every 30 s while it runs (the same jobs API call, filter=latest, as "Wait for the checks to pass"). If that job ends with anything but success, the step stops Gradle and its whole process tree, fails with a message that says what happened and how to retry, and nothing is published. If the checks succeed first it stops polling; if the build ends first its exit status is passed through, then the D8 check runs as before. A trap stops the build if the step itself is cancelled or times out, so the build cannot outlive its job. The tree is stopped by parent pid, not by process group: Gradle's single-use daemon sits in its own group but is a child of its client. "Install jq" moves above this step, which now uses it. "Wait for the checks to pass" is unchanged and still decides whether to publish when the build finishes first. Tested locally with the step's real script: stubbed curl and flox for exit codes (abort on failure and on cancelled, pass-through of a build failure, D8, API errors, SIGTERM to the step), and a real Gradle build with a forked daemon that was stopped mid-task with no process left behind. Not yet run on a runner. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 59 +++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 8c90f93b18..f4fab005b2 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -300,14 +300,65 @@ jobs: run: | command -v advzip || { sudo apt-get update && sudo apt-get install -y advancecomp; } + # For "Assemble Universal APK", which polls the checks job, and for the publish steps. + - name: Install jq + run: command -v jq || { sudo apt-get update && sudo apt-get install -y jq; } + + # The checks job starts with this one and normally ends within minutes. If it fails, this build + # can no longer be published, so it is stopped instead of holding a self-hosted runner for the + # rest of its ten minutes (ADFA-6958). "Wait for the checks to pass" below still decides whether + # to publish when the build finishes first. - name: Assemble Universal APK + env: + CHECKS_JOB: Run checks (API, unit tests, Spotless) + GH_TOKEN: ${{ github.token }} run: | - set -o pipefail # advzip (in recompressApk) only for stage, the debug builds most testers install. Elsewhere # it costs 200-300 s to save about 3.7% of the APK (ADFA-6957). advzip=() if [ "$GITHUB_REF_NAME" = stage ]; then advzip=(-Padvzip); fi - flox activate -d flox/base -- ./gradlew :app:assembleV8Debug --no-daemon "${advzip[@]}" 2>&1 | tee "$RUNNER_TEMP/assemble.log" + + # Stops a process and everything below it. Gradle's single-use daemon is a child of its + # client, so this reaches it too; it ends within seconds of its client (tested, Gradle 8.14). + kill_tree() { + local child + for child in $(pgrep -P "$1"); do kill_tree "$child"; done + kill -TERM "$1" 2>/dev/null || true + } + + ( + set -o pipefail + flox activate -d flox/base -- ./gradlew :app:assembleV8Debug --no-daemon "${advzip[@]}" 2>&1 | tee "$RUNNER_TEMP/assemble.log" + ) & + build=$! + # A cancelled or timed-out job must not leave the build running. + trap 'kill_tree "$build"' EXIT INT TERM + + url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100" + watching=true + while kill -0 "$build" 2>/dev/null; do + if $watching; then + # filter=latest: after "Re-run failed jobs", the newest attempt of the checks job counts. + state=$(curl -fsS --max-time 30 -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "$url" \ + | jq -r --arg name "$CHECKS_JOB" '.jobs[] | select(.name == $name) | "\(.status) \(.conclusion)"') || state="" + case "$state" in + "completed success") watching=false ;; + completed\ *) + echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }' while this build was still running, so the build was stopped and nothing will be published. Its log shows which check failed. To retry, use \"Re-run failed jobs\"." + kill_tree "$build" + wait "$build" 2>/dev/null || true + exit 1 + ;; + esac + fi + # Look again in 30 s, but notice the build ending within a second. + for _ in $(seq 30); do kill -0 "$build" 2>/dev/null || break; sleep 1; done + done + status=0 + wait "$build" || status=$? + trap - EXIT INT TERM + [ "$status" -eq 0 ] || exit "$status" + # D8 logs this (non-fatal) once per class when the pinned R8 is older than the Kotlin # metadata version, burying every real diagnostic. See the `r8` pin in libs.versions.toml. if grep -q "Unexpected error during rewriting of Kotlin metadata" "$RUNNER_TEMP/assemble.log"; then @@ -315,7 +366,6 @@ jobs: exit 1 fi - - name: Find APK file id: find_apk run: | @@ -336,9 +386,6 @@ jobs: fi echo "BUILD_TYPE=$BUILD_TYPE" >> $GITHUB_ENV - - name: Install jq - run: command -v jq || { sudo apt-get update && sudo apt-get install -y jq; } - - name: Get PR and Commit Information id: pr_info run: | From bf390bf6fa8b401fdb2435859d11f984dc6cfcf5 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Mon, 30 Nov 2026 19:10:11 -0800 Subject: [PATCH 09/10] ADFA-6958: Wait for the build's processes to exit before ending the step kill_tree sent SIGTERM and returned, and wait "$build" waits only for the subshell, so the step could end while Gradle was still shutting down. The runner's orphan cleanup caught it (Terminate orphan process: java), but the step should not rely on that. kill_tree now collects the process tree, sends SIGTERM, and returns only when every process has exited (zombies count as gone), with SIGKILL after 30 s. Tested with a stub whose child takes 4 s to exit after SIGTERM: the old function returned after 0 s with the child still running; the new one waits for it. The earlier scenarios (abort on failure or cancel, success, failing build, D8 message, jobs API errors) and a real Gradle build give the same results, and no Gradle process is left behind. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index f4fab005b2..d473a5d730 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -318,12 +318,29 @@ jobs: advzip=() if [ "$GITHUB_REF_NAME" = stage ]; then advzip=(-Padvzip); fi - # Stops a process and everything below it. Gradle's single-use daemon is a child of its - # client, so this reaches it too; it ends within seconds of its client (tested, Gradle 8.14). - kill_tree() { + # Stops a process and everything below it, and returns only when they have exited (KILL + # after 30 s), so the step never ends with Gradle still running. Gradle's single-use daemon + # is a child of its client, so this reaches it too. A zombie counts as gone. + descendants() { local child - for child in $(pgrep -P "$1"); do kill_tree "$child"; done - kill -TERM "$1" 2>/dev/null || true + for child in $(pgrep -P "$1"); do echo "$child"; descendants "$child"; done + } + running() { + local state + state=$(ps -o stat= -p "$1" 2>/dev/null) || return 1 + [ -n "$state" ] && [ "${state#Z}" = "$state" ] + } + kill_tree() { + local pids p i alive + pids="$1 $(descendants "$1")" + for p in $pids; do kill -TERM "$p" 2>/dev/null || true; done + for i in $(seq 30); do + alive=false + for p in $pids; do if running "$p"; then alive=true; fi; done + $alive || return 0 + sleep 1 + done + for p in $pids; do kill -KILL "$p" 2>/dev/null || true; done } ( From 4705cbe5bc1aa195e0c7a27aee9fd94489617491 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Tue, 1 Dec 2026 17:16:15 -0800 Subject: [PATCH 10/10] ADFA-6958: Name the checks job once in the build job, and stop the tree once Three findings from the independent review of the abort step: - CHECKS_JOB moves from the two steps' env to build_apk's env. The checks job's name now has one copy, with comments at both ends. A rename that updated only one step's copy would have disabled the abort without a message. - The abort branch clears the EXIT/INT/TERM trap before `exit 1`, so the trap no longer runs kill_tree a second time on the reaped build pid. - kill_tree's unused loop counter becomes `_` (shellcheck SC2034). kill_tree's comment now says that it does not wait after sending KILL. Checked by running the extracted step under bash -e with stubbed flox and curl. A failed or cancelled checks job gives exit 1 with kill_tree called once; at bf390bf6f the same case calls it twice. A daemon that ignores TERM is killed after the 30 s grace. A passing or running checks job gives exit 0 without a kill. SIGTERM to the step gives exit 143. In every case no stub process was left. actionlint is clean; with shellcheck, the two changed steps report nothing. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --- .github/workflows/debug.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index d473a5d730..8c9e96bd93 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -140,6 +140,7 @@ jobs: # Each machine hosts three runners, so this job often shares one with a build job. --max-workers=2 # keeps it to two of the machine's cores; it is off the critical path, so its own time matters less. checks: + # build_apk's CHECKS_JOB repeats this name; change both together. name: Run checks (API, unit tests, Spotless) runs-on: self-hosted timeout-minutes: 30 @@ -238,6 +239,10 @@ jobs: if: needs.check_changes.outputs.must_build == 'true' env: INCLUDE_LLAMA_ASSETS: "false" + # The checks job's name, which the abort in "Assemble Universal APK" and "Wait for the checks + # to pass" look up. A mismatch disables the abort without a message, and the wait fails only + # at its deadline. + CHECKS_JOB: Run checks (API, unit tests, Spotless) steps: @@ -310,7 +315,6 @@ jobs: # to publish when the build finishes first. - name: Assemble Universal APK env: - CHECKS_JOB: Run checks (API, unit tests, Spotless) GH_TOKEN: ${{ github.token }} run: | # advzip (in recompressApk) only for stage, the debug builds most testers install. Elsewhere @@ -318,9 +322,10 @@ jobs: advzip=() if [ "$GITHUB_REF_NAME" = stage ]; then advzip=(-Padvzip); fi - # Stops a process and everything below it, and returns only when they have exited (KILL - # after 30 s), so the step never ends with Gradle still running. Gradle's single-use daemon - # is a child of its client, so this reaches it too. A zombie counts as gone. + # Stops a process and everything below it: TERM, then up to 30 s for them to exit, then KILL + # for any left (not waited for; KILL cannot be ignored). So the step never ends with Gradle + # still running. Gradle's single-use daemon is a child of its client, so this reaches it + # too. A zombie counts as gone. descendants() { local child for child in $(pgrep -P "$1"); do echo "$child"; descendants "$child"; done @@ -331,10 +336,10 @@ jobs: [ -n "$state" ] && [ "${state#Z}" = "$state" ] } kill_tree() { - local pids p i alive + local pids p alive pids="$1 $(descendants "$1")" for p in $pids; do kill -TERM "$p" 2>/dev/null || true; done - for i in $(seq 30); do + for _ in $(seq 30); do alive=false for p in $pids; do if running "$p"; then alive=true; fi; done $alive || return 0 @@ -364,6 +369,8 @@ jobs: echo "::error::The job '$CHECKS_JOB' ended with '${state#completed }' while this build was still running, so the build was stopped and nothing will be published. Its log shows which check failed. To retry, use \"Re-run failed jobs\"." kill_tree "$build" wait "$build" 2>/dev/null || true + # The build is reaped; without this the EXIT trap would signal its pid again. + trap - EXIT INT TERM exit 1 ;; esac @@ -479,7 +486,6 @@ jobs: # could upload to App Tester without the Jira and Slack steps. - name: Wait for the checks to pass env: - CHECKS_JOB: Run checks (API, unit tests, Spotless) GH_TOKEN: ${{ github.token }} run: | url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100"