Repository navigation
consult --type integration: no way to anchor the diff on the integration branch (gh pr diff inherits the PR's trunk base → 10k-line diffs overflow the reviewer) #1113
Description
Summary
consult --type integration pr <N> can produce a huge diff (10k+ lines) that overflows a reviewer model's context, in repos that maintain a long-lived integration branch ahead of the default branch (e.g. an ci/integration branch well ahead of main). The integration review has no way to anchor the diff on the integration branch — it always inherits whatever base the PR targets on the host.
Verified root cause (the reported "diffs against main" is one level off)
Traced through packages/codev/src/commands/consult/index.ts (source + installed dist agree):
--type integration→buildPRQuery(prId)→fetchPRDiff(prId)→ thepr-diffforge concept →gh pr diff <N>(GitHub) /glab mr diff(GitLab). That's the only diff source for this path — no localgit diff, noresolveDefaultBranch, no hardcodedmain.gh pr diff <N>is anchored on the PR's base branch as recorded on the host (merge-base of base↔head). So the diff balloons when the PR's base is the trunk (main) while the head was branched from an integration branch (ci) that is well ahead of trunk: "changes vs main" then legitimately swallow the entireci-over-maindelta.
So the literal claim "consult diffs against main instead of ci" is a symptom: consult diffs against the PR's base, which in this workflow is main, when the meaningful comparison is against the integration branch the work actually forked from.
The buildPRQuery path already writes the diff to a temp file and points the model at the path (not inlined), so this is not an inlining problem — the diff is genuinely too large because it's anchored on the wrong branch.
Precedent (why integration is the odd one out)
The impl review type was already hardened for exactly this diff-base class:
- consult --type {spec,plan,impl} resolves artifact from invoking workspace (not the builder's branch); impl-review diff base hardcoded to main #777 (CLOSED) — "impl-review diff base hardcoded to main"
- consult: impl-review uses two-dot
<base>..HEADdiff semantics; over-includes when branch is behind on rebases #784 (CLOSED) — two-dot over-include
impl now computes the diff locally as git diff origin/<baseRefName>...origin/<headRefName> (three-dot, merge-base anchored on the PR's actual base), with both refs verified up front. The integration path never received this treatment — it still leans on gh pr diff with no base control.
Prescribed fix (BUGFIX scope — design choice is specified, no plan gate needed)
Give the integration review path a diff-base override, reusing the verified machinery the impl path already has:
- Add an explicit base override for
--type integration— a--base <ref>flag (and/or read an integration-branch from.codev/config.json, e.g.consult.integrationBranch). - When a base override is provided, compute the diff locally as
git diff origin/<base>...origin/<head>(three-dot, merge-base anchored), mirroring theimplpath — verify both refs up front and fail loudly with an actionablegit fetchhint if either is unresolvable (do not silently fall back to reviewing the checked-out tree — that's the cmap-3 degradation guarded against in the impl path). - Default behavior unchanged: with no override, keep
gh pr diff <N>(the PR's host base) for back-compat. - Reuse the existing escaped-ref / three-dot helpers from the impl path rather than duplicating; keep the on-disk diff-file handoff (don't inline).
This lets a repo with a ci-ahead-of-main topology point integration reviews at ci and get a small, correct diff, while everyone else is unaffected.
Out of scope (note as follow-ups, do not implement here): auto-detecting the integration branch without configuration; changing the default base; GitLab parity beyond passing the override through the pr-diff concept if trivial.
Repro
In a repo with an integration branch (ci) well ahead of main, with a PR whose head was branched from ci but which targets main:
consult --type integration pr <N>
→ the diff balloons to the full ci-over-main delta and overflows the reviewer model.
Acceptance
consult --type integration pr <N> --base <ci-ref>(or the configured integration branch) computesorigin/<ci-ref>...origin/<head>three-dot and produces only the PR's actual change.- Unresolvable base/head refs fail loudly with a
git fetchhint — no silent degradation to the local checkout. - No
--base/ no config → behavior identical to today (gh pr diff). - A test covers the override path (small diff) and the no-override default (unchanged).
Reported via an adopter project running a ci-ahead-of-main integration workflow.
Activity
waleedkadous commentedon Jun 29, 2026
On it! Working on a fix now.
[Bugfix #1113] Fix: anchor consult --type integration diff on an inte…
[Bugfix #1113] Test: regression coverage for integration-branch diff …
[Bugfix #1113] Fix: let config-load errors surface in resolveIntegrat…
[Bugfix #1113] Docs: mirror --base / consult.integrationBranch to ske…
[Bugfix #1113] Update thread: CMAP results, fixes applied, pr gate re…
[Bugfix #1113] Test: integration command-path wiring (architect feedb…
[Bugfix #1113] Update thread: architect feedback addressed (wiring te…
Merge pull request #1114 from cluesmith/builder/bugfix-1113
[Spec 1286][Phase: phase_6] docs: make every JSON example parseable, …