Skip to content

[fix] Retry calc-success-rate job listing and fall back to the latest attempt / [fix] calc-success-rate 列出 job 时重试并回退到最新 attempt - #4868

Open
nvpohanh wants to merge 1 commit into
mainfrom
calc-success-rate-retry-fallback-1106
Open

nvpohanh wants to merge 1 commit into
mainfrom
calc-success-rate-retry-fallback-1106

Conversation

@nvpohanh

@nvpohanh nvpohanh commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

calc-success-rate can fail an otherwise green Run Sweep when GitHub's API returns 5xx while the job lists the run's jobs. That failure makes the run's conclusion failure, which also blocks /use <run_id> reuse.

The job lists every job from every attempt (filter=all) in a single gh api --paginate call with no retry. Runs with many reruns are the most exposed. filter=all keeps each attempt's jobs, and every "Re-run failed jobs" adds about 50 more records, so the listing grows with each retry. GitHub can return HTTP 502 for later pages of such a large listing, and in that state each rerun of this job fails again and makes the listing even larger.

This PR changes how the job list is fetched:

  • Each listing page is a separate request. 5xx responses and timeouts are retried on just the failing page with backoff (5s, 15s, 30s).
  • If the full history still can't be listed, the job counts only the latest attempt of each job (filter=latest, normally one page) and emits a workflow ::warning:: saying earlier attempts were not counted.
  • Auth errors, other 4xx responses and malformed listings still fail without writing an artifact. The run_stats.json schema is unchanged.

Workflow YAML is unchanged. A rerun of an existing run keeps the tooling SHA that its setup job resolved, so this helps new runs, not reruns of runs started before it merges.

Validation details
  • test_calc_success_rate.py: 20 tests pass. New tests cover a retried transient page, fallback to the latest attempt with a warning, timeouts treated as transient, and non-transient errors failing without retry. The existing behavior is kept: no artifact on auth or shape errors, and an earlier artifact is preserved when both listings fail.
  • ruff check / ruff format --check on inferencex-e2e/infx pass.
  • Read-only run of the new code against run 41854172505 (14 attempts, 700+ job records), whose listing pages return HTTP 502, with shortened retry delays. Retries recovered pages 1 and 2. Page 3 kept failing, so the job fell back to the latest attempt, printed the warning, and wrote run_stats.json (gb300-nv: 27/27).
AI model disclosure
  • Model/version: Claude Opus 5.5 (claude-opus-5-5)
  • Role: diagnosis, implementation, tests, PR description
PR checklist and change type

Type of Change

  • Bug fix
  • New feature
  • Configuration change
  • Documentation update
  • Other (please describe)

Checklist

  • I have completed the AI model disclosure and kept it current
  • I have tested my changes locally
  • I have updated documentation if necessary
  • If python -m infx.matrix.changed --base origin/main lists affected config keys, I have appended one new entry covering them to the physical end of inferencex-e2e/perf-changelog.yaml; if it lists none, I have added none. I have not edited historical entries
  • If this PR appends an inferencex-e2e/perf-changelog.yaml entry, it carries exactly one primary sweep label (a maintainer applies it on fork PRs): full-sweep-fail-fast (recommended), full-sweep-enabled, or non-canary-full-sweep-enabled. Optional modifiers all-evals, evals-only, and agentx-fast require a primary label; the last two block reuse while applied.
  • Before merging via reuse, an authorized maintainer (OWNER/MEMBER/COLLABORATOR) has commented /use <run_id> (or the legacy /reuse-sweep-run) on this PR. Do this only once there is a final full sweep that is all green with evals passing, since after this comment the primary sweep label will no longer automatically kick off new sweeps. Remove and re-add the primary sweep label to force a new sweep.
中文

当 GitHub API 在列出 run 的 job 时返回 5xx,calc-success-rate 会让一次本已全部通过的 Run Sweep 被标记为失败,进而无法用 /use <run_id> 复用该 run。

原实现用一次 gh api --paginate 调用列出所有 attempt 的全部 job(filter=all),且没有重试。多次重跑的 run 最容易出问题:filter=all 保留每次 attempt 的 job,每次“Re-run failed jobs”都会新增约 50 条记录,列表随之变长。GitHub 对这种大列表的后几页可能返回 HTTP 502;此时重跑该 job 会再次失败,并让列表更长。

本 PR 修改了 job 列表的获取方式:

  • 每一页单独请求。遇到 5xx 或超时时只重试失败的那一页,并按 5s、15s、30s 退避。
  • 若仍无法列出完整历史,则只统计每个 job 的最新一次 attempt(filter=latest,通常只有一页),并输出 workflow ::warning::,说明未计入之前的 attempt。
  • 认证错误、其他 4xx 和格式异常的列表仍会直接失败,不写出 artifact。run_stats.json 的格式不变。

