mirror of
https://github.com/openai/codex.git
synced 2026-12-03 07:47:10 +00:00
Avoid unnecessary post-sampling token estimates (#34789)
## Why The post-sampling trace calculated an estimated token count even when only the always-on diagnostic and state log sinks were listening, adding unnecessary work after every sample. ## What changed - Move the estimate to a dedicated trace target and calculate it only when that event is enabled. - Disable the target for the always-on diagnostic and state log sinks while keeping it available to explicitly configured subscribers. ## Testing - Verify that the combined always-on subscribers do not enable the estimate event. GitOrigin-RevId: ea572584597dda313e7719897d0ab1fdf7362745
This commit is contained in:
1 parent
10cc57c95c
commit
66bd101fff
4 files changed
+42
-6
No files matched your search
@@ -5,6 +5,7 @@ use codex_protocol::ResponseItemId;
|
||||
use codex_protocol::items::AgentMessageContent;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::Arc;
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
struct RewriteAgentMessageContributor;
|
||||
|
||||
@@ -38,6 +39,24 @@ fn assistant_output_text(text: &str) -> ResponseItem {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_sampling_token_estimate_is_disabled_by_always_on_sinks() {
|
||||
let feedback = codex_feedback::CodexFeedback::new();
|
||||
let subscriber = tracing_subscriber::registry()
|
||||
.with(feedback.logger_layer())
|
||||
.with(tracing_subscriber::fmt::layer().with_filter(codex_state::log_db::default_filter()));
|
||||
|
||||
tracing::subscriber::with_default(subscriber, || {
|
||||
assert!(!tracing::event_enabled!(
|
||||
target: POST_SAMPLING_TOKEN_ESTIMATE_TARGET,
|
||||
tracing::Level::TRACE,
|
||||
turn_id,
|
||||
estimated_token_count,
|
||||
message
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn plan_mode_uses_contributed_turn_item_for_last_agent_message() {
|
||||
let (mut session, turn_context) = crate::session::tests::make_session_and_context().await;
|
||||
|
||||
Reference in new issue
Block a user