Skip to content

Add ExecPolicyManager#8349

Merged
pakrym-oai merged 5 commits intomainfrom
pakrym/add-execpolicymanager
Dec 22, 2025
Merged

Add ExecPolicyManager#8349
pakrym-oai merged 5 commits intomainfrom
pakrym/add-execpolicymanager

Conversation

@pakrym-oai
Copy link
Copy Markdown
Collaborator

Move exec policy management into services to keep turn context immutable.

Comment thread codex-rs/core/src/codex.rs Outdated
Comment on lines +1031 to +1036
let state = self.state.lock().await;
(
state
.session_configuration
.original_config_do_not_use
.codex_home
.clone(),
state.session_configuration.exec_policy.clone(),
)
state
.session_configuration
.original_config_do_not_use
.codex_home
.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.

I think you can make this one line if you don't want to use the braces to drop the lock:

let codex_home = self.state.lock().await.session_configuration
                .original_config_do_not_use
                .codex_home
                .clone()

Comment thread codex-rs/core/src/codex.rs Outdated
}

pub(crate) struct ExecPolicyManager {
policy: ArcSwap<Policy>,
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.

So this is a change in behavior? After append_amendment_and_update() is called, anyone who has a reference to the previous value will now have a stale value, right?

I don't know if that's what we want?

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.

We are holding onto an instance of ExecPolicyManager in codex and create_exec_approval_requirement_for_command gets the latest snapshot and doesn't hold onto it.

Do you see a place that's affected by this behavior? Am I missing something?

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.

append_execpolicy_amendment_and_update() returns a new Policy and the method is pub(crate).

I think you're saying the intention of ExecPolicyManager is to never expose the internal Policy directly (which I agree with), though (1) I think that's worth a comment, and (2) I think the visibility of append_execpolicy_amendment_and_update() needs to be changed to honor that.

Also, I haven't heard of ArcSwap before and I don't see existing uses in our codebase. Should we be using it instead of RwLock in more places? It seems weird to only use it here.

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.

Should we be using it instead of RwLock in more places?

I looked for more usages but it only works when the value is immutable and most things we keep under RWLock are actually mutable.

I see your point about append_execpolicy_amendment_and_update now!

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.

inlined append_execpolicy_amendment_and_update into the policy manager and implemented Default to make tests cleaner.

Comment thread codex-rs/core/src/exec_policy.rs
@pakrym-oai pakrym-oai merged commit 96fdbdd into main Dec 22, 2025
26 checks passed
@pakrym-oai pakrym-oai deleted the pakrym/add-execpolicymanager branch December 22, 2025 17:59
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 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.

2 participants