Files
archived-orca/src/main/codex-cli/codex-home-process-lock.ts
OrcaWin 2847bbe9e8 [comment audit] Consolidate completed code comment cleanup
Combine the completed comment cleanup from 319 stacked PRs into one change against `main`, so the full CI suite validates the combined result once. This replaces the previous audit stack; no additional audit work is included.

The change shortens redundant comments across 2,753 source and shell-snapshot files (25,235 net lines removed). Conflicts preserve current-main executable code. Runtime behavior, test assertions, directives, licenses, generated notices, SAFETY rationales, and compatibility markers are preserved. The audit tracker remains local, outside the repository.

Validation:
- Equivalent source/emitted AST and executable tokens across all 2,750 source files, with separate checks for embedded shell, SQL, JavaScript, CSS, and generated fixtures.
- Identical executable lines in the three shell snapshots; protected comments unchanged.
- Changed-code quality gate passed with no new findings.
- 358 tests passed, 2 skipped across 23 focused test files.
- `git diff --check` passed.
2026-10-23 13:15:45 -07:00

49 lines
1.9 KiB
TypeScript

import { homedir } from 'node:os'
import { join } from 'node:path'
import { normalizeRuntimePathForComparison } from '../../shared/cross-platform-path'
// Serialize Orca-owned spawns per home to prevent refresh-token rotation races; terminals are exempt.
const lockTails = new Map<string, Promise<unknown>>()
export function resolveCodexHomeProcessLockKey(codexHomePath?: string | null): string {
const home = codexHomePath ?? process.env.CODEX_HOME ?? join(homedir(), '.codex')
return normalizeRuntimePathForComparison(home)
}
export function resolveCodexHomeProcessLockKeyForSpawnEnv(
env: NodeJS.ProcessEnv | undefined,
wslDistro?: string | null,
commandEnv?: Record<string, string>
): string {
if (wslDistro) {
// Match buildWslLauncherEnv: only explicit overrides reach WSL; otherwise use its default home.
const codexHome =
commandEnv?.CODEX_HOME ??
(env?.CODEX_HOME !== process.env.CODEX_HOME ? (env?.CODEX_HOME ?? null) : null)
// Normalize Linux homes like probes' UNC paths; the sentinel serializes unknown distro defaults.
return normalizeRuntimePathForComparison(
`//wsl$/${wslDistro}${codexHome ?? '/.orca-default-codex-home'}`
)
}
// Explicit child envs can strip CODEX_HOME; do not restore it from the host environment.
const codexHome = env === undefined ? process.env.CODEX_HOME : env.CODEX_HOME
return normalizeRuntimePathForComparison(codexHome ?? join(homedir(), '.codex'))
}
export function withCodexHomeProcessLock<T>(lockKey: string, fn: () => Promise<T>): Promise<T> {
const prior = lockTails.get(lockKey) ?? Promise.resolve()
const run = prior.then(fn)
// Failed runs must not block later entrants.
const tail = run.then(
() => undefined,
() => undefined
)
lockTails.set(lockKey, tail)
void tail.then(() => {
if (lockTails.get(lockKey) === tail) {
lockTails.delete(lockKey)
}
})
return run
}