Skip to content

fix(desktop): resolve GitHub status for branch workspaces#3295

Merged
AviPeltz merged 3 commits into
superset-sh:mainfrom
magerags:triage/issue-2592-23271171553
Apr 21, 2026
Merged

fix(desktop): resolve GitHub status for branch workspaces#3295
AviPeltz merged 3 commits into
superset-sh:mainfrom
magerags:triage/issue-2592-23271171553

Conversation

@magerags
Copy link
Copy Markdown
Contributor

@magerags magerags commented Apr 9, 2026

Summary

  • Use getWorkspacePath() instead of requiring a worktree record so branch-based workspaces can access GitHub PR status, comments, and review thread resolution
  • Pass the workspace branch name explicitly to fetchGitHubPRStatus so the correct branch is looked up even when the repo is checked out to a different branch
  • Bail out early when a branch override's SHA cannot be resolved, preventing getPRForBranch from falling back to HEAD and matching the wrong PR (addresses review feedback from fix(desktop): solve #2592 — GitHub status unavailable for branch workspaces #2593)

Closes #2592 — supersedes #2593

Test plan

  • Added unit tests for getGitHubStatus covering branch workspaces, worktree workspaces, null workspace, unresolvable path, and cache-write behavior
  • Added unit test for getWorktreeInfo returning info for branch workspaces
  • Manual: open a branch workspace (not worktree) and verify GitHub PR status shows correctly
  • Manual: verify worktree workspaces continue to work as before

Summary by cubic

Fixes GitHub PR status, comments, and review thread resolution for branch workspaces by resolving the repo path without a worktree and explicitly targeting the workspace branch. Also improves cache invalidation to prevent stale or wrong PRs.

  • Bug Fixes
    • Resolve repo path via getWorkspacePath for both workspace types; handle missing paths safely.
    • Target the workspace branch for PR status and comments; bail if the branch SHA can’t be resolved to avoid HEAD fallback.
    • Scope GitHub status cache by branch and invalidate with a prefix; clear caches after mutations.
    • Write git/GitHub status to the worktrees table only for worktree workspaces; re-throw unexpected rev-parse errors on the non-override path.
    • Return basic info for branch workspaces in getWorktreeInfo.
    • Closes fix(desktop): GitHub status unavailable for branch workspaces #2592.

Written for commit b2cf68c. Summary will update on new commits.

Summary by CodeRabbit

  • Tests

    • Added comprehensive tests covering git status and GitHub PR behavior for both branch and worktree workspaces, including path-resolution and caching scenarios.
  • Bug Fixes

    • Corrected GitHub PR status/comment resolution for branch-type workspaces to use the intended branch when determining PR state.
    • Prevented unnecessary persistence of status for workspaces without an associated worktree.
  • Improvements

    • Scoped GitHub status cache by repository+branch and expanded cache invalidation to improve freshness.

Use getWorkspacePath() instead of requiring a worktree record so
branch-based workspaces can access GitHub PR status, comments, and
review thread resolution. Pass the workspace branch name explicitly
to fetchGitHubPRStatus so the correct branch is looked up even when
the repo is checked out to a different branch.

Bail out early when a branch override's SHA cannot be resolved to
prevent getPRForBranch from falling back to HEAD and matching the
wrong PR.

Closes superset-sh#2592
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 064709ef-bca9-400c-8022-2a1de0961c5d

📥 Commits

Reviewing files that changed from the base of the PR and between 1daa4db and b2cf68c.

📒 Files selected for processing (1)
  • apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts

📝 Walkthrough

Walkthrough

Replace worktree-only path resolution with unified getWorkspacePath across git-status procedures and GitHub helpers so branch workspaces resolve repo paths and GitHub PR status/comments use an optional branch override; add tests covering branch vs worktree behaviors and adjust cache invalidation to handle branch-scoped keys.

Changes

