Skip to content

[codex] Bind shell snapshots to retained thread environments - #28421

Merged
pakrym-oai merged 3 commits into
mainfrom
pakrym/full-ci-shell-snapshot-environments
Jun 16, 2026
Merged

[codex] Bind shell snapshots to retained thread environments#28421
pakrym-oai merged 3 commits into
mainfrom
pakrym/full-ci-shell-snapshot-environments

Conversation

@pakrym-oai

Copy link
Copy Markdown
Contributor

Why

Shell snapshots are currently session-scoped even though shell and cwd are properties of a selected turn environment. That makes snapshot refresh depend on separate session-cwd plumbing, prevents retained environments from retaining their snapshot work, and can make snapshot construction use a different shell than command execution.

This follows #27955 by making the retained thread-environment service own environment snapshot lifecycles. Session configuration remains the requested selection state, while ThreadEnvironments remains the source of successfully resolved environments.

What changed

  • Configure the shell-snapshot builder before initial environment resolution.
  • Start each local environment snapshot task when its TurnEnvironment is built and retain that shared task while environment ID and cwd still match.
  • Inherit retained environment snapshots into spawned child threads.
  • Carry the selected TurnEnvironment through shell runtimes so snapshot construction and command execution use the same environment-specific shell and cwd.
  • Load project instructions and warm plugins/skills after initial environment resolution.
  • Continue decoding invalid UTF-8 instruction files lossily without emitting a startup warning.
  • Keep requested selections in SessionConfiguration; failed or duplicate resolutions only affect the resolved environment snapshot.

Validation

  • cargo check -p codex-core --tests
  • just test -p codex-home instructions (6 passed)
  • Focused environment, instruction, shell-snapshot, and user-shell tests (84 passed)
  • Focused shell-snapshot, user-shell, and unified-exec tests (126 passed; two event-timing tests passed on retry)

@@ -48,12 +48,6 @@ impl CodexHomeUserInstructionsProvider {
continue;
}
};
if let Err(err) = std::str::from_utf8(&data) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this warning wasn't worth the complexity of carrying it around

@pakrym-oai
pakrym-oai force-pushed the pakrym/full-ci-shell-snapshot-environments branch 2 times, most recently from 828233c to 9480a13 Compare June 16, 2026 01:18
@pakrym-oai
pakrym-oai force-pushed the pakrym/full-ci-shell-snapshot-environments branch from 9480a13 to a6b4a55 Compare June 16, 2026 01:31
@pakrym-oai
pakrym-oai marked this pull request as ready for review June 16, 2026 01:40
@pakrym-oai
pakrym-oai requested a review from a team as a code owner June 16, 2026 01:40
@pakrym-oai

Copy link
Copy Markdown
Contributor Author

@codex review this

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

Copy link
Copy Markdown
Contributor

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: a6b4a554b7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/core/src/tools/runtimes/unified_exec.rs
Comment thread codex-rs/core/src/shell_snapshot.rs
Comment thread codex-rs/core/src/session/session.rs
@pakrym-oai

Copy link
Copy Markdown
Contributor Author

@codex review this

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

Copy link
Copy Markdown
Contributor

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: 6577a4e8f6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/core/src/agent/control.rs
Comment thread codex-rs/core/src/session/session.rs
Comment on lines +540 to +542
.turn_environments
.snapshot()
.await,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Add integration coverage for subagent environment inheritance

This agent logic now inherits the parent TurnEnvironmentSnapshot, but I found no core/suite test_codex coverage that spawns a subagent and verifies inherited turn environments/shell snapshots; please add it, per guidance.

Useful? React with 👍 / 👎.

Comment on lines 310 to 313
maybe_wrap_shell_lc_with_snapshot(
base_command,
session_shell.as_ref(),
shell,
shell_snapshot_location.as_ref(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Prefix PowerShell commands based on the environment shell

When unified exec targets a PowerShell turn environment while the host/session shell is not PowerShell (for example a remote Windows environment or an inherited parent environment), this path now builds the command with shell but the UTF-8 PowerShell prefix check just below still uses session_shell. Those commands will skip the PowerShell UTF-8 wrapper even though they are executed by PowerShell, unlike ShellRuntime which checks the selected environment shell.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

existing bug, will followup

@pakrym-oai
pakrym-oai merged commit 022f122 into main Jun 16, 2026
60 of 78 checks passed
@pakrym-oai
pakrym-oai deleted the pakrym/full-ci-shell-snapshot-environments branch June 16, 2026 03:10
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants