Skip to content

fix(host-service): resolve Against-base diff to local branch when origin/<branch> missing - #6237

Closed
andyst-dev wants to merge 1 commit into
ParadevAI:mainfrom
andyst-dev:fix/changes-tab-local-only-base-branch
Closed

andyst-dev wants to merge 1 commit into
ParadevAI:mainfrom
andyst-dev:fix/changes-tab-local-only-base-branch

Conversation

@andyst-dev

@andyst-dev andyst-dev commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5298

Problem

For a stacked workspace whose base is another local branch that has never been pushed, the Changes tab rendered empty — even though a real, committed, non-empty diff existed against that base.

resolveBaseComparison resolved the "Against base" view via the remote ref origin/<base> and, when no upstream was configured, silently fell through to origin/<branch> — a ref that does not exist for an unpushed local base. The diff against a missing ref is empty, so the UI showed nothing.

Fix

In resolveBaseComparison, when no upstream is configured:

  1. if refs/remotes/origin/<branch> exists → baseRef: origin/<branch> + fetch target (unchanged behavior);
  2. new — if the remote ref is absent but refs/heads/<branch> exists (local-only base) → baseRef: <branch> with fetchTarget: null (there is nothing to fetch for a local branch);
  3. otherwise → unchanged fallback.

Validation

Two integration tests against real on-disk repos (same suite as the existing resolveBaseComparison tests):

bun test on git-helpers.integration.test.ts: 22/22 pass · tsc --noEmit: 0 errors · Biome: clean.


Summary by cubic

Fixes an empty Changes tab for stacked workspaces by resolving the “Against base” diff to a real ref when origin/<branch> is missing. Previously we fell back to origin/<branch> and showed an empty diff; now we probe remotes and use a remote match (prefer origin), otherwise the local branch, so the diff shows actual changes. Addresses #5298.

  • Updated resolveBaseComparison: probe all remotes in parallel; deterministically prioritize origin regardless of remote order; if no remote ref exists but refs/heads/<branch> does, return the local branch with fetchTarget: null.
  • Supports non-origin remotes (fork workflows) and retains preference for origin/<branch> when both remote and local refs exist.
  • Tests: integration covers the full [bug] Changes tab is empty when a workspace's base branch is a local-only, unpushed branch #5298 pipeline (base→diff returns committed work), coexistence and fork cases; unit tests verify parallel probing without wall-clock delays and origin priority.

Written for commit 8e651c0. Summary will update on new commits.

View guided diff

Summary by CodeRabbit

  • Bug Fixes

    • Improved branch comparison across multiple configured remotes.
    • Prioritizes the standard remote when multiple matching branches are available.
    • Detects branches hosted on other remotes when the standard remote lacks them.
    • Supports local-only branches without unnecessary fetching.
    • Retains the standard fallback when no local or remote branch is available.
  • Tests

    • Added coverage for local, standard-remote, and alternate-remote branch scenarios.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6235333e-0665-4bcf-96f0-63e5bb444512

📥 Commits

Reviewing files that changed from the base of the PR and between e266b01 and 01af228.

📒 Files selected for processing (3)
  • packages/host-service/src/trpc/router/git/utils/git-helpers.integration.test.ts
  • packages/host-service/src/trpc/router/git/utils/git-helpers.test.ts
  • packages/host-service/src/trpc/router/git/utils/git-helpers.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/host-service/src/trpc/router/git/utils/git-helpers.integration.test.ts
  • packages/host-service/src/trpc/router/git/utils/git-helpers.ts
  • packages/host-service/src/trpc/router/git/utils/git-helpers.test.ts
📝 Walkthrough

resolveBaseComparison now checks configured remotes concurrently for the base branch, prefers origin, and uses a local branch when no remote ref exists. Unit and integration tests cover these resolution paths.

Changes: Base comparison resolution

