Skip to content

Persist inherited environment removals - #144

Merged
myobie merged 2 commits into
mainfrom
schickling-assistant/2026-07-31-2026-07-31-persisted-env-unset
Jul 31, 2026
Merged

Persist inherited environment removals#144
myobie merged 2 commits into
mainfrom
schickling-assistant/2026-07-31-2026-07-31-persisted-env-unset

Conversation

@schickling-assistant

@schickling-assistant schickling-assistant commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Why

An environment variable that was intentionally absent when a session was created can appear after pty restart or a permanent respawn because the replacement inherits the restarter's ambient environment. Assignments already have a persisted --env representation; removals did not.

Closes #143.

What

  • add repeatable pty run --unset-env KEY and programmatic unsetEnv?: string[];
  • persist removals in session metadata and carry them through manual restart, run -a, bundled CLI delegation, and permanent respawn;
  • document the optional metadata field, child PTY_SESSION/TERM invariants, and regenerate shell completions.

Rationale

Environment assembly remains one ordered policy: inherit (or isolate), remove unsetEnv keys, then apply explicit extraEnv assignments. This makes assignment precedence independent of CLI flag order. Exact env remains mutually exclusive with inherited-environment policy. Older metadata omits unsetEnv and keeps the previous ambient-inheritance behavior.

Validation

  • bun run typecheck
  • bun run build
  • 71 focused tests covering manual restart, run -a recreation, permanent respawn, isolate/remove/assignment precedence, exact-env exclusion, bundled CLI delegation, help, generated completions, and storage-doc drift
  • documentation examples: 12/13 passed; the existing interactive Vim example timed out at its 10-second host boundary

Validated head: c0a1e636aea2ba3ce71dc0e72942394fb7f4fe25.

Posted on behalf of @schickling
field value
agent_name co1-sage
agent_session_id ed878dac-3735-4276-b3e0-ea1b1cd65291
agent_tool Codex CLI
agent_tool_version 0.145.0
agent_runtime Codex CLI 0.145.0
agent_model unknown
runtime_profile /nix/store/mnx8agbdq3wiyb6vz63lhgscgazkrn98-coding-agent-runtime-profile/share/coding-agents/profile.json
skills_manifest /nix/store/5r69m9k2llmri3na81518zx0a7y0d3cn-agent-skills-corpus/share/agent-skills/manifest.json
worktree pty/schickling-assistant/2026-07-31-2026-07-31-persisted-env-unset
machine dev3
tooling_profile dotfiles@0fb7e03

@myobie myobie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact review green at c0a1e63. Removal-before-assignment precedence, exact-env exclusion, restart/permanent persistence, CLI fallback, docs, completions, backward compatibility, and hosted gates agree.

@myobie
myobie merged commit 39e6426 into main Jul 31, 2026
2 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/server.ts
...(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 } : {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@schickling-assistant

Copy link
Copy Markdown
Contributor Author

Thank you, Nathan — this became a genuinely reusable lifecycle primitive instead of a one-off NO_COLOR exception. Persisted removals make restart behavior deterministic for every inherited environment flag.

thank-you celebration

Posted on behalf of @schickling
field value
agent_name co1-sage
agent_session_id ed878dac-3735-4276-b3e0-ea1b1cd65291
agent_tool Codex CLI
agent_tool_version 0.145.0
agent_runtime Codex CLI 0.145.0
agent_model unknown
runtime_profile /nix/store/mnx8agbdq3wiyb6vz63lhgscgazkrn98-coding-agent-runtime-profile/share/coding-agents/profile.json
skills_manifest /nix/store/5r69m9k2llmri3na81518zx0a7y0d3cn-agent-skills-corpus/share/agent-skills/manifest.json
worktree pty/main
machine dev3
tooling_profile dotfiles@0fb7e03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persist inherited environment removals across restart

2 participants