mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Track WebSocket continuation modes and full-input send reasons (#46051)
## Why Per-socket metrics label resends after reconnect as initial requests, obscuring why full input was sent. Client telemetry can preserve that reason across reconnect failures and turn boundaries. ## What changed - Add `codex.websocket.continuation` to count `response.create` send attempts, including failed sends, with `mode`, `reason`, and `phase` tags. - Distinguish incremental continuations, fresh requests, restored history, closed connections, and other full-input sends. Track warmup and generation separately. - Preserve the first continuation reset reason until the next send and identify resumed or forked history. - Allow session telemetry to use a `MetricsClient` supplied through thread extensions and document the counter's semantics. ## Testing Add metric assertions for incremental reuse, warmup, changed requests, account switches, reconnects, and resumed or forked history. Add a unit test for preserving reset reasons across repeated resets and turn boundaries. GitOrigin-RevId: 29324f5e9d5677e0c6068f89b2256a92a5a0d157
This commit is contained in:
1 parent
821ad43f9d
commit
c56dda711c
7 files changed
+295
-70
No files matched your search
@@ -645,13 +645,16 @@ fn websocket_incremental_reuse_tracks_raw_result_metadata() -> anyhow::Result<()
|
||||
})
|
||||
.unwrap();
|
||||
session.websocket_session.last_response_rx = Some(receiver);
|
||||
let (incremental, from_warmup) = session.prepare_websocket_request(¤t);
|
||||
let continuation = session.prepare_websocket_request(¤t);
|
||||
assert_eq!(
|
||||
incremental,
|
||||
expect_incremental.then_some(("previous-response".to_string(), vec![follow_up])),
|
||||
continuation.map(|continuation| (
|
||||
continuation.response_id,
|
||||
continuation.items,
|
||||
continuation.from_untraced_warmup,
|
||||
)),
|
||||
expect_incremental.then_some(("previous-response".to_string(), vec![follow_up], false)),
|
||||
"{scenario}",
|
||||
);
|
||||
assert!(!from_warmup);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -809,6 +812,43 @@ fn test_session_telemetry() -> SessionTelemetry {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn websocket_continuation_reset_reason_survives_failed_reconnect_and_turn_boundary() {
|
||||
for (reason, later_reason) in [
|
||||
("connection_closed", "other"),
|
||||
("other", "connection_closed"),
|
||||
] {
|
||||
let client = test_model_client(SessionSource::Cli);
|
||||
let request = client
|
||||
.build_responses_request(
|
||||
&Prompt::default(),
|
||||
&test_model_info(),
|
||||
/*effort*/ None,
|
||||
codex_protocol::config_types::ReasoningSummary::None,
|
||||
/*service_tier*/ None,
|
||||
&test_responses_metadata_for_client(
|
||||
&client,
|
||||
/*turn_id*/ None,
|
||||
format!("{}:0", client.state.thread_id),
|
||||
/*parent_thread_id*/ None,
|
||||
TestCodexResponsesRequestKind::Turn,
|
||||
),
|
||||
)
|
||||
.expect("build continuation request");
|
||||
let mut session = client.new_session();
|
||||
session.websocket_session.last_request = Some(request);
|
||||
session.websocket_session.reset(Some(reason));
|
||||
session.websocket_session.reset(/*reason*/ None);
|
||||
session.websocket_session.reset(Some(later_reason));
|
||||
drop(session);
|
||||
let session = client.new_session();
|
||||
assert_eq!(
|
||||
session.websocket_session.continuation_reset_reason,
|
||||
Some(reason)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn spawned_session_source() -> SessionSource {
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: ThreadId::new(),
|
||||
|
||||
Reference in new issue
Block a user