fix(host-service): stop background git fetches from opening a sign-in window

RO
14h ago
+101-13

Fixes #10149.

Summary

  • Git calls the host-service makes on its own now run with GCM_INTERACTIVE=never, so Git Credential Manager fails at once instead of opening a sign-in window.
  • Covers the base-branch refresh (every 5 min), the New Workspace branch list, the PR-stack branch warm-up, and the git credential fill token lookup.
  • Fetches the user starts (push, pull, checkout, workspace creation) still prompt as before.

Why / Context

For an HTTPS remote that uses Git Credential Manager (credential.helper = manager, e.g. Azure DevOps), an expired login, or one GCM cannot renew while offline, made GCM open a Microsoft sign-in window from these background fetches. Users saw it every few minutes with no action of their own. Each unanswered prompt also left a git-credential-manager get process waiting forever after the 30 s worker timeout.

GIT_TERMINAL_PROMPT=0 (already set) only stops git's own terminal prompt; GCM's window needs GCM_INTERACTIVE=never.

How It Works

  • withoutSignInPrompt(env) (runtime/git/non-interactive-env.ts) adds GCM_INTERACTIVE=never.
  • GitFactory takes { interactive?: boolean } (default true); searchBranches asks for interactive: false.
  • git/fetchBaseRef and git/fetchBranches worker tasks take a required interactive flag. The status-path base-ref refresh passes false (with its own dedupe key, so it never coalesces with a workspace-creation fetch, which passes true).
  • Host-service git.fetchBranches gets an optional interactive input (default true); the useOpenStackLayer warm-up effect sends false. Additive: older clients and older hosts keep the old behaviour.
  • LocalGitCredentialProvider runs git credential fill non-interactively. The env it returns for real git commands is unchanged, so user-started commands can still prompt.

Manual QA Checklist

Dev app on macOS, a real Azure DevOps HTTPS repo whose GCM login no longer works silently:

  • Before the fix: opening the workspace ran git fetch origin develop; GCM started and waited for sign-in indefinitely. The New Workspace branch list (git fetch --prune) did the same.
  • After the fix: the same fetch runs with GCM_INTERACTIVE=never; GCM exits in 1-3 s with "Cannot prompt because user interactivity has been disabled", the host logs "Background base-ref fetch failed", and no process is left waiting.
  • After the fix: New Workspace branch search fails quietly and the branch picker still loads (develop).
  • Not exercised in the app: the PR-stack warm-up (test repo has no stack) and the token lookup (covered by a test below).

Testing

  • bun test in packages/host-service for runtime/git, workers, providers/git, trpc/router/git, trpc/router/workspace-creation, trpc/router/workspaces: 675 pass
  • New tests: workers/tasks/git-fetch-base-ref.test.ts and a token-lookup case in LocalGitCredentialProvider.test.ts. Each fails with its fix reverted. They use a fake core.sshCommand / credential helper, so there is no network access.
  • bun run typecheck in packages/host-service and apps/desktop
  • bunx biome check on the changed paths

Known Limitations

  • A failed token lookup is still not cached, so a repo with no usable token runs the credential helper on every git call (now fast, since it no longer waits). This was already true before this change.

Summary by cubic

Stops background host-service git calls from opening a Microsoft sign-in window when a saved Git Credential Manager login has expired or can't be renewed (for example while offline). These calls now run with GCM_INTERACTIVE=never, so GCM fails immediately instead of prompting.

  • Covers the 5-minute base-branch refresh, the New Workspace branch list, the PR-stack branch warm-up, and the git credential fill token lookup.
  • Fetches the user starts (push, pull, checkout, workspace creation) still prompt as before.
  • The base-ref refresh uses its own dedupe key so it never coalesces with a workspace-creation fetch, which stays interactive.
  • The git fetchBranches input and worker task options are additive; older clients and hosts keep the old behavior.
  • GIT_TERMINAL_PROMPT=0 alone was not enough: GCM's window is only blocked by GCM_INTERACTIVE=never.

Testing

  • New tests cover the non-interactive base-branch fetch and the credential-fill token lookup; each fails with its fix reverted.
  • 675 host-service tests pass, plus typecheck and biome.
  • A failed token lookup is still not cached, so a repo with no usable token runs the credential helper on every git call (now fast, since it no longer waits).

Summary by CodeRabbit

  • Bug Fixes
    • Background Git fetches and branch searches no longer open sign-in windows unexpectedly. If authentication is required, these operations can fail without prompting.
    • Git operations initiated interactively continue to allow sign-in prompts.