mirror of
https://github.com/openai/codex.git
synced 2026-11-18 15:01:48 +00:00
Allow reviewing and continuing misalignment-paused chats (#42410)
## Why Misalignment policy failures pause the current chat. When the server provides findings and a continuation request, users should be able to inspect them and explicitly decide whether to proceed. ## What changed - Add a `Review findings` flow that shows the detailed explanation and quoted continuation request in an overlay. - Require explicit acknowledgement before starting a continuation turn, while preserving the active approval and sandbox settings. - Keep ordinary input blocked and reject stale, replaced, invalid, or duplicate continuation attempts. - Label the overlay shortcut as `q close` to match its behavior. ## Testing - Add TUI tests covering findings review, explicit confirmation, successful and failed continuation, stale findings, duplicate events, and invalid continuation data. GitOrigin-RevId: 36a738adf272f95db92eaee5712fb00061d0fa52
This commit is contained in:
1 parent
93053c7f5d
commit
fdf23b4097
31 files changed
+740
-41
No files matched your search
@@ -123,3 +123,91 @@ async fn misalignment_policy_failure_stops_the_thread_and_renders_once() {
|
||||
assert_matches!(rx.try_recv(), Ok(AppEvent::OpenAgentsOverview));
|
||||
assert!(chat.bottom_pane.has_active_view());
|
||||
}
|
||||
|
||||
fn review_details() -> codex_app_server_protocol::MisalignmentErrorDetails {
|
||||
codex_app_server_protocol::MisalignmentErrorDetails {
|
||||
error_type: Some("new_category".to_string()),
|
||||
detailed_explanation: Some(
|
||||
"The agent proposed a change outside your instructions.".to_string(),
|
||||
),
|
||||
steer: Some(codex_app_server_protocol::MisalignmentSteer {
|
||||
message: "Continue with the requested change only.".to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn select_review(
|
||||
chat: &mut ChatWidget,
|
||||
rx: &mut tokio::sync::mpsc::UnboundedReceiver<AppEvent>,
|
||||
) -> Arc<MisalignmentReview> {
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
std::iter::from_fn(|| rx.try_recv().ok())
|
||||
.find_map(|event| match event {
|
||||
AppEvent::ReviewMisalignment(review) => Some(review),
|
||||
_ => None,
|
||||
})
|
||||
.expect("review action")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn misalignment_review_requires_current_findings() {
|
||||
let (mut chat, mut rx, _) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
handle_turn_started(&mut chat, "turn-1");
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), Some(review_details()));
|
||||
let review = select_review(&mut chat, &mut rx);
|
||||
chat.show_misalignment_review_confirmation(Arc::clone(&review));
|
||||
assert_chatwidget_snapshot!(
|
||||
"misalignment_review_narrow",
|
||||
render_bottom_popup(&chat, /*width*/ 38)
|
||||
);
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
assert!(
|
||||
matches!(rx.try_recv(), Ok(AppEvent::ContinueMisalignment(current)) if Arc::ptr_eq(¤t, &review))
|
||||
);
|
||||
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
assert!(rx.try_recv().is_err());
|
||||
|
||||
// A duplicate terminal event must not reset an in-progress review.
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), Some(review_details()));
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), /*details*/ None);
|
||||
assert!(chat.is_current_misalignment_review(&review));
|
||||
let mut changed = review_details();
|
||||
changed.detailed_explanation = Some("Updated findings".to_string());
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), Some(changed));
|
||||
assert!(!chat.is_current_misalignment_review(&review));
|
||||
|
||||
// Present-but-invalid findings withdraw the old authorization.
|
||||
for explanation in [None, Some(" ".to_string()), Some("a".repeat(65537))] {
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), Some(review_details()));
|
||||
let replacement = select_review(&mut chat, &mut rx);
|
||||
let mut details = review_details();
|
||||
details.detailed_explanation = explanation;
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), Some(details));
|
||||
assert!(!chat.is_current_misalignment_review(&replacement));
|
||||
}
|
||||
|
||||
for steer in [None, Some(" ".to_string()), Some("a".repeat(1025))] {
|
||||
let mut details = review_details();
|
||||
details.steer =
|
||||
steer.map(|message| codex_app_server_protocol::MisalignmentSteer { message });
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), Some(details));
|
||||
let review = select_review(&mut chat, &mut rx);
|
||||
chat.show_misalignment_review_confirmation(Arc::clone(&review));
|
||||
assert!(review.continuation_message().is_none());
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
assert!(
|
||||
!std::iter::from_fn(|| rx.try_recv().ok())
|
||||
.any(|event| matches!(event, AppEvent::ContinueMisalignment(_)))
|
||||
);
|
||||
assert!(!chat.bottom_pane.composer_input_enabled());
|
||||
}
|
||||
handle_turn_started(&mut chat, "turn-2");
|
||||
chat.on_misalignment_error(Some("turn-1".to_string()), Some(review_details()));
|
||||
assert!(!chat.has_misalignment_policy_violation());
|
||||
assert!(chat.bottom_pane.composer_input_enabled());
|
||||
// A queued Back action cannot reopen the precaution after a new turn starts.
|
||||
chat.show_misalignment_policy_precaution();
|
||||
assert!(!chat.bottom_pane.has_active_view());
|
||||
}
|
||||
Reference in new issue
Block a user