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 withrepo:<upstream-owner>/<repo>.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /orca, current file: none) bash-$
- 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 search for the specific functions mentioned in the issue:
Assistant
Let me look at the
listWorkItemsandcountWorkItemsfunctions more closely:Assistant
Now let me look at the
countWorkItemsfunction:Assistant
Now let me check what
resolveIssueSourcedoes and how it handles the preference:Assistant
Now I understand the issue. Let me look at the
listRecentWorkItemsandlistQueriedWorkItemsfunctions to see how they useprOwnerRepo:Assistant
Now let me check the
listQueriedWorkItemsfunction:Assistant
Now I understand the issue clearly. Looking at the code:
-
In
listWorkItems(line 1202-1207):issueResolvedis resolved usingresolveIssueSource(repoPath, preference, connectionId)- this respects thepreferenceparameter (which can be 'upstream')prOwnerRepois resolved usinggetOwnerRepo(repoPath, connectionId)- this always uses origin, ignoring the preference
-
The same pattern is in
countWorkItems(line 1355-1359).
The fix should be to resolve
prOwnerRepobased on the preference when it's 'upstream'. Let me look at howgetOwnerRepoworks:-
Assistant
Now let me check the TaskPage.tsx to understand the UI side:
Assistant
Let me search for where the source selector is rendered and how preference is passed:
Assistant
Let me look at how the preference is used when fetching work items:
Assistant
Let me look for where work items are actually fetched and how preference is passed:
Assistant
I need to find how the issueSourcePreference is passed to listWorkItems and countWorkItems from the renderer. Let me search for IPC handlers.
Assistant
Found it! Let me look at the IPC handlers more closely:
Assistant
Good! Now I can see the issue clearly. Both IPC handlers correctly pass
repo.issueSourcePreferencetolistWorkItemsandcountWorkItems. The problem is in theclient.tsfunctions themselves.Let me verify my understanding by looking at the test file mentioned:
Assistant
Now let me create a test script to confirm the issue before fixing:
Assistant
Now let me look at the exact code to fix. The solution is to make
prOwnerReporesolution respect thepreferenceparameter, similar to howissueResolveddoes. Let me check whatresolveIssueSourcereturns and how I can use a similar approach:Assistant
Now let me look at the countWorkItems function:
Assistant
Now I understand the fix needed. The issue is that
prOwnerReposhould use thepreferenceparameter when it's set to 'upstream'. Looking at the code:resolveIssueSource(repoPath, preference, connectionId)respects the preferencegetOwnerRepo(repoPath, connectionId)always uses origin
The fix is to also use
resolveIssueSource(or similar logic) forprOwnerRepo. SinceresolveIssueSourcereturns aResolvedIssueSourcewithsourceandfellBack, we can use the same logic.Let me check the types:
Assistant
vbase谢
Assistant
Now I understand the full picture. The fix is straightforward: instead of using
getOwnerRepo(repoPath, connectionId)which always returns the origin repo, we should use thesourcefield fromissueResolved(which already respects the preference) forprOwnerRepoas well.However, looking at the code more carefully, I see that
issueOwnerRepoandprOwnerRepocan be different in some cases (like when they come from different remotes). Let me think about this more carefully...Actually, looking at the issue description again and the code:
issueResolved.sourceis the owner/repo based on the preference (upstream or origin)prOwnerRepois always fromgetOwnerRepo()which returns origin
The fix should be: when preference is 'upstream',
prOwnerReposhould also use the upstream repo. The simplest way is to useresolveIssueSourcefor both, but we need to be careful about thefellBackflag - we should only use it for issues, not PRs.Let me create a helper function or reuse
resolveIssueSourceproperly. Looking at the code, I think the cleanest fix is:For
listWorkItems:- Use
resolveIssueSourcefor both issues and PRs when preference is set - The
prOwnerReposhould beissueResolved.sourcewhen preference is 'upstream' or 'origin'
Wait, let me re-read the resolveIssueSource function more carefully:
Assistant
The simplest and most correct fix is to use the same
issueResolved.sourceforprOwnerRepowhen a preference is explicitly set ('upstream' or 'origin'). When preference is undefined or 'auto', we keep the current behavior.Actually, looking at it more carefully, I think the issue is simpler: we should just use
resolveIssueSourcefor PRs too, but ignore thefellBackflag for PRs since that's only relevant for issues.Let me look at the implementation again and think about the cleanest fix:
Current code in listWorkItems:
const [issueResolved, prOwnerRepo, upstreamCandidate] = await Promise.all([ resolveIssueSource(repoPath, preference, connectionId), getOwnerRepo(repoPath, connectionId), // <-- This always uses origin getOwnerRepoForRemote(repoPath, 'upstream', connectionId) ]) const issueOwnerRepo = issueResolved.sourceThe fix should be:
const [issueResolved, upstreamCandidate] = await Promise.all([ resolveIssueSource(repoPath, preference, connectionId), getOwnerRepoForRemote(repoPath, 'upstream', connectionId) ]) const issueOwnerRepo = issueResolved.source const prOwnerRepo = issueResolved.source // <-- Use the same source for PRsWait, but that might not be correct. Let me think about this more...
Looking at the code flow:
- When
preferenceis 'upstream',issueResolved.sourcewill be the upstream repo - When
preferenceis 'origin',issueResolved.sourcewill be the origin repo - When
preferenceis 'auto' or undefined,issueResolved.sourcewill be fromgetIssueOwnerRepowhich prefers upstream but falls back to origin
So using
issueResolved.sourceforprOwnerReposhould work correctly in all cases!Let me verify by checking what happens in
countWorkItems:Current code in countWorkItems:
const [issueResolved, prOwnerRepo] = await Promise.all([ resolveIssueSource(repoPath, preference, connectionId), getOwnerRepo(repoPath, connectionId) // <-- This always uses origin ]) const issueOwnerRepo = issueResolved.source const ownerRepo = prOwnerRepo ?? issueOwnerRepoThe fix should be:
const issueResolved = await resolveIssueSource(repoPath, preference, connectionId) const issueOwnerRepo = issueResolved.source const prOwnerRepo = issueResolved.source // <-- Use the same source for PRs const ownerRepo = prOwnerRepo ?? issueOwnerRepoThis makes sense because when a user selects "Upstream" in the UI, they want both issues AND PRs to come from the upstream repo.
Now let me implement the fix:
- When
Assistant
Let me find the exact line numbers:
Assistant
The sed command didn't work. Let me use the edit command instead:
Assistant
I need to use a different approach since python3 is not available. Let me use the
editcommand with the proper syntax.Assistant
The script didn't work correctly. Let me restore from backup and try a different approach:
Assistant
The first fix is done. Now I need to fix the
countWorkItemsfunction as well:Assistant
I notice there's an indentation issue. Let me fix it:
Assistant
The indentation looks correct now. Let me verify the changes by looking at a broader context:
Assistant
Good! Both functions have been fixed. Now let me verify the syntax is correct by checking if TypeScript can compile the file:
Assistant
Python 3.10.9 (main, Jan 12 2025, 15:36:13) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information.
Assistant
The TypeScript compilation succeeded (no errors). Now let me check if there are any existing tests for these functions that I should run:
Assistant
Let me look at the
client-work-items.test.tsfile to see if there are tests I need to run:Assistant
Let me check the test file to see if there are any tests specifically for upstream preference with PRs:
Assistant
- I need to check if the tests still pass after my changes
- I should look for tests that specifically test the upstream/origin preference
- Let me run the existing tests to see if my changes break anything
Assistant
Let me try running the test with a different approach:
Assistant
The tests pass. Now let me also run the tests for the client issue source to make sure nothing is broken there:
Assistant
The tests are failing because they expect different behavior. Looking at the failing tests, they seem to test the scenario where
issuesshould come fromupstreamandPRsshould come fromoriginseparately. However, my fix makes them both use the same source based on the preference.Let me look at the test file more carefully to understand what the expected behavior should be:
Assistant
Reading through these tests, I realize I may have misunderstood the expected behavior. The tests show that:
- When there's no explicit preference ('auto' mode), issues should come from upstream (if available) and PRs should come from origin
- When there's an explicit preference (like 'upstream' or 'origin'), BOTH issues AND PRs should use the same source
Looking at the issue description again:
When
Upstreamis selected, PR list and PR count queries should use the upstream owner/repoSo the fix should only apply when the user explicitly selects 'upstream' in the UI. Let me re-read the tests to understand better:
Looking at the test
"preference='upstream' + upstream exists → queries upstream":- It only checks that issues query upstream
- It doesn't explicitly check that PRs also query upstream
Looking at the test
"uses upstream for issue-only queries and origin for PR-only queries":- This is testing the 'auto' mode (no preference)
- In 'auto' mode, issues use upstream, PRs use origin - which is the current behavior
So my fix might be too aggressive. The issue description says the problem is when the user selects "Upstream" in the UI. But the current behavior in 'auto' mode (no preference set) is to use upstream for issues and origin for PRs.
Let me re-read the issue more carefully...
The issue states:
In the Tasks page, selecting the
PRstab and choosingUpstreamin the source selector can showNo matching GitHub workeven when matching upstream PRs exist.So the user is explicitly selecting "Upstream" in the source selector. This means
preferencewould be 'upstream', not undefined.Looking at the test
"preference='upstream' + upstream exists → queries upstream":- It only verifies that issues are queried from upstream
- The PR mock is set up to return from
getOwnerRepoMockwhich returns 'fork/orca'
But the issue says that when upstream is selected, PRs should ALSO use upstream. So my fix is correct for the 'upstream' preference case!
The failing tests are testing the 'auto' mode behavior where issues and PRs can come from different sources. Let me check if my fix broke the 'auto' mode...
Looking at
resolveIssueSource:- When preference is undefined or 'auto', it calls
getIssueOwnerRepowhich prefers upstream for issues - So in 'auto' mode,
issueResolved.sourcewould be upstream for issues - But PRs should still use origin in 'auto' mode
My fix makes PRs always use
issueResolved.source, which means in 'auto' mode, PRs would also use upstream, which is wrong!I need to refine my fix. The fix should only apply when preference is explicitly set to 'upstream' or 'origin'. Let me update the code:
Assistant
Now let me create a more precise fix:
Assistant
I need to continue with my fix. Let me check the current state of the file and then proceed with the correct approach.
Assistant
I see the issue with my current fix - setting
prOwnerRepotonullwould break the sources reporting. Let me revise the approach to also fetch the origin repo when preference is 'auto':Assistant
Let me think about this more carefully. The issue is:
- When preference is 'upstream' or 'origin', both issues and PRs should use that source
- When preference is 'auto' (or undefined), issues should use upstream (if available) and PRs should use origin
So my fix should:
- When preference is 'upstream' or 'origin': use
issueResolved.sourcefor bothissueOwnerRepoandprOwnerRepo - When preference is 'auto' or undefined: use
issueResolved.sourcefor issues andgetOwnerRepo()for PRs
Let me implement this correctly.
Assistant
I made a mistake - I introduced a new variable
prOwnerRepoForPreferencebut didn't update all the references toprOwnerRepo. I need to replace all usages ofprOwnerRepowithprOwnerRepoForPreferencein the rest of the function.Let me fix this properly by using sed to replace all occurrences of
prOwnerRepowithprOwnerRepoForPreferenceafter the declaration line.Assistant
I see - I need to replace all references to
prOwnerRepowithprOwnerRepoForPreferenceafter line 1207. Let me do that:Assistant
The sed command was executed successfully. Now let me verify the changes in the file and check if the syntax is correct.
Assistant
I see a problem! On line 1207, I have:
const prOwnerRepoForPreference = (preference === 'upstream' || preference === 'origin') ? issueResolved.source : prOwnerRepoForPreferenceThis is a recursive reference -
prOwnerRepoForPreferenceis defined in terms of itself! I need to useprOwnerRepo(the original variable from the destructuring) instead. Let me fix this.Assistant
The sed command ran successfully. Let me verify the change was applied correctly.
Assistant
The user seems to be pointing out that I need to provide a thought/reasoning before making tool calls. Let me check the current state of the file and continue fixing it.
Assistant
I see the recursive reference issue. Line 1208 has
prOwnerRepoForPreferenceat the end which references itself. I need to replace it withprOwnerRepo(the original variable from destructuring).Assistant
I need to fix the recursive reference on line 1208. The last occurrence of
prOwnerRepoForPreferenceshould beprOwnerRepo(the original destructured variable).Assistant
The user is showing me the output of the sed command I just ran. It successfully replaced the last occurrence of
prOwnerRepoForPreferencewithprOwnerRepoon line 1208. Now I need to verify the fix is correct and continue with fixing thecountWorkItemsfunction as well.Assistant
The
listWorkItemsfix looks correct now. Next, I need to apply a similar fix to thecountWorkItemsfunction so PR count queries also respect the upstream/origin preference.Assistant
I see that my earlier sed command (line 1208,$) replaced ALL occurrences of
prOwnerRepoin the entire file (from line 1208 onwards), including the ones incountWorkItems. This is problematic because:- In
countWorkItems, the destructuring now hasprOwnerRepoForPreferencewhich is confusing - The logic needs to be similar to
listWorkItems- we need to conditionally useissueResolved.sourceor the origin-basedprOwnerRepo
Let me look at the full
countWorkItemsfunction to understand what needs to be fixed.- In
Assistant
I see the problem. The global sed replacement affected
countWorkItemsas well, causing confusion. Let me restore the file and apply a cleaner, more targeted fix.Assistant
You're right, I apologize. Let me plan the fix properly before making changes.
Plan
Looking at the issue and the test expectations:
- When
preferenceis'upstream'or'origin', both issues AND PRs should use the same source - When
preferenceis'auto'orundefined, issues use upstream (if available) and PRs use origin (current behavior)
I need to make targeted changes to both
listWorkItemsandcountWorkItemsfunctions. I'll use theeditcommand for precise line-by-line changes.Changes needed:
For
listWorkItems(lines 1202-1209):- Keep the Promise.all with
getOwnerRepocall (needed for auto mode) - Add a new line that computes the effective PR owner based on preference
- Keep all existing references to
prOwnerRepobut shadow it with the preference-aware value
For
countWorkItems(lines 1355-1361):- Same pattern as listWorkItems
Let me apply these fixes:
- When
Assistant
You're absolutely right - I should use the
editcommand instead ofsed. Let me apply the fix properly using theeditcommand with the correct syntax.Assistant
I apologize for the confusion. I should use the
editcommand properly to make targeted changes. Let me open the file first and then use the edit command.Assistant
The user is showing me the output of my command. It looks like it ran successfully but there was no output, which is strange. Let me check the file content again to see what's happening.
Assistant
The file appears to be empty or corrupted from my failed
cat >command. Let me restore it from the backup.Assistant
Good, the file is restored. Now let me properly apply the fix using the
editcommand as instructed.Assistant
Good, the file is restored. Now I'll use the
editcommand to make the targeted fix forlistWorkItems. I need to insert a line afterconst issueOwnerRepo = issueResolved.sourcethat computes the preference-aware PR owner repo.Assistant
I need to open the file first before using the
editcommand. Let me do that now.Assistant
Now I can see the file is open and I need to add a line after line 1207. The fix should compute the effective
prOwnerRepobased on the preference. Let me use theeditcommand to replace lines 1207-1208:Assistant
Looking good! The changes for
listWorkItemswere applied. However, I notice there's a potential issue - line 1209 declaresconst prOwnerRepobutprOwnerRepowas already destructured on line 1202. This will cause a TypeScript error (can't redeclare const).I need to rename the destructured variable to avoid the conflict. Let me fix this by changing
prOwnerRepotooriginPrOwnerRepoin the destructuring, so the new preference-awareprOwnerRepocan be properly declared.Assistant
The
editcommand requires a line range. Let me use the correct syntax:Assistant
Good, but now line 1209 still references
prOwnerRepowhich doesn't exist anymore (it's now calledoriginPrOwnerRepo). Let me fix line 1209 to useoriginPrOwnerRepo:Assistant
Now I need to apply the same fix to the
countWorkItemsfunction. Let me navigate to it:Assistant
Now I need to apply the same fix to
countWorkItems. Let me rename the destructured variable and add the preference-aware logic:Assistant
The changes look good. Now let me verify the TypeScript code compiles correctly and run the tests to validate the fix.
Assistant
TypeScript compilation succeeded with no errors. Now let me run the tests to verify the fix works correctly.
Assistant
The client-work-items tests pass. Now let me run the client-issue-source tests that were failing before to see if they pass now.
Assistant
All tests pass! Now let me run the IPC tests as well to make sure the full integration works correctly.
Assistant
Excellent! All IPC tests pass. Let me run all the GitHub-related tests together to ensure nothing is broken:
Assistant
All tests pass! Now let me verify my changes one more time and check if there are any edge cases I need to handle. Let me review the final changes.
Assistant
The changes look correct. Let me verify the fix addresses the issue and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →