Repository navigation
Give agents the user's login-shell env and the worktree's direnv env (#320) - #1693
Conversation
Solenta-Message-Id: 1e89f910-54d3-4b87-b9ad-bf283d1588f3
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7151f199c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try { | ||
| // ENOENT (direnv not installed) lands in the r.err branch below. | ||
| let r = await direnv(cwd, ["export", "json"]); | ||
| if (/is blocked/.test(r.stderr) && inheritsAllow(cwd, opts.mainPath || "")) { |
There was a problem hiding this comment.
Detect blocked envrcs without parsing configurable logs
When a user customizes DIRENV_LOG_FORMAT or sets [global] log_format = "-", the error output may omit the literal is blocked, so an identical worktree .envrc never inherits the main checkout's authorization and every agent starts without its direnv environment. Direnv explicitly allows its output format to be changed or disabled in the direnv configuration documentation; use the failed exit status plus the independently verified inheritsAllow result rather than matching human-readable stderr.
Useful? React with 👍 / 👎.
| for (const [k, v] of Object.entries(JSON.parse(r.stdout))) { | ||
| env[k] = typeof v === "string" ? v : undefined; | ||
| } | ||
| loaded.set(cwd, env); |
There was a problem hiding this comment.
Prevent cancelled loads from overwriting newer environments
If a user stops a run while a slow direnv evaluation is in progress and immediately starts another run in the same worktree, the stopped run's execFile continues in the background. If it completes after the newer load, this unconditional write replaces the fresh cache entry with the old environment; subsequent awaits before provider dispatch can then cause the new agent to receive stale variables. Associate each load with a generation or actually terminate/ignore cancelled evaluations before updating loaded.
Useful? React with 👍 / 👎.
| if (wfProject && !isRemoteProject(wfProject)) { | ||
| await loadDirenv(wfThread.worktreePath || wfProject.path, { mainPath: wfProject.path }); | ||
| } |
There was a problem hiding this comment.
Load direnv before retrying workflow agents
The new direnv load is limited to startWorkflowRun, while retryWorkflowAgent invokes the workflow engine through a separate path. After an application restart the persisted workflow can still be retried, but the in-memory direnv cache is empty, so every withProjectEnv(..., cwd) call in the retried phase contributes no direnv variables; even without a restart, edits to .envrc since the original workflow remain stale. Apply the same load step to the retry entry point.
Useful? React with 👍 / 👎.
…ser-s-real-shell-environm-750222 # Conflicts: # electron/runner.js
Agents now start with the same environment a terminal opened in the worktree would have. That covers vars from
~/.zshrc, SSH/GPG agent sockets, LANG, version managers, and the worktree's direnv /use flakeenv. Before this, only PATH came from the login shell, so a GUI launch dropped everything else. Closes #320.Changes
env -0, and any var the rc files added or changed lands inprocess.env. Every spawn builds onprocess.env, so agents, git and terminals all get it. Shell bookkeeping (PWD,SHLVL, …) and aGPG_TTYof "not a tty" are skipped. These vars are not written to the PATH cache, because rc files often export tokens.direnv export jsonin the worktree.withProjectEnvthen layers the result underproject.envand the provider overlay, for all providers and workflow agents. Stop cancels the wait, remote/WSL projects are skipped, and a missingdirenvor.envrcadds nothing..envrcis already allowed and the worktree's copy is byte-identical, Solenta runsdirenv allowfor the worktree. An.envrcthe branch changed stays blocked.Verification
electron/test/pathenv.test.js(env parsing, the diff/skip rules, no tokens in the cache) andelectron/test/direnvEnv.test.js(a fake direnv: layering, null unsets, remote skip, allow inheritance for identical vs edited.envrc). Both pass./tmp→/private/tmp), and a worktree with an identical.envrcloadsFOO=barend to end.tsc --noEmit: no new errors. The only remaining errors come from deps missing in my local node_modules.test:electron: first run cut off partway. 4 files failed in it; 3 pass when rerun alone (load), and the 4th (attachmentsPDF) needspdfjs-dist, which my local node_modules lacks (file untouched here). A full rerun is in progress; CI is the gate.Notes for reviewers
SSH_AUTH_SOCK). That's intended: it's what a terminal sees.use flakecan hold run start for up to 60 s with no work-log step. Later loads hit nix-direnv's cache.direnv denyon the worktree path itself; Solenta creates those paths, so I expect that to be rare.gpgon PATH,GNUPGHOMEand the agent socket now come through. Pinentry still needs a GUI pinentry (pinentry-mac) since agents have no TTY. Seatbelt-sandboxed threads still can't write~/.gnupg; I left that alone on purpose..envrcnever reaches the worktree, so it isn't loaded.🤖 Generated with Claude Code