Cohort / File(s) Summary
Tests
apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts
Add Bun test suite with extensive mocks covering getGitHubStatus and getWorktreeInfo for branch and worktree workspaces, asserting path resolution, fetchGitHubPRStatus/comments invocation, and caching/DB write behavior.
Workspace git-status procedures
apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.ts
Use getWorkspacePath(workspace) instead of getWorktree(...) for repo path resolution across procedures; pass branch override for branch-type workspaces; only persist worktree-scoped caches/DB when workspace.worktreeId exists; add early-return for branch getWorktreeInfo with null git/github status.
GitHub utilities
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts
Extend functions to accept optional branchName/override (e.g., fetchGitHubPRStatus, fetchGitHubPRComments, refreshGitHubPRStatus, resolvePullRequestCommentsTarget); scope cache keys by worktreePath::branchName and return null early if overridden branch SHA cannot be resolved.
GitHub cache handling
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/cache.ts
Invalidate GitHub status cache by prefix (githubStatusResource.invalidatePrefix(worktreePath)) so branch-scoped cache entries are cleared; other invalidations unchanged.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant Procedure as WorkspacesProcedure
participant WSUtil as getWorkspacePath
participant GitHub as GitHubUtils
participant CacheDB as Cache/DB
Client->>Procedure: request getGitHubStatus(workspaceId)
Procedure->>WSUtil: getWorkspacePath(workspace)
WSUtil-->>Procedure: repoPath (project.mainRepoPath or worktree.path)
alt workspace.type == "branch"
Procedure->>GitHub: fetchGitHubPRStatus(repoPath, branchName)
else worktree
Procedure->>GitHub: fetchGitHubPRStatus(repoPath, null)
end
GitHub->>CacheDB: check cache(key=repoPath[::branch])
CacheDB-->>GitHub: cached or miss
GitHub->>Procedure: GitHubStatus | null
Procedure->>CacheDB: persist githubStatus if workspace.worktreeId exists

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰
I hopped through paths both rough and flat,
Found branch and worktree — fixed where they sat.
One getWorkspacePath now leads the way,
PRs respond and tests did play.
Carrots cheered: the code's less ratty!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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
Title check ✅ Passed The title clearly and concisely summarizes the main change: resolving GitHub status for branch workspaces, which is the core objective of this PR.
Description check ✅ Passed The PR description is comprehensive, covering the problem, solution, testing approach, and related issues. It includes all key sections and provides sufficient detail about the changes.
Linked Issues check ✅ Passed The PR fully addresses the requirements from #2592: uses getWorkspacePath for both workspace types, passes branch name explicitly to GitHub functions, guards worktree cache writes, and bails on unresolvable branch SHAs. Unit tests added for all key code paths.
Out of Scope Changes check ✅ Passed All changes are directly related to enabling GitHub status for branch workspaces and improving cache handling. No unrelated or out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 9, 2026

Greptile Summary

This PR fixes GitHub PR status, comments, and review thread resolution for branch workspaces (workspaces that share the main repo directory rather than using a git worktree). The root cause was that the prior implementation required a worktree record to resolve the repository path, leaving branch workspaces with no path and therefore no GitHub data.

Key changes:

  • Path resolution: getWorkspacePath() is now used consistently for all workspace types in all GitHub/git-status procedures, replacing direct worktree lookups.
  • Branch targeting: workspace.branch is passed as an explicit branchOverride to fetchGitHubPRStatus and fetchGitHubPRComments for branch workspaces, ensuring the correct branch is interrogated even when the main repo is checked out to a different branch.
  • Cache key scoping: The GitHub status cache key is now ${worktreePath}::${branchName} for branch workspaces, preventing collision with the main checkout's status.
  • Cache invalidation: clearGitHubCachesForWorktree now uses invalidatePrefix (was exact-key invalidate), ensuring composite keys like ${path}::${branch} are also evicted on mutation.
  • SHA bail-out: Early return added when git rev-parse refs/heads/<branch> fails for a branch override, preventing getPRForBranch from falling back to HEAD and matching the wrong PR.
  • DB writes scoped to worktrees: GitHub/git status is only persisted to the worktrees table for worktree workspaces; branch workspaces rely entirely on the in-memory cache.
  • getWorktreeInfo extended: Now returns a lightweight stub for branch workspaces so callers don't receive null.
  • Tests: Comprehensive unit tests cover branch workspace, worktree workspace, null workspace, unresolvable path, and no-DB-write scenarios.

Confidence Score: 4/5

Safe to merge — both prior review concerns are resolved and the fix is well-tested.

Both previous reviewer concerns (prefix-based cache invalidation and error re-throw on non-override path) have been fully addressed in this revision. The core logic for branch workspace path resolution, branch-scoped cache keys, and early bail-out on unresolvable SHA is correct. Tests cover the main scenarios well. Score held at 4 rather than 5 due to the manual test plan items still being unchecked.

No files require special attention; git-status.ts and github.ts are the most critical but have been carefully reviewed.

Vulnerabilities

No security concerns identified. The PR does not introduce new network calls, credential handling, or user-controlled data paths beyond what already exists.

Important Files Changed

