Repository navigation
fix(agents): honor environment prefixes in generation commands - #22427
Conversation
Adapted from the proposal by @carlosbaraza. Co-authored-by: carlosbaraza <carlosbaraza@users.noreply.github.com>
|
Warning Review limit reachedNext included review available in 24 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (18)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
|
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline, plus two nitpicks.
Reviewed changes
- Leading assignment parser — new
command-environment.tsextractsNAME=valueprefixes as data (extractLeadingEnvAssignments) and merges them platform-aware (mergeCommandEnvironment, which uppercases all keys onwin32). - Plan plumbing —
planAgentBinary(moved toagent-command-plan.ts) andplanCustomCommandnow strip leading assignments and carry them asenvthroughCommitMessagePlanandplanModelDiscovery. - Local execution — native merges
plan.envinto the child env; WSL leavesenvunmerged and applies assignments in the guest via/usr/bin/env KEY=value binary ...after the login shell. - Remote execution —
SshGitNoninteractiveProviderforwardsplan.env; the relayAgentExecHandlerfolds it overprocess.envand re-runs the Git indexed-config protocol merge. - Codex home lock —
resolveCodexHomeProcessLockKeyForSpawnEnvnow acceptscommandEnvand prefers an explicitly assigned guestCODEX_HOME. - Tests — parser/merge units, real-child native tests, a mocked WSL argv test, the relay casing case, and the SSH provider forwarding case.
The env-once-per-path diagram holds: native callers always pre-merge env and the native branch ignores commandEnv, WSL does the opposite, so an assignment is applied exactly once. I verified every production caller of runLocalSourceControlPlan/discoverModelsLocal/runLocalPlanForAgent — none drops an assignment.
ℹ️ Nitpicks
SpawnSourceControlAgent.commandEnvis consumed only by the WSL branch ofspawnSourceControlAgent; on native it is dead input, and the invariant that both callers pre-mergeplan.envintoenvis implicit. A one-line comment on the type or the native branch would keep a future caller from assumingcommandEnvalone works natively.- The WSL test mocks
wslAwareSpawn, so it asserts the argv it hands over rather than literal preservation — the shell-safety that actually keeps$HOME/$(...)from expanding lives inresolveCommand/quotePosixShelland isn't exercised. The process test covers native, but the title's WSL claim is untested end-to-end (the PR body already notes no native WSL run).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The delta since the prior pullfrog review (5170a86) is the test-and-comment commit 54da185; no production behavior changed.
- Windows environment-key coverage — a new relay test pins mixed-case override folding (
Path→PATH,token→TOKEN) and verifies the indexed Git-config protocol discards stale inherited indices (GIT_CONFIG_KEY_1/VALUE_1) when a smaller override count arrives. I confirmed it fails against the pre-fixmergeGitConfigEnvProtocol(process.env, extraEnv)and passes at head. - Inherited-env assertion normalized — the pass-through test now stubs a dedicated
ORCA_EXEC_INHERITEDvalue instead of spreading...process.env, so it no longer depends on Windows key spelling. ComSpecpreservation pinned — the merge unit test now asserts a mixed-case inherited key survives asCOMSPECon win32.- Native/WSL contract comment —
SpawnSourceControlAgent.commandEnvdocuments that WSL applies assignments in the guest while native callers pre-merge them intoenv.
The prior inline concern (whole-environment uppercasing on Windows) was answered as deliberate normalization, with the affected assertion normalized and a regression test added, so that thread is retired. The five touched test files pass (34 tests).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
A command such as VAR=value agent should run the agent with that variable, instead of looking for a program named VAR=value.
What Changed
Extract leading assignments after command tokenization and carry them as data through generation and model discovery. Merge variables on the execution host, fold Windows environment names consistently, apply WSL assignments after login startup and keep Codex home locks tied to the effective home.
Why
Using the existing argv planner avoids shell evaluation and keeps literal values, Windows casing and remote-host ownership explicit. The command planner is split into a small module to stay within the file-size gate.
Linked Issue
Related to @carlosbaraza’s #5363.
Visual Proof
Historical hidden-renderer proof from audit baseline
6ae5ef2d0031. A synthetic agent returns the fixed response through production Source Control UI; no paid agent request. These images illustrate unchanged behavior after the current-main merge.Before:

After:

Testing
262 tests pass across 24 files on macOS; Node typecheck and changed-code quality pass. After the review follow-up, 26 focused environment tests and changed-code quality pass. The combined-source suite with the SSH login-shell change exercises the real parser and relay handler: 292 pass, two Windows-only cases skip. Earlier audit included Windows/Linux process fixtures; this pass does not claim native WSL, full SSH transport or paid-agent integration.
All tests used
ORCA_BACKGROUND_LAUNCH=1; no visible test window or real agent account was launched. Full lint, test suite and release packaging remain CI coverage.Review
Current-head CI (
54da185953d7) is green, including required PR Checksverify, changed-spec E2E and Docker SSH E2E. One targeted retry cleared an unrelated scan-cache call-count failure; the unchanged failing case passed locally, and the environment parent’s full runtime suite passed 1,294 tests with one skip.Pullfrog’s current-head review at
54da185953d7is clean. The Windows casing thread is resolved: deliberate normalization remains, tests no longer assume inherited key spelling, and mixed-caseComSpecpreservation is covered.Independently reviewed literal argv/environment handling, host ownership, Windows casing, WSL forwarding, cancellation/cleanup and mixed-version fallback. The original integration base was
996f9cc3068c.Agent skill upstream boundary
Notes
The SSH login-shell PR #22428 builds on this PR and must merge after it. Literal assignment values are never shell-expanded; variables after the executable remain arguments.
Checklist