Skip to content

feat: add explicit native trace context - #5508

Merged
markstuart-oai merged 33 commits into
feat/codex-harnessfrom
codex/native-trace-context
Nov 5, 2026
Merged

markstuart-oai merged 33 commits into
feat/codex-harnessfrom
codex/native-trace-context

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Requirement: REQ442 — add native W3C parent propagation and tool-span forwarding as part of the broader tracing requirement.

Pass an incoming TraceContext through parent_trace, then forward ToolContext.trace_context.to_headers() to connect another service to the calling tool span. Queued roots capture their parent. Compaction uses the Session default, and automatic continuations retain their root's parent. Restored work accepts a fresh caller parent; saved state does not restore active trace context.

The supported carrier profile accepts defined trace flags 00–03. Native propagation retains the random-trace-ID bit when the local sampler drops a span. It preserves the child's span ID and sampling decision. Manual request size accounting excludes private trace metadata.

Public header IDs carry ancestry only. They cannot recover SDK workflow policy or export credentials. Root and child admissions carry their own trusted SDK context separately, including an explicitly empty owner. This preserves distributed parents and workflow restrictions without registering incoming IDs or retaining per-turn policy in Session settings. The integration also preserves SessionStore durability and untraced manual-recovery call compatibility.

Test plan

  • Published 54510263 integrates the actual cbde5dd7 v1 base. Its 110 native inputs and complete SDK Python source match release producer eff6e536 (Core 88f56076). Later changes affect test setup, cleanup, and callback scheduling only; their focused checks pass.
  • The public credential-route regression fails on the prior hosted wheel and passes on the fixed wheel. It checks raw headers, startup, direct submission, flags 03, opaque local parents, and independently selected caller policy. Trusted child start, steering, and continuation retain their policy and metadata restrictions.
  • The unchanged trace/history tests passed all 62 cases on 3e98eeaf with the official Linux wheel. The current test source passes all 44 tracing/transport tests, including gRPC, on that same qualified native product. All 51 installed SDK/native files match the wheel and its RECORD. Eight Core trace-context tests and eleven SDK policy tests pass on the unchanged owning OTel source.
  • The qualified GitHub Linux artifact passes 13 installed review regressions. Its merge tree equals its e94d3aaa source. All 110 native inputs and the complete SDK Python source match the current head.
  • Source checks pass: 70 pure tests, four strict typing files, API validation, Rust formatting, two unchanged Ruff passes, and normal source preparation. The policy fixture initializes both Sessions first, then submits concurrently under two distinct workflow scopes. It waits for both admissions and caller scopes to close, then permits either callback order. A serialized-callback control fails with the old barrier and passes with the new one. An injected owner error now surfaces directly. All ancestry and policy assertions remain intact; macOS passed this unchanged fixture on 3e98eeaf.
  • The sequential-loop processor test now accounts exactly for either legal drain shape: the blocked start is lost, and an end queued separately may reach the next loop. Both old assertions fail in a forced split; both revised cases pass. Persistent loss, zero dropped records, and duplicate-free delivery remain checked.
  • Current-head CI is complete: 24 successful checks and five skipped checks, with no failures. Linux Python 3.11 passed 4,385 tests plus all 44 optional tracing/transport cases; macOS passed 4,238 tests. Both previously reported CI failures are resolved on this head. Justin approved this exact commit, all four review threads are resolved, and the automated review summary reports completion for this commit. Two fresh complementary independent reviews returned clean results on this exact content. Final local verification passed in the required order: formatting, lint, complete type checking, then tests (4,241 parallel passes, 174 skips, and 41 serial passes). Source, native files, tools, and review records remained unchanged. Current hosted CI covers the native platform cases excluded by the local sandbox.

Issue number

REQ442.

Checks

  • I've added new tests, if relevant
  • I've run all applicable checks in AGENTS.md, including the current full verification stack when required
  • I've confirmed all required checks pass on the current head
  • I've completed the integration review required for the current trace/workflow combination

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 4, 2026 06:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T13:47:38.610521Z 5451026 New commits
🔒 Security Review ✅ Completed 2026-11-05T13:48:17.755263Z 5451026 New commits

Security findings

Advisory findings (1)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the explicit trace-context API, header validation and native propagation boundaries, queued submission capture, callback span exposure, and fresh-parent manual restore. Carriers are immutable, validated before admission, and excluded from persisted checkpoint carriers; native callback correlation remains optional. No actionable findings.

Static review only; no candidate code or tests run locally. Hosted CI: checks remain pending; no failures observed.

@markstuart-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: e0c84b0b71

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: e0c84b0b71

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@markstuart-oai
markstuart-oai force-pushed the codex/native-trace-context branch from e0c84b0 to d3b8333 Compare November 4, 2026 21:08
@markstuart-oai
markstuart-oai changed the base branch from feat/codex-harness to codex/native-response-history November 4, 2026 21:08
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

"baseline_commit": "71ae120fc4a393c613a81a882c34b54b9b76ed22",

P2 Badge Record the actual squash parent as the API baseline

