Skip to content

fix(ci): address three recurring backend CI flakes - #24528

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/ciflake
Nov 4, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/ciflake

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Requested by David

Summary

  • Fetch only the hermetic scope base history; allow 10 minutes for E2E/gauntlet checkouts with matching job headroom.
  • Rebalance the unchanged backend unit selection from six to eight shards; retain the 720-second regression budget and 25-minute unit job cap.
  • Bound isolated test files to 300 seconds when GNU timeout is available, honor BACKEND_UNIT_FILE_BUDGET_SECONDS, preserve the macOS fallback, and print in-flight filenames on TERM.
  • Update existing regression tests, shard documentation, and the required CI budget inventory. No workflow files added; adjacent test flakes remain with their separate owners.

Root cause per flake

  1. Checkout: the scope job fetched every branch/tag history under a five-minute cap. Other E2E/gauntlet checkouts could trickle longer than five minutes without triggering Git's low-speed retry. Use the event SHA plus one blobless base fetch and 10-minute checkout backstops for the four test jobs, each with five extra job minutes. The targeted fetch includes --unshallow: a local depth-one merge fixture reproduced no merge base with the plan's plain fetch, and succeeds after clearing the shallow boundary.
  2. Shard budget: the suite grew ~47% since six-shard sizing; all assertions passed while a shard took 729 seconds against 720 (run 41672443401). Eight shards restore headroom without relaxing the gate or changing selection/isolation. The inventory scales the prior 8-minute p50 forecast by 6/8 to 6 minutes over eight runners: the aggregate forecast remains 48 Linux runner-minutes/run and caps remain unchanged. This is a forecast; re-seed from completed CI runs after merge.
  3. Anonymous hangs: stalled files had no individual bound and the outer 25-minute cancellation named no in-flight work (including clean-main run 41645945028). The shared per-file runner now uses TERM then KILL after a 30-second grace, carries failures through existing status/rerun reporting, and emits the active-file list on TERM. A whole-VM freeze can still reach the unchanged outer job cap.

Failure-Class: FC-gate-timeout-below-cold-cost

Why isn't this a shared primitive instead? The hang bound is implemented once in the existing shared backend/test.sh runner. The workflow changes resize existing checkout and shard execution; no separate guard workflow is introduced. Regression evidence: runs 41672443108, 41672443401, and 41645945028.

Verification

  • actionlint .github/workflows/backend-hermetic-e2e.yml .github/workflows/backend-unit-tests.yml, bash -n backend/test.sh, CI budget validation, and diff hygiene: passed.
  • Five focused files through bin/omi-heavy and backend/test.sh: 146 tests passed; the worker-death fixture preserves its missing-status-file scenario through the new timeout process.
  • Full-selector deal using the actual sharding code: 2,541 unique files, exact disjoint union at six and eight shards. Eight-shard counts 302–321, load spread 1.70 weight-seconds including shard 1's typecheck reservation.
  • A real scratch pytest hang with BACKEND_UNIT_FILE_BUDGET_SECONDS=5: named timeout, runner exit 1, 5.36 seconds. The plan's test_fast_unit_guard.py is absent in this checkout, so this controlled hanging file exercises the requested path.
  • GNU timeout and no-timeout fallback both passed; the fallback explicitly uses macOS /bin/bash (Bash 3), preserving PATH. TERM names the in-flight file.
  • Nightly workflow contract suite through bin/omi-heavy: 25 tests passed, including the exact revised E2E/gauntlet timeout pins.
  • PR metadata preflight: 4 checks passed.
  • Full make preflight through bin/omi-heavy: 49 checks passed in 457.53s on the final tree. This local run used BACKEND_UNIT_FILE_BUDGET_SECONDS=900: an earlier default-budget attempt timed out three Firestore guard files at 300s under shared-host load averages of 88–113. The committed default remains 300s, and the CI shard regression budget remains 720s.
  • git push -u origin lane/ciflake through bin/omi-heavy: passed the normal pre-push gate and pushed successfully, with the same local 900s file deadline. The gate reran all 49 source checks, selected backend unit tests, and required formatting/policy checks; no skip hatches, force-push, or rebase.

