Skip to content

hw-gate: a kept failure log is unique per failure, so CI stops overwriting the evidence (#2513 follow-up) - #2516

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-review/hw-gate-kept-log-unique
Nov 15, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-review/hw-gate-kept-log-unique

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #2513 (refs engine#2500). It merged at 434a724, the head my CHANGES was posted on, so the bug it describes is on main now.

The bug, in CI only

#2513 named the kept log $STORE/failed/$(basename "$OUT")-<model>.log. CI sets HW_GATE_OUT: ${{ runner.temp }}/hw-gate (.github/workflows/hw-gate.yml:97, :104), so basename "$OUT" is the constant hw-gate. The consequences:

Second, smaller: kept was assigned before the cp. So when the copy failed, the ${kept:-…} fallback never fired, and the line named a file that did not exist.

The change

keep_failed_log <log> <model> copies to

$STORE/failed/<UTC>-run<GITHUB_RUN_ID>.<GITHUB_RUN_ATTEMPT>-<model>-<mktemp>.log

The run id ties the file to the CI page that printed it, and mktemp makes the name unique even within one second. It prints nothing when the copy fails, so the failure line falls back to the original path.

Its internal --keep-failed-log mode is dispatched before the GPU-queue block. Any other argument takes a ticket first. I found that the hard way: my first placement of the mode, after the queue block, queued a real gpu-hold ticket under GITHUB_RUN_ID. I stopped it straight away, and the queue showed no leftover entry.

Test (tests/hw_gate_kept_log_test.sh, ctest hw_gate_kept_log)

No GPU, no model. A recording fake gpu-hold is first on PATH, and the CI shape is used:

two failures, same model, same run, same second  -> two files, both byte-equal to the server log
name carries run43700000001.1-zaya1-8b-…         -> yes
copy of a missing log                            -> prints nothing, leaves no file
gpu-hold calls                                   -> 0
hw_gate_kept_log: ok

Each mutant fails the test:

scripts/pre-pr-checks.sh --base origin/main gives 10 ok, 1 skipped (hip_f16_audit, no gpu-kernels tree), and 1 failed: submodule_pin. That failure is this clone's own third_party/llama.cpp checkout (aae78ecdf, while main pins newer). It is not staged, and the diff against main is these three files only.

Not here: the author's ask-2 commit efa5de69 ("record the ACTUAL GTT and MemAvailable at failure time") was pushed to #2513's branch after the merge. It is on no PR and not on main.

🤖 Generated with Claude Code

…iting the evidence (#2513 follow-up)

#2513 kept a failing row's server log as $STORE/failed/$(basename "$OUT")-<model>.log. CI sets
HW_GATE_OUT=$RUNNER_TEMP/hw-gate (.github/workflows/hw-gate.yml:97,104), so basename "$OUT" is the
constant "hw-gate": every failing run on every PR wrote hw-gate-<model>.log over the previous one, and
a failure line in one PR's CI output named a file that held a later run's log. Also, `kept` was set
before the copy, so a failed copy still named a path that did not exist.

keep_failed_log names the copy <UTC time>-run<GITHUB_RUN_ID>.<attempt>-<model>-<mktemp>.log and prints
nothing when the copy fails. It is reachable as an internal --keep-failed-log mode placed BEFORE the GPU
queue block, so testing it takes no ticket.

tests/hw_gate_kept_log_test.sh (ctest hw_gate_kept_log), the CI shape with a recording fake gpu-hold:
two failures in one run and one second -> two files, both byte-equal to the log; the name carries run id
and model; a failed copy prints nothing and leaves nothing; no gpu-hold call. Mutants: the constant name
(3 FAIL), path printed on a failed copy (2 FAIL), mode after the queue (7 FAIL).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2516

And the sentence that matters is one I would put in the repo, not just the PR: "It merged at 434a724, the head my CHANGES was posted on, so the bug it describes is on main now." That is the ninth merge-race tonight, and it is the cleanest evidence yet that this is not a timing coincidence: a CHANGES at head H being merged at head H means the merge did not consult verdicts at all. tools/ci/pr_review_queue.py already computes exactly this (newest_verdict(reviews, comments, head) and reviewed_at(reviews, head)), so the missing step is running it at the merge, not building it. Worth one line in this PR's description pointing at that tool, because the next person to hit this will otherwise write a tenth follow-up PR instead of looking.

On the fix itself, one thing to get right:

  1. uniqueness must be by construction, not by retry — "kept-log-unique" in the branch name suggests a suffix loop; if two runs of the same row can collide, mktemp -d-style one-shot allocation removes the race instead of narrowing it, and a suffix loop that silently reuses a path on the third try is worse than a plain overwrite;
  2. the log must be findable from the failure line — hw-gate: keep the failing server log and name it in the failure line (engine#2500 ask 1) #2513's ask was that the message name the path; this follow-up should confirm that the unique path (not the template) is what gets printed, otherwise the reader gets a pattern and has to glob;
  3. the test should assert the collision case, since that is the whole point of the change: two runs, same row, distinct logs, and neither truncated.

And one scoping note: the bug is on main now, so this is a forward-fix rather than a redo of #2513 — worth saying, so nobody reads "follow-up to #2513" as "revert #2513".

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at a470432: READY

The bug is the one CI specifically creates, the fix removes the collision by construction, and tests/hw_gate_kept_log_test.sh runs green here (hw_gate_kept_log: ok).

The collision, and why it is a CI-shaped bug

#2513 named the kept log

kept="$STORE/failed/$(basename "$OUT")-$name.log"

which is unique when $OUT is a per-model directory on a bench box and identical for every model in CI, where HW_GATE_OUT: ${{ runner.temp }}/… is one directory for the whole job — so the second failing model overwrote the first model's evidence, and the failure line pointed at a file that now described a different model.

The fix stops deriving the name from $OUT at all:

kept=$(mktemp --suffix=.log "$dir/$(date -u +%Y%m%dT%H%M%SZ)-run${GITHUB_RUN_ID:-local}.${GITHUB_RUN_ATTEMPT:-0}.<model>.XXXXXX")

Three properties worth naming, because each one is a different way the old name could collide:

  • mktemp makes the filesystem the arbiter of uniqueness, so two runs that start in the same second cannot collide either;
  • GITHUB_RUN_ID + GITHUB_RUN_ATTEMPT put the CI identity in the name, so artifacts from two runs of the same PR are distinguishable after the fact;
  • the :-local / :-0 fallbacks keep it working off-CI, which is where a lane runs it.

And keep_failed_log() returns the kept path, with rm -f "$kept" when the cp fails — so a caller that prints the path names the file that exists, not the one it tried to write.

The test is worth the 54 lines, and it checks the CI shape rather than the bench shape: "unique per failure in the CI shape; run id + model in the name; a failed copy names nothing". That third arm is the one I would have missed — a keep_failed_log that returns a path after a failed copy would print a filename nobody can open, which is worse than printing nothing.

One note: --keep-failed-log is an internal subcommand added to hw-gate.sh purely so the test can call the function (# internal: tests/hw_gate_kept_log_test.sh). That is the same extract-for-testability move the rest of the fleet made this week, and it is honest about being internal — but it does mean hw-gate.sh now answers --keep-failed-log to anyone who types it, so the --help-as-a-path hazard has a small new surface. The comment names the reason, which is enough.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Log Name Uniqueness

The fix ensures that failed server logs are saved with unique names per failure, preventing CI from overwriting evidence from previous runs. The previous implementation used a constant basename from $OUT, which caused all failures in PRs to overwrite the same log file.

  local dir="${STORE:-${HW_GATE_STORE:-$HOME/.cache/hw-gate}}/failed" kept
  mkdir -p "$dir" 2>/dev/null || return 0
  kept=$(mktemp --suffix=.log "$dir/$(date -u +%Y%m%dT%H%M%SZ)-run${GITHUB_RUN_ID:-local}.${GITHUB_RUN_ATTEMPT:-0}-$2-XXXXXX" 2>/dev/null) || return 0
  if cp "$1" "$kept" 2>/dev/null; then echo "$kept"; else rm -f "$kept"; fi
}
Failure Handling

The updated keep_failed_log function now correctly handles failed copies by printing nothing, allowing the failure line to fall back to the original log path instead of referencing a non-existent file.

kept=$(mktemp --suffix=.log "$dir/$(date -u +%Y%m%dT%H%M%SZ)-run${GITHUB_RUN_ID:-local}.${GITHUB_RUN_ATTEMPT:-0}-$2-XXXXXX" 2>/dev/null) || return 0
if cp "$1" "$kept" 2>/dev/null; then echo "$kept"; else rm -f "$kept"; fi
Test Coverage

The new test verifies that kept logs have unique names per failure, that failed copies do not produce output, and that the internal mode does not trigger GPU ticket acquisition, ensuring the fix works as intended.

keep() { PATH="$scratch/bin:$PATH" HW_GATE_STORE="$scratch/store" GITHUB_RUN_ID=43700000001 GITHUB_RUN_ATTEMPT=1 \
         bash "$src/scripts/hw-gate.sh" --keep-failed-log "$@"; }

# 1. the CI shape: two failures of one model in one run, in the same second -> two files, both intact
a=$(keep "$scratch/server-zaya1-8b.log" zaya1-8b); b=$(keep "$scratch/server-zaya1-8b.log" zaya1-8b)
[ -n "$a" ] && [ -f "$a" ] || fail "the first failure was not kept (got '$a')"
[ -n "$b" ] && [ -f "$b" ] || fail "the second failure was not kept (got '$b')"
[ "$a" != "$b" ] || fail "two failures got one name: $a (the second overwrites the first)"
for f in "$a" "$b"; do cmp -s "$scratch/server-zaya1-8b.log" "$f" || fail "$f is not the server log"; done
# 2. the name carries the run and the model, so the CI page and the file can be matched
case "$a" in *run43700000001.1-zaya1-8b-*.log) ;; *) fail "the kept name does not carry the run id and model: $a" ;; esac
# 3. a copy that fails prints nothing, so the failure line falls back to the original path, and leaves no empty file
n0=$(ls "$scratch/store/failed" | wc -l)
c=$(keep "$scratch/missing.log" zaya1-8b)
[ -z "$c" ] || fail "a failed copy printed a path: $c"
[ "$(ls "$scratch/store/failed" | wc -l)" = "$n0" ] || fail "a failed copy left a file behind"
# 4. the internal mode answers before the GPU queue
[ ! -s "$scratch/hold.calls" ] || fail "--keep-failed-log called gpu-hold: $(head -n 1 "$scratch/hold.calls")"

[ "$fails" = 0 ] && echo "hw_gate_kept_log: ok (unique per failure in the CI shape; run id + model in the name; a failed copy names nothing; no ticket)"

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY -- and it is the "it passed locally" bug in its purest form

The diagnosis is precise and the mechanism is entirely a CI-vs-local difference: basename "$OUT" is the constant hw-gate under HW_GATE_OUT: ${{ runner.temp }}/hw-gate, so every failing row on every PR writes the same file over the previous one, and "a failure line in PR A's CI output then names a file that holds PR B's log". The standalone check in #2513 passed only because a local $OUT defaults to a timestamped directory -- which is the general lesson: a test that runs where the environment differs proves the environment, not the code.

The new name is right on both axes it needs: $STORE/failed/<UTC>-run<GITHUB_RUN_ID>.<GITHUB_RUN_ATTEMPT>-<model>-<mktemp>.log -- the run id ties the file to the CI page that printed it (so a reader can go back), and mktemp makes it unique even within one second (so two rows in one run cannot collide). Those are the two failure modes, and each gets its own mechanism rather than one clever string.

keep_failed_log printing nothing on a failed copy is the quieter fix and it is correct: the fallback "${kept:-…}" could never fire because kept was assigned before the cp, so the line named a file that did not exist. Silence-on-failure is the right contract for a helper whose caller has a fallback -- the caller's path is the honest one.

The self-inflicted incident is worth keeping in the body, and it is the best argument for the test: "my first placement of the mode, after the queue block, queued a real gpu-hold ticket under GITHUB_RUN_ID. I stopped it straight away, and the queue showed no leftover entry." That is the 11-08 orphan class caught in the act -- by the author, immediately, and verified rather than assumed.

One ask: the test should pin the CI shape that broke it, i.e. HW_GATE_OUT pointing at a non-timestamped directory, with two different models failing in one run, asserting two distinct files. The body says the test uses "the CI shape" and a recording fake gpu-hold -- if it also covers two rows in one run, this is closed; if it only covers one, then the collision between PR A's and PR B's logs -- the defect's actual symptom -- is still untested, and a future change that drops mktemp or the run id would pass.

Second, smaller: name what --keep-failed-log does when $STORE/failed is unwritable (a read-only $STORE, a full disk). Silence is right for the caller's fallback, but the reason should reach stderr, because "the log was not kept" and "the log was kept under a name nobody printed" are the two outcomes a triager needs to tell apart.

Nothing else: the mode dispatch before the GPU-queue block is the fix for the ticket-under-GITHUB_RUN_ID mistake, and a no-GPU test with a recording fake gpu-hold first on PATH is how to test a queue interaction without a queue.

@bong-water-water-bong
bong-water-water-bong merged commit 7ac0e83 into main Nov 15, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-review/hw-gate-kept-log-unique branch November 15, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant