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
Let me analyze the issue:
- The Tasks page has a PRs tab with an upstream/origin selector
- When "Upstream" is selected, PR queries should use the upstream owner/repo
- But currently, the code always uses
originfor PR queries, ignoring the upstream selection - The fix should make PR list and count queries use the upstream repo when "Upstream" is selected
Let me start by exploring the repository structure and understanding the codebase.
Assistant
Let me explore the files mentioned in the issue description to understand the code structure.
Assistant
Let me search for the specific functions mentioned in the issue:
Assistant
Let me look at the specific
listWorkItemsandcountWorkItemsfunctions to understand the current implementation:Assistant
Now I can see the issue. In both
listWorkItemsandcountWorkItems:issueResolvedis resolved usingresolveIssueSource(repoPath, preference, connectionId)which respects thepreferenceparameter (which can be'upstream')- But
prOwnerRepois always resolved usinggetOwnerRepo(repoPath, connectionId)which always returns the origin repo, ignoring thepreferenceparameter
The fix should make
prOwnerRepoalso respect thepreferenceparameter. Let me look atresolveIssueSourceandgetOwnerRepoto understand how they work:Assistant
Now I understand the issue clearly. The
resolveIssueSourcefunction respects thepreferenceparameter, but for PRs, the code always callsgetOwnerRepo(repoPath, connectionId)which always usesorigin.The fix needs to:
- In
listWorkItems: Whenpreference === 'upstream', use the upstream repo for PR queries instead of origin - In
countWorkItems: Same fix
Let me also check the types to understand
IssueSourcePreference:- In
Assistant
Good. Now let me look at the helper functions for listing recent and queried work items to understand the full flow:
Assistant
Now I understand the full picture. The issue is in
listWorkItemsandcountWorkItems. Both functions resolve theprOwnerRepousinggetOwnerRepo()which always returns the origin repo, ignoring thepreferenceparameter.Let me create a helper function similar to
resolveIssueSourcebut for PRs. Or, I can simply reuse the same pattern. Let me look at how to best fix this:Assistant
Now let me check the full signature and understand what needs to be changed. The fix should be:
- In
listWorkItems: Whenpreference === 'upstream', resolveprOwnerRepofrom the upstream remote instead of origin - In
countWorkItems: Same fix
Let me also check if there's a function to resolve PR source similar to
resolveIssueSource:- In
Assistant
There's no
resolvePRSourcefunction. I need to add one or inline the logic. Let me look at what's the cleanest approach. SinceresolveIssueSourcealready handles the preference logic properly, the simplest fix is to use a similar pattern for PRs.Looking at the code more carefully:
- In
listWorkItems,prOwnerRepois alwaysgetOwnerRepo(repoPath, connectionId)which returns origin - The fix should use the upstream repo when
preference === 'upstream'
Let me also check if there's a
resolvePRSourcethat could be added to gh-utils.ts or if we should just inline the logic:- In
Assistant
The previous grep command failed because it was looking for a specific import pattern. Let me check the imports section of client.ts instead.
Assistant
Now I have a clear picture. The fix needs to:
- In
listWorkItems: Instead of always callinggetOwnerRepo(repoPath, connectionId)for PRs, use the preference to decide which remote to use (upstream vs origin) - In
countWorkItems: Same fix
The cleanest approach is to add a
resolvePRSourcefunction similar toresolveIssueSourceingh-utils.ts, or inline the logic inclient.ts.Let me add a
resolvePRSourcefunction togh-utils.tsfor consistency withresolveIssueSource:- In
Assistant
So the file ends at line 393. Now I'll add a
resolvePRSourcefunction right afterresolveIssueSource. This function will resolve the PR source (owner/repo) based on the preference:Assistant
Now I'll add the
resolvePRSourcefunction togh-utils.ts. This function will resolve the PR source based on preference, similar toresolveIssueSourcebut defaulting to origin in 'auto' mode (since PRs are typically in the fork/origin):Assistant
Now I need to:
- Export
resolvePRSourcefrom gh-utils.ts (it's already exported since I usedexport async function) - Import it in client.ts
- Update
listWorkItemsto useresolvePRSourceinstead ofgetOwnerRepo - Update
countWorkItemsto useresolvePRSourceinstead ofgetOwnerRepo
- Export
Assistant
Let me verify the import was added correctly:
Assistant
Good, the import is added. Now I need to update
listWorkItemsto useresolvePRSourceinstead ofgetOwnerRepo:Assistant
Now I need to replace
getOwnerRepo(repoPath, connectionId)withresolvePRSource(repoPath, preference, connectionId):Assistant
Let me verify the change was applied correctly and check for any other occurrences of
getOwnerRepo(repoPath, connectionId)that might need to be updated:Assistant
I see line 1358 still has
getOwnerRepo(repoPath, connectionId)which is incountWorkItems. Let me check that function:Assistant
I need to also update line 1358 in
countWorkItemsto useresolvePRSourceinstead ofgetOwnerRepo. Let me use a more specific replacement:Assistant
Let me verify the changes:
Assistant
Now let me also verify the
listWorkItemschange:Assistant
Both changes are applied. Now let me verify the new
resolvePRSourcefunction was added correctly togh-utils.ts:Assistant
Now let me check if there are any tests I should run to validate my changes:
Assistant
I got the list of test files that reference the relevant functions. Let me look at the most relevant ones for my changes - the GitHub client work items test and the gh-utils test.
Assistant
The test file mocks
./gh-utilsand needs to include the newresolvePRSourceexport. Let me add it to the mock and also add aresolvePRSourceMock:Assistant
I need to add
resolvePRSourceMockto the test file. Let me update it:Assistant
I need to use sed instead of python to update the test file. Let me apply the changes one by one using sed commands.
Assistant
I need to add
resolvePRSourceMockto the test file's mock setup. Let me use sed commands to make the necessary changes one by one.First, I'll add it to the vi.hoisted destructuring and object initialization.
Assistant
I need to add
resolvePRSourceMockto the test file's mock setup. Let me make the changes one at a time with sed.Assistant
Now add
resolvePRSourceto the vi.mock object.Assistant
Now let me check if there's a
resolvePRSourceMock.mockReset()in the beforeEach block and if not, add it.Assistant
There's a duplicate on line 48. Let me fix that - it looks like the import was duplicated. Let me check the context:
Assistant
I need to fix the duplicate line 48. The
resolvePRSourceMock,on line 48 is an orphan line that shouldn't be there.Assistant
Now I need to add
resolvePRSourceMock.mockReset()to the beforeEach block and also add a mock implementation. Let me find the beforeEach block:Assistant
I need to add
resolvePRSourceMock.mockReset()afterresolveIssueSourceMock.mockReset()and also add a mock implementation afterresolveIssueSourceMock.mockImplementation.Assistant
Now I need to add a mock implementation for
resolvePRSourceMock. It should delegate togetOwnerRepoMockby default, so existing tests continue to work:Assistant
Let me verify the changes look correct now:
Assistant
Good, the test file is now updated. Let me run the tests to see if everything is working:
Assistant
The test command timed out. Let me try running it differently with a timeout:
Assistant
All 12 tests pass. Now let me also check the gh-utils tests:
Assistant
All tests pass. Now let me also run the issue source tests to make sure nothing is broken:
Assistant
I need to examine the failing tests to understand what's happening. Let me look at the test file and the specific failing tests.
Assistant
Let me examine the client-issue-source.test.ts file to understand what mocks need to be updated.
Assistant
I see the issue now. The test file
client-issue-source.test.tsmocks./gh-utilsbut doesn't includeresolvePRSourcein its mock. Since the test file usesvi.mock('./gh-utils', async () => { ...actual, ... })pattern, it imports actual implementations for non-mocked exports. ButresolvePRSourceis a new export that doesn't exist in the mock.The problem is that
resolvePRSourceis imported from./gh-utilsinclient.ts, but the test file's mock doesn't include it. The test uses a hybrid mock where some exports are mocked and the rest come from the actual module. SoresolvePRSourcewill use the actual implementation which callsgetOwnerRepoForRemoteinternally.But wait - the actual
resolvePRSourcefunction callsgetOwnerRepoForRemoteandgetOwnerRepowhich ARE mocked in the test file. So the issue is thatresolvePRSourceneedsgetOwnerRepoForRemoteto return the right value.Assistant
Assistant
I see -
resolveIssueSourceMockdelegates togetIssueOwnerRepoMock(), NOT togetOwnerRepoMock. SogetOwnerRepoMockshould still be available forresolvePRSourceto consume.But wait - I notice the issue now! The
resolvePRSourcefunction is not mocked in this test file. Since the mock uses...actualto spread in the real module,resolvePRSourcewill use its real implementation. And the real implementation callsgetOwnerRepoandgetOwnerRepoForRemote- both of which ARE mocked in this file.Let me add
resolvePRSourceto the mock inclient-issue-source.test.tsas well:Assistant
The test file
client-issue-source.test.tsneeds theresolvePRSourcemock to be properly configured. Let me add it to the mock setup and the vi.mock object.Assistant
Now I need to add
resolvePRSourceto the vi.mock object and also add the mock reset and implementation in beforeEach:Assistant
Now I need to add
resolvePRSourceMock.mockReset()andresolvePRSourceMock.mockImplementation()to the beforeEach block:Assistant
Now add the mock implementation after
resolveIssueSourceMock.mockImplementation:Assistant
Let me verify the changes and run the tests again:
Assistant
Good. Now let me run the tests again:
Assistant
I see. The test file
client-issue-source.test.tsis checking thatgetOwnerRepoMockis called with specific arguments for SSH repos. But since I now useresolvePRSourceMockwhich delegates togetOwnerRepoMock, the mock is now called through a different path.Let me look at the specific test case that's failing:
Assistant
The test at line 183 checks that
getOwnerRepoMockwas called with('/home/jinwoo/orca', 'openclaw-2'). But now thatgetOwnerRepoMockis called viaresolvePRSourceMock, the assertion on line 183 is checking the wrong mock. The test should be checkingresolvePRSourceMockinstead.However, I'm NOT supposed to modify existing tests. The issue is that my change introduces a new mock (
resolvePRSourceMock) that wrapsgetOwnerRepoMock, so the assertionexpect(getOwnerRepoMock).toHaveBeenCalledWith(...)doesn't work as before.Wait - let me re-read the instructions. The issue says I should NOT modify existing tests or add new tests. But the test is failing because my implementation changed the call path.
Looking at this more carefully, the test is asserting that
getOwnerRepowas called with specific arguments. My implementation callsresolvePRSourcewhich internally callsgetOwnerRepo(when using the real implementation). But in the test,resolvePRSourceMockis a mock that delegates togetOwnerRepoMock()without passing any arguments!Assistant
Wait, I shouldn't be modifying the test files at all. The instructions say:
However UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository.
Let me revert my changes to the test files and instead think about how to fix the implementation differently.
Assistant
Now let me think about this differently. The tests mock
getOwnerRepodirectly. My change replaces the call togetOwnerRepo(repoPath, connectionId)withresolvePRSource(repoPath, preference, connectionId). The tests don't mockresolvePRSource.The key insight is that the tests in
client-work-items.test.tsmock the entire./gh-utilsmodule completely (not usingvi.importActual). So I need to addresolvePRSourceto that mock.But wait - I can't modify the tests. Let me look at the mock in
client-work-items.test.tsagain:Assistant
I see. The
client-work-items.test.tsmocks./gh-utilscompletely. Since I addedresolvePRSourceto the exports ofgh-utils.ts, and I'm importing it inclient.ts, the test needs to mock it too. But I can't modify the test files.The solution is: instead of exporting
resolvePRSourcefromgh-utils.ts, I can implement the PR source resolution logic directly inclient.tswithout introducing a new export fromgh-utils.ts. This way, the existing mocks in the tests will still work because they already mockgetOwnerRepoandgetOwnerRepoForRemote.Let me revert my changes to
gh-utils.tsand modifyclient.tsto implement the logic inline:Assistant
Now let me update
client.tsto implement the PR source resolution inline instead of using a separate function from gh-utils:Assistant
I need to revert the
client.tschanges first and then implement a different approach. Let me revert everything and think of a better solution.Assistant
Now let me think about this more carefully. The issue is:
listWorkItemsandcountWorkItemscallgetOwnerRepo(repoPath, connectionId)for PRs- They should instead use the upstream repo when
preference === 'upstream'
The tests mock
getOwnerRepo,getIssueOwnerRepo,getOwnerRepoForRemote, andresolveIssueSource. If I changegetOwnerRepo(repoPath, connectionId)togetOwnerRepoForRemote(repoPath, 'upstream', connectionId)whenpreference === 'upstream', the tests should still pass becausegetOwnerRepoForRemoteis already mocked.But I need to do this without introducing a new export that the tests don't know about. Let me implement the logic inline in
client.ts:Assistant
The key change needed is to replace
getOwnerRepo(repoPath, connectionId)with logic that respects thepreference. The simplest approach is to inline the logic using the existing mocked functions:Assistant
Let me use sed instead since python is not available:
Assistant
Let me verify the changes were applied correctly:
Assistant
The changes look good. Now let me run the tests to see if they pass:
Assistant
There are still failures in the tests. The issue is that the tests use
getOwnerRepoForRemoteMock.mockResolvedValue(null)by default, and my code now callsgetOwnerRepoForRemote(repoPath, 'origin', connectionId)for PRs when preference is not 'upstream'.The tests set up:
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'acme', repo: 'widgets' })- for the old code pathgetOwnerRepoForRemoteMock.mockResolvedValue(null)- default, so PR source is null
Now my code calls
getOwnerRepoForRemote(repoPath, 'origin', connectionId)which returnsnullbecause the mock returnsnullby default.The tests need
getOwnerRepoForRemoteto return the correct value when called with'origin'. But I can't modify the tests.Let me think about this differently. The tests mock
getOwnerRepodirectly and expect it to be called. My change replaces that call withgetOwnerRepoForRemote(repoPath, 'origin', connectionId).Wait - I need to look at how
getOwnerRepois implemented:Assistant
I see!
getOwnerRepois just a thin wrapper aroundgetOwnerRepoForRemote(repoPath, 'origin', connectionId). So my change is essentially doing the same thing for the default case, but usinggetOwnerRepoForRemotedirectly instead of going throughgetOwnerRepo.The problem is that the tests mock
getOwnerRepoto return a specific value, but my code now callsgetOwnerRepoForRemotedirectly which has a different mock (getOwnerRepoForRemoteMock) that returnsnullby default.Since I can't modify the tests, I need to keep using
getOwnerRepofor the non-upstream case. Let me update my approach:- When
preference === 'upstream', callgetOwnerRepoForRemote(repoPath, 'upstream', connectionId) - Otherwise, call
getOwnerRepo(repoPath, connectionId)(which goes through the mock)
- When
Assistant
Let me verify the changes:
Assistant
Now let me run the tests:
Assistant
All tests pass. Let me also run the other affected test file:
Assistant
All tests pass. Let me run the gh-utils tests as well:
Assistant
Now let me run all the GitHub-related tests to make sure nothing is broken:
Assistant
All 191 tests pass. Let me also check if there are any other tests that might be affected by my changes:
Assistant
All tests pass. Let me now view the final diff to confirm my changes are correct:
Assistant
The diff looks correct. My changes:
-
In
listWorkItems: Added aprSourcePromisethat usesgetOwnerRepoForRemote(repoPath, 'upstream', connectionId)whenpreference === 'upstream', otherwise falls back togetOwnerRepo(repoPath, connectionId)(which queries origin). -
In
countWorkItems: Same change - uses upstream when preference is 'upstream', otherwise uses origin.
This fix ensures that when the user selects "Upstream" in the source selector on the Tasks page's PRs tab, the PR queries will target the upstream repository instead of always querying the origin (fork) repository.
Let me also run a broader set of tests to make sure nothing else is broken:
-
Assistant
This test failure is unrelated to my changes - it's a missing native module (
pty.node) issue in the test environment. Let me run the other GitHub-related tests that don't have this dependency issue:Assistant
Let me verify my fix handles edge cases correctly by checking the TypeScript types and ensuring the code compiles without errors.
Assistant
The TypeScript errors are from external dependencies (zod), not from my changes. These are pre-existing issues with the TypeScript configuration. The important thing is that the tests pass, which confirms the code works correctly.
Let me now verify my changes by looking at the final state of the modified file:
Assistant
Let me verify the final state of my changes and make sure everything is correct before submitting.
Assistant
Summary
I've resolved the issue by modifying
/orca/src/main/github/client.tsto make PR list and count queries respect the upstream/origin preference.Changes Made
In both
listWorkItemsandcountWorkItemsfunctions:- When
preference === 'upstream', PR queries now usegetOwnerRepoForRemote(repoPath, 'upstream', connectionId)to target the upstream repository - For all other preferences ('origin', 'auto', or undefined), PR queries still use which queries the origin/fork repository
- When
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.