mirror of
https://github.com/openai/codex.git
synced 2026-11-18 15:01:48 +00:00
Acknowledge pending TUI steers by submission ID (#42451)
## Why Completion receipts for identical user messages could acknowledge the wrong pending steer. When the receipt arrived while another thread was displayed, the stale pending state could later be restored and resubmitted. ## What changed - Assign each TUI submission a client message ID and pass it through turn start and steer requests. - Preserve pending steer IDs across thread input snapshots and match completion receipts by ID, while retaining content-based matching for older app servers that do not echo IDs. - Acknowledge matching receipts for inactive threads before their notifications can be discarded, including threads stored in the agents overview. ## Testing Added coverage for identical steer receipts and for switching within and between tasks before interrupting an active turn. GitOrigin-RevId: 28bd80a735ff86cd7bf836f24b448e7499f0a902
This commit is contained in:
1 parent
36984da442
commit
8b8ee28a9b
14 files changed
+250
-97
No files matched your search
@@ -1761,9 +1761,10 @@ async fn restore_thread_input_state_applies_running_state_policy() {
|
||||
..Default::default()
|
||||
}),
|
||||
safety_buffering_prompt: Some(UserMessage::from("buffered prompt")),
|
||||
pending_steers: VecDeque::from([UserMessage::from("submitted to the interrupted turn")]),
|
||||
pending_steer_history_records: VecDeque::from([pending_history.clone()]),
|
||||
pending_steer_compare_keys: VecDeque::new(),
|
||||
pending_steers: VecDeque::from([PendingSteer {
|
||||
history_record: pending_history.clone(),
|
||||
..pending_steer("submitted to the interrupted turn")
|
||||
}]),
|
||||
rejected_steers_queue: VecDeque::new(),
|
||||
rejected_steer_history_records: VecDeque::new(),
|
||||
queued_user_messages: VecDeque::from([UserMessage::from("already queued").into()]),
|
||||
|
||||
@@ -940,6 +940,7 @@ pub(super) fn complete_assistant_message(
|
||||
|
||||
pub(super) fn pending_steer(text: &str) -> PendingSteer {
|
||||
PendingSteer {
|
||||
client_id: "test-submission".to_string(),
|
||||
user_message: UserMessage::from(text),
|
||||
history_record: UserMessageHistoryRecord::UserMessageText,
|
||||
compare_key: PendingSteerCompareKey {
|
||||
|
||||
@@ -360,14 +360,15 @@ async fn review_restores_context_window_indicator() {
|
||||
#[tokio::test]
|
||||
async fn restore_thread_input_state_restores_pending_steers_without_downgrading_them() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let mut pending_steers = VecDeque::new();
|
||||
pending_steers.push_back(UserMessage::from("pending steer"));
|
||||
let expected_compare_key = PendingSteerCompareKey {
|
||||
message: "hidden IDE context\npending steer".to_string(),
|
||||
image_count: 0,
|
||||
};
|
||||
let mut pending_steer_compare_keys = VecDeque::new();
|
||||
pending_steer_compare_keys.push_back(expected_compare_key.clone());
|
||||
let expected_pending = PendingSteer {
|
||||
client_id: "saved-submission".to_string(),
|
||||
compare_key: expected_compare_key,
|
||||
..pending_steer("pending steer")
|
||||
};
|
||||
let mut rejected_steers_queue = VecDeque::new();
|
||||
rejected_steers_queue.push_back(UserMessage::from("already rejected"));
|
||||
let mut queued_user_messages = VecDeque::new();
|
||||
@@ -377,9 +378,7 @@ async fn restore_thread_input_state_restores_pending_steers_without_downgrading_
|
||||
Some(ThreadInputState {
|
||||
composer: None,
|
||||
safety_buffering_prompt: None,
|
||||
pending_steers,
|
||||
pending_steer_history_records: VecDeque::new(),
|
||||
pending_steer_compare_keys,
|
||||
pending_steers: VecDeque::from([expected_pending.clone()]),
|
||||
rejected_steers_queue,
|
||||
rejected_steer_history_records: VecDeque::new(),
|
||||
queued_user_messages,
|
||||
@@ -401,22 +400,38 @@ async fn restore_thread_input_state_restores_pending_steers_without_downgrading_
|
||||
chat.queued_user_message_texts(),
|
||||
vec!["already rejected", "queued draft"]
|
||||
);
|
||||
assert_eq!(chat.input_queue.pending_steers.len(), 1);
|
||||
assert_eq!(
|
||||
chat.input_queue
|
||||
.pending_steers
|
||||
.front()
|
||||
.unwrap()
|
||||
.user_message
|
||||
.text,
|
||||
"pending steer"
|
||||
);
|
||||
assert_eq!(
|
||||
chat.input_queue.pending_steers.front().unwrap().compare_key,
|
||||
expected_compare_key
|
||||
chat.input_queue.pending_steers,
|
||||
VecDeque::from([expected_pending])
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn identical_steer_receipts_only_acknowledge_the_matching_submission() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let pending = pending_steer("continue");
|
||||
chat.input_queue.pending_steers.push_back(pending.clone());
|
||||
|
||||
for (client_id, expected) in [
|
||||
("older-submission", VecDeque::from([pending.clone()])),
|
||||
(pending.client_id.as_str(), VecDeque::new()),
|
||||
] {
|
||||
chat.handle_thread_item(
|
||||
AppServerThreadItem::UserMessage {
|
||||
id: client_id.to_string(),
|
||||
client_id: Some(client_id.to_string()),
|
||||
content: vec![UserInput::Text {
|
||||
text: "continue".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
},
|
||||
"turn-1".to_string(),
|
||||
ThreadItemRenderSource::Live,
|
||||
);
|
||||
assert_eq!(chat.input_queue.pending_steers, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn steer_enter_queues_while_plan_stream_is_active() {
|
||||
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
Reference in new issue
Block a user