Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: PR MCP target resolution reads non-blocking ProjectService.getShell enrichment and skips fallback/refinement when repositoryIdentity is null or "unknown" #41399

Closedzbynekwinkler(GitHub profile, opens in a new tab) opened this issue 0 comments

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:

  1. Start the server (or invalidate a project's enrichment cache) so ProjectEnrichmentService's repositoryIdentityCache has not yet populated for a project.
  2. 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 }), or watch_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):

  1. Open a project whose remote hostname does not match a public host heuristic (e.g., https://gh.example.internal/org/repo.git).
  2. Have initial RepositoryIdentityResolver refinement fail transiently (e.g., gh not yet logged in, keyring locked, or transient probe failure), so RepositoryIdentityResolver caches the identity with provider: "unknown" for DEFAULT_POSITIVE_CACHE_TTL (15 minutes).
  3. Authenticate gh (or recover from the transient failure) and invoke pull_request_read / pull_request_respond / link_pull_request by 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.repositoryIdentity is null because enrichment is cold, await repositoryIdentity resolution rather than failing immediately.
  • If project.repositoryIdentity.provider === "unknown", refine the remote host/provider (the same way PullRequestService.readWorkspaceProjects does via resolveRemoteHosts) rather than failing with PullRequestUrlUnavailableError while PullRequestService.servesProject already considers the project supported.

Actual behavior

  • In Case A (cold cache): ProjectService.getShell returns repositoryIdentity: null immediately (ProjectEnrichmentService.getAvailable only peeks and enqueues background work). locate() then sees branchRepository = undefined and projectHost = { host: null, kind: null }, failing with PullRequestTargetIncompleteError (if repository was omitted) or PullRequestHostRequiredError (if repository was provided).
  • In Case B (cached "unknown" provider): Even after PullRequestService.servesProject succeeds via resolveRemoteHosts (exposing the forge MCP tools to the thread), resolveTarget reads project.repositoryIdentity.provider === "unknown" from getShell and fails with PullRequestUrlUnavailableError until the 15-minute RepositoryIdentityResolver cache expires or is explicitly refreshed.

Cause

Compare how ProjectService.listPage and PullRequestService.readWorkspaceProjects read repositoryIdentity vs. how PR MCP handlers do:

  1. ProjectService.getShell / listShells (apps/server/src/project/ProjectService.ts, lines 783–815) call projectEnrichment.getAvailable(shell.workspaceRoot) (apps/server/src/project/ProjectEnrichmentService.ts, lines 308–314), which is intentionally non-blocking (peek + background request).
  2. ProjectService.listPage (apps/server/src/project/ProjectService.ts, lines 838–845) explicitly awaits projectEnrichment.readRepositoryIdentity(project.workspaceRoot) when repositoryIdentity === null.
  3. PullRequestService.readWorkspaceProjects (apps/server/src/pullRequest/PullRequestService.ts, lines 957–973) both awaits repositoryIdentities.resolve(project.workspaceRoot) when project.repositoryIdentity == null and runs resolveRemoteHosts(projects, filter) (lines 792–904) to refine provider === "unknown" through SourceControlProviderRegistry.
  4. PR MCP target resolution (PullRequestsToolkit.projectOf / locate / locateAll in apps/server/src/mcp/toolkits/pullRequests/handlers.ts, lines 304–314, 361–376, 511–539; and PullRequestWatchService.setWatching in apps/server/src/pullRequest/PullRequestWatchService.ts, lines 111–115) calls projects.getShell / projects.listShells and passes the unawaited/unrefined project straight into resolveTarget.
  5. Additionally, RepositoryIdentityResolver (apps/server/src/project/RepositoryIdentityResolver.ts, lines 23 and 391–404) caches any non-null identity — including one whose refine step left provider: "unknown" — for DEFAULT_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).

  1. tanstack-source added labelsbug

  2. juliusmarminge closed this

Sign in to join this conversation.