diff --git a/apps/mcp-server/tests/integration/tools_lifecycle.rs b/apps/mcp-server/tests/integration/tools_lifecycle.rs index d34b70c..b5b4b95 100644 --- a/apps/mcp-server/tests/integration/tools_lifecycle.rs +++ b/apps/mcp-server/tests/integration/tools_lifecycle.rs @@ -41,10 +41,15 @@ const TOOL: &str = "crm_lifecycle_lead"; const HOLD_MS: u64 = 250; /// A call that is still running when the client cancels it. const LONG_HOLD_MS: u64 = 1_500; -/// The grace period after a cancellation: the call must not complete in it. -const CANCEL_GRACE_MS: u64 = 1_200; +/// The grace period after a cancellation. It must exceed [`LONG_HOLD_MS`]: a call that was *not* +/// stopped completes its upstream request and records the outcome inside this window, so the checks +/// after it prove that the cancellation stopped the call rather than only that it had not finished +/// yet. +const CANCEL_GRACE_MS: u64 = 2_500; +/// The suite depends on that order: the constant must not silently drop back below the hold. +const _: () = assert!(CANCEL_GRACE_MS > LONG_HOLD_MS); -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] enum Revision { Legacy, Modern, @@ -644,40 +649,49 @@ async fn at_3_4_02_malformed_and_oversized_tokens_disable_progress_without_chang let fixture = fixture("lifecycle-bad-token", HOLD_MS, 5_000).await; let session = initialize_session(&fixture.client, &fixture.mcp_url, &fixture.api_key).await; - let oversized = "x".repeat(4096); - let oversized = json!(oversized); - let empty = json!(""); - let object = json!({ "not": "a token" }); - let array = json!([1, 2]); - let boolean = json!(true); - let mut observed = Vec::new(); - for token in [empty, object, array, boolean, oversized] { - let reply = fixture - .call_stream( - Revision::Legacy, - 520, - fixture.call_params(Some(token.clone()), Revision::Legacy), - Some(&session), - "req-bad-token", - ) - .await; - observed.push((token, reply)); - } + // Both supported revisions read the token from the same pinned `RequestMetaObject` field, so an + // unusable token must behave identically in each of them: no progress, unchanged result. + for revision in [Revision::Legacy, Revision::Modern] { + let carrier = match revision { + Revision::Legacy => Some(session.as_str()), + Revision::Modern => None, + }; + let tokens = [ + json!(""), + json!({ "not": "a token" }), + json!([1, 2]), + json!(true), + json!("x".repeat(4096)), + ]; + let mut observed = Vec::new(); + for token in tokens { + let reply = fixture + .call_stream( + revision, + 520, + fixture.call_params(Some(token.clone()), revision), + carrier, + "req-bad-token", + ) + .await; + observed.push((token, reply)); + } - for (token, reply) in observed { - assert!( - reply.progress_frames().is_empty(), - "token {token} must not produce progress, got {}", - reply.raw - ); - let terminal = reply.terminal(); - assert_eq!( - terminal["result"]["structuredContent"], - json!({ "id": "lead_123" }), - "token {token} must not change the execution result, got {terminal}" - ); - assert_eq!(terminal["result"]["isError"], json!(false)); - assert!(terminal["error"].is_null() || terminal.get("error").is_none()); + for (token, reply) in observed { + assert!( + reply.progress_frames().is_empty(), + "{revision:?}: token {token} must not produce progress, got {}", + reply.raw + ); + let terminal = reply.terminal(); + assert_eq!( + terminal["result"]["structuredContent"], + json!({ "id": "lead_123" }), + "{revision:?}: token {token} must not change the execution result, got {terminal}" + ); + assert_eq!(terminal["result"]["isError"], json!(false)); + assert!(terminal["error"].is_null() || terminal.get("error").is_none()); + } } } diff --git a/crates/crank-community-mcp/src/app/lifecycle.rs b/crates/crank-community-mcp/src/app/lifecycle.rs index 637bc99..2bf23d9 100644 --- a/crates/crank-community-mcp/src/app/lifecycle.rs +++ b/crates/crank-community-mcp/src/app/lifecycle.rs @@ -458,8 +458,9 @@ async fn call_future( /// A cancelled call is not answered: the pinned rule for a cancelled request is that no further /// message is sent for it, and the client that cancelled it ignores a late response anyway. Nothing -/// here claims that an outbound side effect did or did not happen — that statement belongs to the -/// Invocation History entry of the call, which records the cancellation as outcome-unknown. +/// here claims that an outbound side effect did or did not happen — and nothing else claims the +/// opposite either: the call is stopped before its terminal outcome, so its Invocation History holds +/// no row for this call at all (see the module docs for why there is no invented cancellation code). fn cancelled_response() -> Response { StatusCode::OK.into_response() }