Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9abdfa0
test(models): restore AnyLLM module bindings after provider tests
markstuart-oai Nov 20, 2026
7de7610
feat(tracing): add per-run capture and an OpenTelemetry processor
markstuart-oai Nov 20, 2026
738e2fb
feat(codex): trace model calls and native tools through the SDK
markstuart-oai Nov 20, 2026
7334833
test: make sandbox collection and App Server startup portable
markstuart-oai Nov 20, 2026
fde2b51
Merge test/simple-codex-fixtures into feature/operation-tracing
markstuart-oai Nov 20, 2026
83962e9
fix(tracing): preserve source nanoseconds on Python 3.10
markstuart-oai Nov 20, 2026
0db5431
Merge feature/operation-tracing into feature/codex-operation-tracing
markstuart-oai Nov 20, 2026
62d933c
fix(codex): preserve source timestamps on Python 3.10
markstuart-oai Nov 20, 2026
bcd1b2c
fix(codex): resolve Windows image paths and file URLs
markstuart-oai Nov 20, 2026
1afab3f
test(models): use the Windows subprocess event loop
markstuart-oai Nov 20, 2026
5fdfada
Merge test/simple-codex-fixtures into feature/operation-tracing
markstuart-oai Nov 20, 2026
52b89a3
fix(tracing): enforce capture budgets before publishing generation pa…
markstuart-oai Nov 20, 2026
eff7774
fix(tracing): preserve Chat Completions messages and tool calls in Op…
markstuart-oai Nov 20, 2026
63058b6
Merge feature/operation-tracing into feature/codex-operation-tracing
markstuart-oai Nov 20, 2026
459729b
fix(codex): bound allocations when capturing operation payloads
markstuart-oai Nov 20, 2026
f4334c8
fix(codex): preserve UTF-8 in captured native tool results
markstuart-oai Nov 20, 2026
a2a5c88
test(tracing): compare callback and tool times at SDK clock precision
markstuart-oai Nov 20, 2026
a67bfc0
Merge feat/simple-codex and retain the AnyLLM fixture fix
markstuart-oai Nov 20, 2026
7bb7c81
Integrate mutable tool hooks with SDK tracing and share the input cap…
markstuart-oai Nov 21, 2026
6ce3a19
Trace embedded Codex Core operations through the native SDK wheel
markstuart-oai Nov 21, 2026
7472be4
Bound AnyLLM Responses capture using the submitted request
markstuart-oai Nov 21, 2026
43091c5
Bound trace capture and apply it through shell and checkpoint callbacks
markstuart-oai Nov 21, 2026
feb693e
Integrate Codex tracing with prepared history and fix native test fix…
markstuart-oai Nov 21, 2026
4ab1102
Preserve visible refusal text in OpenTelemetry messages
markstuart-oai Nov 21, 2026
61d97f8
Include the reviewed refusal projection from SDK tracing
markstuart-oai Nov 21, 2026
690de4c
Time the first macOS parity case using the existing wheel artifact
markstuart-oai Nov 21, 2026
0692e22
Bind the parity test server without reverse DNS on loopback
markstuart-oai Nov 21, 2026
4d10726
Resume pending Codex command and file edit approvals after a worker r…
markstuart-oai Nov 21, 2026
3ff68b0
Merge feat/simple-codex and retain the streamed recovery claim
markstuart-oai Nov 21, 2026
5d26364
fix(codex): bound file reads when saving and checking patch approvals
markstuart-oai Nov 21, 2026
188ef30
fix(codex): report native model usage with the SDK token schema
markstuart-oai Nov 21, 2026
f1bdc65
fix(tracing): observe native approval decisions and resumed tools as …
markstuart-oai Nov 21, 2026
f6b6848
fix(codex): bound aggregate file hashing for approvals
markstuart-oai Nov 21, 2026
85f402e
fix(tracing): export cache and reasoning token counts through OpenTel…
markstuart-oai Nov 21, 2026
26a7cef
fix(codex): keep workspace preimages out of approval checkpoints
markstuart-oai Nov 21, 2026
6fdda2c
fix(codex): preserve cancellation and native failures during cleanup
markstuart-oai Nov 21, 2026
1406c8b
fix(codex): count every completed inference before an approval pause
markstuart-oai Nov 21, 2026
f31f5a8
test(codex): check cancellation reasons on supported Python versions
markstuart-oai Nov 21, 2026
dd901e1
fix(codex): bound native tool results before preparing trace content
markstuart-oai Nov 21, 2026
fe89afa
fix(codex): use stock runtime callbacks and reject unsupported approv…
markstuart-oai Nov 21, 2026
edf541c
fix: reject native approvals in nested run state before restoring con…
markstuart-oai Nov 21, 2026
f9f9235
feat(codex): recover native approvals and trace native calls
markstuart-oai Nov 21, 2026
8ede460
Compare the decoded image path in the installed Codex wheel test
markstuart-oai Nov 21, 2026
e74c1ee
fix(codex): confirm restored commands from the process result
markstuart-oai Nov 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/codex-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
include:
- runner: ubuntu-24.04
target: x86_64-unknown-linux-gnu
test_native: true
platform: manylinux_2_28_x86_64
image: quay.io/pypa/manylinux_2_28_x86_64@sha256:9555ba6c479fa69a2aa80ad1dc57154a60d562b19df159361d9379a02beb1e36
- runner: ubuntu-24.04-arm
Expand Down Expand Up @@ -161,11 +162,9 @@ jobs:
run: |
options=()
if [[ "$RUNNER_OS" == Linux ]]; then options+=(--compatibility manylinux_2_28); fi
if [[ "${{ matrix.test_native }}" == true ]]; then options+=(--test-native); fi
uv run --no-sync python scripts/build_codex_wheel.py \
--out "$GITHUB_WORKSPACE/dist" --target "$WHEEL_TARGET" "${options[@]}"
- name: Test native policy and configuration
if: matrix.platform == 'manylinux_2_28_x86_64'
run: cargo test --locked --release --lib --manifest-path native/codex/Cargo.toml
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: codex-wheel-${{ matrix.platform }}
Expand Down
4 changes: 3 additions & 1 deletion docs/models/codex.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ The workspace sandbox protects the directory that contains the installed helpers

