Files
orca/src/main/git/remote-url-probe.ts
T
Brennan BensonandMerge Sim b5a85890ac perf(git): bound git subprocess execution with an atomic admission scheduler (#16874)
* perf(git): bound git subprocess execution with an atomic admission scheduler

Field traces (#16038, #11363) show Windows freeze storms driven by unbounded
concurrent git children (12+ at once, 50-65s status convoys for 25+ minutes).
Admit every main-process git child against atomic per-budget base+headroom
counters (general / network / per-route), with reserved interactive capacity,
ordering-only aging, close-bound permit release, a 120s fail-safe read timeout
that feeds scheduler backoff, tier plumbing through every option carrier, and
coalesced+jittered visibility pollers. Killswitch: ORCA_GIT_ADMISSION_DISABLED=1.

Storm harness A/B: max concurrent children 65 -> 6, interactive p95 791ms -> 88ms;
output-parity battery byte-identical with admission on vs off.

* test(git): run the admission output-parity battery on every platform

Parity needs real git, not the storm harness's PATH stub, so it must not share
that file's POSIX gate - Windows is the platform where parity evidence matters.

* fix(git): preserve interactive admission invariants

* perf(git): keep admission queue drains linear

* fix(git): close final admission gaps

* perf(git): bound eligible route selection

* fix(merge): remove unrelated stale snapshot changes

* fix(git): preserve refresh lifecycle authority

* test(git): align admission lifetime contracts

* fix(git): harden admission across runtime paths

* fix(git): restore freshness for bulk status reads

* test(git): repoint delete-dialog source pins after admission plumbing

The hydration effect now orders its targets through
orderDeleteWorktreeStatusHydrationTargets and passes includeLineStats
alongside the abort signal, so both literal anchors stopped matching.
The invariants are unchanged and still pinned: dropping the signal, the
main-worktree/folder filter, or getState-instead-of-subscribe each
still reddens this test.

* Fix git admission tier propagation and lock ordering

Decode optional Git status tiers permissively and default runtime RPC status reads to the status lane while preserving renderer caller intent.

Acquire the FETCH_HEAD mutex before atomic admission so same-repository fetch waiters hold no global or route permits.

Preserve automatic pull-request refresh reasons, keep explicit hosted-review refreshes interactive, remove the dead candidate tier, and keep relay scheduling unchanged.

Use tier-aware status lease keys because a shared lease cannot be safely promoted after its admission request is queued or granted.

* test: align expectations with admission plumbing

* refactor(child-process): move the process contract types to process-spec

run-process.ts crossed its line cap after gaining the termination observer;
the public types and defaults move out with re-exports so no caller changes.

* chore: restore pnpm-lock.yaml to main (unintended local drift)

---------

Co-authored-by: Merge Sim <sim@local>
2026-08-30 14:19:05 -07:00

118 lines
3.9 KiB
TypeScript

import {
getSshGitProvider,
SSH_GIT_PROVIDER_UNAVAILABLE_MESSAGE
} from '../providers/ssh-git-dispatch'
import { gitExecFileAsync } from './runner'
import { isStableMissingGitRemoteError } from './stable-missing-git-remote-error'
import type { GitAdmissionTier } from './command-runner/git-exec-options'
/**
* The `git remote get-url` probe every forge integration runs to decide whether
* a repo is theirs (P1-D).
*
* Why: it is a local config read, so the only way it outlasts this bound is a
* wedged host — a dead network mount or stalled WSL interop. Unbounded, the call
* never returns and every caller above it hangs with it. Passing a timeout is
* also what arms the runner's kill path; Node's own waits forever on a child
* that ignores signals. The SSH branch spends the same budget as one deadline
* over the whole round trip: the relay's own bounds are per-phase and restart on
* every frame, so a relay dribbling output outlives them.
*/
export const REMOTE_URL_PROBE_TIMEOUT_MS = 30_000
export type RemoteUrlProbeContext = {
repoPath: string
connectionId?: string | null
wslDistro?: string
admissionTier?: GitAdmissionTier
}
/** Reads a remote URL, or null when the repo's SSH runtime is not connected. */
export async function readRemoteUrl(
context: RemoteUrlProbeContext,
remoteName: string
): Promise<string | null> {
if (context.connectionId) {
const provider = getSshGitProvider(context.connectionId)
if (!provider) {
return null
}
const { stdout } = await provider.exec(['remote', 'get-url', remoteName], context.repoPath, {
signal: AbortSignal.timeout(REMOTE_URL_PROBE_TIMEOUT_MS)
})
return stdout
}
const { stdout } = await gitExecFileAsync(['remote', 'get-url', remoteName], {
cwd: context.repoPath,
timeout: REMOTE_URL_PROBE_TIMEOUT_MS,
...(context.wslDistro ? { wslDistro: context.wslDistro } : {}),
...(context.admissionTier ? { admissionTier: context.admissionTier } : {})
})
return stdout
}
const TRANSIENT_PROBE_PATTERNS = [
/\btimed out\b/i,
/\bETIMEDOUT\b/,
/\bECONNRESET\b/,
/\bEPIPE\b/,
/connection (?:dropped|closed|refused|reset)/i
]
/**
* A probe that was killed on its deadline, or died with its transport, says
* nothing about the remote. Callers must neither cache it as an answer nor
* report it as "no review": it is an unavailable result, not a negative one.
*/
export function isTransientGitProbeError(error: unknown): boolean {
// Why: an abort — this probe's deadline, or a caller cancelling — carries no
// message a pattern could match, but it is the emptiest answer of all.
if (
typeof error === 'object' &&
error !== null &&
(error as { name?: unknown }).name === 'AbortError'
) {
return true
}
const parts: string[] = []
if (error instanceof Error) {
parts.push(error.message)
}
if (typeof error === 'object' && error !== null) {
const execLike = error as { stderr?: unknown; code?: unknown }
if (typeof execLike.stderr === 'string') {
parts.push(execLike.stderr)
}
if (typeof execLike.code === 'string') {
parts.push(execLike.code)
}
}
if (parts.length === 0) {
parts.push(String(error))
}
const text = parts.join('\n')
return TRANSIENT_PROBE_PATTERNS.some((pattern) => pattern.test(text))
}
/**
* Throws when the remote could not be read, and returns normally for every
* answer — including a repo with no remote at all. Lets a caller that treats
* "nothing found" as cacheable tell that apart from a lookup that never got to ask.
*/
export async function assertRemoteUrlReadable(
context: RemoteUrlProbeContext,
remoteName = 'origin'
): Promise<void> {
if (context.connectionId && !getSshGitProvider(context.connectionId)) {
throw new Error(SSH_GIT_PROVIDER_UNAVAILABLE_MESSAGE)
}
try {
await readRemoteUrl(context, remoteName)
} catch (error) {
if (isStableMissingGitRemoteError(error)) {
return
}
throw error
}
}