mirror of
https://github.com/openai/codex.git
synced 2026-11-20 07:06:24 +00:00
## Why The TUI automatically canceled MCP user verification requests, preventing users from completing verification and approving them. ## What changed - Show verification prompts for active and inactive threads, with actions to verify and approve or cancel. - Run approved verification through the local app-server's `userVerification/verify` RPC and return the proof to the original request. Cancel on failure and show a warning in the requesting thread; remote workspaces remain unsupported. - Deduplicate prompts, preserve foreground streaming when another thread requests verification, and surface queued prompts when returning from a side conversation. - Cancel verification when its thread is discarded and ignore stale results after cancellation. ## Testing Add RPC, routing, and snapshot tests covering successful verification, unsupported binaries and remote workspaces, cancellation and late proofs, prompt replay, side conversation switching, and foreground stream preservation. GitOrigin-RevId: 2ae12f47c443e17de25f4ec033f6078ac28b1e03
140 lines
5.0 KiB
Rust
140 lines
5.0 KiB
Rust
//! Coordinates approval through the local app-server, keeping proofs out of views.
|
|
//!
|
|
//! Attempt IDs are UI-local generations: cancellation, resolution, or reconnect removes the
|
|
//! pending generation, so a late RPC response cannot approve a newly surfaced request.
|
|
|
|
use codex_app_server_protocol::ClientRequest;
|
|
use codex_app_server_protocol::RequestId;
|
|
use codex_app_server_protocol::ServerNotification;
|
|
use codex_app_server_protocol::UserVerificationProof;
|
|
use codex_app_server_protocol::UserVerificationVerifyResponse;
|
|
use codex_app_server_protocol::WarningNotification;
|
|
use codex_protocol::ThreadId;
|
|
use uuid::Uuid;
|
|
|
|
use super::App;
|
|
use super::app_server_requests::ResolvedAppServerRequest;
|
|
use super::user_verification_errors::verification_error_message;
|
|
use crate::app_command::AppCommand;
|
|
use crate::app_command::UserVerificationResponse;
|
|
use crate::app_event::AppEvent;
|
|
use crate::app_server_session::AppServerSession;
|
|
|
|
impl App {
|
|
pub(super) async fn start_user_verification(
|
|
&mut self,
|
|
app_server: &AppServerSession,
|
|
thread_id: ThreadId,
|
|
server_name: String,
|
|
request_id: RequestId,
|
|
) -> color_eyre::Result<()> {
|
|
if app_server.uses_remote_workspace() {
|
|
self.chat_widget.dismiss_app_server_request(
|
|
&ResolvedAppServerRequest::McpElicitation {
|
|
server_name: server_name.clone(),
|
|
request_id: request_id.clone(),
|
|
},
|
|
);
|
|
self.enqueue_thread_notification(
|
|
thread_id,
|
|
ServerNotification::Warning(WarningNotification {
|
|
thread_id: Some(thread_id.to_string()),
|
|
message: "User verification is unavailable for remote workspaces.".to_string(),
|
|
}),
|
|
)
|
|
.await?;
|
|
self.app_event_tx.resolve_user_verification(
|
|
thread_id,
|
|
server_name,
|
|
request_id,
|
|
UserVerificationResponse::Cancel,
|
|
);
|
|
return Ok(());
|
|
}
|
|
let Some(attempt) = self
|
|
.pending_app_server_requests
|
|
.user_verification
|
|
.begin(&server_name, &request_id)
|
|
else {
|
|
return Ok(());
|
|
};
|
|
let handle = app_server.request_handle();
|
|
let app_event_tx = self.app_event_tx.clone();
|
|
tokio::spawn(async move {
|
|
let attempt_id = attempt.id;
|
|
let verification = handle.request_typed::<UserVerificationVerifyResponse>(
|
|
ClientRequest::UserVerificationVerify {
|
|
request_id: RequestId::String(format!("user-verification-{attempt_id}")),
|
|
params: attempt.params,
|
|
},
|
|
);
|
|
let result = tokio::select! {
|
|
biased;
|
|
_ = attempt.cancelled.cancelled() => return,
|
|
result = verification => result,
|
|
}
|
|
.map(|response| response.proof)
|
|
.map_err(|error| verification_error_message(&error).to_string());
|
|
app_event_tx.send(AppEvent::UserVerificationFinished {
|
|
thread_id,
|
|
server_name,
|
|
request_id,
|
|
attempt_id,
|
|
result,
|
|
});
|
|
});
|
|
Ok(())
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub(super) async fn finish_user_verification(
|
|
&mut self,
|
|
app_server: &mut AppServerSession,
|
|
thread_id: ThreadId,
|
|
server_name: String,
|
|
request_id: RequestId,
|
|
attempt_id: Uuid,
|
|
result: Result<UserVerificationProof, String>,
|
|
) -> color_eyre::Result<()> {
|
|
if self.abandoned_side_threads.contains(&thread_id)
|
|
|| !self
|
|
.pending_app_server_requests
|
|
.user_verification
|
|
.is_pending(&server_name, &request_id, attempt_id)
|
|
{
|
|
return Ok(());
|
|
}
|
|
let response = match result {
|
|
Ok(proof) => UserVerificationResponse::Accept { proof },
|
|
Err(message) => {
|
|
self.enqueue_thread_notification(
|
|
thread_id,
|
|
ServerNotification::Warning(WarningNotification {
|
|
thread_id: Some(thread_id.to_string()),
|
|
message,
|
|
}),
|
|
)
|
|
.await?;
|
|
// Another trusted device may be supported later. For now every incomplete
|
|
// verification cancels the original elicitation without a fallback provider.
|
|
UserVerificationResponse::Cancel
|
|
}
|
|
};
|
|
self.chat_widget
|
|
.dismiss_app_server_request(&ResolvedAppServerRequest::McpElicitation {
|
|
server_name: server_name.clone(),
|
|
request_id: request_id.clone(),
|
|
});
|
|
self.submit_thread_op(
|
|
app_server,
|
|
thread_id,
|
|
AppCommand::resolve_user_verification(server_name, request_id, response),
|
|
)
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "user_verification_tests.rs"]
|
|
mod tests;
|