On Windows, the preview rejects a local Codex executor configured with the legacy elevated sandbox. That sandbox needs a setup helper that Codex cannot securely locate from a Python process. If your organization requires this sandbox, use an SDK-managed executor or configure a remote executor with `include_local = false` in `environments.toml`.

Native Codex approval prompts are separate from SDK tool approvals. This provider cannot answer native approval requests and fails the model call when one arrives. For a non-interactive read-only workflow, configure Codex to avoid approval prompts:
Pass a `ResumableSession` to `Runner.run(..., session=session)` to pause a built-in `exec_command` or `apply_patch` for approval. A new worker can load that session and approve or reject the original call. Recovery requires the same workspace and permissions, one local environment, and no tool hooks. Other native approval requests fail the model call.

For a non-interactive read-only workflow, disable approval prompts.

```python
provider = CodexProvider(
Expand Down
2 changes: 2 additions & 0 deletions native/codex/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions native/codex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pyo3 = { version = "0.29", features = ["extension-module", "abi3-py310"] }
pyo3-async-runtimes = { version = "0.29", features = ["tokio-runtime"] }
tokio = { version = "1", features = ["rt-multi-thread", "sync", "time"] }
futures = "0.3"
serde = "1"
serde_json = "1"
toml = "0.9.5"
codex-arg0 = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
Expand All @@ -27,6 +28,7 @@ codex-config = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8
codex-core = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
codex-core-api = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
codex-exec-server = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
codex-extension-api = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
codex-features = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
codex-http-client = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
codex-hooks = { git = "https://github.com/openai/codex", rev = "6ff1e1ca3b30fc8b914720681fcf5fe62e95f856" }
Expand Down
24 changes: 24 additions & 0 deletions native/codex/patches/01-operation-tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Trace the request Codex sends and the time a tool runs

Codex can change the model input just before sending it. Its normal tool timer can also include time spent waiting for approval. Those details matter when debugging a slow or unexpected turn.

[This patch](01-operation-tracing.patch) lets the SDK observe the final HTTP or WebSocket request, distinguish a failed connection from cancellation, and start timing a command or edit after approval. These callbacks cannot change the request or grant permission to run a tool.

Native spans contain metadata by default. To include text in model and tool spans, pass this configuration to the Runner.

```python
from agents import RunConfig
from agents.models.codex import CodexProvider

