Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
(Found via code audit of PullRequestsToolkit vs. PullRequestService while investigating #41385 / #41394 / #41396.)
Case A — Cold ProjectEnrichmentService cache:
- Start the server (or invalidate a project's enrichment cache) so
ProjectEnrichmentService'srepositoryIdentityCachehas not yet populated for a project. - Before the background enrichment worker finishes, invoke a PR MCP tool targeting by number (e.g.,
pull_request_read({ number: 123 }),pull_request_respond({ number: 123, body: "..." }),link_pull_request({ repository: "org/repo", number: 123 }), orwatch_pull_request({ repository: "org/repo", number: 123 })).
Case B — Transiently unrefined provider: "unknown" cached on a custom self-hosted forge (e.g., GHES/GitLab/Forgejo):
- Open a project whose remote hostname does not match a public host heuristic (e.g.,
https://gh.example.internal/org/repo.git). - Have initial
RepositoryIdentityResolverrefinement fail transiently (e.g.,ghnot yet logged in, keyring locked, or transient probe failure), soRepositoryIdentityResolvercaches the identity withprovider: "unknown"forDEFAULT_POSITIVE_CACHE_TTL(15 minutes). - Authenticate
gh(or recover from the transient failure) and invokepull_request_read/pull_request_respond/link_pull_requestby number.
Expected behavior
PR MCP target resolution (PullRequestsToolkit.locate, link_pull_request, unlink_pull_request, locateAll, and PullRequestWatchService.setWatching) should behave consistently with PullRequestService.readWorkspaceProjects and ProjectService.listPage:
- If
project.repositoryIdentityisnullbecause enrichment is cold, awaitrepositoryIdentityresolution rather than failing immediately. - If
project.repositoryIdentity.provider === "unknown", refine the remote host/provider (the same wayPullRequestService.readWorkspaceProjectsdoes viaresolveRemoteHosts) rather than failing withPullRequestUrlUnavailableErrorwhilePullRequestService.servesProjectalready considers the project supported.
Actual behavior
- In Case A (cold cache):
ProjectService.getShellreturnsrepositoryIdentity: nullimmediately (ProjectEnrichmentService.getAvailableonly peeks and enqueues background work).locate()then seesbranchRepository = undefinedandprojectHost = { host: null, kind: null }, failing withPullRequestTargetIncompleteError(ifrepositorywas omitted) orPullRequestHostRequiredError(ifrepositorywas provided). - In Case B (cached
"unknown"provider): Even afterPullRequestService.servesProjectsucceeds viaresolveRemoteHosts(exposing the forge MCP tools to the thread),resolveTargetreadsproject.repositoryIdentity.provider === "unknown"fromgetShelland fails withPullRequestUrlUnavailableErroruntil the 15-minuteRepositoryIdentityResolvercache expires or is explicitly refreshed.
Cause
Compare how ProjectService.listPage and PullRequestService.readWorkspaceProjects read repositoryIdentity vs. how PR MCP handlers do:
ProjectService.getShell/listShells(apps/server/src/project/ProjectService.ts, lines 783–815) callprojectEnrichment.getAvailable(shell.workspaceRoot)(apps/server/src/project/ProjectEnrichmentService.ts, lines 308–314), which is intentionally non-blocking (peek+ backgroundrequest).ProjectService.listPage(apps/server/src/project/ProjectService.ts, lines 838–845) explicitly awaitsprojectEnrichment.readRepositoryIdentity(project.workspaceRoot)whenrepositoryIdentity === null.PullRequestService.readWorkspaceProjects(apps/server/src/pullRequest/PullRequestService.ts, lines 957–973) both awaitsrepositoryIdentities.resolve(project.workspaceRoot)whenproject.repositoryIdentity == nulland runsresolveRemoteHosts(projects, filter)(lines 792–904) to refineprovider === "unknown"throughSourceControlProviderRegistry.- PR MCP target resolution (
PullRequestsToolkit.projectOf/locate/locateAllinapps/server/src/mcp/toolkits/pullRequests/handlers.ts, lines 304–314, 361–376, 511–539; andPullRequestWatchService.setWatchinginapps/server/src/pullRequest/PullRequestWatchService.ts, lines 111–115) callsprojects.getShell/projects.listShellsand passes the unawaited/unrefinedprojectstraight intoresolveTarget. - Additionally,
RepositoryIdentityResolver(apps/server/src/project/RepositoryIdentityResolver.ts, lines 23 and 391–404) caches any non-null identity — including one whoserefinestep leftprovider: "unknown"— forDEFAULT_POSITIVE_CACHE_TTL(15 minutes).
Impact
Minor bug or occasional failure
Version or commit
Confirmed in v0.1.11 and main @ d63b9c4c76.
Environment
Server-side (apps/server), platform-independent.
Logs or stack traces
N/A (identified via static code analysis of ProjectService, ProjectEnrichmentService, RepositoryIdentityResolver, PullRequestService, and PullRequestsToolkit).
Workaround
Retry the tool call after background enrichment completes, or wait for the 15-minute RepositoryIdentityResolver cache TTL / trigger a turn completion that refreshes repository identity.
Analyzed and drafted with Gemini 4 Neon (Antigravity).
Activity