mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Expose assistant content token counts in completion notifications (#59041)
## What changed Add optional `contentTokenCount` metadata to `item/completed` notifications, carrying the producer-supplied token count for each completed assistant message in default and plan modes. Counts include any sampled footer and are `null` when unavailable. Keep this telemetry separate from stored thread items and omit it from subsequent model requests. Update the protocol schemas and generated TypeScript and Python types. ## Testing Add coverage for per-message counts, including zero, in default and plan modes; missing and malformed metadata; backward-compatible notification decoding; and exclusion from subsequent model requests. GitOrigin-RevId: 35973037a42650fa2d7569da8e88cb81215cf971
This commit is contained in:
@@ -9293,6 +9293,7 @@ async fn prompt_edit_reverts_earlier_and_first_visible_prompts_in_place_scenario
|
||||
collaboration_mode_kind: ModeKind::default(),
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id: ThreadId::from_string(&source_thread_id)?,
|
||||
turn_id: turn_id.to_string(),
|
||||
item: TurnItem::UserMessage(UserMessageItem {
|
||||
|
||||
@@ -65,6 +65,7 @@ async fn history_fixture(
|
||||
})];
|
||||
for item in 0..*count {
|
||||
events.push(EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id,
|
||||
turn_id: turn_id.clone(),
|
||||
started_at_ms: None,
|
||||
|
||||
@@ -87,6 +87,7 @@ pub(super) async fn completed_history_app(
|
||||
];
|
||||
events.extend(items.into_iter().map(|item| {
|
||||
EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id,
|
||||
turn_id: turn_id.clone(),
|
||||
item,
|
||||
|
||||
@@ -2517,6 +2517,7 @@ async fn older_pagination_reconciles_review_prompts_across_page_boundaries() ->
|
||||
}))
|
||||
.chain(items.into_iter().map(|item| {
|
||||
EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id,
|
||||
turn_id: "cross-page-review-turn".to_string(),
|
||||
item,
|
||||
@@ -2681,6 +2682,7 @@ async fn transcript_alt_beginning_loads_every_older_history_page() -> Result<()>
|
||||
}))
|
||||
.chain((0..305).map(|index| {
|
||||
EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id,
|
||||
turn_id: "multi-page-turn".to_string(),
|
||||
item: TurnItem::AgentMessage(AgentMessageItem {
|
||||
@@ -3097,6 +3099,7 @@ async fn underfilled_scrollback_fetches_older_pages_without_opening_the_transcri
|
||||
}))
|
||||
.chain((0..120).map(|index| {
|
||||
EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id,
|
||||
turn_id: "scrollback-pagination-turn".to_string(),
|
||||
item: TurnItem::AgentMessage(AgentMessageItem {
|
||||
@@ -5345,6 +5348,7 @@ async fn command_center_read_only_open_requests_and_failure_preservation() -> Re
|
||||
collaboration_mode_kind: Default::default(),
|
||||
}),
|
||||
EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id,
|
||||
turn_id: format!("saved-turn-{index}"),
|
||||
item: TurnItem::UserMessage(UserMessageItem::new(&[CoreUserInput::Text {
|
||||
@@ -5355,6 +5359,7 @@ async fn command_center_read_only_open_requests_and_failure_preservation() -> Re
|
||||
completed_at_ms: 0,
|
||||
}),
|
||||
EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
content_token_count: None,
|
||||
thread_id,
|
||||
turn_id: format!("saved-turn-{index}"),
|
||||
item: TurnItem::AgentMessage(AgentMessageItem {
|
||||
|
||||
@@ -1010,6 +1010,7 @@ mod tests {
|
||||
let mut expected = serde_json::json!({
|
||||
"method": "item/completed", "params": {
|
||||
"threadId": "thread", "turnId": "turn", "completedAtMs": 20,
|
||||
"contentTokenCount": null,
|
||||
"item": {
|
||||
"type": "agentMessage", "id": "question", "text": "already in the snapshot",
|
||||
"startedAtMs": 10, "completedAtMs": 20,
|
||||
|
||||
Reference in New Issue
Block a user