mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Exclude per-item usage attribution by default (#63219)
## What changed Add `usage.attribution` to the `x-codex-exclude` header for Responses HTTP requests and WebSocket handshakes by default. Threads started with `experimentalRawEvents` keep receiving per-item attribution in raw responses. Subagents inherit the policy, and the app server restores it when a thread resumes with an existing raw-event subscription. ## Testing Cover the default exclusion, raw completion events with upstream usage, subagent inheritance, and resuming a closed subagent after both its runtime and its parent's runtime have unloaded. GitOrigin-RevId: 0dad92f97606300907f1294f09dd7845d1e6476f
This commit is contained in:
@@ -41,6 +41,7 @@ use response_delivery::ResponseDelivery;
|
||||
|
||||
use crate::CodexResponsesHeaders;
|
||||
use crate::PromptCacheKey;
|
||||
use crate::UsageAttributionPolicy;
|
||||
use crate::tools::ExecutedToolCalls;
|
||||
use async_channel::Sender;
|
||||
use codex_api::AgentIdentityTelemetry;
|
||||
@@ -354,6 +355,7 @@ impl RequestRouteTelemetry {
|
||||
/// call site.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ModelClient {
|
||||
usage_attribution_policy: UsageAttributionPolicy,
|
||||
state: Arc<ModelClientState>,
|
||||
agent_identity_policy: AgentIdentityAuthPolicy,
|
||||
prompt_cache_key_policy: PromptCacheKey,
|
||||
@@ -708,6 +710,7 @@ impl ModelClient {
|
||||
prompt_cache_key_policy: PromptCacheKey::default(),
|
||||
session_id_override: None,
|
||||
codex_responses_headers: None,
|
||||
usage_attribution_policy: UsageAttributionPolicy::default(),
|
||||
event_sender: None,
|
||||
http_client_factory,
|
||||
restored_history: false,
|
||||
@@ -749,7 +752,7 @@ impl ModelClient {
|
||||
prompt_cache_key: PromptCacheKey,
|
||||
session_id_override: Option<String>,
|
||||
event_sender: Sender<ProtocolEvent>,
|
||||
codex_responses_headers: Option<Arc<CodexResponsesHeaders>>,
|
||||
thread_extension_data: &codex_extension_api::ExtensionData,
|
||||
api_key_cyber_access_programs: cyber_access_program::ApiKeyCyberAccessPrograms,
|
||||
required_cyber_access_programs: Option<
|
||||
Arc<cyber_access_program::RequiredCyberAccessPrograms>,
|
||||
@@ -758,7 +761,11 @@ impl ModelClient {
|
||||
self.prompt_cache_key_policy = prompt_cache_key;
|
||||
self.session_id_override = session_id_override;
|
||||
self.event_sender = Some(event_sender);
|
||||
self.codex_responses_headers = codex_responses_headers;
|
||||
self.codex_responses_headers = thread_extension_data.get::<CodexResponsesHeaders>();
|
||||
self.usage_attribution_policy = thread_extension_data
|
||||
.get::<UsageAttributionPolicy>()
|
||||
.map(|policy| *policy)
|
||||
.unwrap_or_default();
|
||||
self.api_key_cyber_access_programs = api_key_cyber_access_programs;
|
||||
self.required_cyber_access_programs = required_cyber_access_programs;
|
||||
self
|
||||
@@ -1690,6 +1697,7 @@ impl ModelClient {
|
||||
) -> ApiHeaderMap {
|
||||
let mut headers = build_responses_headers(
|
||||
self.state.beta_features_header.as_deref(),
|
||||
self.usage_attribution_policy,
|
||||
/*turn_state*/ None,
|
||||
);
|
||||
add_originator_header(&mut headers, self.state.originator.as_str());
|
||||
@@ -1766,6 +1774,7 @@ impl<'a> ResponsesHttpExecutor<'a> {
|
||||
extra_headers: {
|
||||
let mut headers = build_responses_headers(
|
||||
self.client.state.beta_features_header.as_deref(),
|
||||
self.client.usage_attribution_policy,
|
||||
Some(turn_state),
|
||||
);
|
||||
add_originator_header(&mut headers, self.client.state.originator.as_str());
|
||||
@@ -2947,13 +2956,18 @@ fn is_guardian_reviewer(responses_headers: &ApiHeaderMap) -> bool {
|
||||
///
|
||||
/// - `x-codex-beta-features`: comma-separated beta feature keys enabled for the session.
|
||||
/// - `x-codex-turn-state`: sticky routing token captured earlier in the turn.
|
||||
/// - `x-codex-exclude` asks the server to omit the echoed tool catalog.
|
||||
/// - `x-codex-exclude`: response fields the client can omit from the stream.
|
||||
fn build_responses_headers(
|
||||
beta_features_header: Option<&str>,
|
||||
usage_attribution_policy: UsageAttributionPolicy,
|
||||
turn_state: Option<&Arc<OnceLock<String>>>,
|
||||
) -> ApiHeaderMap {
|
||||
let mut headers = ApiHeaderMap::new();
|
||||
headers.insert("x-codex-exclude", HeaderValue::from_static("tools"));
|
||||
let exclusions = match usage_attribution_policy {
|
||||
UsageAttributionPolicy::Exclude => "tools,usage.attribution",
|
||||
UsageAttributionPolicy::Retain => "tools",
|
||||
};
|
||||
headers.insert("x-codex-exclude", HeaderValue::from_static(exclusions));
|
||||
if let Some(value) = beta_features_header
|
||||
&& !value.is_empty()
|
||||
&& let Ok(header_value) = HeaderValue::from_str(value)
|
||||
|
||||
Reference in New Issue
Block a user