Layer / File(s) Summary
Remote and local reference resolution
packages/host-service/src/trpc/router/git/utils/git-helpers.ts
When no upstream is configured, resolveBaseComparison probes remote refs concurrently in deterministic origin-first order. If no remote ref exists, it uses the local branch without a fetch target.
Resolution test coverage
packages/host-service/src/trpc/router/git/utils/git-helpers.test.ts, packages/host-service/src/trpc/router/git/utils/git-helpers.integration.test.ts
Tests cover concurrent probing, origin precedence, local-only stacked bases, and branches available only on upstream. The integration setup adds an origin remote.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant resolveBaseComparison
  participant SimpleGit
  Caller->>resolveBaseComparison: resolve base branch
  resolveBaseComparison->>SimpleGit: list remotes
  resolveBaseComparison->>SimpleGit: probe remote refs concurrently
  SimpleGit-->>resolveBaseComparison: matching remote ref or no match
  resolveBaseComparison->>SimpleGit: verify local branch if no remote ref exists
  SimpleGit-->>resolveBaseComparison: local base
  resolveBaseComparison-->>Caller: return base and fetch target
Loading

Possibly related PRs

Mergeability Score: ⚪ Minimal · up to 01af2

This localized fix resolves comparisons against unpushed local branches while preserving remote-branch behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title uses conventional commit format and clearly identifies the fix for missing origin branch references.
Description check ✅ Passed The description clearly covers the problem, fix, and validation, but it omits the template checklist.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes against-base comparisons for stacked workspaces whose base exists only as an unpushed local branch.

  • Checks for the existing origin/<branch> ref first and preserves remote fetch behavior when present.
  • Falls back to the local branch with no fetch target when only refs/heads/<branch> exists.
  • Adds integration coverage for local-only bases and remote-over-local precedence.

Confidence Score: 5/5

The PR appears safe to merge, with the intended local-base fallback covered while preserving remote-ref precedence.

The new resolution path selects an existing local branch only when no configured upstream or matching origin ref exists, and no concrete blocking or non-blocking defect remains.

Important Files Changed

Filename Overview
packages/host-service/src/trpc/router/git/utils/git-helpers.ts Adds remote-first ref detection and a local-only branch fallback without changing configured-upstream behavior.
packages/host-service/src/trpc/router/git/utils/git-helpers.integration.test.ts Adds real-repository coverage for local-only branch resolution and remote-ref precedence.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Resolve base branch] --> B{Configured upstream?}
  B -->|Yes| C[Use upstream ref and fetch target]
  B -->|No| D{origin/branch exists?}
  D -->|Yes| E[Use origin/branch and fetch target]
  D -->|No| F{Local branch exists?}
  F -->|Yes| G[Use local branch with no fetch]
  F -->|No| H[Preserve origin/branch fallback]
Loading

