Repository navigation
fix(ci): address three recurring backend CI flakes - #24528
Conversation
There was a problem hiding this comment.
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.shmisses 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 becauseactive_test_pathsis 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
| "${runner[@]}" -m pytest "${file_pytest_args[@]}" "$test_path" | ||
| status=$? | ||
| set -e | ||
| if [[ "$status" -eq 124 ]]; then |
There was a problem hiding this comment.
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>
| if [[ "$status" -eq 124 ]]; then | |
| if [[ "$status" -eq 124 || "$status" -eq 137 ]]; 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 |
There was a problem hiding this comment.
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>
| 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 |
| 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") |
There was a problem hiding this comment.
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>
| 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 |
There was a problem hiding this comment.
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>
Requested by David
Summary
BACKEND_UNIT_FILE_BUDGET_SECONDS, preserve the macOS fallback, and print in-flight filenames on TERM.Root cause per flake
--unshallow: a local depth-one merge fixture reproducedno merge basewith the plan's plain fetch, and succeeds after clearing the shallow boundary.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.shrunner. 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.bin/omi-heavyandbackend/test.sh: 146 tests passed; the worker-death fixture preserves its missing-status-file scenario through the new timeout process.BACKEND_UNIT_FILE_BUDGET_SECONDS=5: named timeout, runner exit 1, 5.36 seconds. The plan'stest_fast_unit_guard.pyis absent in this checkout, so this controlled hanging file exercises the requested path./bin/bash(Bash 3), preserving PATH. TERM names the in-flight file.bin/omi-heavy: 25 tests passed, including the exact revised E2E/gauntlet timeout pins.make preflightthroughbin/omi-heavy: 49 checks passed in 457.53s on the final tree. This local run usedBACKEND_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/ciflakethroughbin/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
🤖 Generated with Claude Code