mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
The speculative warm-up that runs while the create composer is open resolved
refs and fetched with host Git even when the project's runtime is a WSL distro,
while both the checkout preparation it feeds (`prepareWorktreeCreateForRepo`,
which already resolves `{ wslDistro }` itself) and the real create path run
inside the distro.
The concrete cost was a discarded fetch: `getCanonicalFetchKey` namespaces the
runtime's remote-fetch cache `wsl:<distro>` vs `local`, so the warm-up's fetch
landed in a namespace create never looks at, and create fetched again. On a
Windows host with no usable host-side Git the probes also failed outright, so
that cohort got no warm-up at all.
Thread the project's worktree Git options through the prefetch (resolved by a
non-throwing helper, because an optimistic warm-up must not surface a
repair-required runtime as a failure) so every probe and fetch runs where create
runs. `gitOptions` is a required argument, so a caller cannot drop the routing
silently. Host-routed calls keep their original arity, so macOS, Linux,
native-Windows-host projects, SSH repos and folder workspaces are unchanged.
Narrower than it looks: for a repo under \\wsl.localhost\<distro>\... the probes
were already routed by cwd, and for a repo on a Windows drive letter host Git
and WSL Git read the same on-disk repository, so the answers were already
correct there. What those cohorts gain is a fetch create can reuse; what they
pay is that the probes now run inside the distro (over /mnt/c for drive-letter
repos, which also newly arms the linked-worktree routing probe) and the
speculative fetch now shares create's per-remote fetch queue, as it always has
on native platforms.
Also collapse the three byte-equivalent copies of `hasLocalWorktreeBaseRef`
(create, prefetch, remote-repo create) into one in
git/worktree-base-ref-probe.ts, drop the host-only `hasLocalCommitObject` that
caused the routing bug, and add the first routing assertions on the create-path
consumers of the now-shared probe.
131 lines
4.5 KiB
TypeScript
131 lines
4.5 KiB
TypeScript
import { isFolderRepo } from '../shared/repo-kind'
|
|
import type { Repo } from '../shared/repo-types'
|
|
import { isFullGitObjectId } from './git/commit-object-ref'
|
|
import { hasLocalWorktreeBaseRef } from './git/worktree-base-ref-probe'
|
|
import { getBaseRefDefault } from './git/repo'
|
|
import { getSshGitProvider } from './providers/ssh-git-dispatch'
|
|
import { prefetchRemoteWorktreeCreateBase } from './ipc/worktree-remote'
|
|
import { resolveWorktreeCreateBase } from './worktree-create-base'
|
|
|
|
type WorktreeCreateBaseGitOptions = {
|
|
wslDistro?: string
|
|
}
|
|
|
|
type RemoteTrackingBaseForPrefetch = {
|
|
remote: string
|
|
branch: string
|
|
ref: string
|
|
base: string
|
|
}
|
|
|
|
type WorktreeCreateBasePrefetchRuntime = {
|
|
resolveRemoteTrackingBase: (
|
|
repoPath: string,
|
|
baseBranch: string,
|
|
options?: WorktreeCreateBaseGitOptions
|
|
) => Promise<RemoteTrackingBaseForPrefetch | null>
|
|
hasRemoteTrackingRef: (
|
|
repoPath: string,
|
|
base: RemoteTrackingBaseForPrefetch,
|
|
options?: WorktreeCreateBaseGitOptions
|
|
) => Promise<boolean>
|
|
getOrStartRemoteTrackingBaseRefresh: (
|
|
repoPath: string,
|
|
base: RemoteTrackingBaseForPrefetch,
|
|
options?: WorktreeCreateBaseGitOptions
|
|
) => Promise<unknown>
|
|
fetchRemoteWithCache: (
|
|
repoPath: string,
|
|
remote: string,
|
|
options?: WorktreeCreateBaseGitOptions
|
|
) => Promise<void>
|
|
}
|
|
|
|
async function prefetchLocalWorktreeCreateBase(
|
|
repo: Repo,
|
|
baseBranch: string | undefined,
|
|
runtime: WorktreeCreateBasePrefetchRuntime,
|
|
options: WorktreeCreateBaseGitOptions
|
|
): Promise<string | undefined> {
|
|
// Keep host-routed calls at their original arity so they stay on the runtime's default options.
|
|
const optionArgs: [] | [WorktreeCreateBaseGitOptions] = options.wslDistro ? [options] : []
|
|
const resolvedBaseBranch = await resolveWorktreeCreateBase({
|
|
requestedBaseBranch: baseBranch,
|
|
repoWorktreeBaseRef: repo.worktreeBaseRef,
|
|
resolveDefaultBaseRef: () => getBaseRefDefault(repo.path, ...optionArgs),
|
|
isBaseUsable: async (baseBranchCandidate) => {
|
|
const remoteTrackingBase = await runtime.resolveRemoteTrackingBase(
|
|
repo.path,
|
|
baseBranchCandidate,
|
|
...optionArgs
|
|
)
|
|
if (remoteTrackingBase) {
|
|
if (await runtime.hasRemoteTrackingRef(repo.path, remoteTrackingBase, ...optionArgs)) {
|
|
return true
|
|
}
|
|
return hasLocalWorktreeBaseRef(repo.path, baseBranchCandidate, options)
|
|
}
|
|
return hasLocalWorktreeBaseRef(repo.path, baseBranchCandidate, options)
|
|
}
|
|
})
|
|
if (!resolvedBaseBranch) {
|
|
return undefined
|
|
}
|
|
if (
|
|
isFullGitObjectId(resolvedBaseBranch) &&
|
|
(await hasLocalWorktreeBaseRef(repo.path, resolvedBaseBranch, options))
|
|
) {
|
|
return resolvedBaseBranch
|
|
}
|
|
const remoteTrackingBase = await runtime.resolveRemoteTrackingBase(
|
|
repo.path,
|
|
resolvedBaseBranch,
|
|
...optionArgs
|
|
)
|
|
if (remoteTrackingBase) {
|
|
if (
|
|
(await runtime.hasRemoteTrackingRef(repo.path, remoteTrackingBase, ...optionArgs)) ||
|
|
!(await hasLocalWorktreeBaseRef(repo.path, resolvedBaseBranch, options))
|
|
) {
|
|
await runtime.getOrStartRemoteTrackingBaseRefresh(
|
|
repo.path,
|
|
remoteTrackingBase,
|
|
...optionArgs
|
|
)
|
|
return resolvedBaseBranch
|
|
}
|
|
}
|
|
if (await hasLocalWorktreeBaseRef(repo.path, resolvedBaseBranch, options)) {
|
|
// Why: hosted-review start points and local branch bases are already local; a broad remote fetch cannot make them fresher.
|
|
return resolvedBaseBranch
|
|
}
|
|
|
|
// Why: same best-effort fallback create takes, on create's own fetch key, so a
|
|
// create that lands here reuses this fetch instead of repeating it. A create
|
|
// that instead resolves an exact remote base still queues behind it.
|
|
await runtime.fetchRemoteWithCache(repo.path, 'origin', ...optionArgs)
|
|
return resolvedBaseBranch
|
|
}
|
|
|
|
export async function prefetchWorktreeCreateBase(args: {
|
|
repo: Repo
|
|
baseBranch?: string
|
|
runtime: WorktreeCreateBasePrefetchRuntime
|
|
/** Routing for the project's Git host; required so a caller cannot silently
|
|
* warm up the wrong ref store — pass `{}` for host Git. */
|
|
gitOptions: WorktreeCreateBaseGitOptions
|
|
}): Promise<string | undefined> {
|
|
if (isFolderRepo(args.repo)) {
|
|
return undefined
|
|
}
|
|
if (args.repo.connectionId) {
|
|
const provider = getSshGitProvider(args.repo.connectionId)
|
|
if (!provider) {
|
|
return undefined
|
|
}
|
|
await prefetchRemoteWorktreeCreateBase(provider, args.repo, { baseBranch: args.baseBranch })
|
|
return undefined
|
|
}
|
|
return prefetchLocalWorktreeCreateBase(args.repo, args.baseBranch, args.runtime, args.gitOptions)
|
|
}
|