Files
orca/config/provider-exec-resources.cjs
Brennan Benson 980352d897 Reduce native chat memory by replacing per-chat Electron supervisors (#42760)
* Launch provider CLIs without a per-chat runtime supervisor

* Initialize process-owner fixtures with an isolated app environment

* Retire provider output transports and failed ownership drafts

* Finish provider stops when the session group empties

* Complete native cleanup from verified watcher exit and cancel held launches

* Let native watcher finish one-shot provider exits

* Retire late ownership records after canceled provider launches settle

* Reap each provider subtree in an isolated native parent

* Preserve provider outcomes and compatibility with native parents

* Publish actual provider identities and retire native parent observers

* Retire numeric writer PIDs when their group is proven absent

* Retire provider transports and accept proven group absence

* Fence retired process identities across asynchronous cleanup

* Use native timer types and readonly process fixtures

* Reuse bounded timeout for compatibility output drain

* Release launch scopes held by late transport error handlers

* Keep processless launch failures out of watcher waits

* Align lifecycle validation with final ownership contracts

* Remove duplicate helper preparation from the dev launcher

* Keep legacy fallback in place and simplify native ownership handoff

* Defer background provider maintenance until the first window

* Release startup hook maintenance for terminal launches

* Use relocated artifact module in native prebuild scripts

* Preserve agent failure outcomes and clean tools before ownership is lost

* Budget ownership capture for its bounded identity reads

* Keep lifecycle regressions at their behavior-owning seam

* Explain the fake-clock process-read fixture

* Capture tool ownership before restart recovery removes the CLI

* Skip descendant inventories for absent provider roots

* Make final output drain regression test deterministic

* Keep output drain fixture assertions type-safe with IPC

* Use existing provider fixtures across Node and Bun

* Prepare native provider helper for Codex contract CI

* Verify provider ownership using its recorded start precision

* Preserve exact provider ownership through reader failures

* Retire exhausted recovery records without blocking watcher cleanup

* Distinguish exited descendants from unreaped zombies

* Preserve group retirement without trusting an exited root

* Keep CLI input owned through native parent loss

* Keep watcher cleanup proof through lost-parent retirement

* Guard retirement against late watcher cleanup proof

* Contain provider launches that fail before stdio setup

* fix(claude): preserve startup diagnostics after input pipe failures

* fix(provider): capture lost outcomes before native completion cleanup

* fix(provider): retire speculative captures after a valid outcome

* fix(provider): share spawn absence classification through its existing boundary
2026-11-16 01:01:24 -08:00

58 lines
1.9 KiB
JavaScript

const { spawnSync } = require('node:child_process')
const { chmodSync, existsSync, lstatSync } = require('node:fs')
const { join } = require('node:path')
const PROVIDER_EXEC_EXECUTABLE = 'orca-provider-exec'
// electron-builder `Arch` enum: x64=1, arm64=3. POSIX provider CLIs cannot launch without it.
function providerExecTarget(platform, archEnum) {
const arch = { 1: 'x64', 3: 'arm64' }[archEnum]
if (!arch || (platform !== 'darwin' && platform !== 'linux')) {
throw new Error(`Unsupported provider exec packaging target: ${platform} ${archEnum}`)
}
return `${platform}-${arch}`
}
function ensureBundledProviderExec(
platform,
archEnum,
root = join(__dirname, '..'),
run = spawnSync
) {
const target = providerExecTarget(platform, archEnum)
const result = run(
process.execPath,
[
join(root, 'config', 'scripts', 'native-build', 'posix', 'build-provider-exec.mjs'),
'--target',
target
],
{ cwd: root, stdio: 'inherit' }
)
if (
result.error ||
result.status !== 0 ||
!existsSync(join(root, 'native', 'provider-exec', '.build', target, PROVIDER_EXEC_EXECUTABLE))
) {
throw new Error(`The ${target} package requires a built provider exec helper.`)
}
}
/** Packaged path the main process resolves; macOS keeps it beside the app executable. */
function packagedProviderExecPath(resourcesDir, platform) {
return platform === 'darwin'
? join(resourcesDir, '..', 'MacOS', PROVIDER_EXEC_EXECUTABLE)
: join(resourcesDir, 'bin', PROVIDER_EXEC_EXECUTABLE)
}
function finalizePackagedProviderExec(resourcesDir, platform) {
const helper = packagedProviderExecPath(resourcesDir, platform)
if (!existsSync(helper) || !lstatSync(helper).isFile()) {
throw new Error(`The ${platform} package is missing its provider exec helper at ${helper}.`)
}
chmodSync(helper, 0o755)
return helper
}
module.exports = { ensureBundledProviderExec, finalizePackagedProviderExec }