mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Record statusline mode on the first prompt of each thread visit (#62045)
## What changed Emit `codex.statusline.first_prompt` once per thread visit, with a `mode` label of `feature_off`, `builtin`, or `custom`. Reset the counter guard when attaching a different primary thread, and count only user prompts for the active primary thread. Use the existing analytics consent and exporter checks. ## Testing Add coverage for counting once across first prompts and follow-ups on fresh and resumed threads, and verify that cloud async-question replies do not emit the metric. GitOrigin-RevId: 3ba48a8fbbb3015d22de3252efcc5ae3ba96baab
This commit is contained in:
@@ -1677,6 +1677,7 @@ impl App {
|
||||
// Initial messages are for freshly attached primary threads only. Thread switches and
|
||||
// resume/fork flows pass `None` so they cannot replay old history and then auto-submit a new
|
||||
// user turn by accident.
|
||||
let new_visit = self.primary_thread_id != Some(started.session.thread_id);
|
||||
if !matches!(
|
||||
presentation,
|
||||
ThreadAttachPresentation::SessionLineageAfterClear
|
||||
@@ -1755,6 +1756,9 @@ impl App {
|
||||
presentation,
|
||||
)
|
||||
.await?;
|
||||
if new_visit {
|
||||
self.statusline_metrics.begin_visit();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ use super::*;
|
||||
use crate::app::session_lifecycle::FreshSessionStart;
|
||||
use crate::app_event::TranscriptExportDestination;
|
||||
use crate::bottom_pane::BottomPaneView;
|
||||
use crate::statusline_metrics::tests::Collector;
|
||||
use crate::test_support::boxed_future;
|
||||
use app_test_support::create_fake_paginated_rollout;
|
||||
use app_test_support::create_fake_parented_rollout_with_source;
|
||||
@@ -226,6 +227,8 @@ async fn cloud_async_question_reply_uses_cloud_admission() -> Result<()> {
|
||||
|
||||
for rejected in [false, true] {
|
||||
let (mut app, _events, mut ops) = make_test_app_with_channels().await;
|
||||
let metrics = Collector::new();
|
||||
app.statusline_metrics = metrics.metrics(&mut app.config);
|
||||
let id = ThreadId::new();
|
||||
app.enqueue_primary_thread_session(
|
||||
test_thread_session(id, app.config.cwd.to_path_buf()),
|
||||
@@ -303,6 +306,7 @@ async fn cloud_async_question_reply_uses_cloud_admission() -> Result<()> {
|
||||
command.response.send(Ok(receipt)).unwrap();
|
||||
});
|
||||
result?;
|
||||
assert!(metrics.snapshot().is_empty());
|
||||
let composer = app.chat_widget.composer_text_with_pending();
|
||||
if rejected {
|
||||
insta::assert_snapshot!(composer, @r"
|
||||
@@ -1957,6 +1961,64 @@ async fn make_history_test_app() -> Result<(Box<App>, tempfile::TempDir)> {
|
||||
Ok((app, codex_home))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn first_prompt_counts_once_before_and_after_resume() -> Result<()> {
|
||||
use crate::app::session_lifecycle::ThreadAttachPresentation::Fresh;
|
||||
use crate::app::session_lifecycle::ThreadAttachPresentation::SessionLineage;
|
||||
use core_test_support::responses;
|
||||
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let model = responses::start_mock_server().await;
|
||||
app_test_support::MockResponsesConfig::new(&model.uri()).write(&app.config.codex_home)?;
|
||||
app.config = app
|
||||
.rebuild_config_for_cwd(app.config.cwd.to_path_buf())
|
||||
.await?;
|
||||
let metrics = Collector::new();
|
||||
app.statusline_metrics = metrics.metrics(&mut app.config);
|
||||
let mut server = crate::start_embedded_app_server_for_picker(&app.config).await?;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let saved = create_history_rollout(&app.config, ThreadHistoryMode::Legacy, "saved prompt")?;
|
||||
let fresh = server.start_thread(&app.config).await?;
|
||||
let resumed = server
|
||||
.resume_thread(
|
||||
&app.local_settings,
|
||||
app.config.clone(),
|
||||
saved,
|
||||
app.resume_model_settings(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
for (thread, presentation, mode) in [
|
||||
(fresh, Fresh, "feature_off"),
|
||||
(resumed, SessionLineage, "builtin"),
|
||||
] {
|
||||
let thread_id = thread.session.thread_id;
|
||||
app.replace_chat_widget_with_app_server_thread(
|
||||
&mut tui,
|
||||
thread,
|
||||
presentation,
|
||||
/*initial_user_message*/ None,
|
||||
)
|
||||
.await?;
|
||||
drain_app_events(&mut app, &mut tui, &mut server, &mut events).await?;
|
||||
app.chat_widget
|
||||
.set_feature_enabled(Feature::TuiExtensionsStatusLine, mode == "builtin");
|
||||
for text in ["first prompt", "follow-up"] {
|
||||
let sent = responses::mount_sse_once(&model, responses::sse_completed("ok")).await;
|
||||
app.chat_widget.apply_external_edit(text.into());
|
||||
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
||||
drain_app_events(&mut app, &mut tui, &mut server, &mut events).await?;
|
||||
super::safety_buffering::wait_for_turn_completed(&mut app, &mut server, thread_id)
|
||||
.await;
|
||||
let input = sent.single_request().message_input_texts("user");
|
||||
assert_eq!(input.last().map(String::as_str), Some(text));
|
||||
}
|
||||
assert_eq!(metrics.snapshot(), [format!("first_prompt mode={mode} 1")]);
|
||||
}
|
||||
server.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_only_history_hides_the_statusline_until_interactive_resume() -> Result<()> {
|
||||
let (mut app, _codex_home) = make_history_test_app().await?;
|
||||
|
||||
@@ -25,6 +25,19 @@ pub(super) async fn try_submit_user_turn(
|
||||
else {
|
||||
return Ok(false);
|
||||
};
|
||||
let is_user_prompt = *turn_trigger == "user"
|
||||
&& matches!(
|
||||
cloud_submission,
|
||||
CloudSubmissionIntent::StartOrSteer | CloudSubmissionIntent::StartIfIdle
|
||||
);
|
||||
if is_user_prompt
|
||||
&& app.primary_thread_id == Some(thread_id)
|
||||
&& app.active_thread_id == Some(thread_id)
|
||||
&& app.chat_widget.thread_id() == Some(thread_id)
|
||||
{
|
||||
app.statusline_metrics
|
||||
.record_first_prompt(&app.config, &app.chat_widget);
|
||||
}
|
||||
let intent = if *turn_trigger == "user" {
|
||||
match (*cloud_submission, app_server.thread_params_mode()) {
|
||||
(
|
||||
|
||||
@@ -72,7 +72,7 @@ impl StatuslineReadEvent {
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
pub(super) fn selected_statusline_provider(&self) -> Option<&StatusLineProviderId> {
|
||||
pub(crate) fn selected_statusline_provider(&self) -> Option<&StatusLineProviderId> {
|
||||
if self.statusline_disconnected
|
||||
|| self.read_only_history
|
||||
|| self
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
//! Aggregate statusline counters with fixed labels and the current analytics consent.
|
||||
|
||||
use crate::chatwidget::ChatWidget;
|
||||
use crate::legacy_core::config::Config;
|
||||
use codex_config::types::DEFAULT_OTEL_ENVIRONMENT;
|
||||
use codex_config::types::OtelExporterKind;
|
||||
use codex_features::Feature;
|
||||
use codex_otel::MetricsClient;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct StatuslineMetrics {
|
||||
first_prompt_recorded: bool,
|
||||
collector: Option<(MetricsClient, OtelExporterKind)>,
|
||||
}
|
||||
|
||||
@@ -40,12 +43,36 @@ impl StatuslineMetrics {
|
||||
OtelExporterKind::OtlpHttp { .. } | OtelExporterKind::OtlpGrpc { .. } => true,
|
||||
};
|
||||
Self {
|
||||
first_prompt_recorded: false,
|
||||
collector: metrics
|
||||
.filter(|_| eligible)
|
||||
.map(|client| (client, exporter.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn begin_visit(&mut self) {
|
||||
self.first_prompt_recorded = false;
|
||||
}
|
||||
|
||||
pub(crate) fn record_first_prompt(&mut self, config: &Config, chat: &ChatWidget) {
|
||||
if self.first_prompt_recorded {
|
||||
return;
|
||||
}
|
||||
self.first_prompt_recorded = true;
|
||||
let mode = if !chat
|
||||
.config_ref()
|
||||
.features
|
||||
.enabled(Feature::TuiExtensionsStatusLine)
|
||||
{
|
||||
"feature_off"
|
||||
} else if chat.selected_statusline_provider().is_some() {
|
||||
"custom"
|
||||
} else {
|
||||
"builtin"
|
||||
};
|
||||
self.record(config, "codex.statusline.first_prompt", &[("mode", mode)]);
|
||||
}
|
||||
|
||||
pub(crate) fn record(
|
||||
&self,
|
||||
config: &Config,
|
||||
|
||||
Reference in New Issue
Block a user