config = RunConfig(
model_provider=CodexProvider(),
tracing={"operation_detail": "content"},
trace_include_sensitive_data=True,
)
```

The SDK uses existing Codex events for model responses, usage and tool results. It excludes request headers, encrypted reasoning, media and values over 32 KiB. Captured text can still contain secrets. Setting `trace_include_sensitive_data=False` always disables content capture.

## Check and remove

Build and test the wheel as described in the [patch guide](README.md). Check both metadata and content modes. Failed requests and cancellations should have distinct outcomes. Denied commands should have no execution span. Remove the patch and guide once upstream Codex exposes the same events.
147 changes: 147 additions & 0 deletions native/codex/patches/01-operation-tracing.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs
index 2ac9b93..7257291 100644
--- a/codex-rs/core/src/client.rs
+++ b/codex-rs/core/src/client.rs
@@ -2017,7 +2017,7 @@ impl ResponsesHttpExecutor<'_> {
let request_session_telemetry =
session_telemetry_for_request(session_telemetry, &request);
options.extra_headers.extend(responses_headers);
- let interceptors = crate::model_request::prepare(
+ let mut interceptors = crate::model_request::prepare(
&self.client.request_contributors,
&self.client.state.thread_id.to_string(),
&model_info.slug,
@@ -2032,6 +2032,11 @@ impl ResponsesHttpExecutor<'_> {
}
request.input = input;
}
+ for interceptor in &mut interceptors {
+ interceptor.observe_request(codex_extension_api::ModelRequestContent::Responses(
+ &request,
+ ));
+ }
inference_trace_attempt.record_started(&request);
let client = ApiResponsesClient::new(
transport,
@@ -2040,6 +2045,11 @@ impl ResponsesHttpExecutor<'_> {
)
.with_telemetry(Some(request_telemetry), Some(sse_telemetry));
let stream_result = client.stream_request(request, options).await;
+ if stream_result.is_err() {
+ for interceptor in &mut interceptors {
+ interceptor.request_failed();
+ }
+ }

match stream_result {
Ok(stream) => {
@@ -2315,7 +2325,7 @@ impl ModelClientSession {
client_setup.auth.as_ref(),
&responses_headers,
);
- let interceptors = crate::model_request::prepare(
+ let mut interceptors = crate::model_request::prepare(
&self.client.request_contributors,
&self.client.state.thread_id.to_string(),
&model_info.slug,
@@ -2337,6 +2347,11 @@ impl ModelClientSession {
let ResponsesWsRequest::ResponseCreate(payload) = &mut ws_request;
payload.input = input;
}
+ let ResponsesWsRequest::ResponseCreate(payload) = &ws_request;
+ for interceptor in &mut interceptors {
+ interceptor
+ .observe_request(codex_extension_api::ModelRequestContent::WebSocket(payload));
+ }
if !previous_response_id_from_untraced_warmup {
inference_trace_attempt.record_started(&ws_request);
}
@@ -2377,6 +2392,9 @@ impl ModelClientSession {
self.websocket_session.last_request = Some(request);
self.websocket_session.last_response_from_untraced_warmup = warmup;
let stream_result = stream_result.map_err(|err| {
+ for interceptor in &mut interceptors {
+ interceptor.request_failed();
+ }
let response_debug_context = extract_response_debug_context_from_api_error(&err);
let err = self.client.state.provider.map_api_error(err);
inference_trace_attempt.record_failed(
diff --git a/codex-rs/core/src/tools/orchestrator.rs b/codex-rs/core/src/tools/orchestrator.rs
index a1a88e4..c5f8077 100644
--- a/codex-rs/core/src/tools/orchestrator.rs
+++ b/codex-rs/core/src/tools/orchestrator.rs
@@ -102,6 +102,18 @@ impl ToolOrchestrator {
.as_ref()
.map(ActiveNetworkApproval::execution_proxy),
};
+ for contributor in tool_ctx
+ .session
+ .services
+ .extensions
+ .tool_lifecycle_contributors()
+ {
+ contributor.on_tool_execution_start(
+ &tool_ctx.session.thread_id.to_string(),
+ &tool_ctx.step_context.turn.sub_id,
+ &tool_ctx.call_id,
+ );
+ }
let run_result = tool
.run(req, &attempt_with_network_approval, &attempt_tool_ctx)
.await;
diff --git a/codex-rs/ext/extension-api/src/contributors.rs b/codex-rs/ext/extension-api/src/contributors.rs
index dc95f99..e985a9a 100644
--- a/codex-rs/ext/extension-api/src/contributors.rs
+++ b/codex-rs/ext/extension-api/src/contributors.rs
@@ -413,6 +413,10 @@ pub trait ToolContributor: Send + Sync {
/// rewriting the invocation. Use `ToolContributor` for owning a tool implementation
/// and hooks for policy that changes tool payloads.
pub trait ToolLifecycleContributor: Send + Sync {
+ /// One admitted native runtime attempt, after approval and network admission.
+ /// May repeat on sandbox retry; denied attempts never reach this callback.
+ fn on_tool_execution_start(&self, _thread_id: &str, _turn_id: &str, _call_id: &str) {}
+
/// Observe direct calls before readiness, dispatch waiting, and hooks, including blocked calls.
/// Excludes nested code-mode calls. Observers must return promptly.
fn on_tool_dispatch(&self, _input: ToolDispatchInput<'_>) {}
diff --git a/codex-rs/ext/extension-api/src/lib.rs b/codex-rs/ext/extension-api/src/lib.rs
index 147b52f..bd94076 100644
--- a/codex-rs/ext/extension-api/src/lib.rs
+++ b/codex-rs/ext/extension-api/src/lib.rs
@@ -128,6 +128,7 @@ pub use contributors::ToolDispatchInput;
mod model_request;
pub use model_request::GuardianAssessment;
pub use model_request::ModelRequestContributor;
+pub use model_request::ModelRequestContent;
pub use model_request::ModelRequestInput;
pub use model_request::ModelRequestKind;
pub use model_request::ModelResponseError;
diff --git a/codex-rs/ext/extension-api/src/model_request.rs b/codex-rs/ext/extension-api/src/model_request.rs
index 0f477aa..6514694 100644
--- a/codex-rs/ext/extension-api/src/model_request.rs
+++ b/codex-rs/ext/extension-api/src/model_request.rs
@@ -35,10 +35,24 @@ pub trait ModelRequestContributor: Send + Sync + std::fmt::Debug {
fn request(&self, input: ModelRequestInput<'_>) -> Option<Box<dyn ModelResponseInterceptor>>;
}

+/// Borrowed final request body, after transport-specific input adjustment.
+/// Headers and authentication are deliberately outside this view.
+pub enum ModelRequestContent<'a> {
+ Responses(&'a codex_api::ResponsesApiRequest),
+ WebSocket(&'a codex_api::ResponseCreateWsRequest<'a>),
+}
+
/// Owns request state until consumed by the response stream or dropped on failure.
/// Interceptors compose in registration order; dropping their stream must release unfinished work.
/// Trusted host implementations must bound any model-visible content they synthesize.
pub trait ModelResponseInterceptor: Send + Sync {
+ /// Observe the final request without modifying it. Implementations must opt in,
+ /// bound any retained content, and return promptly; the default retains nothing.
+ fn observe_request(&mut self, _request: ModelRequestContent<'_>) {}
+
+ /// The transport returned an error before opening a response stream.
+ fn request_failed(&mut self) {}
+
/// Wrap the response stream, optionally buffering, inspecting, or transforming events.
/// The returned stream must own request state and propagate cancellation by dropping upstream.
fn intercept(self: Box<Self>, stream: ModelResponseStream) -> ModelResponseStream;
27 changes: 27 additions & 0 deletions native/codex/patches/02-approval-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Resume a built-in command or edit after a worker stops

Codex normally keeps a pending approval in memory. When the process stops, restoring conversation history cannot finish that action. Asking the model to propose it again could run a different command or repeat a write.

[This patch](02-approval-recovery.patch) lets the SDK save one local `exec_command` or `apply_patch` before it runs. A replacement worker can submit that call directly to Codex without asking the model again.

1. Create a session with `session = await ResumableSession.create(store)`. Pass it to `Runner.run(..., session=session)` and keep `session.session_id`. The SDK saves the pending call before returning the approval request.
2. On the replacement worker, load the same session with `session = await ResumableSession.resume(store, session_id)`. Then use `state = await session.load_state(agent)`.
3. Match the user's decision to the call in `state.get_interruptions()`. Use `state.approve(call)` or `state.reject(call)`, then `await Runner.run(agent, state, session=session, run_config=config)`.

Only one worker can claim that session revision. Denial stops the call. On approval, Codex checks the workspace, permissions and newly prepared action. A mismatch stops execution.

## Safety limits

Recovery requires direct tools in one local environment, human review and no tool hooks. The SDK saves the model's submitted command or patch, so protect the session store. Codex replaces prepared update diffs with hashes and removes the original contents of deleted files.

The patch includes a bounded file read because the existing stream can follow symbolic links. Before saving and again before execution, Codex checks file hashes and confirms that new destinations are absent. Each check covers at most 32 paths, 8 MiB per file, 16 MiB in total and 10 seconds. An unreadable or oversized file stops recovery.

A restored call gets one attempt. For a command, Codex checks the call ID and exit code and refuses a live process handle. This check works even if the exit notification arrives after the turn. A new worker cannot continue an interactive process.

When Codex policy already allows an approved edit to run outside the sandbox on retry, recovery uses that permission on the first attempt.

The application must restore the same workspace and prevent concurrent edits. If the worker stops after a write and before saving the result, the session stays active. Check the external system before retrying.

## Check and remove

Follow the [patch guide](README.md) and run the approval tests. On another worker, approve and deny a saved command and edit. Check that a stale file, changed permissions or a duplicate approval causes no extra write. Remove the patch when upstream Codex can resume the same action with these checks.
Loading
Loading