Reviews (1): Last reviewed commit: "fix(host-service): resolve Against-base ..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Architecture diagram
sequenceDiagram
    participant UI as Changes Tab (UI)
    participant API as resolveBaseComparison
    participant Git as Git Client
    participant LocalRefs as refs/heads/*
    participant RemoteRefs as refs/remotes/origin/*
    
    Note over UI,RemoteRefs: NEW: Resolve Against-base diff for stacked workspace
    
    UI->>API: request base comparison for branch
    API->>Git: check for configured upstream
    
    alt upstream configured
        API->>API: return upstream baseRef + fetchTarget
    else no upstream configured
        API->>Git: rev-parse --verify refs/remotes/origin/<branch>
        Git->>RemoteRefs: check remote ref existence
        
        alt remote ref exists
            RemoteRefs-->>Git: confirm exists
            Git-->>API: exists
            API->>API: return remote baseRef + fetchTarget
        else remote ref absent
            Git-->>API: not found
            API->>Git: rev-parse --verify refs/heads/<branch>
            Git->>LocalRefs: check local ref existence
            
            alt local ref exists
                LocalRefs-->>Git: confirm exists
                Git-->>API: exists
                API-->>UI: return local baseRef, fetchTarget=null
            else local ref absent
                API-->>UI: return fallback origin/<branch>
            end
        end
    end
    
    Note over UI: NEW: Local base branch renders real diff<br>instead of silent empty result
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@andyst-dev

Copy link
Copy Markdown
Contributor Author

Thanks — both P3s are addressed in ab8f855:

  • Test now covers the real reported pipeline (cubic P3 @ test:185): the [bug] Changes tab is empty when a workspace's base branch is a local-only, unpushed branch #5298 test creates a local-only parent branch, checks out a child branch with committed work, resolves the base against the parent, and runs getChangedFilesForDiff([parent..HEAD]) — asserting the committed work is returned. This is the exact chain that rendered an empty Changes tab before the fix, and it would have caught the HEAD-vs-base trap the previous version had.
  • Remote probe no longer hardcodes origin (cubic P3 @ git-helpers:191): the no-upstream path now iterates git.getRemotes() and picks the first remote holding refs/remotes/<remote>/<branch>, so a base that exists only on a non-origin remote (fork workflow) resolves correctly with its fetch target. New test: base found on a remote named upstream.

bun test: 23/23 pass · tsc --noEmit: 0 errors · Biome: clean.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@andyst-dev

Copy link
Copy Markdown
Contributor Author

Thanks - both findings are addressed in a3ac9d2.

  • Remote refs are still probed concurrently with Promise.all, avoiding sequential subprocess latency.
  • Selection is deterministic after the probes complete: origin is always prioritized when it contains the branch, regardless of configured remote order or which probe finishes first.
  • Non-origin-only refs still fall back correctly for fork workflows.

Coverage now includes concurrent three-remote probing with origin priority, a non-origin-only unit case, and an integration case where both origin and upstream contain the branch.

Validation:

  • focused Bun tests -> 52 passed, 79 assertions
  • host-service typecheck -> passed
  • Biome on the 3 changed files -> clean
  • git diff --check -> clean

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/host-service/src/trpc/router/git/utils/git-helpers.test.ts`:
- Line 31: Replace the setTimeout-based delay in the raw test helper with a
microtask yield using Promise.resolve(), preserving the activeProbes increment
and concurrency assertion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c738d1e-f0c8-4c94-a3c7-e550cf31219f

📥 Commits

Reviewing files that changed from the base of the PR and between ab8f855 and a3ac9d2.

📒 Files selected for processing (3)
  • packages/host-service/src/trpc/router/git/utils/git-helpers.integration.test.ts
  • packages/host-service/src/trpc/router/git/utils/git-helpers.test.ts
  • packages/host-service/src/trpc/router/git/utils/git-helpers.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/host-service/src/trpc/router/git/utils/git-helpers.ts
  • packages/host-service/src/trpc/router/git/utils/git-helpers.integration.test.ts

@andyst-dev

Copy link
Copy Markdown
Contributor Author

Good catch - fixed in 5f2e203.

The concurrency helper now yields with await Promise.resolve() instead of a real 10 ms timer. Each probe still increments activeProbes before yielding, so the test continues to prove that all remote probes are created concurrently without depending on wall-clock scheduling.

Validation:

  • bun test packages/host-service/src/trpc/router/git/utils/git-helpers.test.ts -> 28 passed, 40 assertions
  • Biome on the test file -> clean
  • git diff --check -> clean

@andyst-dev
andyst-dev force-pushed the fix/changes-tab-local-only-base-branch branch from 5f2e203 to 01af228 Compare August 13, 2026 07:21
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@andyst-dev
andyst-dev force-pushed the fix/changes-tab-local-only-base-branch branch from 01af228 to b4ff1eb Compare August 13, 2026 08:16
…anch

A stacked workspace whose base is another local branch that was never
pushed rendered an empty Changes tab even though a real committed diff
existed. `resolveBaseComparison` looked the base up as `<remote>/<branch>`
and, with no upstream configured, silently fell through to
`origin/<branchName>` - a ref that does not exist for an unpushed local
base, and a diff against a missing ref is empty (#5298).

Now: probe every remote for `refs/remotes/<remote>/<branch>` (origin
first, since the old fallback hardcoded it) and use the first match, then
fall back to the local `refs/heads/<branch>` with `fetchTarget: null` -
there is nothing to fetch for a local branch - before the unchanged
last-resort fallback.

Workspace branches are created with `--no-track`, so `resolveUpstream`
returns null for this case and main still returns `origin/<branchName>`:
the bug is live in main, not superseded.

Rebased onto current main (was 1378 commits behind). Integration tests
build real on-disk repos and cover the missing-remote-ref path.
@andyst-dev
andyst-dev force-pushed the fix/changes-tab-local-only-base-branch branch from b4ff1eb to 8e651c0 Compare October 14, 2026 08:55
@andyst-dev andyst-dev closed this Nov 17, 2026
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.

[bug] Changes tab is empty when a workspace's base branch is a local-only, unpushed branch

1 participant