When this squashed commit is used for release preparation, the snapshot identifies 71ae120... as its source parent, but that commit is not an ancestor of 4ae6c22 and did not contain the trace-context API captured below. The release workflow treats baseline_commit as the candidate-parent provenance while only validating that it looks like a SHA, so leaving the stacked-branch commit here produces incorrect release metadata; regenerate the snapshot against this commit's actual parent (a3cf563...).


# Retained occurrences only, without a guarantee of complete attempt coverage.
# Absence leaves response coverage unknown for legacy snapshots.
responses: NotRequired[list[RecordedResponse]]

P2 Badge Remove the unrelated response-history feature

For this trace-context change, RecordedTurn.responses and the associated RecordedResponse types introduce a separate public history contract backed by a 1,600-line Codex patch, new persistence records, projection logic, and failure behavior; none of the new parent_trace or ToolContext.trace_context paths consumes that machinery. Shipping it here silently expands the public and persisted-state surface beyond the stated task, so remove the response-observation/cache-write additions from this change and review them separately if they are required.

AGENTS.md reference: AGENTS.md:L106-L107


if state.parent_trace is not None:
request["trace"] = state.parent_trace.to_headers()

P2 Badge Forward the session trace parent to model compaction

When a caller opens a Session with parent_trace and then calls await session.compact(), _start(None, ...) captures the Session parent in state.parent_trace, but these lines forward it only through the input-bearing _submit branch; the input is None branch calls _compact() without any carrier. Model-backed compaction therefore falls outside the explicit trace tree despite Agent.session() documenting the Session parent as the default for every new root, so extend the native compact admission path to consume the captured parent as well.

AGENTS.md reference: AGENTS.md:L114-L116

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the response-observation and cache-write history increment. The observation implementation and main regressions match the independently reviewed response-history change. Received facts remain distinct from aggregate accounting, unknown counters stay optional, and Python repair receipts accept the signed values supported by the history codec. No JS-style nonnegative receipt mismatch exists here.

Coordinator and independent static reviews of actual old/new file contents found no actionable issue. Hosted CI on this new head remains pending; prior-head results do not qualify it. No candidate code or local tests executed.

@jbeckwith-oai

Copy link
Copy Markdown
Contributor

Hosted CI follow-up at d3b8333: the macOS native SDK job reached 99% but hit the test step’s 10-minute limit at 22:31:35 UTC. The available log has no FAILED assertion or final pytest summary; this does not establish a new code defect. This is separate from the previously reported inherited response-history assertion failures in the Linux jobs. Approval is unchanged and CI follow-up remains open. Evidence: https://github.com/openai/openai-agents-python/actions/runs/41913204016/job/126904691205 . No local tests or reruns executed.

Copy link
Copy Markdown
Contributor Author

Follow-up to #5508 (comment):

Model-backed Session.compact() now forwards the captured Session parent through native admission. The regression checks exported spans after an overridden turn, during compaction, and on the following default turn. A matching native wheel and a separate installed-wheel consumer each passed 65 focused checks.

The other two findings refer to an earlier branch layout. The published d3b8333 commit has parent 71ae120, which matches its API snapshot's baseline_commit. Release preparation updates that field for a release candidate. Response-history types belong to the target branch in #5512; the trace change contains 14 files and adds no separate response-history feature.

The repair also incorporates #5512's corrected integrity-rejection assertion, which accepts the existing failed or cancelled settlement outcomes. The prior macOS timeout still needs a successful run on the new commit; its earlier log did not show an assertion failure.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at a3b51bd. Static re-review of the three feature-specific changed files confirms model compaction now carries the submission/session W3C trace parent through the native bridge and submit_with_trace, rather than inheriting a preceding turn override. The new regression checks overridden first turn, session-parent compaction, and subsequent ordinary turn. Existing ownership and cancellation paths are unchanged; the fourth updated file matches the base. Coordinator and independent review found no actionable issue. Hosted native CI remains pending; no candidate code or local tests ran.

@markstuart-oai
markstuart-oai force-pushed the codex/native-response-history branch from 7964d53 to efa3e9a Compare November 5, 2026 03:11
@markstuart-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a3b51bd4f3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: a3b51bd4f3

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@markstuart-oai
markstuart-oai force-pushed the codex/native-trace-context branch from a3b51bd to 259c311 Compare November 5, 2026 04:37

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after coordinator and independent static re-review of the updated base integration. The production tracing feature changes remain unchanged relative to the base; instruction-file and parent-trace admission compose correctly, with explicit regression coverage for validation order. No actionable findings or new feedback. Lint and documentation checks passed; current-head Linux/macOS native checks are pending. The prior-head macOS timeout is not evidence of a passing new run; CI follow-up remains open. No candidate code or local tests ran.