Filename Overview
apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.ts Core fix: consistently uses getWorkspacePath() for all procedures, scopes branchOverride for GitHub calls, gates DB writes on worktreeId, and adds branch-workspace stub in getWorktreeInfo. Logic is correct.
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts Introduces composite cache key for branch workspaces and SHA bail-out to prevent wrong-PR fallback. Error handling correctly re-throws unexpected errors on the non-override path. Previous thread concerns addressed.
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/cache.ts clearGitHubCachesForWorktree updated to use invalidatePrefix for the status resource, correctly evicting composite-key entries for branch workspaces.
apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts Good coverage: tests for branch workspaces, worktree workspaces, null workspace, unresolvable path, and no-DB-write constraint. Test assertions are accurate and match the implementation logic.

Sequence Diagram

sequenceDiagram
    participant Client
    participant git-status.ts as git-status router
    participant worktree.ts as getWorkspacePath
    participant github.ts as fetchGitHubPRStatus
    participant cache.ts as githubStatusResource

    Client->>git-status.ts: getGitHubStatus(workspaceId)
    git-status.ts->>worktree.ts: getWorkspacePath(workspace)
    alt branch workspace
        worktree.ts-->>git-status.ts: mainRepoPath
        git-status.ts->>github.ts: fetchGitHubPRStatus(mainRepoPath, workspace.branch)
        github.ts->>cache.ts: read(mainRepoPath::branch, loader)
    else worktree workspace
        worktree.ts-->>git-status.ts: worktreePath
        git-status.ts->>github.ts: fetchGitHubPRStatus(worktreePath, null)
        github.ts->>cache.ts: read(worktreePath, loader)
    end
    cache.ts-->>github.ts: GitHubStatus or null
    github.ts-->>git-status.ts: GitHubStatus or null
    alt worktree workspace and status changed
        git-status.ts->>git-status.ts: localDb.update(worktrees)
    end
    git-status.ts-->>Client: GitHubStatus or null

    Client->>git-status.ts: resolveReviewThread(workspaceId, threadId)
    git-status.ts->>git-status.ts: resolveReviewThread(worktreePath)
    git-status.ts->>cache.ts: clearGitHubCachesForWorktree(repoPath)
    cache.ts->>cache.ts: invalidatePrefix(repoPath)
Loading

Reviews (2): Last reviewed commit: "fix(desktop): address PR review feedback" | Re-trigger Greptile

Comment thread apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts
Comment thread apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

3 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts">

<violation number="1" location="apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts:120">
P2: `rev-parse` error handling now swallows all failures, masking real git errors and continuing with undefined SHA instead of failing the status refresh path.</violation>

<violation number="2" location="apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts:222">
P2: Branch-scoped GitHub status cache keys were introduced, but invalidation still clears only the old worktree-only key, leaving branch entries stale.</violation>
</file>

<file name="apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.ts">

<violation number="1" location="apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.ts:235">
P2: Branch workspace PR comments can be resolved from repo HEAD instead of the workspace branch when PR target input is omitted.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts Outdated
Comment thread apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts (1)

110-135: Consider adding assertion for getWorktree not being called.

For completeness, the branch workspace test could also verify that getWorktree is not called when worktreeId is null, since this was part of the original bug (unnecessary dependency on worktree lookup).

