Persist inherited environment removals - #144
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0a1e636ae
ℹ️ 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".
| ...(options.displayName ? { displayName: options.displayName } : {}), | ||
| ...(options.isolateEnv ? { isolateEnv: true } : {}), | ||
| ...(options.extraEnv && Object.keys(options.extraEnv).length > 0 ? { extraEnv: options.extraEnv } : {}), | ||
| ...(options.unsetEnv && options.unsetEnv.length > 0 ? { unsetEnv: options.unsetEnv } : {}), |
There was a problem hiding this comment.
Preserve unsetEnv in interactive restarts
When an exited or vanished session is restarted by selecting it in the interactive session manager, src/tui/interactive.ts's doRestart recreates it without passing meta.unsetEnv. Consequently, an environment variable removed by --unset-env can reappear from the TUI process's ambient environment, despite being persisted here and preserved by the CLI and permanent-restart paths. Pass the persisted removal policy through this restart path as well.
Useful? React with 👍 / 👎.
|
Thank you, Nathan — this became a genuinely reusable lifecycle primitive instead of a one-off Posted on behalf of @schickling
|

Why
An environment variable that was intentionally absent when a session was created can appear after
pty restartor a permanent respawn because the replacement inherits the restarter's ambient environment. Assignments already have a persisted--envrepresentation; removals did not.Closes #143.
What
pty run --unset-env KEYand programmaticunsetEnv?: string[];run -a, bundled CLI delegation, and permanent respawn;PTY_SESSION/TERMinvariants, and regenerate shell completions.Rationale
Environment assembly remains one ordered policy: inherit (or isolate), remove
unsetEnvkeys, then apply explicitextraEnvassignments. This makes assignment precedence independent of CLI flag order. Exactenvremains mutually exclusive with inherited-environment policy. Older metadata omitsunsetEnvand keeps the previous ambient-inheritance behavior.Validation
bun run typecheckbun run buildrun -arecreation, permanent respawn, isolate/remove/assignment precedence, exact-env exclusion, bundled CLI delegation, help, generated completions, and storage-doc driftValidated head:
c0a1e636aea2ba3ce71dc0e72942394fb7f4fe25.Posted on behalf of @schickling
agent_nameagent_session_idagent_toolagent_tool_versionagent_runtimeagent_modelruntime_profileskills_manifestworktreemachinetooling_profile