Add cancellation for native user-verification RPCs (#43925)

## Why

Canceling an elicitation does not stop a separate native verification RPC. Clients need a way to cancel that work and prevent a canceled proof from being delivered while it waits for outbound queue capacity.

## What changed

- Add experimental `userVerification/cancel` with `{requestId}` to signal cancellation of status, enroll, delete, or verify requests on the same connection.
- Return an empty acknowledgment without waiting for native work to exit. Unknown, finished, unrelated, and other-connection requests are no-ops.
- Retain request cancellation state until outbound capacity is available so canceled proofs are checked before enqueueing. Already enqueued responses and completed effects cannot be retracted.
- Document the API, request ID requirements, and independent lifetimes of elicitations and native verification RPCs.

## Testing

Add coverage for experimental opt-in, parameter validation, connection and request ID isolation, cancellation before native dispatch, repeated cancellation, worker-slot retention, and proof cancellation while waiting for outbound capacity.

GitOrigin-RevId: 03fcb83fcc5fab4169c68668822fc0bbb4970938
This commit is contained in:
riley-oai authored and copyberry committed 2026-09-08 21:48:53 +00:00
1 parent 9ec33e1926
commit 82d4a98912
11 files changed
+455 -7

No files matched your search

@@ -34,6 +34,7 @@ async fn user_verification_methods_require_experimental_opt_in() -> Result<()> {
("userVerification/status", json!({})),
("userVerification/enroll", json!({})),
("userVerification/delete", json!({})),
("userVerification/cancel", json!({"requestId": 1})),
(
"userVerification/verify",
json!({"challenge": "AQ", "title": "Approve", "description": ""}),
@@ -75,6 +76,49 @@ async fn user_verification_status_without_account_returns_local_readiness() -> R
Ok(())
}
#[tokio::test]
async fn user_verification_cancel_stdio_validates_and_acknowledges_unknown_requests() -> Result<()>
{
let mut app_server = TestAppServer::builder().build().await?;
let id = app_server
.send_raw_request(
"userVerification/cancel",
Some(json!({"requestId": "verify"})),
)
.await?;
let error = app_server
.read_stream_until_error_message(RequestId::Integer(id))
.await?;
assert_eq!(error.error.message, "Not initialized");
app_server.initialize().await?;
for params in [
json!({}),
json!({"requestId": null}),
json!({"requestId": 1.5}),
json!({"requestId": 1, "connectionId": 2}),
] {
let id = app_server
.send_raw_request("userVerification/cancel", Some(params))
.await?;
app_server
.read_stream_until_error_message(RequestId::Integer(id))
.await?;
}
for request_id in [json!(100), json!("100"), json!("100")] {
let id = app_server
.send_raw_request(
"userVerification/cancel",
Some(json!({"requestId": request_id})),
)
.await?;
let response = app_server
.read_stream_until_response_message(RequestId::Integer(id))
.await?;
assert_eq!(response.result, json!({}));
}
Ok(())
}
#[tokio::test]
async fn user_verification_without_provider_returns_typed_unavailability() -> Result<()> {
let mut app_server = TestAppServer::builder().build_initialized().await?;