💡 Optional enhancement
 	test("returns GitHub status for branch workspaces (no worktreeId)", async () => {
 		const branchWorkspace = {
 			id: "ws-branch-1",
 			projectId: "proj-1",
 			worktreeId: null,
 			type: "branch" as const,
 			branch: "feature/branch-workspace",
 			name: "Feature Branch",
 		};

 		mockFetchGitHubPRStatus.mockClear();
+		mockGetWorktree.mockClear();
 		mockGetWorkspace.mockReturnValue(branchWorkspace);
 		mockGetWorkspacePath.mockReturnValue("/repos/my-project");
 		mockFetchGitHubPRStatus.mockResolvedValue(fakeGitHubStatus);

 		const result = await procedures.getGitHubStatus({
 			input: { workspaceId: "ws-branch-1" },
 		});

 		expect(result).not.toBeNull();
 		expect(mockGetWorkspacePath).toHaveBeenCalledWith(branchWorkspace);
 		expect(mockFetchGitHubPRStatus).toHaveBeenCalledWith(
 			"/repos/my-project",
 			"feature/branch-workspace",
 		);
+		expect(mockGetWorktree).not.toHaveBeenCalled();
 	});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts`
around lines 110 - 135, The branch-workspace test for procedures.getGitHubStatus
should assert that getWorktree is not invoked when worktreeId is null; after
calling procedures.getGitHubStatus in this test (the one that sets
branchWorkspace.worktreeId = null), add an expectation like
expect(mockGetWorktree).not.toHaveBeenCalled() to ensure mockGetWorktree is not
called, keeping the existing assertions for mockGetWorkspacePath and
mockFetchGitHubPRStatus.
apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts (1)

218-226: Use invalidatePrefix for GitHub status cache to clear branch-specific entries.

The cache invalidation has an inconsistency: pullRequestCommentsResource correctly uses invalidatePrefix() to clear all entries matching a worktree prefix, but githubStatusResource uses exact-key invalidate(). Since fetchGitHubPRStatus creates composite cache keys like ${worktreePath}::${branchName} when called with a branch override (as in git-status.ts:194), branch-specific entries won't be cleared by clearGitHubCachesForWorktree.

Update githubStatusResource.invalidate(worktreePath) to githubStatusResource.invalidatePrefix(worktreePath) in cache.ts to match the pattern already used for PR comments and ensure stale branch-specific data doesn't persist after cache invalidation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts` around
lines 218 - 226, The github status cache is being invalidated by exact key which
misses composite keys created by fetchGitHubPRStatus (which uses cache keys like
`${worktreePath}::${branchName}`); update the cache invalidation in the cache.ts
code that calls githubStatusResource.invalidate(worktreePath) to instead call
githubStatusResource.invalidatePrefix(worktreePath) so branch-specific entries
are cleared; locate usages around clearGitHubCachesForWorktree or where
githubStatusResource is referenced and replace invalidate(...) with
invalidatePrefix(...) consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts`:
- Around line 110-135: The branch-workspace test for procedures.getGitHubStatus
should assert that getWorktree is not invoked when worktreeId is null; after
calling procedures.getGitHubStatus in this test (the one that sets
branchWorkspace.worktreeId = null), add an expectation like
expect(mockGetWorktree).not.toHaveBeenCalled() to ensure mockGetWorktree is not
called, keeping the existing assertions for mockGetWorkspacePath and
mockFetchGitHubPRStatus.

In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts`:
- Around line 218-226: The github status cache is being invalidated by exact key
which misses composite keys created by fetchGitHubPRStatus (which uses cache
keys like `${worktreePath}::${branchName}`); update the cache invalidation in
the cache.ts code that calls githubStatusResource.invalidate(worktreePath) to
instead call githubStatusResource.invalidatePrefix(worktreePath) so
branch-specific entries are cleared; locate usages around
clearGitHubCachesForWorktree or where githubStatusResource is referenced and
replace invalidate(...) with invalidatePrefix(...) consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 13f6f86f-98eb-414e-98a6-c163d3df479d

📥 Commits

Reviewing files that changed from the base of the PR and between 89d7903 and dc36a1c.

📒 Files selected for processing (3)
  • apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.test.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/procedures/git-status.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/github/github.ts

- Use invalidatePrefix for GitHub status cache so branch-scoped keys
  (path::branch) are properly cleared on invalidation
- Restore re-throw for unexpected git rev-parse errors on the
  non-override (worktree) path instead of swallowing all errors
- Pass branch override to resolvePullRequestCommentsTarget so PR
  comments resolve from the workspace branch, not HEAD
@magerags
Copy link
Copy Markdown
Contributor Author

magerags commented Apr 9, 2026

@greptileai

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 9, 2026

Tip:

Greploop — Automatically fix all review issues by running /greploops in Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.

Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.

@magerags
Copy link
Copy Markdown
Contributor Author

magerags commented Apr 9, 2026

Hey @Kitenite — this supersedes #2593 (fixes #2592) with a clean rebase and addresses all review feedback. Would appreciate a review when you get a chance!

@magerags
Copy link
Copy Markdown
Contributor Author

@saddlepaddle @AviPeltz - would appreciate a review!

@AviPeltz AviPeltz merged commit 4d32cf2 into superset-sh:main Apr 21, 2026
6 of 7 checks passed
@magerags magerags deleted the triage/issue-2592-23271171553 branch April 21, 2026 15:04
MocA-Love added a commit to MocA-Love/superset that referenced this pull request Apr 23, 2026
MocA-Love added a commit to MocA-Love/superset that referenced this pull request Apr 23, 2026
upstream 取り込み PR #5: superset-sh#3295 + 19 procedure architecture rework
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.

fix(desktop): GitHub status unavailable for branch workspaces

2 participants