mirror of
https://github.com/stablyai/orca.git
synced 2026-09-25 16:02:38 +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>
102 lines
3.8 KiB
TypeScript
102 lines
3.8 KiB
TypeScript
import type { GitUpstreamStatus } from '../../shared/git-status-types'
|
|
import type { GitPushTarget } from '../../shared/worktree/types'
|
|
import { upstreamOnlyCommitsArePatchEquivalent } from '../../shared/git-upstream-status'
|
|
import { isNoUpstreamError, normalizeGitErrorMessage } from '../../shared/git-remote-error'
|
|
import { getEffectiveGitUpstreamStatus } from '../../shared/git-effective-upstream'
|
|
import { getPublishTargetStatus } from '../../shared/git-publish-target-status'
|
|
import { gitExecFileAsync } from './runner'
|
|
import { validateGitPushTarget } from './push-target-validation'
|
|
import { nativeAndWslGitUpstreamStatusReadOwner } from './git-upstream-status-read-owner'
|
|
import type { GitAdmissionTier } from './command-runner/git-exec-options'
|
|
|
|
type GitExecOptions = {
|
|
wslDistro?: string
|
|
admissionTier?: GitAdmissionTier
|
|
}
|
|
|
|
export function invalidateGitUpstreamStatusReads(): void {
|
|
nativeAndWslGitUpstreamStatusReadOwner.invalidate()
|
|
}
|
|
|
|
function gitExecOptions(
|
|
cwd: string,
|
|
options: GitExecOptions = {}
|
|
): { cwd: string; wslDistro?: string; admissionTier?: GitAdmissionTier } {
|
|
return {
|
|
cwd,
|
|
...(options.wslDistro ? { wslDistro: options.wslDistro } : {}),
|
|
...(options.admissionTier ? { admissionTier: options.admissionTier } : {})
|
|
}
|
|
}
|
|
|
|
async function getBehindCommitsArePatchEquivalent(
|
|
worktreePath: string,
|
|
upstreamName: string,
|
|
options: GitExecOptions = {}
|
|
): Promise<boolean> {
|
|
try {
|
|
const { stdout } = await gitExecFileAsync(
|
|
['log', '--oneline', '--cherry-mark', '--right-only', `HEAD...${upstreamName}`, '--'],
|
|
gitExecOptions(worktreePath, options)
|
|
)
|
|
return upstreamOnlyCommitsArePatchEquivalent(stdout)
|
|
} catch {
|
|
// Why: patch-equivalence is an optimization for the rebase case. If the
|
|
// probe fails, keep the conservative pull-first behavior.
|
|
return false
|
|
}
|
|
}
|
|
|
|
async function readUpstreamStatus(
|
|
worktreePath: string,
|
|
pushTarget?: GitPushTarget,
|
|
options: GitExecOptions = {}
|
|
): Promise<GitUpstreamStatus> {
|
|
try {
|
|
if (pushTarget) {
|
|
const target = await validateGitPushTarget(worktreePath, pushTarget, options)
|
|
return await getPublishTargetStatus(
|
|
(args) => gitExecFileAsync(args, gitExecOptions(worktreePath, options)),
|
|
target,
|
|
(upstreamName) => getBehindCommitsArePatchEquivalent(worktreePath, upstreamName, options)
|
|
)
|
|
}
|
|
return await getEffectiveGitUpstreamStatus(
|
|
(args) => gitExecFileAsync(args, gitExecOptions(worktreePath, options)),
|
|
(upstreamName) => getBehindCommitsArePatchEquivalent(worktreePath, upstreamName, options)
|
|
)
|
|
} catch (error) {
|
|
// Why: we only swallow clearly-no-upstream signals — that's an expected
|
|
// state, not a failure. Other errors (auth, corruption, "not a git
|
|
// repository", sparse-checkout) should surface to the user so they can
|
|
// act on them. The shared isNoUpstreamError helper intentionally omits
|
|
// broad phrases like "no such branch" to avoid masking real errors.
|
|
if (isNoUpstreamError(error)) {
|
|
return {
|
|
hasUpstream: false,
|
|
ahead: 0,
|
|
behind: 0
|
|
}
|
|
}
|
|
// Why: parity with gitPush/gitPull/gitFetch — normalize before crossing
|
|
// the IPC boundary so renderers don't see execFile stderr preambles or local paths.
|
|
throw new Error(normalizeGitErrorMessage(error, 'upstream'))
|
|
}
|
|
}
|
|
|
|
export function getUpstreamStatus(
|
|
worktreePath: string,
|
|
pushTarget?: GitPushTarget,
|
|
options: GitExecOptions = {}
|
|
): Promise<GitUpstreamStatus> {
|
|
const executionIdentity = options.wslDistro
|
|
? ({ kind: 'wsl', distro: options.wslDistro } as const)
|
|
: ({ kind: 'native' } as const)
|
|
return nativeAndWslGitUpstreamStatusReadOwner.read(
|
|
executionIdentity,
|
|
worktreePath,
|
|
pushTarget,
|
|
() => readUpstreamStatus(worktreePath, pushTarget, options)
|
|
)
|
|
}
|