Repository navigation
fix(codex): pair structured launches with the CLI runtime #32061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cadd671
fix(codex): pair structured launches with the CLI runtime
nwparker 4f1cbc7
test(codex): align launch snapshots with runtime pairing
nwparker 6b1ec55
fix(agent-session): keep this app's CLI ahead of the paired runtime dir
nwparker cd3d6c4
fix(cli-runtime): skip compiled CLIs and keep inherited PATH when pai…
nwparker 63d6b63
test(cli-runtime): type the PATH-less env fixture
nwparker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { closeSync, openSync, readSync } from 'node:fs' | ||
|
|
||
| const NATIVE_EXECUTABLE_MAGIC = [ | ||
| [0x7f, 0x45, 0x4c, 0x46], // ELF | ||
| [0xcf, 0xfa, 0xed, 0xfe], // Mach-O 64-bit | ||
| [0xce, 0xfa, 0xed, 0xfe], // Mach-O 32-bit | ||
| [0xca, 0xfe, 0xba, 0xbe], // Mach-O universal | ||
| [0x4d, 0x5a] // Windows PE | ||
| ] | ||
|
|
||
| /** A compiled binary runs on no `node`, so pairing would only reorder PATH (Homebrew, /usr/bin). */ | ||
| export function isNativeExecutable(commandPath: string): boolean { | ||
| let fd: number | null = null | ||
| try { | ||
| fd = openSync(commandPath, 'r') | ||
| const head = Buffer.alloc(4) | ||
| const read = readSync(fd, head, 0, head.length, 0) | ||
| return NATIVE_EXECUTABLE_MAGIC.some( | ||
| (magic) => read >= magic.length && magic.every((byte, index) => head[index] === byte) | ||
| ) | ||
| } catch { | ||
| return false | ||
| } finally { | ||
| if (fd !== null) { | ||
| closeSync(fd) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Why: Win32 resolves env names case-insensitively and object order preserves | ||
| // the block order, so the entry the child will actually read is the FIRST | ||
| // case-insensitive match — not necessarily `Path` or `PATH`. Reading a narrower | ||
| // set than withCliRuntimeOnPath's twin dedupe deletes would destroy a third spelling unread. | ||
| // Mirrors resolvePathEnvKey in src/main/pty/windows-path-segment-merge.ts, which | ||
| // src/shared must not import. | ||
| export function firstWindowsPathEnvKey(env: NodeJS.ProcessEnv): string { | ||
| for (const key of Object.keys(env)) { | ||
| if (key.toLowerCase() === 'path' && env[key] !== undefined) { | ||
| return key | ||
| } | ||
| } | ||
| return 'Path' | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: stablyai/orca
Length of output: 41239
🌐 Web query:
Node.js 24 child_process spawn env Windows case insensitive duplicate PATH keys lexicographic sorted first only💡 Result:
🏁 Script executed:
Repository: stablyai/orca
Length of output: 10420
🏁 Script executed:
Repository: stablyai/orca
Length of output: 1655
Select the Windows PATH key using Node’s spawn ordering.
When both keys exist with different values,
firstWindowsPathEnvKeyselectsPathby insertion order, but Node 24 selectsPATHlexicographically. The pairing routine then modifiesPathand deletesPATH, so the structured child can lose directories from the effective PATH and fail to find commands. This is limited to duplicate case variants with different values.Suggested fix
Update the duplicate-key test to expect only
PATHand to preserve the originalPATHvalue, prefixed with the runtime directory.📝 Committable suggestion