ISSUE DESCRIPTION Tasks PR Upstream source still queries origin This was generated by AI…
- User
ISSUE DESCRIPTION
Tasks PR Upstream source still queries origin
This was generated by AI during triage.
Summary
In the Tasks page, selecting the
PRstab and choosingUpstreamin the source selector can showNo matching GitHub workeven when matching upstream PRs exist.The upstream/origin selector is visible in the PRs view, but the GitHub client still resolves PR list/count queries from
origin, sois:pr is:open author:@mesearches the fork/origin repo instead of the selected upstream repo.Reproduction
- Open a forked repository in Orca where
originpoints to the fork andupstreampoints to the canonical repo. - Open Tasks.
- Select
PRs. - Select
Upstreamin the source selector. - Use a PR-only query such as
is:pr is:open author:@me.
Actual behavior
The list can be empty with
No matching GitHub work, despite matching PRs existing in the upstream repository.Expected behavior
When
Upstreamis selected, PR list and PR count queries should use the upstream owner/repo, so the PRs tab returns matching upstream PRs.Code evidence
src/main/github/client.tsresolvesissueResolvedwith the selected preference, but resolvesprOwnerReposeparately viagetOwnerRepo(repoPath, connectionId), which is the origin repo.listWorkItemspasses thatprOwnerRepointo both recent and queried PR fetches.countWorkItemsuses the sameprOwnerRepofor PR count queries, so pagination/count can also be wrong.src/renderer/src/components/TaskPage.tsxrenders the selector usingorigin={s.sources.prs}andupstream={s.sources.upstreamCandidate}, which makes the control appear relevant in the PRs surface while the backend still routes PR queries to origin.
Suggested regression coverage
Add tests for:
listWorkItems('/repo-root', 10, 'is:pr is:open author:@me', undefined, 'upstream')using the upstream slug in--repo.countWorkItems('/repo-root', 'is:pr is:open author:@me', 'upstream')building a search query with .
- Open a forked repository in Orca where
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files mentioned in the issue.
- Assistant
Let me look for the specific files mentioned in the issue.
- Assistant
Great, I found both files. Let me first examine the
client.tsfile to understand the current implementation, particularly focusing onlistWorkItems,countWorkItems, and howprOwnerRepois resolved. - Assistant
Let me search for the relevant functions.
- Assistant
Let me examine the
listWorkItemsfunction around line 1188: - Assistant
Let me look at the
countWorkItemsfunction: - Assistant
Let me look at the
IssueSourcePreferencetype to understand what values it can have: - Assistant
Let me check the IssueSourcePreference type definition to understand what values it takes.
- Assistant
Let me understand the full picture. The issue says:
listWorkItemsresolvesprOwnerRepoviagetOwnerRepo(repoPath, connectionId)which is always the origin repo.countWorkItemsalso usesgetOwnerRepo(repoPath, connectionId)for PR count.- The
preferenceparameter is used for issues viaresolveIssueSource, but NOT used for PRs.
So when
preferenceis'upstream', the issue source gets resolved to upstream, but the PR source always stays as origin. The fix should be to use thepreferenceparameter (or the upstream candidate) to resolve the PR owner/repo when the preference is 'upstream'.Let me look at the
resolveIssueSourcefunction to understand how it works, and then figure out how to apply a similar pattern for PRs. - Assistant
Let me examine the
resolveIssueSourcefunction: - Assistant
Now I have a clear understanding of the issue. Let me examine the
listRecentWorkItemsfunction to understand the full picture: - Assistant
Now I have a clear understanding of the issue. Let me look at the
listQueriedWorkItemsfunction and the existing tests: - Assistant
Now I have a clear picture of the issue. Let me also look at the
TaskPage.tsxto understand the renderer side: - Assistant
Now let me look at how
IssueSourceSelectorpasses the preference in the renderer: - Assistant
Now I understand the core issue. Let me check
resolveIssueSourceingh-utils.tsto see how the preference is applied for issues: - Assistant
Now I understand the full picture. Let me look at existing tests for these functions:
- Assistant
Let me look at the client-work-items.test.ts and client-issue-source.test.ts to understand the test patterns:
- Assistant
Let me look at the work items test and issue source test to understand how tests are structured.
- Assistant
Let me read more of the test file to understand the patterns better.
- Assistant
Let me look at the issue source test to understand the pattern:
- Assistant
Let me continue reading this test file to understand the existing patterns:
- Assistant
Let me also look at more of the issue source test to understand how the PR source should behave with preference:
- Assistant
Let me read the preference-specific tests to understand what they expect:
- Assistant
Let me continue reading to understand how the PR queries are handled when
preference='upstream'is used. - Assistant
Now I have a clear understanding of the issue. Let me trace through the complete flow:
- Assistant
Let me look at the
countWorkItemsForQueryfunction: - Assistant
Now I understand the issue completely. Let me trace through the key problem:
- In
listWorkItems,prOwnerRepois always resolved viagetOwnerRepo(repoPath, connectionId)which returns the origin repo, regardless of thepreferenceparameter. - In
countWorkItems, same issue -prOwnerRepoalways comes fromgetOwnerRepo(repoPath, connectionId). - When
preference='upstream',issueResolvedcorrectly resolves to upstream viaresolveIssueSource, butprOwnerRepostill uses origin.
I need to create a
resolvePRSourcefunction that respects the preference, similar toresolveIssueSource, and use it in bothlistWorkItemsandcountWorkItems. Let me also check if there's aresolvePRSourcealready or similar function: - In
- Assistant
Now I understand the full picture. Let me look at the
gh-utils.tsimports and exports to understand the pattern: - Assistant
Now I have a complete understanding of the issue. Let me summarize my analysis:
The Problem:
- In
listWorkItems(line 1202-1205),prOwnerRepois always resolved viagetOwnerRepo(repoPath, connectionId)which always returns the origin repo - In
countWorkItems(line 1355-1357),prOwnerRepois also always resolved viagetOwnerRepo(repoPath, connectionId) - The
preferenceparameter is only used for issue resolution viaresolveIssueSource, but NOT for PR resolution - When a user selects "Upstream" in the source selector, issues are correctly routed to upstream but PRs still query origin
The Fix:
- Create a
resolvePRSourcefunction ingh-utils.tsthat respects the preference for PRs - Use it in both
listWorkItemsandcountWorkItems - Add tests for the new behavior
Let me implement the fix step by step. First, let me add the
resolvePRSourcefunction togh-utils.ts: - In
- Assistant
Now I have a clear understanding. Let me implement the fix. First, I'll add a
resolvePRSourcefunction togh-utils.ts: - Assistant
Now let me add the
resolvePRSourcefunction togh-utils.ts. I'll add it right after theresolveIssueSourcefunction: - Assistant
Now I have a clear picture of the fix needed. Let me implement it:
- Add
resolvePRSourcetogh-utils.ts - Update
listWorkItemsandcountWorkItemsinclient.tsto use it - Update the
sources.prsreturn value to reflect the preference
Let me start with
gh-utils.ts: - Add
- Assistant
Good, the
resolvePRSourcefunction is added. Now I need to updateclient.tsto:- Import
resolvePRSource - Use it in
listWorkItemsinstead ofgetOwnerRepofor PR resolution - Use it in
countWorkItemsinstead ofgetOwnerRepofor PR resolution
Let me first check the imports in
client.ts: - Import
- Assistant
Now let me add the import for
resolvePRSource: - Assistant
Now let me modify
listWorkItemsto useresolvePRSourceinstead ofgetOwnerRepofor the PR owner repo: - Assistant
Now let me modify
listWorkItemsto useresolvePRSourceinstead ofgetOwnerRepo: - Assistant
I see there's a duplicate line. Let me fix that:
- Assistant
I see a duplicate line. Let me remove it:
- Assistant
Good. Now I need to update
countWorkItemsto useresolvePRSourceinstead ofgetOwnerRepo: - Assistant
Now let me update
countWorkItemsto useresolvePRSourceinstead ofgetOwnerRepo: - Assistant
Good. Now I need to update the test files to mock
resolvePRSourcesince it's now used bylistWorkItemsandcountWorkItems. Let me first run the existing tests to see what breaks: - Assistant
As expected, the tests need to be updated to mock
resolvePRSource. Let me update both test files. First,client-work-items.test.ts: - Assistant
I need to update both test files to add
resolvePRSourceMock. Let me updateclient-work-items.test.tsfirst: - Assistant
Now let me add
resolvePRSourceto the mock and set up the mock implementation: - Assistant
Now I need to add the
resolvePRSourceMocksetup in thebeforeEachblock. Let me update it: - Assistant
Good. Now let me run the tests to see if they pass:
- Assistant
All tests pass. Now let me check and update the
client-issue-source.test.tsfile: - Assistant
I need to update the issue-source test file too. Let me first look at the structure of that test:
- Assistant
I need to update this test file to add
resolvePRSourceMock. Let me add it to the hoisted mocks and the mock module: - Assistant
Now let me add
resolvePRSourceto the mock module: - Assistant
Now let me update the
beforeEachto also reset and configureresolvePRSourceMock: - Assistant
Good. Now let me run the issue-source test again to see if the test updates fixed the failures:
- Assistant
Almost there! Only 1 test is failing. Let me look at that test:
- Assistant
The test at line 189 expects
getOwnerRepoMockto be called directly, but nowresolvePRSourceis called instead. I need to update this test to checkresolvePRSourceMockinstead: - Assistant
Good. Let me run the issue-source tests again to see if all tests pass:
- Assistant
All tests pass! Now let me run both test files together to make sure they work:
- Assistant
All tests pass. Now let me check if there are other tests that might be affected by my changes:
- Assistant
Let me also check other test files that reference
listWorkItemsorcountWorkItems: - Assistant
That test fails due to native module issues, not related to my changes. Let me check the renderer store test:
- Assistant
These are environment issues unrelated to my changes. Let me now verify my changes are correct by running the full GitHub-specific test suite:
- Assistant
All 191 tests pass across all 17 GitHub test files. Now let me verify the IPC test as well since it's relevant:
- Assistant
All tests pass. Let me now verify my changes by looking at the full diff:
- Assistant
Let me see the full diff:
- Assistant
The diff looks clean. Let me now also verify that the specific scenarios mentioned in the issue work correctly by looking at the preference-specific tests more closely:
- Assistant
Let me verify the final state of all changes and run a comprehensive test:
- Assistant
All 206 tests pass across 18 test files. Let me now review the changes one final time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.