Workflow YAML 未修改。已有 run 的重跑会沿用其 setup job 解析出的 tooling SHA,因此本修复只对新的 run 生效,对合并前已启动的 run 的重跑无效。

验证:test_calc_success_rate.py 共 20 个测试通过,ruff 检查通过。另外用缩短的重试间隔,对列表页返回 HTTP 502 的 run 41854172505(14 次 attempt、700 多条 job 记录)只读运行了新代码:重试恢复了第 1、2 页,第 3 页持续失败后回退到最新 attempt,输出警告并写出 run_stats.json(gb300-nv:27/27)。

AI 模型使用说明:Claude Opus 5.5(claude-opus-5-5),负责问题诊断、实现、测试和 PR 描述。

🤖 Generated with Claude Code

calc-success-rate listed every job of every attempt (filter=all) in one
`gh api --paginate` call with no retry, so a single 5xx page failed the
job and marked an otherwise green Run Sweep as failed. A run with many
reruns is the usual trigger: filter=all keeps each attempt's jobs, every
"Re-run failed jobs" adds ~50 more, and GitHub can return HTTP 502 for
later pages of such a large listing, which makes each rerun more likely
to fail again.

- Fetch the listing one page per request and retry 5xx/timeouts with
  backoff (5s, 15s, 30s) on just the failing page.
- If the full history still cannot be listed, count only the latest
  attempt of each job (filter=latest) and emit a workflow warning.
- Auth errors, other 4xx and malformed listings still fail without
  writing an artifact; the run-stats JSON schema is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nvpohanh
nvpohanh requested a review from a team November 6, 2026 15:15
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

inferencex-e2e/infx diff: +217 -42

Generally most InferenceX submissions don't need to add changes to the infx package. On the off chance they do, generally the diff is small. Please prompt your agent to clean your PR to keep your diff to only necessary & minimal changes too. We have an increased code quality bar for changes to the infx package.

中文

大多数 InferenceX 提交通常不需要修改 infx 包。即使确实需要,改动通常也很小。请让你的 agent 清理 PR,使改动只包含必要且最小的内容。infx 包的改动有更高的代码质量要求。

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment on lines +56 to +60
def _is_transient(exc: Exception) -> bool:
"""True for gh failures worth retrying: 5xx gateway/server errors and timeouts."""
if isinstance(exc, subprocess.TimeoutExpired):
return True
return isinstance(exc, github.APIError) and exc.status in TRANSIENT_STATUSES

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 (optional) Some Run Sweeps can still fail on a GitHub 502 with no retry and no fallback. This happens when gh prints the status without parentheses, e.g. gh: HTTP 502. _is_transient relies on APIError.status, which is parsed only from (HTTP 502) at the end of a line. For a non-JSON 5xx body, gh prints gh: HTTP 502, so status is None. Fix: classify transient errors the way infx/klaud/github.py does, matching \bHTTP ([1-5][0-9]{2})\b anywhere in stderr plus the TRANSPORT_FAILURE patterns, while still failing fast on 4xx such as gh: HTTP 403: API rate limit exceeded.

Why this was flagged

GitHub's gateway sometimes returns a 5xx with an HTML or empty body. In that case gh writes gh: HTTP 502 (no message, no parentheses) to stderr. The repo already tests this form as status-without-parentheses in infx/tests/klaud/test_klaud_reliability.py:63. github.APIError.__init__ (infx/github.py:23) parses status only with \(HTTP ([1-5][0-9]{2})\)\s*$, so exc.status is None. _is_transient (calc_success_rate.py:60) then returns False. _fetch_page re-raises at once, and list_jobs_for_stats re-raises instead of falling back to filter=latest. calc-success-rate fails the run just as on the base branch, which this PR is meant to stop. Transport failures fail the same way, because github.api turns them into an APIError with status None. Examples are connection reset by peer, unexpected EOF and TLS handshake timeout, which infx/klaud/github.py:30 TRANSPORT_FAILURE treats as transient. The new tests only use the (HTTP 502) form, so they do not catch this.

Verification: pre-existing. Trigger: GitHub returns a 5xx whose body is not JSON, so gh prints gh: HTTP 502 without parentheses. github.APIError.__init__ (infx/github.py:23) parses the status only with re.search(r"\(HTTP ([1-5][0-9]{2})\)\s*$", stderr, re.MULTILINE), so for stderr gh: HTTP 502\n the self.status is None. That means no retry and no fallback to filter=latest, and the job fails as it did before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant