Mark history ingestion requests in turn metadata (#41743)

## What changed

- Set `history_ingest_requested` to `true` in Responses turn metadata when the
  history-notes token-budget extension is enabled.
- Reserve the metadata key so caller-provided metadata cannot override the
  core-owned value, and omit it when the extension is disabled.

GitOrigin-RevId: e750bcb729292c407e1d443857cdb584a88aac97
This commit is contained in:
pmccrary-oai
2026-08-31 00:15:37 +00:00
committed by copyberry
parent 79b04f1ab5
commit b7cd519c76
2 changed files with 13 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ pub(crate) const COMPACTION_KEY: &str = "compaction";
pub(crate) const LEGACY_CODE_MODE_TOOL_NAMES_KEY: &str = "code_mode_tool_names";
pub(crate) const TOOL_NAMESPACES_INFO_KEY: &str = "tool_namespaces_info";
pub(crate) const TURN_STARTED_AT_UNIX_MS_KEY: &str = "turn_started_at_unix_ms";
pub(crate) const HISTORY_INGEST_REQUESTED_KEY: &str = "history_ingest_requested";
pub(crate) const FORKED_FROM_THREAD_ID_KEY: &str = "forked_from_thread_id";
pub(crate) const FORKED_FROM_ORDINAL_EXCLUSIVE_KEY: &str = "forked_from_ordinal_exclusive";
@@ -75,6 +76,7 @@ const RESERVED_METADATA_KEYS: &[&str] = &[
LEGACY_CODE_MODE_TOOL_NAMES_KEY,
TOOL_NAMESPACES_INFO_KEY,
TURN_STARTED_AT_UNIX_MS_KEY,
HISTORY_INGEST_REQUESTED_KEY,
FORKED_FROM_THREAD_ID_KEY,
FORKED_FROM_ORDINAL_EXCLUSIVE_KEY,
PARENT_THREAD_ID_KEY,
@@ -242,6 +244,7 @@ pub struct CodexResponsesMetadata {
pub(crate) workspaces: BTreeMap<String, TurnMetadataWorkspace>,
pub(crate) tool_namespaces_info: Option<TurnToolNamespacesInfo>,
pub(crate) turn_started_at_unix_ms: Option<i64>,
pub(crate) history_ingest_requested: Option<bool>,
pub(crate) extra: BTreeMap<String, String>,
}
@@ -280,6 +283,7 @@ impl CodexResponsesMetadata {
workspaces: BTreeMap::new(),
tool_namespaces_info: None,
turn_started_at_unix_ms: None,
history_ingest_requested: None,
extra: BTreeMap::new(),
}
}
@@ -407,6 +411,7 @@ impl CodexResponsesMetadata {
workspaces: non_empty_workspaces(&self.workspaces),
tool_namespaces_info: self.tool_namespaces_info.as_ref(),
turn_started_at_unix_ms: self.turn_started_at_unix_ms,
history_ingest_requested: self.history_ingest_requested,
compaction,
// Extra metadata enriches the Codex turn metadata blob, not literal top-level
// Responses client_metadata. Product metadata is validated while loading config;
@@ -552,6 +557,8 @@ struct CodexTurnMetadataPayload<'a> {
#[serde(default, skip_serializing_if = "Option::is_none")]
turn_started_at_unix_ms: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
history_ingest_requested: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
compaction: Option<CompactionTurnMetadata>,
#[serde(flatten)]
extra: &'a BTreeMap<String, String>,

View File

@@ -612,6 +612,12 @@ impl Session {
CodexResponsesMetadata {
window_number: Some(window_number),
context_window_id: Some(context_window_id),
history_ingest_requested: turn_context
.config
.token_budget
.as_ref()
.is_some_and(|config| config.use_history_notes_extension)
.then_some(true),
forked_from_ordinal_exclusive: self
.forked_from_ordinal_exclusive
.filter(|_| responses_metadata.forked_from_thread_id.is_some()),