Skip to content

PR agent: work on and push against the expected head only - #2020

Merged
github-actions[bot] merged 3 commits into
mainfrom
claude/routine-recheck-head-before-push
Oct 7, 2026
Merged

github-actions[bot] merged 3 commits into
mainfrom
claude/routine-recheck-head-before-push

Conversation

@jss367

@jss367 jss367 commented Oct 7, 2026

Copy link
Copy Markdown
Owner

What changed

pr-agent.yml already binds fix-ci to the failing run's head and skips a stale run when it fires the routine (test_ci_fix_binds_to_failing_run_head_not_live_pr_head). But the routine runs afterwards, in the cloud, and checks the branch out by name, then pushes with a plain git push. If someone pushes to the PR in between, the routine works on their newer commit and stacks a fix for a stale failure on top of it.

That happened on #2011. The routine was fired for 125f0f389's Windows failure. By then ac7c34fcf had already fixed that failure in the test. The routine still pushed ebaf66065 on top, and its "fix" changed the moved query's semantics (case-insensitive LIKE to a case-sensitive substr). Codex flagged it as a regression for in-place imports on case-insensitive drives, and it was reverted.

docs/pr-agent-routine-prompt.md:

  • Common Setup: after checkout, confirm git rev-parse HEAD equals EXPECTED_HEAD, and push only with --force-with-lease="refs/heads/$HEAD:$EXPECTED_HEAD". The routine's commit has EXPECTED_HEAD as its parent, so that push is a plain fast-forward when nothing moved, and git rejects it when the head did move, even if the model skipped or raced the re-check. A rejected push is a silent no-op, never a rebase onto the new head.
  • Reconciliation: the same check after the checkout (step 2), and the lease on the push (step 10).
  • fix-ci: the same check after the checkout (step 2), with the reason (a newer push may already fix the failure another way), and the lease on the push (step 6).

New test_routine_works_on_and_pushes_against_the_expected_head_only pins both guards in the shared rules, the reconciliation flow and fix-ci.

Action needed after merge: the stored routine prompt isn't synced from the repo (see CLAUDE.md, PR Agent System). Paste the updated docs/pr-agent-routine-prompt.md into the routine at claude.ai/code/routines for this to take effect.

Test results

  • tests/test_pr_agent_workflow.py: 30 passed.
  • The new test fails against the old prompt (checked by reverting the prompt change locally).

🤖 Generated with Claude Code

pr-agent.yml already binds fix-ci to the failing run's head and skips a
stale run at dispatch, but the routine runs later. On #2011 it was fired
for 125f0f3's Windows failure; by the time it checked the branch out by
name, a newer push (ac7c34f) had fixed that failure in the test. The
routine stacked its own fix on top anyway with a plain push, and that fix
changed the moved query's semantics (case-insensitive LIKE to a
case-sensitive substr), which Codex then flagged as a regression.

Make the routine confirm `git rev-parse HEAD` equals EXPECTED_HEAD after
checkout (Common Setup, reconciliation step 2, fix-ci step 2), and push
only with `--force-with-lease=refs/heads/$HEAD:$EXPECTED_HEAD`, so git
rejects a push onto a head that moved even if the model skips or races the
re-check. A rejected push is a silent no-op, never a rebase onto the new
head.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: abef637b-50e2-4ec0-85fd-5dad4c704d6b
📥 Commits

Reviewing files that changed from the base of the PR and between 45cbb58 and 91369ec.

📒 Files selected for processing (2)
  • docs/pr-agent-routine-prompt.md
  • tests/test_pr_agent_workflow.py
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jss367

jss367 commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

@codex review current head 5aa1fa1

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 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-10-07T21:59:21.661745Z 91369ec 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5aa1fa18d7

ℹ️ 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".

Comment thread docs/pr-agent-routine-prompt.md
Codex flagged that the Absolute Rules at the bottom of the routine prompt
told the routine to pull with rebase and push whenever the branch had
"diverged unexpectedly". The new EXPECTED_HEAD lease push rejects exactly
when the head moved while the routine was working — i.e. "the branch
diverged" — so the labeled-absolute rebase instruction gave the routine
a licensed path to rebase a stale fix onto the newer head and push it
anyway. That recreates the #2011 regression this PR exists to prevent.

Rewrite that rule to:
  - prohibit only unconditional force-push (`git push --force` / `-f`),
  - name the Common Setup `--force-with-lease` push as the only push used,
  - spell out that a rejected lease push is a silent stop — no rebase
    onto the new head, no retry, no comment,
  - carve out the base-divergence (merge-conflict) path as a merge of
    `origin/$BASE` into the PR head inside the reconciliation flow, not
    a rebase to recover from the lease.

Extend `test_routine_works_on_and_pushes_against_the_expected_head_only`
to pin these guards inside the Absolute Rules section itself, so a future
edit to that section cannot silently reintroduce the contradiction.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KUTQVZPcuFFxjT3ebkTQaQ
@jss367 jss367 added the claude-agent PR managed by Claude PR Agent label Oct 7, 2026 — with Claude
@jss367

jss367 commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

@codex review current head 5ebfe47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ebfe47996

ℹ️ 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".

Comment thread docs/pr-agent-routine-prompt.md
Codex flagged the Absolute Rule as contradicting the fix-main flow:
`fix-main` has no `EXPECTED_HEAD` because it opens a new
`claude/fix-main-*` branch from current `main`, so the
`--force-with-lease="refs/heads/$HEAD:$EXPECTED_HEAD"` push the rule
labels as the "only push used" has nothing to lease against. The rule
as written would either try to lease against an empty ref or refuse
the ordinary first push needed before `gh pr create`, breaking
automated recovery whenever `main` goes red.

Changes:

- Absolute Rules: scope the lease-is-only-push rule to every single-PR
  task — the task kinds that carry `EXPECTED_HEAD` (`reconcile-pr`,
  `reconcile-pr-auto`, `address-review`, `address-comment`,
  `address-codex-review`, `fix-ci`) — and spell out that `fix-main` is
  the one exempt task, with the reason (no `EXPECTED_HEAD`, brand-new
  remote branch) and the pointer to its own live-state revalidation
  (steps 1 and 7) as the real guard against publishing on a stale
  incident.
- `fix-main` step 8: make the first push explicit
  (`git push -u origin "claude/fix-main-$WORKFLOW_RUN"`) and name it as
  the one place a plain `git push` is used, so the exemption is
  visible from inside the task flow itself.
- `test_routine_works_on_and_pushes_against_the_expected_head_only`:
  pin the scoping ("every task that carries `EXPECTED_HEAD`") and the
  exemption ("`fix-main` is the one task this scoping exempts",
  `git push -u origin "claude/fix-main-\$WORKFLOW_RUN"`, "explicitly
  exempt") so a future edit cannot silently reintroduce the
  contradiction.

Action needed after merge: the stored routine prompt isn't synced from
the repo. Re-paste `docs/pr-agent-routine-prompt.md` into the routine
at claude.ai/code/routines for the exemption to take effect.

Validation: `python -m pytest tests/test_pr_agent_workflow.py -v` — 30
passed. `ruff check` — clean.

[pr-agent-review-fix:2020]

<!-- pr-agent-generated -->

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015tgq6WBZh3tf2aqQjVw4bG
@jss367

jss367 commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

@codex review current head 91369ec

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 91369ec667

ℹ️ 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".

@github-actions
github-actions Bot merged commit 2451a3d into main Oct 7, 2026
48 checks passed
@github-actions
github-actions Bot deleted the claude/routine-recheck-head-before-push branch October 7, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-agent PR managed by Claude PR Agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants