Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

ci: poll ci-gate every 10 s after a 120 s window instead of 90 s + 120 s steps (#5819)

Francesco Bonacci52ae7bb0c1c1
diff --git a/.github/scripts/tests/test_ci_gate_workflow.py b/.github/scripts/tests/test_ci_gate_workflow.py
index aaaa6f5066..58e09b2639 100644
--- a/.github/scripts/tests/test_ci_gate_workflow.py
+++ b/.github/scripts/tests/test_ci_gate_workflow.py
@@ -40,8 +40,7 @@ def test_gate_wiring():
assert 'claude-auto-fix|ci-release-reminder|review-cua-perception-candidates' in SCRIPT
-def run_gate(rows, jobs='test\tsuccess', older_jobs=None):
- mock = '''
+MOCK = '''
set -uo pipefail
api() {
case "$*" in
@@ -51,26 +50,58 @@ api() {
else
printf '%s' "$JOBS"
fi ;;
- *'head_sha='*) printf '%s' "$ROWS" ;;
+ *'head_sha='*)
+ if [[ -n "${ROWS_DIR:-}" ]]; then
+ file=
+ for candidate in "$ROWS_DIR"/rows.*; do
+ at=${candidate##*rows.}
+ if (( at <= SECONDS )) && [[ -z "$file" || ${file##*rows.} -lt $at ]]; then file=$candidate; fi
+ done
+ cat "$file"
+ else
+ printf '%s' "$ROWS"
+ fi ;;
*) printf '999' ;;
esac
}
sleeps=0
sleep() {
sleeps=$((sleeps + 1))
- if (( sleeps > 4 )); then exit 124; fi
+ printf 'sleep %s\\n' "$1" >&2
+ SECONDS=$((SECONDS + $1))
+ if (( sleeps > MAX_SLEEPS || SECONDS > MAX_SECONDS )); then exit 124; fi
}
'''
+
+
+def run_gate(rows, jobs='test\tsuccess', older_jobs=None, rows_dir=None,
+ max_sleeps=4, max_seconds=10**9):
+ # Mirrors the runner: GitHub runs a bare `run:` step with `bash -e`. The mocked
+ # sleep advances SECONDS, so the poll schedule is observable without waiting.
return subprocess.run(
- ['bash', '-c', mock + SCRIPT[SCRIPT.index('sha=$PR_SHA'):]],
+ ['bash', '-e', '-c', MOCK + SCRIPT[SCRIPT.index('sha=$PR_SHA'):]],
env={**os.environ, 'PR_SHA': 'abc', 'QUEUE_REF': '',
'GITHUB_REPOSITORY': 'test/repo', 'GITHUB_RUN_ID': '99',
'ROWS': rows, 'JOBS': jobs,
- 'OLDER_JOBS': jobs if older_jobs is None else older_jobs},
- capture_output=True, text=True, timeout=5,
+ 'OLDER_JOBS': jobs if older_jobs is None else older_jobs,
+ 'ROWS_DIR': str(rows_dir) if rows_dir else '',
+ 'MAX_SLEEPS': str(max_sleeps), 'MAX_SECONDS': str(max_seconds)},
+ capture_output=True, text=True, timeout=10,
)
+def sleeps_of(completed):
+ return [int(line.split()[1]) for line in completed.stderr.splitlines()
+ if line.startswith('sleep ')]
+
+
+def timeline(tmp_path, snapshots):
+ """Run listings by simulated second: {0: rows, 125: rows} shows `rows` from 125 s on."""
+ for at, rows in snapshots.items():
+ (tmp_path / f'rows.{at}').write_text(rows)
+ return tmp_path
+
+
@pytest.mark.parametrize(('rows', 'jobs', 'older_jobs', 'code', 'result'), [
('1\t11\tbuild\tsuccess\tcompleted\n1\t10\tbuild\tfailure\tcompleted', 'test\tsuccess', None, 0, 'build: pass'),
('1\t11\tbuild\tsuccess\tcompleted\n1\t10\tbuild\tcancelled\tcompleted', '', 'test\tcancelled', 0, 'build: skipped'),
@@ -92,3 +123,60 @@ def test_gate_waits_until_timeout_without_completed_runs(rows):
completed = run_gate(rows)
assert completed.returncode == 124
assert 'build: pass' not in completed.stdout
+
+
+DONE = '1\t11\tbuild\tsuccess\tcompleted'
+LATE_FAILURE = DONE + '\n2\t12\tlint\tfailure\tcompleted'
+MIN_WINDOW = 120
+
+
+def test_gate_gives_no_verdict_before_the_minimum_window():
+ completed = run_gate(DONE)
+ assert completed.returncode == 0, completed.stderr
+ sleeps = sleeps_of(completed)
+ assert sleeps[0] >= MIN_WINDOW
+ assert sleeps == [MIN_WINDOW, 10]
+
+
+def test_gate_catches_a_failing_run_that_appears_inside_the_window(tmp_path):
+ # Identical completed listings at 30 s and 40 s would have passed this PR; the
+ # failing workflow only shows up at 45 s. No poll may count before the window ends.
+ rows = timeline(tmp_path, {0: DONE, 45: LATE_FAILURE})
+ completed = run_gate('', rows_dir=rows)
+ assert completed.returncode == 1, completed.stderr
+ assert sleeps_of(completed) == [MIN_WINDOW, 10]
+ assert 'build: pass' in completed.stdout
+ assert 'lint: fail' in completed.stdout
+
+
+def test_gate_needs_two_identical_completed_polls(tmp_path):
+ rows = timeline(tmp_path, {0: '1\t11\tbuild\t\tin_progress', 125: DONE})
+ completed = run_gate('', rows_dir=rows)
+ assert completed.returncode == 0, completed.stderr
+ assert sleeps_of(completed) == [MIN_WINDOW, 10, 10]
+ assert 'build: pass' in completed.stdout
+
+
+def test_gate_holds_for_a_run_that_appears_after_the_first_poll(tmp_path):
+ rows = timeline(tmp_path, {0: DONE, 125: LATE_FAILURE})
+ completed = run_gate('', rows_dir=rows)
+ assert completed.returncode == 1, completed.stderr
+ assert sleeps_of(completed) == [MIN_WINDOW, 10, 10]
+ assert 'build: pass' in completed.stdout
+ assert 'lint: fail' in completed.stdout
+
+
+def test_gate_poll_schedule_backs_off_and_stays_within_the_api_budget():
+ stuck = '1\t11\tbuild\t\tin_progress'
+ completed = run_gate(stuck, max_sleeps=1000, max_seconds=3600)
+ assert completed.returncode == 124
+ sleeps = sleeps_of(completed)
+ assert sleeps[0] == MIN_WINDOW
+ intervals = sleeps[1:]
+ assert intervals == sorted(intervals)
+ assert set(intervals) == {10, 30, 60}
+ # Fast polling only while quick PRs finish, then 30 s, then one poll a minute.
+ assert intervals.count(10) == 18
+ assert intervals.count(30) == 20
+ # One run listing is one or two API calls; keep a long suite under 100 an hour.
+ assert len(sleeps) <= 100
diff --git a/.github/workflows/ci-gate.yml b/.github/workflows/ci-gate.yml
index 9257d6a7a7..dc28894416 100644
--- a/.github/workflows/ci-gate.yml
+++ b/.github/workflows/ci-gate.yml
@@ -34,7 +34,20 @@ jobs:
--jq ".workflow_runs[] | select(.workflow_id != $GITHUB_WORKFLOW_ID and (.event == \"pull_request\" or .event == \"pull_request_target\") and (.path | test(\"claude-auto-fix|ci-release-reminder|review-cua-perception-candidates\") | not)) | [.workflow_id, .id, .name, .conclusion // \"\", .status] | @tsv"
}
GITHUB_WORKFLOW_ID=$(api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" --jq .workflow_id) || exit 1
- sleep 90
+ # Two identical listings cannot prove every run has appeared, so no verdict is allowed
+ # before a fixed 120 s window. Runs for one event are created within 4 s of it (30 recent
+ # PRs); the window leaves 30x margin for slow fan-out. After it, a poll counts only when
+ # the run set equals the previous poll's and every run is completed. Poll fast while quick
+ # PRs finish, then back off: a long suite costs about 85 run listings an hour.
+ poll_interval() {
+ local elapsed=$((SECONDS - started))
+ if (( elapsed < 300 )); then echo 10
+ elif (( elapsed < 900 )); then echo 30
+ else echo 60
+ fi
+ }
+ started=$SECONDS
+ sleep 120
previous=
while :; do
current=$(runs) || exit 1
@@ -42,7 +55,7 @@ jobs:
break
fi
previous=$current
- sleep 120
+ sleep "$(poll_interval)"
done
failed=0
for workflow in $(cut -f1 <<<"$current" | sort -u); do