[codex] core: restore absolute turn context cwd (#28629)

## Why

#28152 jumped the gun on moving the rollout format to store URIs, and
would likely break compat with some features that don't go through the
same types as the core logic.

## What

Make `TurnContextItem.cwd` an `AbsolutePathBuf` again, remove test added
for `PathUri` serialization in rollouts. Also drops a bunch of error
paths that are no longer needed.
This commit is contained in:
Adam Perry @ OpenAI
2026-06-16 19:05:26 -07:00
committed by GitHub
parent 69bc0645ac
commit 3d02c443bc
21 changed files with 142 additions and 282 deletions
@@ -380,12 +380,12 @@ impl EnvironmentContext {
pub(crate) fn diff_from_turn_context_item(
before: &TurnContextItem,
after: &EnvironmentContext,
) -> std::io::Result<Self> {
) -> Self {
let before_network = Self::network_from_turn_context_item(before);
let before_filesystem = Self::filesystem_from_turn_context_item(before)?;
let before_filesystem = Self::filesystem_from_turn_context_item(before);
let environments = match &after.environments {
EnvironmentContextEnvironments::Single(environment) => {
if before.cwd != environment.cwd {
if PathUri::from_abs_path(&before.cwd) != environment.cwd {
EnvironmentContextEnvironments::Single(EnvironmentContextEnvironment::legacy(
environment.cwd.clone(),
environment.shell.clone(),
@@ -409,14 +409,14 @@ impl EnvironmentContext {
} else {
before_filesystem
};
Ok(EnvironmentContext::new_with_environments(
EnvironmentContext::new_with_environments(
environments,
after.current_date.clone(),
after.timezone.clone(),
network,
filesystem,
/*subagents*/ None,
))
)
}
pub(crate) fn from_turn_context(turn_context: &TurnContext, shell: &Shell) -> Self {
@@ -440,18 +440,18 @@ impl EnvironmentContext {
pub(crate) fn from_turn_context_item(
turn_context_item: &TurnContextItem,
shell: String,
) -> std::io::Result<Self> {
Ok(Self::new_with_environments(
) -> Self {
Self::new_with_environments(
EnvironmentContextEnvironments::from_vec(vec![EnvironmentContextEnvironment::legacy(
turn_context_item.cwd.clone(),
PathUri::from_abs_path(&turn_context_item.cwd),
shell,
)]),
turn_context_item.current_date.clone(),
turn_context_item.timezone.clone(),
Self::network_from_turn_context_item(turn_context_item),
Self::filesystem_from_turn_context_item(turn_context_item)?,
Self::filesystem_from_turn_context_item(turn_context_item),
/*subagents*/ None,
))
)
}
pub(crate) fn with_subagents(mut self, subagents: String) -> Self {
@@ -498,11 +498,11 @@ impl EnvironmentContext {
fn filesystem_from_turn_context_item(
turn_context_item: &TurnContextItem,
) -> std::io::Result<Option<FileSystemContext>> {
Ok(Some(FileSystemContext::from_permission_profile(
&turn_context_item.permission_profile()?,
) -> Option<FileSystemContext> {
Some(FileSystemContext::from_permission_profile(
&turn_context_item.permission_profile(),
&workspace_roots_from_turn_context_item(turn_context_item),
)))
))
}
}
@@ -513,12 +513,7 @@ fn workspace_roots_from_turn_context_item(
return workspace_roots.clone();
}
// Older rollout items did not persist workspace roots. Fall back to the
// legacy cwd binding only when reconstructing that historical context.
match turn_context_item.cwd.to_abs_path() {
Ok(cwd) => vec![cwd],
Err(_) => Vec::new(),
}
vec![turn_context_item.cwd.clone()]
}
impl ContextualUserFragment for EnvironmentContext {
@@ -190,7 +190,7 @@ fn turn_context_item_filesystem_uses_workspace_roots_instead_of_cwd() {
let repo_private = repo.join("private");
let item = TurnContextItem {
turn_id: None,
cwd: PathUri::from_abs_path(&test_abs_path("/not-the-workspace")),
cwd: test_abs_path("/not-the-workspace"),
workspace_roots: Some(vec![repo.clone(), other_repo.clone()]),
current_date: None,
timezone: None,
@@ -209,9 +209,7 @@ fn turn_context_item_filesystem_uses_workspace_roots_instead_of_cwd() {
summary: codex_protocol::config_types::ReasoningSummary::Auto,
};
let context = EnvironmentContext::from_turn_context_item(&item, fake_shell_name())
.expect("turn context should hydrate")
.render();
let context = EnvironmentContext::from_turn_context_item(&item, fake_shell_name()).render();
assert!(
context.contains(&format!(