Live scope logs, post-merge push/nightly behavior, and the next ~10 workflow runs remain follow-up observations, not local verification claims.

Product invariants affected

none

View guided diff Turn on auto-fix

🤖 Generated with Claude Code

@Git-on-my-level Git-on-my-level self-assigned this Nov 3, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 11 files

Confidence score: 3/5

  • In backend/test.sh, the TERM trap swallows cancellation, so a cancelled runner can keep working until the job-level hard kill. Re-raise TERM or exit with its conventional status.
  • The timeout diagnostic in backend/test.sh misses status 137, so files that ignore TERM are not reported as budget timeouts. Recognize the forced-kill status too.
  • With BACKEND_PYTEST_PARALLEL_SESSION=1, the parallel partition bypasses the per-file timeout and a hanging test can run until the job-level timeout. Apply the budget to the parallel session.
  • In backend/test.sh, cancellation during a parallel session reports no files in flight because active_test_paths is empty. Include the batched session’s paths in the report.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/test.sh">

<violation number="1" location="backend/test.sh:193">
P2: This TERM trap swallows cancellation after printing the in-flight files. Re-raise TERM or exit with its conventional status so a cancelled runner stops instead of continuing until its job-level hard kill.</violation>

<violation number="2" location="backend/test.sh:193">
P3: The TERM trap reports only isolated workers. With `BACKEND_PYTEST_PARALLEL_SESSION=1`, the batched pytest session runs while `active_test_paths` is empty, so cancellation reports no files in flight.</violation>

<violation number="3" location="backend/test.sh:267">
P2: The new timeout wrapper does not cover the parallel partition. A hanging file with `BACKEND_PYTEST_PARALLEL_SESSION=1` bypasses `BACKEND_UNIT_FILE_BUDGET_SECONDS` and can consume the job until its outer timeout.</violation>

