Files
archived-orca/src/main/git/command-runner/git-command-timeout-behavior.test.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

145 lines
4.5 KiB
TypeScript

import { chmod, mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { gitExecFileAsync, gitExecFileAsyncBuffer } from './git-exec-file'
import { GitCommandTimeoutError } from './git-command-timeout'
import { gitStreamStdout } from './git-stream-stdout'
const tempRoots: string[] = []
afterEach(async () => {
await Promise.all(tempRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })))
})
async function createTimedGitFixture(): Promise<{
cwd: string
env: NodeJS.ProcessEnv
}> {
const root = await mkdtemp(path.join(tmpdir(), 'orca-git-timeout-'))
tempRoots.push(root)
const binDir = path.join(root, 'bin')
const cwd = path.join(root, 'repo')
await mkdir(binDir)
await mkdir(cwd)
const script = path.join(binDir, 'git')
await writeFile(
script,
`#!/usr/bin/env node
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
async function run() {
if (process.env.ORCA_STUB_PROGRESSIVE === '1') {
const remaining = Math.max(0, Number(process.env.ORCA_STUB_EXIT_AT_MS) - Date.now())
const step = remaining / 3
await sleep(step)
process.stdout.write('one')
await sleep(step)
process.stdout.write('two')
await sleep(step)
process.stdout.write('three')
return
}
await sleep(Number(process.env.ORCA_STUB_SLEEP_MS))
process.stdout.write('done')
}
void run()
`
)
await chmod(script, 0o755)
return {
cwd,
env: { ...process.env, PATH: `${binDir}${path.delimiter}${process.env.PATH ?? ''}` }
}
}
describe.skipIf(process.platform === 'win32')('git read timeout behavior', () => {
it('allows a progressively streaming read that exits at 0.9 times the deadline', async () => {
const fixture = await createTimedGitFixture()
let output = ''
await expect(
gitStreamStdout(['status', '--porcelain=v2'], {
...fixture,
env: {
...fixture.env,
ORCA_STUB_PROGRESSIVE: '1',
ORCA_STUB_EXIT_AT_MS: String(Date.now() + 900)
},
timeoutMsForTest: 1000,
onStdout: (chunk) => {
output += chunk
}
})
).resolves.toEqual({ stoppedEarly: false })
expect(output).toBe('onetwothree')
})
it('rejects a silent read at 1.1 times the deadline with a typed error', async () => {
const fixture = await createTimedGitFixture()
await expect(
gitExecFileAsync(['status', '--porcelain=v2'], {
...fixture,
env: { ...fixture.env, ORCA_STUB_SLEEP_MS: '110' },
timeoutMsForTest: 100
})
).rejects.toBeInstanceOf(GitCommandTimeoutError)
})
it('times out a silent streaming read with the same typed error', async () => {
const fixture = await createTimedGitFixture()
await expect(
gitStreamStdout(['status'], {
...fixture,
env: { ...fixture.env, ORCA_STUB_SLEEP_MS: '110' },
timeoutMsForTest: 100,
onStdout: () => {}
})
).rejects.toBeInstanceOf(GitCommandTimeoutError)
})
it('applies the read default to binary blob reads', async () => {
const fixture = await createTimedGitFixture()
await expect(
gitExecFileAsyncBuffer(['show', 'HEAD:file.bin'], {
...fixture,
env: { ...fixture.env, ORCA_STUB_SLEEP_MS: '110' },
timeoutMsForTest: 100
})
).rejects.toBeInstanceOf(GitCommandTimeoutError)
})
it.each([['fetch'], ['checkout'], ['unrecognized-command']])(
'does not default-timeout the fail-safe %s class',
async (subcommand) => {
const fixture = await createTimedGitFixture()
await expect(
gitExecFileAsync([subcommand], {
...fixture,
env: { ...fixture.env, ORCA_STUB_SLEEP_MS: '110' },
timeoutMsForTest: 100
})
).resolves.toMatchObject({ stdout: 'done' })
}
)
})
describe.skipIf(process.platform === 'win32' || process.env.ORCA_RUN_SLOW_GIT_SMOKE !== '1')(
'slow git read timeout smoke',
() => {
it('allows a 90 second read and terminates a 130 second wedge', async () => {
const fixture = await createTimedGitFixture()
await expect(
gitExecFileAsync(['status'], {
...fixture,
env: { ...fixture.env, ORCA_STUB_SLEEP_MS: '90000' }
})
).resolves.toMatchObject({ stdout: 'done' })
await expect(
gitExecFileAsync(['status'], {
...fixture,
env: { ...fixture.env, ORCA_STUB_SLEEP_MS: '130000' }
})
).rejects.toBeInstanceOf(GitCommandTimeoutError)
}, 230_000)
}
)