@markstuart-oai
markstuart-oai force-pushed the codex/native-response-history branch from efa3e9a to a776c72 Compare November 5, 2026 05:35
@markstuart-oai
markstuart-oai force-pushed the codex/native-trace-context branch from 259c311 to 0730558 Compare November 5, 2026 05:53

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the base integration using exact old/new trees and overlapping source. Trace ownership remains captured through queued submission, continuation, restoration, compaction, and repair; writable-root and recovery integration preserves the existing trace contract. No new findings. Hosted native CI is pending. Coordinator and independent static review; no candidate code or local tests executed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0730558ab5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/_trace_context.py Resolved
Comment thread packages/codex/rust/python_tools.rs Resolved

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes for the existing P2 public-parent policy restoration finding, independently confirmed by static review. No duplicate inline finding added.

A session created with caller-supplied parent_trace and no ambient workflow/options can submit with trace_policy=None. submission_dispatch_span then installs context_from_w3c_trace_context unchanged. That parser invokes restore_policy, which looks up the trace/span IDs in the live local policy registry. A carrier naming a still-live local span therefore inherits its ScopePolicy, including the export-route credential; RoutedSpanProcessor consumes that credential when enqueuing the resulting span. This permits same-process reentry to borrow another workflow’s export policy. Public parent parsing must preserve W3C linkage without recovering local policy by caller-visible IDs; attach only policy owned by the new submission. Ensure downstream policy lookup cannot restore it either, and add a same-live-span/no-captured-policy regression test.

The new test-only distinction between the independent caller span and disabled child export is sound. The earlier explicit-parent overwrite finding remains fixed, but this newly confirmed issue supersedes my prior approval. Hosted CI remains pending. No candidate code or tests ran locally.

@jbeckwith-oai

jbeckwith-oai commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Hosted CI is complete at 5451026: 24 successful checks and 5 skipped checks, with no failures or pending checks. Linux Python 3.10–3.14, both Windows test jobs, macOS sandbox, native packages, lint/docs/type checks and CodeQL all passed. This verifies both the previously reported Linux 3.11 loop-loss failure and macOS concurrent-policy failure are resolved on this commit.

Linux 3.11: https://github.com/openai/openai-agents-python/actions/runs/42038549384/job/127295053037
macOS sandbox: https://github.com/openai/openai-agents-python/actions/runs/42038549384/job/127293460165

Static approval remains: #5508 (review) . CI follow-up is complete. No candidate code or local tests executed; no CI reruns requested.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at e94d3aa. The public-parent policy restoration finding is addressed: #5508 (comment). Public W3C carriers remain remote ancestry only, parser restoration is removed, and registry lookup rejects remote identities. Private policy/credentials are retained only through captured caller policy or opaque SDK handles. Explicit admission ownership, including no owner, prevents unrelated native spans from supplying policy; child callbacks retain creation/admission ownership.

Coordinator and two independent static reviews found no actionable regression. Reviewed added route-isolation, admission-ownership and waiter-cleanup tests; patch digest matches the series manifest. This approval supersedes my previous request-changes decision for this finding at older commits. It does not clear branches that have not incorporated this fix.

Fresh hosted CI is still running (native producers and Python/Rust CodeQL); follow-up remains open. No candidate code or local tests executed and no CI reruns requested.

@markstuart-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: e94d3aaa91

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: e94d3aaa91

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@markstuart-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: e94d3aaa91

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: e94d3aaa91

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@markstuart-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at c08a715. Coordinator and independent static re-review found no actionable issue in the policy-isolation test change. Both owners must finish admission and close their caller scopes before callbacks are released, while callbacks may run serially. Both callback-policy and exported-span assertions remain intact. Setup failures are surfaced immediately, and the finally block releases, cancels and joins outstanding tasks. Production code and the previously approved public-parent security fix are unchanged.

Fresh hosted native CI is pending. This scheduling change plausibly addresses the prior macOS timeout, but a passing hosted run is still needed; prior-head failure follow-up remains open. No candidate code or local tests executed and no CI reruns requested.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: c08a71594b

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: c08a71594b

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at 3e98eea. Coordinator and independent static review found no actionable issue. The test initializes sessions sequentially before concurrent submissions, separating resource setup from admission-policy capture. Session.submit captures each caller policy while retaining the shared explicit parent; callback-policy and export assertions remain intact after both caller scopes close. Owner tasks are joined before the shared exit stack closes sessions and their peers. Phase diagnostics improve any subsequent admission timeout. Production tracing/security code is unchanged.

Fresh hosted native CI is pending; the previous macOS timeout is not yet verified resolved. No candidate code or local tests executed and no CI reruns requested.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at 5451026. Static follow-up review with an independent reviewer found no actionable issues in the loop-loss regression change. The processor pump can select start before end is queued: shutdown then accounts for one failed delivery and the queued end can reach the next loop. If both records were selected, both are lost. The revised test checks the exact loss for either schedule, zero drops, cumulative partial status, no replay, and delivery of new events. Production code is unchanged from the previously reviewed commit.

Hosted CI is still running on this commit. The prior Linux 3.11 failure is addressed by this assertion correction, but a successful new run is still needed; the prior macOS timeout also remains unverified. No candidate code or local tests executed; no CI reruns requested.

@markstuart-oai
markstuart-oai merged commit 84391a2 into feat/codex-harness Nov 5, 2026
29 checks passed
@markstuart-oai
markstuart-oai deleted the codex/native-trace-context branch November 5, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants