Skip to content

[2/3] core: track starting environments in snapshots#28683

Merged
sayan-oai merged 5 commits into
mainfrom
codex/turn-environment-starting-snapshots
Jun 19, 2026
Merged

[2/3] core: track starting environments in snapshots#28683
sayan-oai merged 5 commits into
mainfrom
codex/turn-environment-starting-snapshots

Conversation

@sayan-oai

@sayan-oai sayan-oai commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Why

Remote environments may still be resolving when Codex creates a session or turn. Waiting for the existing all-or-nothing environment snapshot can hold startup until the selected environment is usable.

Behind the default-off deferred_executor feature, let callers take a useful snapshot immediately: completed environments remain available normally, while unfinished environments are reported without blocking startup. With the feature disabled, snapshots preserve the existing blocking behavior.

Depends on #28674.

What changed

  • Store one ordered list of selected environments in ThreadEnvironments. Each selection owns one shared resolution that produces its complete TurnEnvironment.
  • Start new resolutions in the background with remote_handle(), allowing snapshots and the future wait tool to share the same result while cancellation follows the retained handles.
  • Make snapshot() a read-only operation: nonblocking snapshots collect completed resolutions and retain handles for unfinished ones, while blocking snapshots await every resolution.
  • Replace completed failed resolutions from the current manager entry and log when failed environments are omitted.
  • Return attached and starting environments as a point-in-time view, and count starting environments when deciding whether a snapshot is local-only.
  • Keep existing consumers attached-only. to_selections() derives from attached environments, so child threads do not inherit an environment that is still starting.

Test plan

  • just test -p codex-core environment_selection
  • just test -p codex-core deferred_executor_reaches_model_before_remote_environment_is_ready

Landing note

Keep deferred_executor disabled for slow-starting executors until configurable environment/add connection timeouts and caller support land. When enabled, an environment that attaches after session startup may remain absent from environment-derived model context, tools, instructions, skills, and related state until follow-up refresh work lands.

@sayan-oai sayan-oai changed the title [codex] Track starting environments in snapshots [2/2] core: Track starting environments in snapshots Jun 17, 2026
@sayan-oai sayan-oai changed the title [2/2] core: Track starting environments in snapshots [2/2] core: track starting environments in snapshots Jun 17, 2026
@sayan-oai sayan-oai marked this pull request as ready for review June 17, 2026 07:30
@sayan-oai sayan-oai requested a review from a team as a code owner June 17, 2026 07:30
@sayan-oai

Copy link
Copy Markdown
Collaborator 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: e9cd1c8697

ℹ️ 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 codex-rs/core/src/environment_selection.rs Outdated
Comment thread codex-rs/core/src/environment_selection.rs
Comment thread codex-rs/core/src/environment_selection.rs Outdated
Comment thread codex-rs/core/src/environment_selection.rs Outdated
@sayan-oai sayan-oai force-pushed the codex/remote-environment-connection-lifecycle branch from ff3f3a6 to f4f57bb Compare June 18, 2026 01:06
@sayan-oai sayan-oai force-pushed the codex/turn-environment-starting-snapshots branch from e9cd1c8 to fea9d37 Compare June 18, 2026 04:02
Comment thread codex-rs/core/src/environment_selection.rs Outdated
Comment thread codex-rs/core/src/environment_selection.rs Outdated

@jif-oai jif-oai 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.

I think the state machine we're trying to build here is not fully closed... this illustrate well my concerns on the difficulty to handle failure modes

Some(Err(_)) => {}
None => starting.push(StartingTurnEnvironment {
selection: environment.selection.clone(),
resolution: environment.resolution.clone(),

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.

Doesn't this make the remote’s AGENTS.md disappear for the whole loaded session, not just the turn that races startup?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yep. the end state is going to be having these react to env readiness changes and get injected. that will be in a follow up, so i added a deferred_executor feature flag so we can land stuff incrementally without causing issues for existing testing.

Comment thread codex-rs/core/src/environment_selection.rs
Comment thread codex-rs/core/src/environment_selection.rs Outdated
@sayan-oai sayan-oai force-pushed the codex/remote-environment-connection-lifecycle branch from f4f57bb to 918b9bc Compare June 18, 2026 20:46
@sayan-oai sayan-oai force-pushed the codex/turn-environment-starting-snapshots branch 2 times, most recently from 77c7b18 to aad2139 Compare June 19, 2026 01:50
@sayan-oai sayan-oai changed the title [2/2] core: track starting environments in snapshots [2/3] core: track starting environments in snapshots Jun 19, 2026
Comment thread codex-rs/core/src/environment_selection.rs Outdated
Comment thread codex-rs/core/src/environment_selection.rs Outdated
Comment thread codex-rs/core/src/environment_selection.rs Outdated
Comment thread codex-rs/core/src/environment_selection.rs Outdated
Comment thread codex-rs/core/src/environment_selection.rs
Base automatically changed from codex/remote-environment-connection-lifecycle to main June 19, 2026 04:50
@sayan-oai sayan-oai force-pushed the codex/turn-environment-starting-snapshots branch from 253a6ba to bb8869d Compare June 19, 2026 04:52
@sayan-oai sayan-oai enabled auto-merge (squash) June 19, 2026 04:55
@sayan-oai sayan-oai merged commit 45a133b into main Jun 19, 2026
31 checks passed
@sayan-oai sayan-oai deleted the codex/turn-environment-starting-snapshots branch June 19, 2026 05:06
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants