Skip to content

Conversation

@bolinfest
Copy link
Collaborator

@bolinfest bolinfest commented Dec 18, 2025

This is some minor API cleanup that will make it easier to use AbsolutePathBuf in more places in a subsequent PR.

@bolinfest bolinfest changed the title feat: migrate to new constraint-based loading strategy chore: prefer AsRef<Path> to &Path Dec 18, 2025
@jif-oai
Copy link
Collaborator

jif-oai commented Dec 18, 2025

@codex review

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Hooray!

ℹ️ 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".

Copy link
Collaborator

@jif-oai jif-oai left a comment

Choose a reason for hiding this comment

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

Just questions on the abstraction but otherwise LGTM

}

fn paths_match(expected: &Path, provided: &Path) -> bool {
fn paths_match<P: AsRef<Path>, Q: AsRef<Path>>(expected: P, provided: Q) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

OOC, why preferring this abstraction over a dyn?
OOC(2), why having both P and Q if they are the same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AsRef<Path> is what I see in the standard library mainly. Chat says I can do impl AsRef<Path>, so maybe I can drop P and Q.

I have both because I discovered that if you use the same letter and pass one as, say, PathBuf and the other as AbsolutePathBuf, then the typechecker fails. (I can double check...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the PR to use impl AsRef<Path>. Maybe I'll ask Codex to try to update the codebase to use this wherever possible...

FYI, so now I have:

pub fn normalize_for_path_comparison(path: impl AsRef<Path>) -> std::io::Result<PathBuf> {
    let canonical = path.as_ref().canonicalize()?;
    Ok(normalize_for_wsl(canonical))
}

But if it were:

pub fn normalize_for_path_comparison(path: &dyn AsRef<Path>) -> std::io::Result<PathBuf> {
    let canonical = path.as_ref().canonicalize()?;
    Ok(normalize_for_wsl(canonical))
}

then this call site no longer compiles:

fn paths_match(a: &Path, b: &Path) -> bool {
    if let (Ok(ca), Ok(cb)) = (
        path_utils::normalize_for_path_comparison(a),
        path_utils::normalize_for_path_comparison(b),
    ) {
        return ca == cb;
    }
    a == b
}

because it fails with:

error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
    --> tui2/src/resume_picker.rs:675:51
     |
 675 |         path_utils::normalize_for_path_comparison(a),
     |                                                   ^ doesn't have a size known at compile-time
     |
     = help: within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`

so I think sticking with impl AsRef<Path> is the way to go?

bolinfest added a commit that referenced this pull request Dec 18, 2025
Over in `config_loader/macos.rs`, we were doing this complicated `mod`
thing to expose one version of `load_managed_admin_config_layer()` for
Mac:


https://github.com/openai/codex/blob/580c59aa9af61cb4bffb5b204bd16a5dcc4bc911/codex-rs/core/src/config_loader/macos.rs#L4-L5

While exposing a trivial implementation for non-Mac:


https://github.com/openai/codex/blob/580c59aa9af61cb4bffb5b204bd16a5dcc4bc911/codex-rs/core/src/config_loader/macos.rs#L110-L117

That was being used like this:


https://github.com/openai/codex/blob/580c59aa9af61cb4bffb5b204bd16a5dcc4bc911/codex-rs/core/src/config_loader/layer_io.rs#L47-L48

This PR simplifies that callsite in `layer_io.rs` to just be:

```rust
    #[cfg(not(target_os = "macos"))]
    let managed_preferences = None;
```

And updates `config_loader/mod.rs` so we only pull in `macos.rs` on Mac:

```rust
#[cfg(target_os = "macos")]
mod macos;
```

This simplifies `macos.rs` considerably, though it looks like a big
change because everything gets unindented and reformatted because we can
drop the whole `mod native` thing now.




---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/8248).
* #8251
* #8249
* __->__ #8248
Base automatically changed from pr8248 to main December 18, 2025 15:35
@bolinfest bolinfest merged commit deafead into main Dec 18, 2025
87 of 95 checks passed
@bolinfest bolinfest deleted the pr8249 branch December 18, 2025 16:50
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2025
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.

5 participants