Skip to content

Say when a failing pull_request job is testing a stale merge ref - #11386

Merged
danielhanchen merged 1 commit into
mainfrom
ci/stale-merge-ref-notice
Sep 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/stale-merge-ref-notice

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Three open PRs are red today for a failure that was fixed hours ago, and nothing in CI says so.

What happens

A pull_request run does not test the branch head. It tests refs/pull/N/merge, a merge of the branch into the base as the base stood when the run was created. GitHub does not rebuild that ref because the base later moved, and re-running the workflow replays the same merge commit, so a fix that lands on main after a run starts is invisible to that run until someone pushes to the branch.

#11372 gave three test files encoding = "utf-8" and merged at 14:35 UTC as 7cc58b4. These runs were created before that:

PR Run created Still failing on
#11375 13:39 UTC tests/test_source_read_encoding.py on the three lines #11372 fixed
#11357 14:26 UTC same three lines
#11373 14:29 UTC same three lines

None of those branches touches those files. The trap is that the jobs started at 16:06 UTC, well after the fix, so the timestamps on the job page read as if the fix should have been included.

What this adds

.github/actions/merge-ref-age asks the compare endpoint how far the base branch has moved since this run's merge ref was built, and prints a notice if the answer is not zero:

This run's merge ref is N commit(s) behind main ... If this failure was fixed on main in that window, the fix is not in this run, and re-running will not pick it up because a re-run replays the same merge commit. Push to the branch to have the merge ref rebuilt. This notice does not mean the failure is spurious.

It is wired into the two studio-backend-ci.yml jobs that run pytest, gated on failure(). A green job never runs it, and it stays silent when the base has not moved, so it adds nothing to the common case where a failure is simply real.

It asks the API rather than the clone because these checkouts are shallow and deepening them enough to hold both commits costs more than the answer is worth.

It cannot fail a job

That is the property worth stating. It runs exactly when a job is already failing, so a bug in it would land as a second, misleading error on top of the real one. The script never exits non-zero and never emits ::error::. A stale merge ref does not make a failure untrue, the merge really does fail, and deciding otherwise on the reader's behalf would be worse than the confusion this is fixing.

Guard

tests/studio/test_merge_ref_age_is_reported.py keeps both properties: every job in that workflow that runs pytest carries the step under failure(), and the action's script cannot fail the job it sits in. It deliberately does not check the wording of the notice, since prose guards have to parse English to be right.

Each assertion was checked by reverting it individually against a green baseline and confirming it failed its own case and only its own:

  • dropping the step from repo-cpu-tests fails the per-job check, naming that job
  • removing failure() from the if fails the gating check
  • making the script exit 1 fails the cannot-fail check
  • turning the notice into ::error fails the advisory check

The repo's own test_workflow_guards_run_unfiltered then caught the new guard missing from the unfiltered job, so it is registered in workflow-trigger-lint.yml as well.

A pull_request run does not test the branch head. It tests refs/pull/N/merge,
a merge of the branch into the base as the base stood when the run was created.
GitHub does not rebuild that ref because the base later moved, and a re-run
replays the same merge commit, so a fix that lands on main after a run starts
stays invisible to that run until someone pushes to the branch.

That cost real time today. #11372 gave three test files encoding = "utf-8" and
merged at 14:35 UTC. Runs created at 13:39, 14:26 and 14:29 on #11375, #11357
and #11373 all went on failing tests/test_source_read_encoding.py on exactly
those three lines, and all three were first read as defects in branches that
had never touched the files.

Adds .github/actions/merge-ref-age, which asks the compare endpoint how far the
base branch has moved since this run's merge ref was built and prints a notice
if the answer is not zero. It is wired into the two studio-backend-ci.yml jobs
that run pytest, gated on failure(), so a green job never pays for it and it
stays quiet when the base has not moved.

It is advisory and cannot fail a job. A stale merge ref does not make a failure
untrue: the merge really does fail. Deciding otherwise for the reader would be
worse than the confusion it is fixing, so the script never exits non-zero and
never emits ::error::.

tests/studio/test_merge_ref_age_is_reported.py keeps both properties: every job
in that workflow running pytest carries the step under failure(), and the
action's script cannot fail the job it sits in. Each assertion was checked by
reverting it individually against a green baseline. The repo's own
test_workflow_guards_run_unfiltered caught the new guard missing from the
unfiltered job, so it is registered in workflow-trigger-lint.yml too.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-20T20:57:04.939365Z b30173f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: b30173fbd7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 8090d95 into main Sep 20, 2026
30 checks passed
@danielhanchen
danielhanchen deleted the ci/stale-merge-ref-notice branch September 20, 2026 21:20
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…lothai#11386)

A pull_request run does not test the branch head. It tests refs/pull/N/merge,
a merge of the branch into the base as the base stood when the run was created.
GitHub does not rebuild that ref because the base later moved, and a re-run
replays the same merge commit, so a fix that lands on main after a run starts
stays invisible to that run until someone pushes to the branch.

That cost real time today. unslothai#11372 gave three test files encoding = "utf-8" and
merged at 14:35 UTC. Runs created at 13:39, 14:26 and 14:29 on unslothai#11375, unslothai#11357
and unslothai#11373 all went on failing tests/test_source_read_encoding.py on exactly
those three lines, and all three were first read as defects in branches that
had never touched the files.

Adds .github/actions/merge-ref-age, which asks the compare endpoint how far the
base branch has moved since this run's merge ref was built and prints a notice
if the answer is not zero. It is wired into the two studio-backend-ci.yml jobs
that run pytest, gated on failure(), so a green job never pays for it and it
stays quiet when the base has not moved.

It is advisory and cannot fail a job. A stale merge ref does not make a failure
untrue: the merge really does fail. Deciding otherwise for the reader would be
worse than the confusion it is fixing, so the script never exits non-zero and
never emits ::error::.

tests/studio/test_merge_ref_age_is_reported.py keeps both properties: every job
in that workflow running pytest carries the step under failure(), and the
action's script cannot fail the job it sits in. Each assertion was checked by
reverting it individually against a green baseline. The repo's own
test_workflow_guards_run_unfiltered caught the new guard missing from the
unfiltered job, so it is registered in workflow-trigger-lint.yml too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant