From 63da9588136c1511c7270d1af2c0a2866d63a970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E8=BE=89?= <42717106+OnlyYu1996@users.noreply.github.com> Date: Tue, 21 Jul 2026 14:19:35 +0800 Subject: [PATCH] fix(github): keep work-item searches repo-scoped (#9668) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(github): prevent unscoped work item queries * fix(review): translate non-English rationale comment to English (client.ts:1151) Restores the English '// Why:' convention and re-states the allSettled partial-results rationale that was dropped when the comment was replaced. Flagged by Ce-code-review (maintainability/previous-comments) and a prior PR reviewer. No behavior change. Co-authored-by: Orca * fix(tasks): surface repos with no resolvable GitHub source Since #9660 an unresolvable GitHub source returns an empty null-source envelope instead of an unscoped search. That empty was indistinguishable from a genuine zero-result query — no log, no telemetry, no UI signal. Surface it in the Tasks list: a per-repo info row with Retry for each fetched repo that resolved neither an issue nor a PR source (told apart from genuine-zero and not-yet-fetched purely via the cached `sources`). Renderer-only — the signal was already threaded through the envelope. - selectTaskPageUnresolvedSourceRepos selector (+ unit tests) - per-repo row reusing the existing banner region + handleRetryIssuesFetch - suppress the generic empty state while those rows show - assert the null-source envelope contract in client-work-items test Co-authored-by: Orca --------- Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Co-authored-by: Orca --- .../client-work-items-query-paging.test.ts | 2 - src/main/github/client-work-items.test.ts | 42 ++-- src/main/github/client.ts | 229 +++++++----------- .../github/gh-cwd-repo-negative-cache.test.ts | 65 ----- src/main/github/gh-cwd-repo-negative-cache.ts | 83 ------- src/renderer/src/components/TaskPage.tsx | 45 ++++ .../task-page-cache-selectors.test.ts | 49 ++++ .../components/task-page-cache-selectors.ts | 34 +++ src/renderer/src/i18n/locales/en.json | 4 +- src/renderer/src/i18n/locales/es.json | 4 +- src/renderer/src/i18n/locales/ja.json | 4 +- src/renderer/src/i18n/locales/ko.json | 4 +- src/renderer/src/i18n/locales/zh.json | 4 +- 13 files changed, 257 insertions(+), 312 deletions(-) delete mode 100644 src/main/github/gh-cwd-repo-negative-cache.test.ts delete mode 100644 src/main/github/gh-cwd-repo-negative-cache.ts diff --git a/src/main/github/client-work-items-query-paging.test.ts b/src/main/github/client-work-items-query-paging.test.ts index b3f819c21..f9cf934e2 100644 --- a/src/main/github/client-work-items-query-paging.test.ts +++ b/src/main/github/client-work-items-query-paging.test.ts @@ -117,7 +117,6 @@ import { _resetMergeQueueCacheForTests, _resetOwnerRepoCache } from './client' -import { _resetGhCwdRepoNegativeCache } from './gh-cwd-repo-negative-cache' import { GITHUB_WORK_ITEMS_QUERY_MAX_BYTES } from '../../shared/github-work-items-query-bounds' import { _resetOriginGitHubApiRepositoryCache } from './github-api-repository' @@ -158,7 +157,6 @@ describe('listWorkItems query paging', () => { getOwnerRepoForRemoteMock.mockResolvedValue(null) _resetOwnerRepoCache() _resetMergeQueueCacheForTests() - _resetGhCwdRepoNegativeCache() }) it('returns zero for oversized count queries before resolving repo sources', async () => { diff --git a/src/main/github/client-work-items.test.ts b/src/main/github/client-work-items.test.ts index 0ac756c9b..0226b2af4 100644 --- a/src/main/github/client-work-items.test.ts +++ b/src/main/github/client-work-items.test.ts @@ -111,7 +111,6 @@ import { _resetMergeQueueCacheForTests, _resetOwnerRepoCache } from './client' -import { _resetGhCwdRepoNegativeCache } from './gh-cwd-repo-negative-cache' import { GITHUB_WORK_ITEMS_QUERY_MAX_BYTES } from '../../shared/github-work-items-query-bounds' import { _resetOriginGitHubApiRepositoryCache } from './github-api-repository' @@ -154,7 +153,6 @@ describe('listWorkItems', () => { ) _resetOwnerRepoCache() _resetMergeQueueCacheForTests() - _resetGhCwdRepoNegativeCache() }) it('routes GHES work-item listing through the Enterprise host', async () => { @@ -172,22 +170,36 @@ describe('listWorkItems', () => { expect(calls.every(([, options]) => options?.host === 'github.acme-corp.com')).toBe(true) }) - it('stops re-spawning gh for a repo whose cwd resolution already failed with no remotes', async () => { + it('does not run unscoped work-item queries when a local repository has no GitHub source', async () => { getIssueOwnerRepoMock.mockResolvedValue(null) getOwnerRepoMock.mockResolvedValue(null) - ghExecFileAsyncMock.mockRejectedValue( - Object.assign(new Error('Command failed: gh pr list\nno git remotes found'), { - stderr: 'no git remotes found' - }) + + // Why: unresolved sources must return empty null-source envelopes (not throw, not query) so the renderer can + // distinguish "no GitHub source detected" from genuine zero via `sources` (#9660 follow-up). + await expect(listWorkItems('/private-repo', 36)).resolves.toMatchObject({ + items: [], + sources: { issues: null, prs: null } + }) + await expect(listWorkItems('/private-repo', 36, 'is:open')).resolves.toMatchObject({ + items: [], + sources: { issues: null, prs: null } + }) + + expect(ghExecFileAsyncMock).not.toHaveBeenCalled() + }) + + it('queries only the resolved PR source when the issue source is unavailable', async () => { + getIssueOwnerRepoMock.mockResolvedValue(null) + getOwnerRepoMock.mockResolvedValue({ owner: 'acme', repo: 'widgets' }) + ghExecFileAsyncMock.mockResolvedValue({ stdout: '[]' }) + + await expect(listWorkItems('/private-repo', 36)).resolves.toMatchObject({ items: [] }) + + expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(1) + expect(ghExecFileAsyncMock).toHaveBeenCalledWith( + expect.arrayContaining(['pr', 'list', '--repo', 'acme/widgets']), + { cwd: '/private-repo' } ) - - await expect(listWorkItems('/no-remote-repo', 36)).rejects.toThrow('no git remotes found') - // The first refresh pays the two cwd-fallback spawns (issue + pr list). - expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(2) - - await expect(listWorkItems('/no-remote-repo', 36)).rejects.toThrow('no git remotes found') - // The second refresh is served from the negative cache — zero new spawns. - expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(2) }) it('runs both issue and PR GitHub searches for a mixed query and merges the results by recency', async () => { diff --git a/src/main/github/client.ts b/src/main/github/client.ts index 6c05d286c..5229c187f 100644 --- a/src/main/github/client.ts +++ b/src/main/github/client.ts @@ -74,12 +74,6 @@ import { } from '../source-control/hosted-review-git-options' import { shouldHideNonOpenReviewOnDefaultBranch } from '../source-control/repo-default-branch' import { readLocalGitConfigSignature } from './local-git-config-signature' -import { - getRememberedGhCwdResolutionFailure, - isGhCwdRepoResolutionFailure, - rememberGhCwdResolutionFailure -} from './gh-cwd-repo-negative-cache' -import type { GitHubRepoContext } from './github-repository-identity' import { getGitHubApiRepositoryForRemote, getIssueGitHubApiRepository, @@ -1001,7 +995,7 @@ function normalizeWorkItemPage(page: number | undefined): number { function buildWorkItemListRequest(args: { kind: 'issue' | 'pr' - ownerRepo: OwnerRepo | null + ownerRepo: OwnerRepo limit: number query: ParsedTaskQuery page: number @@ -1009,7 +1003,7 @@ function buildWorkItemListRequest(args: { const { kind, ownerRepo, limit, query, page } = args const searchParts: string[] = [] - if (kind === 'issue' && ownerRepo) { + if (kind === 'issue') { searchParts.push(`repo:${ownerRepo.owner}/${ownerRepo.repo}`) } searchParts.push(kind === 'issue' ? 'is:issue' : 'is:pr') @@ -1076,9 +1070,7 @@ function buildWorkItemListRequest(args: { '--json', WORK_ITEM_PR_LIST_JSON_FIELDS ] - if (ownerRepo) { - out.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`) - } + out.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`) out.push('--search', searchParts.join(' ')) return { args: out, offset: (page - 1) * limit } } @@ -1122,30 +1114,6 @@ async function resolvePrWorkItemSource( return { source, originCandidate, upstreamCandidate } } -/** - * gh exec relying on gh's own cwd→repo resolution. Serves a remembered resolution failure - * without spawning, so a remote-less repo costs one gh spawn per config change/TTL, not two per refresh. - */ -async function ghCwdResolvedExec( - context: GitHubRepoContext, - args: string[], - ghOptions: GhExecOptions -): Promise<{ stdout: string; stderr: string }> { - const remembered = await getRememberedGhCwdResolutionFailure(context) - if (remembered !== null) { - throw new Error(remembered) - } - try { - return await ghExecFileAsync(args, ghOptions) - } catch (err) { - const message = err instanceof Error ? err.message : String(err) - if (isGhCwdRepoResolutionFailure(message)) { - await rememberGhCwdResolutionFailure(context, message) - } - throw err - } -} - async function listRecentWorkItems( repoPath: string, issueOwnerRepo: OwnerRepo | null, @@ -1156,104 +1124,87 @@ async function listRecentWorkItems( noCache?: boolean, localGitOptions: LocalGitExecOptions = {} ): Promise { - const repoContext = githubRepoContext(repoPath, connectionId, localGitOptions) - const ghOptions = ghRepoExecOptions(repoContext) - const requiresExplicitRepo = Boolean(connectionId) + const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)) assertSshRepoHasResolvedGitHubSource({ connectionId, issueOwnerRepo, prOwnerRepo }) const recentQuery = parseTaskQuery('is:open') - const issueRequest = buildWorkItemListRequest({ - kind: 'issue', - ownerRepo: issueOwnerRepo, - limit, - query: recentQuery, - page - }) - const prRequest = buildWorkItemListRequest({ - kind: 'pr', - ownerRepo: prOwnerRepo, - limit, - query: recentQuery, - page - }) - if (noCache) { + const issueRequest = issueOwnerRepo + ? buildWorkItemListRequest({ + kind: 'issue', + ownerRepo: issueOwnerRepo, + limit, + query: recentQuery, + page + }) + : null + const prRequest = prOwnerRepo + ? buildWorkItemListRequest({ + kind: 'pr', + ownerRepo: prOwnerRepo, + limit, + query: recentQuery, + page + }) + : null + if (noCache && issueRequest) { issueRequest.args.splice(1, 2) } - if (issueOwnerRepo || prOwnerRepo || requiresExplicitRepo) { - // Why: allSettled so a 403 on the issue side doesn't zero the PR half — partial results + banner (parent doc §2). - const [issuesSettled, prsSettled] = await Promise.allSettled([ - issueOwnerRepo - ? ghExecFileAsync(issueRequest.args, { - ...ghOptions, - ...githubHostExecOptions(issueOwnerRepo) - }) - : requiresExplicitRepo - ? Promise.resolve({ stdout: '[]' }) - : ghCwdResolvedExec(repoContext, issueRequest.args, ghOptions), - prOwnerRepo - ? ghExecFileAsync(prRequest.args, { ...ghOptions, ...githubHostExecOptions(prOwnerRepo) }) - : requiresExplicitRepo - ? Promise.resolve({ stdout: '[]' }) - : ghCwdResolvedExec(repoContext, prRequest.args, ghOptions) - ]) - - let issues: MainWorkItem[] = [] - let issuesError: ClassifiedError | undefined - if (issuesSettled.status === 'fulfilled') { - issues = (JSON.parse(issuesSettled.value.stdout) as Record[]) - // Why: search/issues can still return PRs (pull_request marker) even with is:issue; filter them out. - .filter((item) => !('pull_request' in item)) - .map(mapIssueWorkItem) - } else { - const stderr = - issuesSettled.reason instanceof Error - ? issuesSettled.reason.message - : String(issuesSettled.reason) - issuesError = classifyListIssuesError(stderr) - } - - let prs: MainWorkItem[] = [] - if (prsSettled.status === 'fulfilled') { - prs = (JSON.parse(prsSettled.value.stdout) as Record[]) - .slice(prRequest.offset, prRequest.offset + limit) - .map((item) => mapPullRequestWorkItem(item, prOwnerRepo)) - prs = await hydrateWorkItemRepositoryMergeMetadata(prs, prOwnerRepo, { - ...ghOptions, - ...githubHostExecOptions(prOwnerRepo) - }) - } else { - // Why: re-throw PR errors so the cross-repo aggregator counts the repo failed; this feature only fixes issue-side swallowing (#1076). - // Why: log issuesError first so a both-sides-failed case isn't blind to the classification we're about to drop. - if (issuesError) { - console.warn( - 'listRecentWorkItems: both issue and PR sides failed; issuesError was classified:', - issuesError.type, - issuesError.message - ) - } - throw prsSettled.reason - } - - return { - items: sortWorkItemsByNumber([...issues, ...prs]).slice(0, limit), - issuesError - } - } - - // Why: non-GitHub remotes have no sources for a partial-failure banner, so keep Promise.all (reject-all) instead of allSettled. - const [issuesResult, prsResult] = await Promise.all([ - ghCwdResolvedExec(repoContext, issueRequest.args, ghOptions), - ghCwdResolvedExec(repoContext, prRequest.args, ghOptions) + // Why: unresolved sources must stay empty — an unscoped Search API would return other public repos' issues (#9660). + // Why: allSettled so a 403 on the issue side doesn't zero the PR half (partial results + banner). + const [issuesSettled, prsSettled] = await Promise.allSettled([ + issueRequest && issueOwnerRepo + ? ghExecFileAsync(issueRequest.args, { + ...ghOptions, + ...githubHostExecOptions(issueOwnerRepo) + }) + : Promise.resolve({ stdout: '[]' }), + prRequest && prOwnerRepo + ? ghExecFileAsync(prRequest.args, { + ...ghOptions, + ...githubHostExecOptions(prOwnerRepo) + }) + : Promise.resolve({ stdout: '[]' }) ]) - const issues = (JSON.parse(issuesResult.stdout) as Record[]) - .filter((item) => !('pull_request' in item)) - .map(mapIssueWorkItem) - const prs = (JSON.parse(prsResult.stdout) as Record[]) - .slice(prRequest.offset, prRequest.offset + limit) - .map((item) => mapPullRequestWorkItem(item, null)) + let issues: MainWorkItem[] = [] + let issuesError: ClassifiedError | undefined + if (issuesSettled.status === 'fulfilled') { + issues = (JSON.parse(issuesSettled.value.stdout) as Record[]) + // Why: search/issues can still return PRs (pull_request marker) even with is:issue; filter them out. + .filter((item) => !('pull_request' in item)) + .map(mapIssueWorkItem) + } else { + const stderr = + issuesSettled.reason instanceof Error + ? issuesSettled.reason.message + : String(issuesSettled.reason) + issuesError = classifyListIssuesError(stderr) + } + + let prs: MainWorkItem[] = [] + if (prsSettled.status === 'fulfilled') { + prs = (JSON.parse(prsSettled.value.stdout) as Record[]) + .slice(prRequest?.offset ?? 0, (prRequest?.offset ?? 0) + limit) + .map((item) => mapPullRequestWorkItem(item, prOwnerRepo)) + prs = await hydrateWorkItemRepositoryMergeMetadata(prs, prOwnerRepo, { + ...ghOptions, + ...githubHostExecOptions(prOwnerRepo) + }) + } else { + // Why: re-throw PR errors so the cross-repo aggregator counts the repo failed; this feature only fixes issue-side swallowing (#1076). + // Why: log issuesError first so a both-sides-failed case isn't blind to the classification we're about to drop. + if (issuesError) { + console.warn( + 'listRecentWorkItems: both issue and PR sides failed; issuesError was classified:', + issuesError.type, + issuesError.message + ) + } + throw prsSettled.reason + } return { - items: sortWorkItemsByNumber([...issues, ...prs]).slice(0, limit) + items: sortWorkItemsByNumber([...issues, ...prs]).slice(0, limit), + issuesError } } @@ -1267,9 +1218,7 @@ async function listQueriedWorkItems( connectionId?: string | null, localGitOptions: LocalGitExecOptions = {} ): Promise { - const repoContext = githubRepoContext(repoPath, connectionId, localGitOptions) - const ghOptions = ghRepoExecOptions(repoContext) - const requiresExplicitRepo = Boolean(connectionId) + const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)) assertSshRepoHasResolvedGitHubSource({ connectionId, issueOwnerRepo, prOwnerRepo }) const hasPrOnlyFilter = query.state === 'merged' || @@ -1287,7 +1236,7 @@ async function listQueriedWorkItems( if (!issueScope) { return { items: [] } } - if (requiresExplicitRepo && !issueOwnerRepo) { + if (!issueOwnerRepo) { return { items: [] } } const request = buildWorkItemListRequest({ @@ -1298,12 +1247,10 @@ async function listQueriedWorkItems( page: page ?? 1 }) try { - const { stdout } = issueOwnerRepo - ? await ghExecFileAsync(request.args, { - ...ghOptions, - ...githubHostExecOptions(issueOwnerRepo) - }) - : await ghCwdResolvedExec(repoContext, request.args, ghOptions) + const { stdout } = await ghExecFileAsync(request.args, { + ...ghOptions, + ...githubHostExecOptions(issueOwnerRepo) + }) const items = (JSON.parse(stdout) as Record[]) .filter((item) => !('pull_request' in item)) .map(mapIssueWorkItem) @@ -1324,7 +1271,7 @@ async function listQueriedWorkItems( if (!prScope) { return [] } - if (requiresExplicitRepo && !prOwnerRepo) { + if (!prOwnerRepo) { return [] } const request = buildWorkItemListRequest({ @@ -1335,12 +1282,10 @@ async function listQueriedWorkItems( page: page ?? 1 }) try { - const { stdout } = prOwnerRepo - ? await ghExecFileAsync(request.args, { - ...ghOptions, - ...githubHostExecOptions(prOwnerRepo) - }) - : await ghCwdResolvedExec(repoContext, request.args, ghOptions) + const { stdout } = await ghExecFileAsync(request.args, { + ...ghOptions, + ...githubHostExecOptions(prOwnerRepo) + }) const mapped = (JSON.parse(stdout) as Record[]) .slice(request.offset, request.offset + limit) .map((item) => mapPullRequestWorkItem(item, prOwnerRepo)) diff --git a/src/main/github/gh-cwd-repo-negative-cache.test.ts b/src/main/github/gh-cwd-repo-negative-cache.test.ts deleted file mode 100644 index 240711143..000000000 --- a/src/main/github/gh-cwd-repo-negative-cache.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { afterEach, describe, expect, it, vi } from 'vitest' - -const { readLocalGitConfigSignatureMock } = vi.hoisted(() => ({ - readLocalGitConfigSignatureMock: vi.fn() -})) - -vi.mock('./local-git-config-signature', () => ({ - readLocalGitConfigSignature: readLocalGitConfigSignatureMock -})) - -import { - _resetGhCwdRepoNegativeCache, - getRememberedGhCwdResolutionFailure, - isGhCwdRepoResolutionFailure, - rememberGhCwdResolutionFailure -} from './gh-cwd-repo-negative-cache' - -const context = { repoPath: '/repo', connectionId: null } - -afterEach(() => { - _resetGhCwdRepoNegativeCache() - readLocalGitConfigSignatureMock.mockReset() -}) - -describe('isGhCwdRepoResolutionFailure', () => { - it('matches gh cwd-resolution failures only', () => { - expect(isGhCwdRepoResolutionFailure('Command failed: gh\nno git remotes found')).toBe(true) - expect( - isGhCwdRepoResolutionFailure( - 'none of the git remotes configured for this repository point to a known GitHub host' - ) - ).toBe(true) - expect(isGhCwdRepoResolutionFailure('gh: API rate limit exceeded (HTTP 403)')).toBe(false) - expect(isGhCwdRepoResolutionFailure('gh: Not Found (HTTP 404)')).toBe(false) - }) -}) - -describe('remembered failures', () => { - it('serves the remembered failure while the config signature is unchanged', async () => { - readLocalGitConfigSignatureMock.mockResolvedValue('sig-1') - await rememberGhCwdResolutionFailure(context, 'no git remotes found') - await expect(getRememberedGhCwdResolutionFailure(context)).resolves.toBe('no git remotes found') - }) - - it('invalidates when the git config signature changes (remote added)', async () => { - readLocalGitConfigSignatureMock.mockResolvedValueOnce('sig-1') - await rememberGhCwdResolutionFailure(context, 'no git remotes found') - readLocalGitConfigSignatureMock.mockResolvedValue('sig-2') - await expect(getRememberedGhCwdResolutionFailure(context)).resolves.toBeNull() - // The stale entry is gone, not just skipped. - readLocalGitConfigSignatureMock.mockResolvedValue('sig-1') - await expect(getRememberedGhCwdResolutionFailure(context)).resolves.toBeNull() - }) - - it('separates repos and runtimes by cache key', async () => { - readLocalGitConfigSignatureMock.mockResolvedValue('sig') - await rememberGhCwdResolutionFailure(context, 'no git remotes found') - await expect( - getRememberedGhCwdResolutionFailure({ repoPath: '/other-repo', connectionId: null }) - ).resolves.toBeNull() - await expect( - getRememberedGhCwdResolutionFailure({ repoPath: '/repo', connectionId: 'ssh-1' }) - ).resolves.toBeNull() - }) -}) diff --git a/src/main/github/gh-cwd-repo-negative-cache.ts b/src/main/github/gh-cwd-repo-negative-cache.ts deleted file mode 100644 index 97a810f5e..000000000 --- a/src/main/github/gh-cwd-repo-negative-cache.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { readLocalGitConfigSignature } from './local-git-config-signature' -import type { GitHubRepoContext } from './github-repository-identity' - -/** - * Negative cache for repos where gh's cwd-based repo resolution fails - * ("no git remotes found" etc). Orca only falls back to cwd resolution when - * it could not resolve an owner/repo itself, so for a remote-less repo the - * failure is deterministic — yet the Tasks page re-spawned gh for every such - * repo on every refresh (×90 repos in the reported storm). Remember the - * failure and re-throw it without a subprocess until the repo's git config - * changes (signature check) or the TTL lapses. - */ -const NEGATIVE_CACHE_TTL_MS = 5 * 60_000 -const MAX_ENTRIES = 512 - -type NegativeCacheEntry = { - message: string - configSignature: string | undefined - expiresAt: number -} - -const entries = new Map() - -function negativeCacheKey(context: GitHubRepoContext): string { - const runtimeKey = context.connectionId ?? `local:${context.wslDistro ?? 'host'}` - return `${runtimeKey}\0${context.repoPath}` -} - -export function isGhCwdRepoResolutionFailure(text: string): boolean { - const s = text.toLowerCase() - return ( - s.includes('no git remotes found') || - s.includes('not a git repository') || - s.includes('unable to determine base repository') || - s.includes('none of the git remotes configured') - ) -} - -export async function getRememberedGhCwdResolutionFailure( - context: GitHubRepoContext -): Promise { - const key = negativeCacheKey(context) - const entry = entries.get(key) - if (!entry) { - return null - } - if (entry.expiresAt <= Date.now()) { - entries.delete(key) - return null - } - // Why: adding a remote is the way out of this failure; the config signature - // (mtime/size of the repo's git config chain) changes when that happens. - const signature = await readLocalGitConfigSignature(context) - if (signature !== entry.configSignature) { - entries.delete(key) - return null - } - return entry.message -} - -export async function rememberGhCwdResolutionFailure( - context: GitHubRepoContext, - message: string -): Promise { - const configSignature = await readLocalGitConfigSignature(context) - entries.set(negativeCacheKey(context), { - message, - configSignature, - expiresAt: Date.now() + NEGATIVE_CACHE_TTL_MS - }) - while (entries.size > MAX_ENTRIES) { - const oldest = entries.keys().next() - if (oldest.done) { - break - } - entries.delete(oldest.value) - } -} - -/** @internal — test-only */ -export function _resetGhCwdRepoNegativeCache(): void { - entries.clear() -} diff --git a/src/renderer/src/components/TaskPage.tsx b/src/renderer/src/components/TaskPage.tsx index 90146054f..2430505d6 100644 --- a/src/renderer/src/components/TaskPage.tsx +++ b/src/renderer/src/components/TaskPage.tsx @@ -199,6 +199,7 @@ import { reconcileTaskPagePagesAfterLandingRefresh, reconcileTaskPagePagesWithWorkItemsCache, shouldResetTaskPagePaginationAfterLandingRefresh, + selectTaskPageUnresolvedSourceRepos, selectTaskPageWorkItemsCacheEntries, shouldReplaceTaskPageItemsAfterRefresh, type TaskPageRepoSourceState @@ -3985,6 +3986,12 @@ export default function TaskPage(): React.JSX.Element { [selectedRepos, selectedWorkItemsCacheEntries] ) + // Why: repos that fetched but resolved no GitHub source (#9660) show empty like a genuine zero-result; surface them explicitly with Retry. + const unresolvedSourceRepos = useMemo( + () => selectTaskPageUnresolvedSourceRepos(selectedRepos, perRepoSourceState), + [selectedRepos, perRepoSourceState] + ) + useEffect(() => { if (taskSource !== 'github' || githubMode !== 'items') { return @@ -9138,6 +9145,43 @@ export default function TaskPage(): React.JSX.Element { ) })} + {unresolvedSourceRepos.map((r) => ( + // Why: null-source repos (#9660) render empty like genuine zero — name the repo and offer Retry so a transient resolve blip is recoverable. +
+ + {translate( + 'auto.components.TaskPage.noGithubSourceDetected', + 'No GitHub source detected for' + )}{' '} + {r.label} —{' '} + {translate( + 'auto.components.TaskPage.noGithubSourceDetectedHint', + 'it may have no GitHub remote, or the source could not be resolved.' + )} + + +
+ ))} + {showGitHubTaskSkeletons ? ( // Why: fill a typical viewport with shimmer rows so the table doesn't jump in height when results land.
@@ -9189,6 +9233,7 @@ export default function TaskPage(): React.JSX.Element { !tasksError && !githubUnavailable && failedCount === 0 && + unresolvedSourceRepos.length === 0 && perRepoSourceState.every((s) => !s.error) ? (

diff --git a/src/renderer/src/components/task-page-cache-selectors.test.ts b/src/renderer/src/components/task-page-cache-selectors.test.ts index 71b85b8ad..b1c925125 100644 --- a/src/renderer/src/components/task-page-cache-selectors.test.ts +++ b/src/renderer/src/components/task-page-cache-selectors.test.ts @@ -5,6 +5,7 @@ import { workItemsCacheKey, type CacheEntry } from '@/store/slices/github' import type { GitHubWorkItem, LinearCollectionResult, LinearIssue } from '../../../shared/types' import { buildTaskPageRepoSourceState, + selectTaskPageUnresolvedSourceRepos, deriveTaskPageGitHubWorkItemsFetchOptions, findTaskPageDialogWorkItem, findTaskPageLinearDrawerIssue, @@ -73,6 +74,54 @@ describe('task page cache selectors', () => { ]) }) + it('flags fetched repos that resolved neither an issue nor a PR GitHub source', () => { + const sourcesEntry = ( + sources: { issues: unknown; prs: unknown } | null + ): CacheEntry => + ({ + data: [], + fetchedAt: 1, + ...(sources + ? { sources: { originCandidate: null, upstreamCandidate: null, ...sources } } + : {}) + }) as CacheEntry + + const repos = [ + { id: 'unresolved', path: '/repos/unresolved', displayName: 'unresolved-repo' }, + { id: 'issues-ok', path: '/repos/issues-ok', displayName: 'issues-repo' }, + { id: 'prs-ok', path: '/repos/prs-ok', displayName: 'prs-repo' }, + { id: 'no-name', path: '/repos/no-name' }, + { id: 'not-fetched', path: '/repos/not-fetched', displayName: 'pending-repo' } + ] + const entries = [ + sourcesEntry({ issues: null, prs: null }), + sourcesEntry({ issues: { owner: 'acme', repo: 'issues-ok' }, prs: null }), + sourcesEntry({ issues: null, prs: { owner: 'acme', repo: 'prs-ok' } }), + sourcesEntry({ issues: null, prs: null }), + sourcesEntry(null) + ] + const sourceState = buildTaskPageRepoSourceState(repos, entries) + + // Only both-null fetched repos are flagged; label falls back to path when displayName is absent. + expect(selectTaskPageUnresolvedSourceRepos(repos, sourceState)).toEqual([ + { repoId: 'unresolved', sourceKey: 'unresolved::local', label: 'unresolved-repo' }, + { repoId: 'no-name', sourceKey: 'no-name::local', label: '/repos/no-name' } + ]) + }) + + it('does not flag an unresolved-source repo that already carries a per-repo error', () => { + const repos = [{ id: 'errored', path: '/repos/errored', displayName: 'errored-repo' }] + const erroredEntry = { + data: [], + fetchedAt: 1, + sources: { issues: null, prs: null, originCandidate: null, upstreamCandidate: null }, + error: { type: 'rate_limited', message: 'slow down', source: { owner: 'acme', repo: 'x' } } + } as unknown as CacheEntry + const sourceState = buildTaskPageRepoSourceState(repos, [erroredEntry]) + + expect(selectTaskPageUnresolvedSourceRepos(repos, sourceState)).toEqual([]) + }) + it('scopes repo source rows by source cache scope for retry ownership', () => { const localRepo = { id: 'repo-1', diff --git a/src/renderer/src/components/task-page-cache-selectors.ts b/src/renderer/src/components/task-page-cache-selectors.ts index 67b3a7c1c..37644ce76 100644 --- a/src/renderer/src/components/task-page-cache-selectors.ts +++ b/src/renderer/src/components/task-page-cache-selectors.ts @@ -79,6 +79,40 @@ export function buildTaskPageRepoSourceState( }) } +export type TaskPageUnresolvedSourceRepo = { + repoId: string + sourceKey: string + label: string +} + +/** + * Select the fetched repos that resolved neither an issue nor a PR GitHub source. + * + * Why: since #9660 an unresolvable source returns an empty null-source envelope + * instead of an unscoped search. That empty is otherwise indistinguishable from a + * genuine zero-result query, so surface these repos to the user. The three states + * are told apart purely by `sources`: present-but-both-null = unresolved (this + * function), a non-null side = resolved (genuine zero), `null` = not yet fetched. + */ +export function selectTaskPageUnresolvedSourceRepos( + repos: readonly { id: string; displayName?: string; path: string }[], + sourceState: readonly TaskPageRepoSourceState[] +): TaskPageUnresolvedSourceRepo[] { + const stateByRepoId = new Map(sourceState.map((state) => [state.repoId, state])) + const unresolved: TaskPageUnresolvedSourceRepo[] = [] + for (const repo of repos) { + const state = stateByRepoId.get(repo.id) + if (state?.sources && !state.sources.issues && !state.sources.prs && !state.error) { + unresolved.push({ + repoId: repo.id, + sourceKey: state.sourceKey, + label: repo.displayName ?? repo.path + }) + } + } + return unresolved +} + function taskPageWorkItemCacheKey(item: GitHubWorkItem): string { return `${item.repoId}\u0000${item.id}` } diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 6ebb791d9..9de3068eb 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -1806,7 +1806,9 @@ "jiraSortDescending": "descending", "jiraSortBy": "Sort by", "jiraToggleSortDirection": "Sort {{value0}}", - "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly." + "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly.", + "noGithubSourceDetected": "No GitHub source detected for", + "noGithubSourceDetectedHint": "it may have no GitHub remote, or the source could not be resolved." }, "Terminal": { "73768427cf": "Close", diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index 92677acdd..3e0090677 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -1783,7 +1783,9 @@ "jiraSortDescending": "descendente", "jiraSortBy": "Ordenar por", "jiraToggleSortDirection": "Ordenar de forma {{value0}}", - "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly." + "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly.", + "noGithubSourceDetected": "No GitHub source detected for", + "noGithubSourceDetectedHint": "it may have no GitHub remote, or the source could not be resolved." }, "Terminal": { "73768427cf": "Cerrar", diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index 2181d64b8..2258a9bdc 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -1783,7 +1783,9 @@ "jiraSortDescending": "降順", "jiraSortBy": "並べ替え", "jiraToggleSortDirection": "{{value0}}に並べ替え", - "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly." + "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly.", + "noGithubSourceDetected": "No GitHub source detected for", + "noGithubSourceDetectedHint": "it may have no GitHub remote, or the source could not be resolved." }, "Terminal": { "73768427cf": "閉じる", diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index b5b1f87d7..eda40a50d 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -1783,7 +1783,9 @@ "jiraSortDescending": "내림차순", "jiraSortBy": "정렬 기준", "jiraToggleSortDirection": "{{value0}}으로 정렬", - "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly." + "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly.", + "noGithubSourceDetected": "No GitHub source detected for", + "noGithubSourceDetectedHint": "it may have no GitHub remote, or the source could not be resolved." }, "Terminal": { "73768427cf": "닫기", diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index a62090c51..35ec638a6 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -1783,7 +1783,9 @@ "jiraSortDescending": "降序", "jiraSortBy": "排序方式", "jiraToggleSortDirection": "按{{value0}}排序", - "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly." + "75a38d7df8": "GitHub data is temporarily unavailable. Its API may be down, rate-limited, or unreachable. Please try again shortly.", + "noGithubSourceDetected": "No GitHub source detected for", + "noGithubSourceDetectedHint": "it may have no GitHub remote, or the source could not be resolved." }, "Terminal": { "73768427cf": "关闭",