Repository navigation
feat(autofix): keep the round status comment live during long rounds #9771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ebcc88d
feat(autofix): keep the round status comment live during long rounds
wenshao 7fc3fd5
fix(autofix): harden the heartbeat self-exit and pin its behavior
wenshao e0c4c9c
fix(autofix): fail fast on a token-less heartbeat launch; correct orp…
wenshao 32ac987
fix(autofix): close the heartbeat's token paths at the kill and the g…
wenshao 114af68
fix(autofix): degrade pre-merge rounds past the absent heartbeat script
wenshao b34aae0
fix(autofix): pin the heartbeat's command resolution off the plantabl…
wenshao ae2c682
fix(autofix): clear the staged heartbeat plant and re-verify at the l…
wenshao ccbd641
fix(autofix): clear directory plants at staging; gate the launch witn…
wenshao 0b0279e
Merge branch 'main' into feat/autofix-round-heartbeat
wenshao 3c12d96
Merge branch 'main' into feat/autofix-round-heartbeat
wenshao 895ea67
chore: merge origin/main into feat/autofix-round-heartbeat
wenshao 6cb68dd
fix(ci): record ci.yml's accumulated growth in the size baseline
wenshao 190847f
chore: integrate remote branch fixes (heartbeat hardening rounds)
wenshao a36c121
fix(ci): exact-size the qwen-autofix.yml baseline line after integration
wenshao edeb7ed
fix(ci): close round-8 heartbeat findings R8-1/R8-2/R8-3
wenshao aac8a2a
fix(ci): close round-9 finding R9-1 with an env -i finalize child
wenshao 6022bd4
Merge remote-tracking branch 'origin/main' into feat/autofix-round-he…
wenshao 8375fca
fix(autofix): bound the heartbeat pid-identity read (R10-3)
wenshao 81b311a
fix(autofix): close R10-1/R10-2 on the gate kill block and the finali…
wenshao 9f78012
fix(autofix): mint the hermetic gh config per call (R11-1)
wenshao 31065a6
Merge remote-tracking branch 'origin/main' into feat/autofix-round-he…
wenshao a9f04a5
fix(autofix): gate the gh-config witness on the env-log it reads (R12-1)
wenshao 538f2db
Merge branch 'main' into feat/autofix-round-heartbeat
wenshao 578748b
Merge branch 'main' into feat/autofix-round-heartbeat
wenshao 62c3bbd
fix(autofix): confirm heartbeat pid lifecycle and drain in-flight tic…
wenshao 9bdf37f
Merge branch 'main' into feat/autofix-round-heartbeat
qwen-code-dev-bot b287dbb
fix(autofix): env-route heartbeat kill targets, cap override magnitud…
qwen-code-dev-bot dd5cb59
Merge remote-tracking branch 'origin/main' into feat/autofix-round-he…
qwen-code-dev-bot 7ee39a0
fix(autofix): byte-bound pid/stamp reads, digit-bound overrides, clos…
qwen-code-dev-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| #!/usr/bin/env bash | ||
| # Live-progress heartbeat for the autofix round status comment. | ||
| # | ||
| # A review-address round can run for hours (130-minute agent step, 330- | ||
| # minute job) while the PR's status comment stays frozen at "working" — | ||
| # a healthy long round and a dead one look identical on the PR page. | ||
| # 'Post autofix status comment' starts this script as a detached loop; | ||
| # every interval it re-PATCHes the SAME status comment with elapsed time | ||
| # and last agent activity, and 'Finalize autofix status comment' kills it | ||
| # before writing the terminal text. Full rationale → qwen-autofix.md#af-148. | ||
| # | ||
| # Subcommands: | ||
| # body — print the full bilingual working-state comment body to stdout. | ||
| # Used for the initial post AND by every loop tick, so the two | ||
| # can never drift apart. | ||
| # loop — sleep–compose–PATCH until killed or a self-exit bound trips. | ||
| # | ||
| # Environment (both): HB_ROUND (display round, already +1'd by the step), | ||
| # HB_CAP, HB_URL, HB_WORKDIR, HB_START_EPOCH; NOW_EPOCH overrides the | ||
| # clock for tests. loop additionally needs: HB_REPO, HB_COMMENT_ID, and | ||
| # GITHUB_TOKEN for gh; HB_INTERVAL_SECONDS (default 600) and | ||
| # HB_MAX_AGE_SECONDS (default 43200) bound the pulse. | ||
| # | ||
| # Kill contract: the loop writes heartbeat.pid (diagnostics + its own | ||
| # self-exit check), checks heartbeat-stop, and exits on either signal or | ||
| # when its own age cap trips. The killers target the pid the launch | ||
| # recorded in EXPRESSION CONTEXT (steps.post_status.outputs.heartbeat_pid) | ||
| # — WORKDIR is sandbox-writable, so no WORKDIR file is ever read as a kill | ||
| # target. The round's verification gate kills the loop before running any | ||
| # branch code on the host; finalize and the always() cleanup kill again. | ||
| # | ||
| # PAT note: the loop holds the bot PAT in its environment. Its lifetime is | ||
| # bounded to the sandboxed agent phase — the agent executes PR content only | ||
| # inside the docker sandbox there, so no fork code runs on the host beside | ||
| # this loop; the verification gate ends the loop BEFORE the first step that | ||
| # runs branch code on the host. See af-148 for the trade. | ||
|
|
||
| # -e is deliberately absent: the (( ... < 0 )) clamp guards exit non-zero | ||
| # on a false test and are load-bearing here. pipefail matches the sibling | ||
| # scripts' house line. | ||
| set -uo pipefail | ||
|
|
||
| MARKER='<!-- autofix-status -->' | ||
|
|
||
| require() { | ||
| local name | ||
| for name in "$@"; do | ||
| if [[ -z "${!name:-}" ]]; then | ||
| echo "autofix-status-heartbeat: ${name} is required" >&2 | ||
| exit 2 | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| emit_body() { | ||
| require HB_ROUND HB_CAP HB_URL HB_WORKDIR HB_START_EPOCH | ||
| local now elapsed_min mtime active_min line_en line_zh | ||
| now="${NOW_EPOCH:-$(date +%s)}" | ||
| elapsed_min=$(( (now - HB_START_EPOCH) / 60 )) | ||
| (( elapsed_min < 0 )) && elapsed_min=0 | ||
| if [[ -f "${HB_WORKDIR}/agent.log" ]]; then | ||
| # date -r FILE reads the file's mtime on both GNU and BSD date. | ||
| mtime="$(date -r "${HB_WORKDIR}/agent.log" +%s 2>/dev/null || echo "${now}")" | ||
| active_min=$(( (now - mtime) / 60 )) | ||
| (( active_min < 0 )) && active_min=0 | ||
| line_en="⏱ Running for ${elapsed_min} min · agent active ${active_min} min ago" | ||
| line_zh="⏱ 已运行 ${elapsed_min} 分钟 · agent 最近活动在 ${active_min} 分钟前" | ||
| else | ||
| line_en="⏱ Running for ${elapsed_min} min · agent starting" | ||
| line_zh="⏱ 已运行 ${elapsed_min} 分钟 · agent 准备中" | ||
| fi | ||
| printf '%s\n\n🔄 **AutoFix is working on this PR** — round %s/%s. [Watch live progress](%s); this round posts its report here when it finishes.\n%s\n\n<details>\n<summary>中文说明</summary>\n\n🔄 **AutoFix 正在处理此 PR** —— 第 %s/%s 轮。[查看实时进度](%s);本轮结束后会在此发布报告。\n%s\n\n</details>' \ | ||
| "${MARKER}" "${HB_ROUND}" "${HB_CAP}" "${HB_URL}" "${line_en}" \ | ||
| "${HB_ROUND}" "${HB_CAP}" "${HB_URL}" "${line_zh}" | ||
| } | ||
|
|
||
| run_loop() { | ||
| # Validate EVERYTHING a tick needs, not just the loop's own three: a | ||
| # launch missing a body var would otherwise produce an immortal loop | ||
| # that never pulses — the exact "healthy round looks dead" failure this | ||
| # feature eliminates. Fail fast instead. | ||
| require HB_REPO HB_COMMENT_ID HB_WORKDIR HB_ROUND HB_CAP HB_URL HB_START_EPOCH | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| # Self-detach from the launching step: log to WORKDIR and never hold the | ||
| # step's pipes, or the step would never report completion. | ||
| exec >> "${HB_WORKDIR}/heartbeat.log" 2>&1 < /dev/null | ||
| echo "$$" > "${HB_WORKDIR}/heartbeat.pid" | ||
| local interval="${HB_INTERVAL_SECONDS:-600}" | ||
| local max_age="${HB_MAX_AGE_SECONDS:-43200}" | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| # Numeric guards: a malformed or zero override must degrade to the | ||
| # defaults, never into a sleep-less busy loop hammering the API. | ||
| [[ "${interval}" =~ ^[1-9][0-9]*$ ]] || interval=600 | ||
| [[ "${max_age}" =~ ^[1-9][0-9]*$ ]] || max_age=43200 | ||
| local start="${HB_START_EPOCH}" | ||
| echo "$(date -u +%FT%TZ) heartbeat started: comment ${HB_COMMENT_ID} interval ${interval}s max_age ${max_age}s" | ||
| while :; do | ||
| sleep "${interval}" | ||
| local now age body | ||
| now="$(date +%s)" | ||
| age=$(( now - start )) | ||
| if (( age > max_age )); then | ||
| echo "$(date -u +%FT%TZ) self-exit: age ${age}s exceeds ${max_age}s" | ||
| exit 0 | ||
| fi | ||
| # IDENTITY, not existence: WORKDIR is PR-scoped (/tmp/autofix-review-<pr>), | ||
| # so after a crashed round's reset the NEXT round recreates heartbeat.pid | ||
| # at the same path. An existence check would let the orphaned old loop | ||
| # pass and keep PATCHing with its stale launch env, alternating with the | ||
| # new round's body on the same comment. The file must still hold THIS | ||
| # loop's own pid — removed OR replaced (by a newer round) ends the loop. | ||
| # This reads the file to self-identify only; it never kills anything. | ||
| if [[ "$(cat "${HB_WORKDIR}/heartbeat.pid" 2> /dev/null)" != "$$" ]]; then | ||
| echo "$(date -u +%FT%TZ) self-exit: pid file removed or replaced" | ||
|
wenshao marked this conversation as resolved.
Resolved
|
||
| exit 0 | ||
| fi | ||
| if [[ -f "${HB_WORKDIR}/heartbeat-stop" ]]; then | ||
| echo "$(date -u +%FT%TZ) self-exit: stop marker present" | ||
| exit 0 | ||
| fi | ||
| if ! body="$(emit_body)"; then | ||
| echo "$(date -u +%FT%TZ) body composition failed; skipping this tick" | ||
| continue | ||
| fi | ||
| # Best-effort: a transient API failure skips one tick, never the pulse. | ||
| # `timeout` bounds the request itself — a black-holed connection must | ||
| # not stall the loop past the age cap, which only runs between ticks | ||
| # (a stuck gh would hold the PAT forever). `timeout` is coreutils on | ||
| # the Linux pool; hosts without it (macOS dev runs) fall back to the | ||
| # unbounded call. | ||
| GH_PATCH=(gh) | ||
| if command -v timeout > /dev/null 2>&1; then | ||
| GH_PATCH=(timeout 60 gh) | ||
| fi | ||
|
wenshao marked this conversation as resolved.
Resolved
wenshao marked this conversation as resolved.
Resolved
|
||
| if ! "${GH_PATCH[@]}" api --method PATCH \ | ||
| "repos/${HB_REPO}/issues/comments/${HB_COMMENT_ID}" \ | ||
| -f body="${body}" > /dev/null 2>&1; then | ||
| echo "$(date -u +%FT%TZ) PATCH failed; continuing" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| case "${1:-}" in | ||
| body) emit_body ;; | ||
| loop) run_loop ;; | ||
| *) | ||
| echo "usage: $(basename "$0") {body|loop}" >&2 | ||
| exit 2 | ||
| ;; | ||
| esac | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.