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 start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the relevant sections of the file:
Assistant
Let me look at
resolveIssueSourceto understand how it handles the preference:Assistant
Let me look at the renderer side to understand what
sourcesare being passed and look at how the data flows from the main process to the renderer:Assistant
Let me look at the IssueSourcePreference type and understand how this is wired up:
Assistant
Now let me look at the test files to understand testing patterns:
Assistant
Now let me look at the existing tests for
client-issue-source.test.tssince the issue is about adding similar preference-aware behavior to the PR side:Assistant
Let me run the existing tests to make sure they pass before making changes:
Assistant
Good. Now let me understand the architecture a bit more by checking the
countWorkItemsand how theprOwnerRepoparameter is used in that:Assistant
Let me look at where the preference flows from renderer to main process:
Assistant
Hmm, the preload doesn't have a
preferencefield forlistWorkItemsandcountWorkItems! Let me check the IPC handler.Assistant
Let me look at how the test for
countWorkItemsand howprOwnerRepois currently resolved:Assistant
Let me look at how countWorkItems tests are structured:
Assistant
Now I have enough understanding. Let me plan the fix:
- Add a preference-aware PR source resolver function
resolvePRSourcetogh-utils.ts(similar toresolveIssueSource) - Update
listWorkItemsinclient.tsto useresolvePRSourceinstead ofgetOwnerRepo - Update
countWorkItemsinclient.tsto useresolvePRSourceinstead ofgetOwnerRepo - Make sure
sources.prsfield reflects the effective PR source
Let me first create a reproduction script to verify the issue:
- Add a preference-aware PR source resolver function
Assistant
Now let me implement the fix. First, I'll add
resolvePRSourcetogh-utils.ts:Assistant
Now let me add a
resolvePRSourcefunction togh-utils.ts. The PR side, by design, generally points toorigin(the fork), but when the user explicitly picksupstream, PR queries should target the upstream repo:Assistant
Now let me update
client.tsto use this new resolver:Assistant
Let me add the resolvePRSource import.
Assistant
I see the import was duplicated. Let me fix it:
Assistant
The replace inserted literal
\ncharacters. Let me fix this by using bash instead:Assistant
Now the imports are clean. Let me update
listWorkItemsto useresolvePRSource:Assistant
Now let me update
listWorkItemsto useresolvePRSource:Assistant
Now let me update
countWorkItemssimilarly:Assistant
Now let me verify the change:
Assistant
Now let me run the existing tests to make sure I haven't broken anything:
Assistant
The tests are failing because the existing tests don't mock
resolvePRSource. Let me refactor my approach so existing tests still work - I'll only useresolvePRSourcewhen preference is explicitly 'upstream', and use the existinggetOwnerRepofor other cases:Assistant
Let me think about this. Looking at the issue more carefully:
- The suggested regression coverage says:
listWorkItems('/repo-root', 10, 'is:pr is:open author:@me', undefined, 'upstream')should use the upstream slug in--repo.
So the change is specifically when preference is 'upstream'. For other preferences, the existing behavior is preserved. Let me refactor to only call
resolvePRSourcewhen preference is explicitly 'upstream':- The suggested regression coverage says:
Assistant
Let me fix the type inconsistency:
Assistant
Let me normalize the result properly:
Assistant
Let me keep the parallelism for non-upstream preferences:
Assistant
Now let me also update
countWorkItemssimilarly:Assistant
Now let me run the tests to make sure existing tests still pass:
Assistant
All existing tests pass. Now let me write a reproduction script to verify my fix:
Assistant
My fix works for the upstream case. Let me also verify the fix doesn't break the existing behavior (origin preference should still use origin):
Assistant
All my tests pass. Let me also test the
resolvePRSourcefunction directly:Assistant
Let me delete this test file since it's testing the wrong thing:
Assistant
Let me now verify the implementation by looking at the final code:
Assistant
Let me check that
resolvePRSourceis exported and works correctly:Assistant
Let me check if
resolvePRSourceis also tested in the gh-utils.test.ts to see how it should be structured:Assistant
Let me run all the related tests:
Assistant
All 191 tests pass. Let me also run the renderer tests to make sure the renderer side still works:
Assistant
Let me check the failing tests to see if they're related to my changes:
Assistant
These test failures are unrelated to my changes - they're due to missing native modules (
pty.node) and timeouts. Let me verify by running the github tests in isolation:Assistant
All 206 github tests pass. Let me also write a more focused reproduction test to verify the fix works end-to-end:
Assistant
Excellent! All my reproduction tests pass. Let me also test the upstream-candidate divergence edge case to make sure
sources.prsreflects the new effective PR source:Assistant
The test needs to mock
ghExecFileAsyncproperly. Let me fix:Assistant
All the tests pass. Now let me clean up the temporary reproduction files:
Assistant
Let me look at the final implementation to verify it:
Assistant
Let me run the tests one more time to confirm everything works:
Assistant
All 206 tests pass. Now let me also verify the TypeScript compiles:
Assistant
TypeScript compiles fine. Let me check if there are any other related callers that need fixing:
Assistant
Let me also check the
preference === 'origin'case to ensure I'm correctly NOT usingresolvePRSource:Assistant
All edge cases work correctly. Let me clean up the temporary test file:
Assistant
Now let me run the full GitHub test suite once more to confirm:
Assistant
All 206 tests pass. Let me verify my final changes by looking at the diff:
Assistant
My changes are clean. Let me verify by running my final test scenario one more time and verifying the changes are correct:
Assistant
Both suggested regression tests pass. Let me also confirm the temporary file was deleted:
Assistant
Only my two intended changes are modified. Let me also do one final check on the linting:
Assistant
The file is over the max-lines limit. Let me check the original state:
Assistant
The original file passed the lint check (393 lines), and my change brings it to 431 lines, exceeding the 300-line limit (which is much stricter than 393). Wait, the original file is 393 lines? Let me restore my changes and check morecarefully:
Assistant
So the .ts files have a 300-line max. The original file had 393 lines, which seems over the limit too. Let me check why it didn't show errors before:
Assistant
The original file had exactly 300 non-blank, non-comment lines. So my change pushed it over the limit by adding my new function with comments.
Let me check the effectiveline count after my changes:
Assistant
I need to split my function into a separate file to comply with the max-lines rule. Let me extract
resolvePRSourceinto its own focused module:Assistant
Let me look at what's in
gh-utils.tsto see what to extract:Assistant
Let me create a focused module for GitHub source resolution and move both
resolveIssueSourceandresolvePRSourcethere. First, let me see the full functions:Assistant
Let me create a new file
pr-source.tsfor the PR source resolution:Assistant
Let me clean up the imports in
pr-source.ts:Assistant
Now let me remove
resolvePRSourcefromgh-utils.ts:Assistant
Hmm, the deletion was incomplete. Let me look at the file again:
Assistant
Let me clean up the orphan code:
Assistant
Now the file is back to 393 lines (matching the original). Now let me update
client.tsto import from the new file:Assistant
Now let me add the new import:
Assistant
Now let me run the tests to make sure everything still works:
Assistant
All 206 tests pass. Now let me check the lint:
Assistant
Lint passes. Let me also check the file line counts:
Assistant
Both files have effective line counts within limits. Let me verify TypeScript compiles:
Assistant
TypeScript compiles cleanly. Let me check my final diff:
Assistant
Now let me consolidate the two
import { ... } from './gh-utils'lines inpr-source.tsinto one:Assistant
Let me run the tests one more time to make sure everything is good:
Assistant
All 206 tests pass. Let me also run lint on the entire repository to make sure I haven't broken anything else:
Assistant
All lint checks pass. Let me also do a final reproduction test to verify the fix works end-to-end:
Assistant
Both suggested regression tests pass. Let me also verify the temporary file was removed:
Assistant
Only the intended changes are present. Let me do one final verification of the full GitHub test suite:
Assistant
All 206 tests pass.
Summary of Changes
Let me go over the checklist:
Files Changed
- Modified:
src/main/github/client.ts— UpdatedlistWorkItemsandcountWorkItemsto honor the user's preference when resolving PR source. - : — New focused module exporting (preference-aware PR source resolver, mirroring ).
- Modified:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.