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 problem is that when selecting "Upstream" in the PRs tab, the GitHub client still queries from
origininstead ofupstream. - The key files mentioned are:
src/main/github/client.ts- where the issue resolution happenssrc/renderer/src/components/TaskPage.tsx- where the selector is rendered
Let me start by exploring the repository structure and understanding the codebase.
- The problem is that when selecting "Upstream" in the PRs tab, the GitHub client still queries from
Assistant
Let me see more of the file, particularly the
listWorkItemsandcountWorkItemsfunctions:Assistant
Let me look at the
listWorkItemsfunction more closely:Assistant
Let me see the
resolveIssueSourcefunction andIssueSourcePreference:Assistant
Let me look at the
IssueSourcePreferencetype and theresolveIssueSourcefunction:Assistant
Now I need to look at
resolveIssueSourceingh-utils.ts:Assistant
Let me look at the
resolveIssueSourcefunction ingh-utils.tsto understand how it resolves the source for issues, and then understand the issue better.The problem is:
listWorkItemscallsresolveIssueSource(repoPath, preference, connectionId)which resolvesissueOwnerRepobased on the preference (origin, upstream, auto)- But
prOwnerRepois resolved separately viagetOwnerRepo(repoPath, connectionId)which always returns the origin repo - When "Upstream" is selected, the
issueOwnerRepois resolved to upstream, butprOwnerRepostill points to origin
So the fix needs to be:
- When
preferenceis 'upstream', bothissueOwnerRepoandprOwnerReposhould be resolved to the upstream repo - The
prOwnerReporesolution should also respect thepreferencewhen it's set to 'upstream' or 'origin'
Let me look at the full
resolveIssueSourcefunction.Assistant
Now I understand the issue. Let me look at the
listWorkItemsfunction again:const [issueResolved, prOwnerRepo, upstreamCandidate] = await Promise.all([ resolveIssueSource(repoPath, preference, connectionId), getOwnerRepo(repoPath, connectionId), // <-- This always gets origin, ignoring preference getOwnerRepoForRemote(repoPath, 'upstream', connectionId) ])Assistant
Let me also check what
getOwnerRepoandgetIssueOwnerRepodo:Assistant
Assistant
Now let me look at the TaskPage to understand how the preference is passed:
Assistant
Now I understand the issue clearly. Let me verify the exact lines that need to be changed:
Assistant
Now I have a clear understanding of the issue. Let me implement the fix.
Summary of the issue:
- In
listWorkItems(line ~1204),prOwnerRepois resolved viagetOwnerRepo(repoPath, connectionId)which always returns the origin repo, ignoring thepreferenceparameter - In
countWorkItems(line ~1356-1357), same issue - When the user selects "Upstream" in the PRs source selector, the
preferenceis 'upstream', butprOwnerRepostill resolves to origin
The fix:
- When
preference === 'upstream', resolveprOwnerRepofrom the upstream remote - When
preference === 'origin', resolve from origin (which is whatgetOwnerRepodoes anyway) - When
preferenceis 'auto' or undefined, keep the default behavior
- In
Assistant
Let me look at the exact lines to modify in both functions:
Assistant
Now I have a clear understanding of the issue. Let me verify the exact lines in both functions that need to be changed:
Assistant
Now I understand the issue completely. The problem is in two functions in
client.ts:listWorkItems(line ~1204):prOwnerRepois resolved viagetOwnerRepo(repoPath, connectionId)which always returns the origin repo, ignoring thepreferenceparametercountWorkItems(line ~1357): Same issue
When the user selects "Upstream", the
preferenceis'upstream', butprOwnerRepostill resolves to origin instead of upstream.The fix: When resolving
prOwnerRepo, respect thepreferenceparameter:- If
preference === 'upstream', get the owner/repo from the upstream remote - If
preference === 'origin', get from origin - If
preferenceis'auto'or undefined, use the default behavior (origin)
Let me apply the fix:
Assistant
The tool is asking for a different format for the edit command. Let me check the tool documentation again. The
editcommand requires the formatedit --file PATH LINE_RANGEor edits the currently open file withedit LINE_RANGE. Let me open the file first, then use the edit command properly.Assistant
Let me open the file first with the correct command format.
Assistant
The tool requires proper formatting. Let me open the file properly.
Assistant
Now the file is open. Let me navigate to the relevant lines for
listWorkItems:Assistant
Good, the file is open. Now I can use the edit command properly. Let me apply the fix to
listWorkItemsfirst. I need to change line 1204 from usinggetOwnerRepodirectly to respecting the preference.Assistant
Let me try using the
replacecommand instead, which seems to work better:Assistant
Let me use sed to make the changes directly:
Assistant
Let me check if the edit was applied correctly:
Assistant
The change was applied but the em-dash character got mangled. Let me fix that:
Assistant
Good, let me verify the first change is correct:
Assistant
The first change looks correct. Now I need to apply the same fix to
countWorkItems. Let me find the exact line:Assistant
Let me verify the
countWorkItemsfix was also applied (since sed replaced all occurrences):Assistant
The sed command only replaced the first occurrence because the patterns were slightly different (the
countWorkItemscase doesn't have a trailing comma). I need to fix thecountWorkItemsfunction separately:Assistant
Let me use the
--fileoption properly:Assistant
The search string didn't match exactly because of whitespace or other formatting differences. Let me navigate to that line and check the exact content.
Assistant
Let me use a bash command to get the exact content of those lines.
Assistant
The content looks correct. Let me try a different approach using sed:
Assistant
The issue is that line 1365 has
getOwnerRepo(repoPath, connectionId)without a trailing comma, which is different from the one I already replaced inlistWorkItems. I need to replace this specific instance. Let me use sed to target line 1365 specifically.Assistant
I need to replace line 1365 which is:
getOwnerRepo(repoPath, connectionId)with the same logic but without a trailing comma (since it's the last item in the array).
Let me create a temp script to do the replacement.
Assistant
Python3 is not available. Let me try a different approach using sed or awk.
Assistant
I can use node to apply the fix.
Assistant
Let me use a script file approach to avoid shell escaping issues:
Assistant
Let me verify both fixes were applied correctly:
Assistant
Both fixes are now applied correctly. Let me verify the
listWorkItemsfix is also correct:Assistant
Both fixes look correct. Let me verify the TypeScript compiles correctly:
Assistant
The TypeScript compilation succeeded without errors. Now let me run the existing tests to make sure nothing is broken:
Assistant
Let me run the existing tests to make sure the changes don't break anything. I should look at the relevant test files, particularly:
client.test.ts- main client testsclient-work-items.test.ts- work items testsclient-issue-source.test.ts- issue source tests
Let me run the tests first.
Assistant
Let me check the package.json to understand the test setup:
Assistant
Let me try running the tests with a timeout limit to see if they pass.
Assistant
Let me look at the failing test to understand what's happening:
Assistant
The test is failing because my change affects the
upstreamCandidatein the result. Let me look at the test case and understand what's happening.Looking at the test failure:
- Expected:
upstreamCandidate: { owner: 'stablyai', repo: 'orca' } - Received:
upstreamCandidate: null
The test expects
upstreamCandidateto be present with the upstream owner/repo, but my change caused it to be null.Wait, looking at my change more carefully, I didn't change the
upstreamCandidateresolution at all. Let me look at the test to understand what's happening.Actually, looking at the test failure again:
Expected: "issues": { owner: 'fork', repo: 'orca' }, "prs": { owner: 'fork', repo: 'orca' }, "upstreamCandidate": { owner: 'stablyai', repo: 'orca' }, Received: "issues": { owner: 'fork', repo: 'orca' }, "prs": { owner: 'fork', repo: 'orca' }, "upstreamCandidate": null,- Expected:
Assistant
I see the issue. The test mocks
getOwnerRepoForRemoteMockonly once, but my change now calls it twice whenpreferenceis 'origin' (once forprOwnerRepoat line ~1211, and once forupstreamCandidateat line ~1213). The first call consumes the mock for the 'origin' remote, and the second call (for 'upstream') has no mock, returningundefined/null.This is expected - the test needs to be updated to account for the additional
getOwnerRepoForRemotecall, but per the instructions, I should not modify existing tests. The instructions explicitly say: "if existing tests break because they need to be updated to reflect the changes you made, just ignore it."Let me verify the code changes are syntactically correct and the TypeScript compilation still passes:
Assistant
Good, TypeScript compilation passes. Let me verify the full diff of my changes:
Assistant
The diff shows exactly the changes I intended. Let me verify my changes are correct by summarizing:
The Issue: When "Upstream" was selected in the PRs source selector, the
listWorkItemsandcountWorkItemsfunctions were still resolvingprOwnerRepoviagetOwnerRepo(repoPath, connectionId), which always returns the origin repo. This caused PR queries to search the fork repo instead of the selected upstream repo.The Fix: In both
listWorkItemsandcountWorkItems, changed theprOwnerReporesolution to respect thepreferenceparameter:- When
preference === 'upstream': resolve from the upstream remote - When
preference === 'origin': resolve from the origin remote - When
preferenceis 'auto' or undefined: keep the original behavior (getOwnerRepo)
The one failing test (
surfaces upstreamCandidate in sources regardless of effective preference) fails because it only mocksgetOwnerRepoForRemoteonce, but my change now calls it twice whenpreference === 'origin'(once for and once for ). This is expected - the test needs to be updated to reflect the new call pattern, but per the instructions, I should not modify existing tests.- When
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.