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.
Assistant
Now let me look at
resolveIssueSourceandcountWorkItems:Assistant
Now let me look at
countWorkItemsand the rest of the relevant code:Assistant
Now I have a clear understanding. Let me look at the upstream/upstream preference, sources state in renderer, and TaskPage's selector:
Assistant
Now let me look at
IssueSourceSelectorand the preference state store:Assistant
Now let me look at
setIssueSourcePreferenceand the rest of relevant code:Assistant
Now let me check the existing tests to understand the test infrastructure:
Assistant
Now let me look at
listQueriedWorkItems(after the prOwnerRepo resolution):Assistant
Now let me look at the full chain of issue-resolution to confirm the bug:
Assistant
Now I have a clear picture. The bug is:
listWorkItemsresolvesprOwnerRepoviagetOwnerRepo(repoPath, connectionId)which callsgetOwnerRepoForRemote(repoPath, 'origin', connectionId). So PR queries always go to the origin repo, regardless of the user's preference.- Same for
countWorkItems.
The fix: PR owner/repo should also honor the user's
preference. When preference is'upstream'and the upstream remote exists, PR queries should target the upstream repo. When preference is'origin', they target the origin repo. When preference is'auto'or undefined, they should follow the same heuristic used for issues (getIssueOwnerRepo).Let me look at the test file more carefully and the rest of the test setup:
Assistant
Now let me see how the SSR renderer queries set up the preference and where it's passed down to listWorkItems:
Assistant
Now let me find the issueSourcePreference propagation to the call:
Assistant
The IPC handlers DO thread the
issueSourcePreferencetolistWorkItems/countWorkItems. The issue is just that insidelistWorkItems/countWorkItems, theprOwnerRepois computed independently viagetOwnerRepo(...)(which is always origin). Let me check the existing tests for the preference threading:Assistant
Good. The IPC handler threads it correctly, the issue is the implementation inside
listWorkItems/countWorkItemsdoesn't use the preference for PR owner repo. Let me run the existing test first to make sure it works:Assistant
Good, tests pass. Now let me reproduce the bug first by writing a quick script:
Assistant
Let me look at the test config to understand which paths to use:
Assistant
Let me create a temporary test inline (in the existing test file's location):
Assistant
Bug confirmed. The PR list goes to
octocat/widgets-forkinstead ofacme/widgets. Now let me fix the issue.The fix needs to:
- Compute
prOwnerRepobased on the preference (so it honorsupstream/origin/auto). - Apply same logic to
countWorkItems.
Let me design the fix:
Option A: Add a new helper
resolvePRSource(repoPath, preference, connectionId)that mirrorsresolveIssueSource. This is symmetric and clear.Option B: Reuse
resolveIssueSource. But that returnsfellBackflag intended for the issue path. Cleaner to add a new helper.Let me go with Option A.
- Compute
Assistant
Assistant
Assistant
OK, so
sources.prsis used in the fallback toast — the toast about "fell back to origin" displaysentry.sources.prsas the slug. That's the issue-source fellBack toast. After the fix:- When preference=upstream and upstream is missing,
issueResolved.fellBackis true. - The toast shows the slug of where issues went (which would be origin if it fell back).
- The
sources.prsshould reflect where PR queries go (also origin in fallback case, matching the issue).
So
sources.prsshould now reflect where PR queries actually go (preference-aware). Let me ensure that.Now let me also look at the
countWorkItemspath — it also usesprOwnerReposeparately. The same fix should apply.Let me now implement the fix. First, I'll add
resolvePRSourceto gh-utils.ts (since it's parallel toresolveIssueSource):- When preference=upstream and upstream is missing,
Assistant
Now let me look at the existing imports in client.ts to know what's already imported:
Assistant
Good. Now let me also look at how the
listIssuesfunction uses preference (to see if PR-source should also be made preference-aware in any similar place):Assistant
OK. Now let me also think about one more thing. The
prOwnerRepoinlistWorkItemsis also used in the returnedsourcesobject asprs: prOwnerRepo. After the fix, this should reflect the preference-aware PR source. Let me ensure the UI'shasUpstreamCandidateDivergencelogic still works:jsconst hasUpstreamCandidateDivergence = (s) => !!s.sources.upstreamCandidate && !sameGitHubOwnerRepo(s.sources.prs, s.sources.upstreamCandidate)After fix:
Assistant
Assistant
Assistant
Assistant
Assistant
Let me now also look at the countWorkItems test:
Assistant
OK, I understand the pattern now. Let me now implement the fix.
First, add
resolvePRSourceto gh-utils.ts:Assistant
Now update
client.tsto useresolvePRSource:Assistant
Now update
listWorkItemsto useresolvePRSource:Assistant
Now update
countWorkItems:Assistant
I have a duplicate comment block. Let me fix that:
Assistant
Now let me also fix the missing blank line between the function definition and the next function:
Assistant
I have duplicated
defaultOpenWorkItemQueryand the structure got mangled. Let me look at the file and fix:Assistant
I have corrupted the file. Let me fix:
Assistant
There's still a duplicate. Let me look at it more carefully:
Assistant
There's still a duplicate comment. Let me remove the extra:
Assistant
I still have a duplicate. Let me remove it:
Assistant
Good, no more duplicate. Now I also need to add a blank line between the
}ofdefaultOpenWorkItemQueryand the// Whycomment block. Let me also look at the listWorkItems function:Assistant
Oh dear, the file is getting worse. Let me reset the file and start over with the countWorkItems edit:
Assistant
I see the file has some corruption. Let me just restore from git and re-apply the changes carefully:
Assistant
Good, the file is restored. Now let me apply the changes carefully. Let me first re-verify the structure of the file:
Assistant
Good. Now let me apply the countWorkItems change:
Assistant
The file is missing lines now. Let me look at the surrounding code to see what's missing:
Assistant
The lines are missing. The
if (!ownerRepo) { return 0 }and the query parsing are gone. Let me restore and try again:Assistant
Let me look at the original carefully and understand the structure to make sure I replace correctly:
Assistant
OK now I see the structure clearly. Let me only replace the lines that need to change. First, just the
const [issueResolved, prOwnerRepo] = ...block:Assistant
The file got messed up again. The issue is that I have a stale
const [issueResolved, prOwnerRepo] = ...line and an extra closing}. Let me restore and try a different approach:Assistant
Let me use a more targeted approach using
replace:Assistant
countWorkItems is now correctly updated. Now let me update listWorkItems:
Assistant
Now I see the structure. The issue was that my prior edit was searching a different version. Let me apply the edit again now:
Assistant
Now I need to update the returned
prsto useprsSelectorOrigin:Assistant
Now let me add the import for
resolvePRSource:Assistant
Hmm. Let me check the actual content of the file:
Assistant
The file looks fine. The issue must be the way
replacematches. Let me useeditinstead:Assistant
Wait, the import edit removed the
import { getSshGitProvider } from '../providers/ssh-git-dispatch';line! Let me check:Assistant
The import is gone! Let me fix:
Assistant
The
type OwnerRepois missing now. Let me restore and start fresh with a clean approach:Assistant
Let me re-apply the changes carefully. First, the import:
Assistant
Good. Now let me update listWorkItems:
Assistant
Let me look at the actual file to see what's there:
Assistant
I see, the search text is missing the empty line between
const trimmedQueryandawait acquire(). Let me try without:Assistant
Hmm. Let me look at the actual content with the precise characters:
Assistant
I see, the
—(em dash) in the search string is causing a problem. Let me look closer:Assistant
OK, the issue is the em dash. My REPLACE block has em dash but the original text doesn't. Let me look:
Assistant
Yes, the em dash
—is342 200 224in UTF-8, and the search block I sent earlier may have used a different representation. Let me re-check by writing the search text directly:Assistant
OK so the em dash is in the original. The problem is when I copy the search text and re-paste, the em dash might be encoded differently. Let me use a script approach via a temporary file:
Assistant
Now I need to also update the
prs:line in the returned object:Assistant
Now let me update
countWorkItems:Assistant
All changes are in place. Let me verify the file is syntactically valid:
Assistant
No errors. Now let me run the bug repro test:
Assistant
The repro test needs to add
resolvePRSourceto the mock. Let me update the repro test:Assistant
The test failure is because the API path is URL-encoded. The test just needs to URL-decode it. Let me fix:
Assistant
Both repro tests pass. Now let me run the existing tests to make sure I didn't break anything:
Assistant
The existing test file needs to add the
resolvePRSourcemock. Let me update:Assistant
The test needs the
resolvePRSourceMockto be initialized in beforeEach, similar to howresolveIssueSourceMockis set up:Assistant
One test failure. The test uses
mockResolvedValueOnceforgetOwnerRepoMockonce, but I changed the order in the test — let me look:Assistant
The test does:
jsgetOwnerRepoMock.mockResolvedValueOnce({ owner: 'acme', repo: 'widgets' })This is
mockResolvedValueOnce— only the FIRST call returns this value. The first call togetOwnerRepoMockhappens inresolvePRSourceMock(now used first in my Promise.all). The second call togetOwnerRepoMockhappens for theprsSelectorOrigininlistWorkItems, which would return undefined (no value queued).Assistant
I see, there are many
mockResolvedValueOncecalls. Let me check what test files look like to understand:Assistant
Let me think about this. The cleanest approach: I should NOT have the implementation call twice (once for prOwnerRepo, once for prsSelectorOrigin). Let me think...
Assistant
OK so:
getOwnerRepo: getOwnerRepoMock— direct mock.getIssueOwnerRepo: getIssueOwnerRepoMock— direct mock.getOwnerRepoForRemote: getOwnerRepoForRemoteMock— direct mock.
getOwnerRepoMockis the mock forgetOwnerRepo(which the real impl uses forprsSelectorOrigin).getOwnerRepoForRemoteMockis the mock forgetOwnerRepoForRemote.In the test,
getOwnerRepoMock.mockResolvedValueOnce({ owner: 'acme', repo: 'widgets' })queues one value. The first call togetOwnerRepoMock(inresolvePRSourceMock's implementation) consumes it. The second call togetOwnerRepoMock(in the newlistWorkItemsforprsSelectorOrigin) returns undefined.That's why the test fails. Let me look at the test more carefully:
Assistant
11 of 12 tests pass! Only the first one fails. Let me look at how many calls to
getOwnerRepohappen. The new code callsgetOwnerRepoonly once (forprsSelectorOrigin). Let me check the test:In the test:
Assistant
Now update
client.tsto use the neworiginfield:Assistant
Now I need to also update the test's
resolvePRSourceMockto return the new shape:Assistant
Also update the repro test:
Assistant
Now let me run the tests:
Assistant
All 12 existing tests pass! Now let me run the repro test:
Assistant
Both pass. Now let me also run the other tests in the github directory:
Assistant
The other test file (
client-issue-source.test.ts) also needs updating. Let me look at it:Assistant
The
client-issue-source.test.tsdoesn't mockresolvePRSourceMockso it falls back to undefined. Let me look at the test and update it similarly:Assistant
I see, this test uses
vi.importActualwhich is why it gets the realresolvePRSource. Now I need to mockresolvePRSourcesimilarly:Assistant
Just one test failure now. Let me look at it:
Assistant
This test asserts that
getOwnerRepoMockis called with('/home/jinwoo/orca', 'openclaw-2'). But in my new code, I'm not callinggetOwnerRepodirectly anymore —resolvePRSourcehandles the origin lookup. So the assertion fails.This is a test that was checking the threading of SSH connectionId through
getOwnerRepo. In the new design, this threading is throughresolvePRSource. Let me check if there's a similar test forresolvePRSource:Assistant
This test specifically asserts that
getOwnerRepois called with the SSH connection. The test needs to be updated to checkresolvePRSourceinstead. Let me update:Assistant
All 17 tests pass. Now let me also check the IPC test:
Assistant
Let me now also run the full test suite:
Assistant
All 193 tests in
src/main/github/pass. Let me also run the tests that exercise the renderer-side handling:Assistant
All 90 tests pass. Let me also check the typescript compiles cleanly:
Assistant
No type errors. Let me also check the renderer typecheck:
Assistant
No type errors in renderer. Let me also check the CLI:
Assistant
No errors. Let me now look at the overall changes I've made:
Assistant
Wait, my repro test file is untracked. I need to delete it before submitting (since it's not part of the real fix):
Assistant
Assistant
The diffs look clean. Let me also check if
getOwnerRepois still being used elsewhere in the file (it was a separate import that I no longer need):Assistant
Assistant
All 14 tests pass (including the 2 new ones). Let me think more about edge cases:
-
What if
upstreamremote is the same asorigin? This shouldn't happen, butsameOwnerRepowould catch it. The selector wouldn't render. -
What if connectionId is set (SSH)? My fix uses
resolvePRSource(repoPath, preference, connectionId). Let me verify that the function properly forwards the connectionId:
-
Assistant
Good,
connectionIdis properly forwarded. Now let me also run the lint:Assistant
Let me fix these lint issues:
Assistant
The script only fixed 2 occurrences. The 3rd one is in the new test I added. Let me check:
Assistant
Now I need to deal with the max-lines error in gh-utils.ts. The file went from ~393 to 453 lines. Let me look:
Assistant
The file is 153 lines over the limit. I need to extract the new code into a separate file. The AGENTS.md says:
Never add a
max-linesdisable ... Split the file, extract focused modules, move fixtures/builders into named files, or otherwise reduce the counted lines instead.Let me extract
resolvePRSourceto its own file:Assistant
Let me see if there's a more focused file I can extract to. The issue is: the new code I added is about 60 lines. Let me check what other extracted modules exist:
Assistant
Let me create a new file for the source resolution helpers. Looking at the names of files, something like
work-item-source.tswould be appropriate since it contains source resolution for work items:Assistant
Now let me remove these from gh-utils.ts:
Assistant
gh-utils.ts is now 349 lines (over the 300 limit). Let me also check what's left:
Assistant
349 is over 300. Let me check what the max-line rule actually says. The issue says "Never add a max-lines disable". The current file was at 393 lines, and we removed ~60 lines, so it's now 349. The rule is "max 300 lines" but the file was already 393 before. Let me check if the file already had a disable:
Assistant
Hmm, the file was 393 lines and was not flagged. Let me check the lint configuration:
Assistant
So
.tsfiles have a 300 line limit. The current file is 349 lines, but withskipBlankLines: true, skipComments: trueit might be under 300 in non-blank/non-comment lines. Let me see:Assistant
349 - 35 - 39 = 275. That's under 300. Let me run lint:
Assistant
Good, the max-lines error is gone. Now there's an unused import. Let me fix:
Assistant
Now let me also update the imports in client.ts to use the new file:
Assistant
Now let me also update the test files to import from the new location:
Assistant
The test mocks both
resolveIssueSourceandresolvePRSourcefrom./gh-utils, but they're now in./work-item-source. Let me update:Assistant
There's another test file that uses these directly. Let me find it:
Assistant
The existing
gh-utils.test.tsimportsresolveIssueSourcefromgh-utils, but it's now inwork-item-source. Let me update:Assistant
All 193 tests pass! Now let me also run the typecheck and lint:
Assistant
There's an import in
issues.tsthat needs updating:Assistant
No type errors. Let me also run the lint:
Assistant
No lint errors. Let me run the full test suite:
Assistant
There are some test failures, but most pass. Let me see if these are related to my changes:
Assistant
These look like pre-existing test failures (unrelated to my changes — daemon, browser, pty, etc.). Let me check if these failures pre-existed by running on git stash:
Assistant
Yes, this is a pre-existing failure (missing native module). Let me restore my changes:
Assistant
Good, my changes are back. Let me check those failures are pre-existing:
Assistant
The ipc failures are pre-existing (native module issues). Let me check the github issues tests:
Assistant
The issues.test.ts is also affected by my changes (because I moved
resolveIssueSourceto a new file). Let me check:Assistant
The issues.test.ts is mocking
resolveIssueSourcefrom./gh-utilsbut it's now in./work-item-source. Let me update:Assistant
All 6 issues tests pass now. Let me also check if there are any other test files I might have missed:
Assistant
Let me check if
ipc/repos.tsuses it:Assistant
OK, just a comment. The other gitlab files are unrelated to my changes. Let me check
client-file-viewed.test.ts:Assistant
The
client-file-viewed.test.tsmocksresolveIssueSourcefrom./gh-utils(in the vi.mock factory), but it's not actually used in this test. Let me check if the test still passes:Assistant
Tests pass (because
vi.mockof an unrelated module doesn't matter for this test). The mock is harmless because it adds an unused export. But it might be considered a leftover. Let me clean it up:Assistant
Good. Now let me run the entire github test suite once more to make sure everything's good:
Assistant
All 193 tests pass! Let me also verify the typecheck:
Assistant
No type errors. Let me run lint:
Assistant
No lint errors. Now let me also look at the work-item-source file to see if it has the right structure:
Assistant
Looking at this, the inline
getIssueOwnerRepois duplicate logic. Let me check if I can just import it from gh-utils:Assistant
Yes,
getIssueOwnerRepois exported fromgh-utils. Let me just use it:Assistant
All 193 tests pass and no type errors. Let me also check the renderer tests:
Assistant
All 90 renderer tests pass too. Now let me verify the final state of changes:
Assistant
Let me also look at the final state of the changes more carefully:
Assistant
The new tests are added. Now let me also make sure I haven't introduced any other issues. Let me check the final state of files:
Assistant
Let me also run the entire test suite to check:
Assistant
All 283 tests pass! Let me now also check the gitlab tests to make sure I haven't broken those (they have similar functions):
Assistant
All 146 gitlab tests pass. Now let me also run the full test suite to ensure I haven't broken anything elsewhere:
Assistant
Let me see if any of these failures are related to my changes:
Assistant
These are all pre-existing failures (related to native modules like PTY, file system permissions, etc.) — not related to my changes. Let me verify by running these specific tests on the original code:
Assistant
Yes, the daemon test failures are pre-existing (missing native modules). Let me confirm my changes are restored:
Assistant
Good. Now let me also think about edge cases that I should test manually. Let me re-read the issue and check the suggestions:
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>.
I already added tests for both of these. Let me look at the final state of my added tests:
Assistant
Excellent! Both tests look good. Now let me also look at the imports issue. Let me check that the lint passes:
Assistant
No lint errors. Let me also run the lint:switch-exhaustiveness:
Assistant
All lints pass. Let me now also re-read my final changes one more time to make sure they're correct:
Assistant
The diff looks clean. Now let me think about whether I need to add more tests for edge cases. Looking at the issue's "Suggested regression coverage":
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>. ✓
I've added both. Let me also re-verify the final state:
Assistant
Let me also verify the tests one more time:
Assistant
All 283 tests pass.
Let me now think about the checklist:
Checklist
-
If an error was reported in the issue description, I have successfully reproduced it.
- I created a reproduction test that demonstrated the bug. The PR list and count queries were using the origin repo even when preference=upstream was set.
-
Assistant
All 14 tests pass (12 original + 2 new). The fix is complete and verified.
Let me also look at the final list of changes:
Assistant
And the new file:
Assistant
Summary
The fix addresses the bug where PR list and count queries were going to the origin (fork) repo even when the user selected
'upstream'in the PR/Issue source selector.Key Changes
-
New file
src/main/github/work-item-source.ts: Contains theresolvePRSourcehelper (and the existingresolveIssueSource, which was moved here fromgh-utils.tsto keep related code together). The newresolvePRSource:- Honors the per-repo preference (
'upstream','origin','auto'/undefined). - For
'upstream': returns upstream if it exists, falls back to origin (with ).
- Honors the per-repo preference (
-
Assistant
All changes look correct. Now let me submit:
Assistant
I'll now submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.