Skip to content

fix(code-review): base local branch/file diff on origin/<default>, not frozen local ref - #171

Closed
parkerbyrd-ux wants to merge 1 commit into
closedloop-ai:mainfrom
parkerbyrd-ux:fix/code-review-stale-base-diff
Closed

parkerbyrd-ux wants to merge 1 commit into
closedloop-ai:mainfrom
parkerbyrd-ux:fix/code-review-stale-base-diff

Conversation

@parkerbyrd-ux

Copy link
Copy Markdown

Summary

Local /code-review:start / :deep with no PR (the default branch-scope path) computed its changeset against the bare local default branch via a 3-dot diff (main...HEAD).

In a linked git worktree (e.g. Conductor workspaces) the local main ref is frozen at workspace-creation time and never auto-updates — the live base is the remote-tracking ref origin/main. With 3-dot semantics the merge-base becomes the workspace's creation point, so the "diff" silently balloons to include every PR merged to main since the workspace was created. Observed in the wild: local main 198 commits behind origin/maingit diff main...HEAD = 633 files (operator's ~57 + 198 unrelated merged PRs) vs git diff origin/main...HEAD = ~57 files. The oversized diff flagged findings in unrelated already-merged code and tripped a spurious HIGH coverage-gap.

resolve-scope now, for local branch/file scope:

  • detects the repo default branch via origin/HEAD (no longer hardcodes main, fixing a latent master/develop mis-base),
  • bases the diff on the live remote-tracking ref origin/<default> (best-effort git fetch; falls back to the local ref when offline / no remote),
  • prints a stderr ⚠️ local '<branch>' is N commits behind origin/<branch> warning when the local default has drifted.

base_ref stays the plain branch name, preserving the <BASE_REF> token and STATE_KEY = "<review_branch>:<base_ref>". Base resolution runs only when the diff is actually based on the local default — never on the PR-detected or staged paths, so neither a needless fetch nor a misleading drift warning occurs there.

Feature Flags

None.

Breaking changes

None. The PR path, --base <ref> override, staged (--cached), and GitHub mode are unchanged. Local branch/file reviews now diff against origin/<default>...HEAD instead of <default>...HEAD — this is the intended fix (a stale local default branch no longer inflates the diff).

Test plan

  • uv run pytest plugins/1994 passed, 3 skipped
  • uv run ruff check . → clean
  • uv run pyright → 0 errors
  • Updated existing TestResolveScope cases (now assert origin/main...HEAD; made the local-path tests hermetic) and added coverage: offline fallback to local ref, non-main default branch, file-paths pathspec preservation, and the drift-warning helper (fires when behind, silent at 0). PR-path / --base override / worktree-isolation tests unchanged.
  • Plugin version bumped 3.1.0 → 3.1.1; commands/start.md usage comment and resolve-scope section updated.

🤖 Generated with Claude Code

…t frozen local ref

Local `/code-review:start`/`:deep` with no PR computed its changeset against
the bare local default branch via a 3-dot diff (`main...HEAD`). In a linked git
worktree (e.g. Conductor) the local `main` ref is frozen at workspace-creation
time, so the merge-base became the workspace's creation point and the "diff"
silently ballooned to include every PR merged to main since — flagging findings
in unrelated, already-merged code and tripping spurious coverage-gap HIGHs.

resolve-scope now:
- detects the repo default branch via `origin/HEAD` (no longer hardcodes `main`),
- bases local branch/file scope on the live remote-tracking ref `origin/<default>`
  (best-effort fetch; falls back to the local ref when offline / no remote),
- warns on stderr when the local default branch has drifted behind origin.

base_ref stays the plain branch name (preserving the <BASE_REF> token and
STATE_KEY). The PR path, `--base` override, staged (`--cached`), and GitHub mode
are unchanged — base resolution runs only when the diff is actually based on the
local default (never on the PR-detected or staged paths).

Adds unit coverage (origin-based default, offline fallback, non-main default,
file-paths pathspec, drift warning) and bumps the plugin version to 3.1.1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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