Skip to content

core: reuse parent shell snapshot for thread-spawn subagents#13052

Merged
daveaitel-openai merged 1 commit intomainfrom
exp/parent-shell-snapshot-reuse
Mar 2, 2026
Merged

core: reuse parent shell snapshot for thread-spawn subagents#13052
daveaitel-openai merged 1 commit intomainfrom
exp/parent-shell-snapshot-reuse

Conversation

@daveaitel-openai
Copy link
Contributor

@daveaitel-openai daveaitel-openai commented Feb 27, 2026

Summary

  • reuse the parent shell snapshot when spawning/forking/resuming SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. }) sessions
  • plumb inherited snapshot through AgentControl -> ThreadManager -> Codex::spawn -> SessionConfiguration
  • skip shell snapshot refresh on cwd updates for thread-spawn subagents so inherited snapshots are not replaced

Why

  • avoids per-subagent shell snapshot creation and cleanup work
  • keeps thread-spawn subagents on the parent snapshot path, matching the intended parent/child snapshot model

Validation

  • just fmt (in codex-rs)
  • cargo test -p codex-core --no-run
  • cargo test -p codex-core spawn_agent -- --nocapture
  • cargo test -p codex-core --test all suite::agent_jobs::spawn_agents_on_csv_runs_and_exports

Notes

  • full cargo test -p codex-core --test all was left running separately for broader verification

Pass the parent session's shell snapshot into spawned/resumed/forked thread-spawn subagents so they bootstrap from inherited shell state instead of creating a fresh snapshot.

Also skip shell snapshot refresh on cwd changes for thread-spawn subagents, so inherited snapshots are not replaced during child-session updates.

Co-authored-by: Codex <noreply@openai.com>
@daveaitel-openai daveaitel-openai enabled auto-merge (squash) February 27, 2026 21:52
return;
}

if matches!(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This means we never refresh the shell snapshot. But what if a sub-agent change cwd for example? In this case we need to be able to refresh it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a really good point and I'm not sure how to address it yet.

agent_control: AgentControl,
session_source: SessionSource,
persist_extended_history: bool,
inherited_shell_snapshot: Option<Arc<ShellSnapshot>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the end we will have to pack all those things in a struct instead of having to wire those agrs everywhere but we can do as a follow-up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agree.

@daveaitel-openai daveaitel-openai merged commit c2e126f into main Mar 2, 2026
89 of 107 checks passed
@daveaitel-openai daveaitel-openai deleted the exp/parent-shell-snapshot-reuse branch March 2, 2026 15:53
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 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.

2 participants