mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* 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>
121 lines
3.9 KiB
TypeScript
121 lines
3.9 KiB
TypeScript
import { spawn, type ChildProcess, type SpawnOptions } from 'node:child_process'
|
|
import { recordSubprocessSpawn } from '../../diagnostics/main-thread-churn-probe'
|
|
import { startGitSpan } from '../../observability/instrumentation'
|
|
import { createAbortError } from './abort-error'
|
|
import { resolveGitCommand } from './git-command-resolution'
|
|
import { untranslatedGitOutputEnv } from './git-process-env'
|
|
import { prepareWindowsHostGitEnvironment } from './windows-host-git-environment'
|
|
import type { GitAdmissionTier } from './git-exec-options'
|
|
import { acquireGitAdmission } from './git-subprocess-admission'
|
|
|
|
/**
|
|
* Spawn a git child process. Drop-in replacement for
|
|
* `spawn('git', args, { cwd, stdio, ... })`.
|
|
*/
|
|
export type GitSpawnOptions = SpawnOptions & {
|
|
cwd: string
|
|
wslDistro?: string
|
|
admissionTier?: GitAdmissionTier
|
|
}
|
|
|
|
export async function gitSpawnAfterWindowsEnvironmentReady(
|
|
args: string[],
|
|
options: GitSpawnOptions
|
|
): Promise<ChildProcess> {
|
|
if (options.signal?.aborted) {
|
|
throw createAbortError()
|
|
}
|
|
const resolved = resolveGitCommand(args, {
|
|
cwd: options.cwd,
|
|
...(options.wslDistro ? { wslDistro: options.wslDistro } : {}),
|
|
...(options.env ? { env: options.env } : {})
|
|
})
|
|
const env = await (prepareWindowsHostGitEnvironment(resolved, options.env, options.signal) ??
|
|
options.env)
|
|
if (options.signal?.aborted) {
|
|
throw createAbortError()
|
|
}
|
|
return withGitAdmission(args, env === options.env ? options : { ...options, env })
|
|
}
|
|
|
|
export async function withGitAdmission(
|
|
args: string[],
|
|
options: GitSpawnOptions,
|
|
spawnChild: () => ChildProcess = () => gitSpawn(args, options)
|
|
): Promise<ChildProcess> {
|
|
const span = startGitSpan({ args, cwd: options.cwd })
|
|
let grant: Awaited<ReturnType<typeof acquireGitAdmission>> | null = null
|
|
try {
|
|
grant = await acquireGitAdmission({
|
|
args,
|
|
cwd: options.cwd,
|
|
wslDistro: options.wslDistro,
|
|
tier: options.admissionTier,
|
|
signal: options.signal
|
|
})
|
|
span.setAttribute('git.queue_wait_ms', grant.queueWaitMs)
|
|
if (options.signal?.aborted) {
|
|
grant.release()
|
|
span.fail(createAbortError())
|
|
throw createAbortError()
|
|
}
|
|
const child = spawnChild()
|
|
let finalized = false
|
|
let liveError: Error | null = null
|
|
const finalize = (error?: Error): void => {
|
|
if (finalized) {
|
|
return
|
|
}
|
|
finalized = true
|
|
child.off('error', handleError)
|
|
child.off('close', handleClose)
|
|
grant?.release()
|
|
if (error) {
|
|
span.fail(error)
|
|
} else {
|
|
span.end()
|
|
}
|
|
}
|
|
const handleError = (error: Error): void => {
|
|
if (!child.pid) {
|
|
finalize(error)
|
|
} else {
|
|
liveError = error
|
|
}
|
|
}
|
|
const handleClose = (code: number | null, signal: NodeJS.Signals | null): void => {
|
|
const exitError =
|
|
liveError ??
|
|
(code === 0 && signal === null
|
|
? undefined
|
|
: new Error(`git exited with ${code ?? signal ?? 'unknown'}.`))
|
|
finalize(exitError)
|
|
}
|
|
child.on('error', handleError)
|
|
child.once('close', handleClose)
|
|
return child
|
|
} catch (error) {
|
|
grant?.release()
|
|
span.fail(error instanceof Error ? error : new Error(String(error)))
|
|
throw error
|
|
}
|
|
}
|
|
|
|
export function gitSpawn(args: string[], options: GitSpawnOptions): ChildProcess {
|
|
const { wslDistro, admissionTier: _admissionTier, ...spawnOptions } = options
|
|
const resolved = resolveGitCommand(args, {
|
|
cwd: options.cwd,
|
|
...(wslDistro ? { wslDistro } : {}),
|
|
...(spawnOptions.env ? { env: spawnOptions.env } : {})
|
|
})
|
|
const spawnStartedAt = performance.now()
|
|
const child = spawn(resolved.binary, resolved.args, {
|
|
...spawnOptions,
|
|
env: untranslatedGitOutputEnv(spawnOptions.env ?? process.env),
|
|
windowsHide: true,
|
|
cwd: resolved.cwd
|
|
})
|
|
recordSubprocessSpawn(resolved.binary, resolved.args, performance.now() - spawnStartedAt)
|
|
return child
|
|
}
|