<violation number="4" location="backend/test.sh:292">
P2: The 30-second kill-after path returns status 137, but this check recognizes only 124. Include the forced-kill status in the timeout diagnostic so files that ignore TERM are reported as budget timeouts rather than unexplained failures.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread backend/test.sh
"${runner[@]}" -m pytest "${file_pytest_args[@]}" "$test_path"
status=$?
set -e
if [[ "$status" -eq 124 ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The 30-second kill-after path returns status 137, but this check recognizes only 124. Include the forced-kill status in the timeout diagnostic so files that ignore TERM are reported as budget timeouts rather than unexplained failures.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/test.sh, line 292:

<comment>The 30-second kill-after path returns status 137, but this check recognizes only 124. Include the forced-kill status in the timeout diagnostic so files that ignore TERM are reported as budget timeouts rather than unexplained failures.</comment>

<file context>
@@ -276,9 +286,12 @@ if [[ "$use_file_isolation" == "1" || "$use_file_isolation" == "true" ]]; then
+        "${runner[@]}" -m pytest "${file_pytest_args[@]}" "$test_path"
         status=$?
         set -e
+        if [[ "$status" -eq 124 ]]; then
+          echo "::error title=Backend unit file timed out::$test_path exceeded ${file_budget}s (TERM, then KILL) and was terminated"
+        fi
</file context>
Suggested change
if [[ "$status" -eq 124 ]]; then
if [[ "$status" -eq 124 || "$status" -eq 137 ]]; then

Comment thread backend/test.sh
active_pids=()
active_status_files=()
active_test_paths=()
trap 'set +u; [ "${#active_test_paths[@]}" -gt 0 ] && echo "backend unit: cancelled with files in flight: ${active_test_paths[*]}" >&2 || true' TERM

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This TERM trap swallows cancellation after printing the in-flight files. Re-raise TERM or exit with its conventional status so a cancelled runner stops instead of continuing until its job-level hard kill.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/test.sh, line 193:

<comment>This TERM trap swallows cancellation after printing the in-flight files. Re-raise TERM or exit with its conventional status so a cancelled runner stops instead of continuing until its job-level hard kill.</comment>

<file context>
@@ -190,6 +190,7 @@ if [[ "$use_file_isolation" == "1" || "$use_file_isolation" == "true" ]]; then
   active_pids=()
   active_status_files=()
   active_test_paths=()
+  trap 'set +u; [ "${#active_test_paths[@]}" -gt 0 ] && echo "backend unit: cancelled with files in flight: ${active_test_paths[*]}" >&2 || true' TERM
   failed_test_paths=()
   failed=0
</file context>
Suggested change
trap 'set +u; [ "${#active_test_paths[@]}" -gt 0 ] && echo "backend unit: cancelled with files in flight: ${active_test_paths[*]}" >&2 || true' TERM
trap 'set +u; [ "${#active_test_paths[@]}" -gt 0 ] && echo "backend unit: cancelled with files in flight: ${active_test_paths[*]}" >&2 || true; trap - TERM; kill -TERM "$$"' TERM

Comment thread backend/test.sh
file_budget="${BACKEND_UNIT_FILE_BUDGET_SECONDS:-300}"
runner=("$PYTHON_BIN")
if command -v timeout >/dev/null 2>&1; then
runner=(timeout --signal=TERM --kill-after=30s "${file_budget}s" "$PYTHON_BIN")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new timeout wrapper does not cover the parallel partition. A hanging file with BACKEND_PYTEST_PARALLEL_SESSION=1 bypasses BACKEND_UNIT_FILE_BUDGET_SECONDS and can consume the job until its outer timeout.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/test.sh, line 267:

<comment>The new timeout wrapper does not cover the parallel partition. A hanging file with `BACKEND_PYTEST_PARALLEL_SESSION=1` bypasses `BACKEND_UNIT_FILE_BUDGET_SECONDS` and can consume the job until its outer timeout.</comment>

<file context>
@@ -257,6 +258,15 @@ if [[ "$use_file_isolation" == "1" || "$use_file_isolation" == "true" ]]; then
+  file_budget="${BACKEND_UNIT_FILE_BUDGET_SECONDS:-300}"
+  runner=("$PYTHON_BIN")
+  if command -v timeout >/dev/null 2>&1; then
+    runner=(timeout --signal=TERM --kill-after=30s "${file_budget}s" "$PYTHON_BIN")
+  fi
+
</file context>

Comment thread backend/test.sh
active_pids=()
active_status_files=()
active_test_paths=()
trap 'set +u; [ "${#active_test_paths[@]}" -gt 0 ] && echo "backend unit: cancelled with files in flight: ${active_test_paths[*]}" >&2 || true' TERM

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The TERM trap reports only isolated workers. With BACKEND_PYTEST_PARALLEL_SESSION=1, the batched pytest session runs while active_test_paths is empty, so cancellation reports no files in flight.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/test.sh, line 193:

<comment>The TERM trap reports only isolated workers. With `BACKEND_PYTEST_PARALLEL_SESSION=1`, the batched pytest session runs while `active_test_paths` is empty, so cancellation reports no files in flight.</comment>

<file context>
@@ -190,6 +190,7 @@ if [[ "$use_file_isolation" == "1" || "$use_file_isolation" == "true" ]]; then
   active_pids=()
   active_status_files=()
   active_test_paths=()
+  trap 'set +u; [ "${#active_test_paths[@]}" -gt 0 ] && echo "backend unit: cancelled with files in flight: ${active_test_paths[*]}" >&2 || true' TERM
   failed_test_paths=()
   failed=0
</file context>

@Git-on-my-level
Git-on-my-level merged commit bb07716 into main Nov 4, 2026
72 of 73 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/ciflake branch November 4, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant