Skip to content

fix: pin adversarial branch review context to commit revisions - #840

Open
Linxiushen wants to merge 3 commits into
openai:mainfrom
Linxiushen:fix/pin-branch-review-snapshot
Open

Linxiushen wants to merge 3 commits into
openai:mainfrom
Linxiushen:fix/pin-branch-review-snapshot

Conversation

@Linxiushen

Copy link
Copy Markdown

/codex:adversarial-review --scope branch collects file counts, diffs and commit logs through separate Git commands. If another process checks out a different branch or advances a ref between those calls, the resulting review context can include changes from the other branch and disagree with its initial file count.

Resolve HEAD and the base ref once, then use their immutable revisions throughout branch context collection. Reuse the initial branch label and give lightweight reviews the fixed commit range to inspect. Two regression tests perform a real checkout and base-ref update between Git calls, covering inline and lightweight context. This keeps the comparison consistent after ref resolution; it does not make repository reads a transaction.

Validation on Windows with Node 24.19.0 and Git 2.55.0:

  • New race tests: both fail on unchanged upstream and pass with the fix; independently reproduced.
  • node --test tests/git.test.mjs: 12 passed; the existing broken-symlink fixture fails at fs.symlinkSync with Windows EPERM.
  • Independent real-Git checks for detached HEAD and an annotated-tag base passed.
  • Direct TypeScript build (tsc -p tsconfig.app-server.json), version consistency and git diff --check passed. The TypeScript check used locally generated app-server types.
  • Extended native Windows full-suite comparison remained incomplete; full-suite or Linux success is not claimed.

AI assistance was used for implementation, reproduction and independent review.

@Linxiushen
Linxiushen requested a review from a team November 9, 2026 13:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T05:39:22.803770Z 8151d49 New commits
ℹ️ 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.

@mangeshraut712 mangeshraut712 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.

Resolving HEAD and the base once and threading the SHAs (plus currentBranch) through is a clean way to make the collected context self-consistent. The spawnSync-mocking test that switches branches and moves main mid-collection is a convincing reproduction. Two observations below.

Comment thread plugins/codex/scripts/lib/git.mjs Outdated

return "The repository context below is a lightweight summary. Inspect the target diff yourself with read-only git commands before finalizing findings.";
const pinnedRange = options.comparison
? ` For this branch review, use the pinned commit range ${options.comparison.commitRange}.`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In lightweight/self-collect mode, pinning the range doesn't fully pin what the reviewer reads. The model will very likely also open files from the working tree for surrounding context, and after the user switches branches (exactly the scenario in the new test) the working tree holds feature/other's content, not the reviewed head's. It might be worth extending the guidance to something like: "Read file contents at the pinned head with git show <headCommit>:<path> rather than from the working tree." That would need headCommit exposed on comparison. Otherwise the findings can still mix two snapshots even though the diff itself is pinned.

Comment thread plugins/codex/scripts/lib/git.mjs Outdated
function buildBranchComparison(cwd, baseRef) {
const mergeBase = gitChecked(cwd, ["merge-base", "HEAD", baseRef]).stdout.trim();
const headCommit = gitChecked(cwd, ["rev-parse", "--verify", "HEAD"]).stdout.trim();
const baseRevision = gitChecked(cwd, ["rev-parse", "--verify", "--end-of-options", baseRef]).stdout.trim();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small one: for an annotated tag used as the base (e.g. --base v1.2.0), rev-parse --verify returns the tag object id, not the commit. I checked locally (git 2.47): merge-base/diff/log still peel it, so behaviour is fine. But reviewRange / the guidance text would then show a tag-object SHA, which is confusing if the model or a human pastes it into other commands. --verify --end-of-options "${baseRef}^{commit}" peels it to the commit and also rejects a ref that doesn't point at a commit. (Same consideration for HEAD, though that's always a commit.)

@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: 4ed3792704

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread plugins/codex/scripts/lib/git.mjs Outdated
Comment on lines +297 to +300
return "Use the repository context below as primary evidence.";
}

return "The repository context below is a lightweight summary. Inspect the target diff yourself with read-only git commands before finalizing findings.";
const pinnedRange = options.comparison

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include pinned read guidance for inline branch reviews

When a small branch diff is inlined and another process checks out a different branch after collection (especially for advertised background reviews), this early return omits both the pinned range and the warning that the working tree may have moved. executeReviewRun starts the app-server turn only after collectReviewContext, and inline content contains the diff but not full surrounding files, so any reviewer tool read of those files will come from the new branch and can support a false finding. Include the comparison.headCommit/git show guidance for branch comparisons even when includeDiff is true.

Useful? React with 👍 / 👎.

@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: 8151d49d92

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

);
includeDiff = options.includeDiff ?? (fileCount <= maxInlineFiles && diffBytes <= maxInlineDiffBytes);
details = collectBranchContext(repoRoot, target.baseRef, { includeDiff, comparison });
details = collectBranchContext(repoRoot, target.baseRef, { includeDiff, comparison, currentBranch });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Tie the branch label to the pinned HEAD

When another process checks out branch B after getCurrentBranch(repoRoot) captures branch A but before buildBranchComparison resolves HEAD, comparison.headCommit and the pinned diff come from B while this call passes A into collectBranchContext. The returned context therefore says Reviewing branch A for a review of B (and persists that metadata in JSON), so background review results can be attributed to the wrong change; resolve the captured branch ref to its commit, or capture the label and OID consistently.

Useful? React with 👍 / 👎.

Edo771977 added a commit to Edo771977/codex-plugin-cc that referenced this pull request Nov 11, 2026
Import upstream openai#840, and pass --effort to native reviews (from openai#837)
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.

2 participants