From 02de56addf5ffb51263631f067be880467a16935 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Fri, 13 Nov 2026 18:57:13 +0000 Subject: [PATCH 1/3] fix(session): open CloudFetch-disabled sessions on warehouses that reject can_cloud_download Since #436, a session with CloudFetch disabled sends can_cloud_download=false at CreateSession. Lakehouse Real-Time (Reyden) warehouses reject it with INVALID_CONF_VALUE, so use_cloud_fetch=False now fails at connect() there. When CreateSession rejects that setting, retry once without it and request INLINE results for the session, which is what 1.4.0 did. Signed-off-by: Vu Anh Phung Co-authored-by: Isaac --- NEXT_CHANGELOG.md | 1 + src/client/sea.rs | 82 +++++++++++++++++++++++++++--------- tests/v0_execute_wiremock.rs | 82 ++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 21 deletions(-) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 6aa75289..805f55a0 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -26,6 +26,7 @@ changes go in their respective binding's NEXT_CHANGELOG. ### Fixed - `Session::open` authenticates once before resolving feature flags. A failed OAuth token request now fails the open immediately instead of being sent a second time by CreateSession. +- With CloudFetch disabled, sessions open again on warehouses that reject the `can_cloud_download` session setting (Lakehouse Real-Time). Those sessions request `INLINE` results, as 1.4.0 did, so results over the 25 MiB inline limit fail. --- *Note: When making changes, please add your change under the appropriate diff --git a/src/client/sea.rs b/src/client/sea.rs index 7003150f..ea6999bd 100644 --- a/src/client/sea.rs +++ b/src/client/sea.rs @@ -180,6 +180,10 @@ pub(crate) struct SeaRestTransport { config: TransportConfig, session_route: OnceLock, session_version: AtomicI64, + /// Set when CloudFetch is disabled and the warehouse rejected the + /// `can_cloud_download` session conf (Reyden does): the session then + /// requests `INLINE` results instead of paged inline results. + inline_disposition: AtomicBool, reader_factory: OnceLock, runtime_handle: OnceLock, } @@ -222,6 +226,7 @@ impl SeaRestTransport { config, session_route: OnceLock::new(), session_version: AtomicI64::new(NO_SESSION_VERSION), + inline_disposition: AtomicBool::new(false), reader_factory: OnceLock::new(), runtime_handle: OnceLock::new(), } @@ -672,7 +677,12 @@ impl SeaRestTransport { session_version: self.current_session_version(), catalog: params.catalog.clone(), schema: params.schema.clone(), - disposition: "INLINE_OR_EXTERNAL_LINKS".to_string(), + disposition: if self.inline_disposition.load(Ordering::Relaxed) { + "INLINE" + } else { + "INLINE_OR_EXTERNAL_LINKS" + } + .to_string(), format: "ARROW_STREAM".to_string(), wait_timeout: params.wait_timeout.clone(), on_wait_timeout: params.on_wait_timeout.clone(), @@ -1057,6 +1067,16 @@ impl SeaRestTransport { } } +/// Whether a CreateSession error is the server rejecting the `can_cloud_download` +/// session conf (e.g. Reyden: `[INVALID_CONF_VALUE] ... "can_cloud_download"`). +fn rejects_can_cloud_download(error: &Error) -> bool { + error.http_status == Some(400) + && error + .message + .to_ascii_lowercase() + .contains("can_cloud_download") +} + /// Convert a parsed `GetChunksResponse` into the kernel-facing /// `ChunkLinkFetchResult`. Extracted from `get_result_chunks` /// so the continuation derivation (top-level vs per-link @@ -1141,31 +1161,51 @@ impl Transport for SeaRestTransport { session_config.insert("can_cloud_download".to_string(), "false".to_string()); } - let request_body = CreateSessionRequest { - warehouse_id: None, - catalog: catalog.map(|s| s.to_string()), - schema: schema.map(|s| s.to_string()), - session_confs: session_config, - execution_mode: SessionExecutionMode::Fast, + let build_request = |session_confs: HashMap| { + let request_body = CreateSessionRequest { + warehouse_id: None, + catalog: catalog.map(|s| s.to_string()), + schema: schema.map(|s| s.to_string()), + session_confs, + execution_mode: SessionExecutionMode::Fast, + }; + self.http_client + .inner() + .request(Method::POST, &url) + .header("Content-Type", "application/json") + .json(&request_body) + .build() + .map_err(|e| { + Error::invalid_argument().message(format!("Failed to build request: {e}")) + }) }; debug!("Creating session at {}", url); - let request = self + let response = match self .http_client - .inner() - .request(Method::POST, &url) - .header("Content-Type", "application/json") - .json(&request_body) - .build() - .map_err(|e| { - Error::invalid_argument().message(format!("Failed to build request: {e}")) - })?; - - let response = self - .http_client - .execute(request, RequestType::CreateSession) - .await?; + .execute( + build_request(session_config.clone())?, + RequestType::CreateSession, + ) + .await + { + Ok(response) => response, + Err(e) if !self.config.cloudfetch_enabled && rejects_can_cloud_download(&e) => { + // Reyden rejects `can_cloud_download` but serves INLINE results + // (and fails statements over the inline byte limit). + warn!( + error = %e, + "warehouse rejected can_cloud_download; using INLINE results for this session" + ); + session_config.retain(|key, _| !key.eq_ignore_ascii_case("can_cloud_download")); + self.inline_disposition.store(true, Ordering::Relaxed); + self.http_client + .execute(build_request(session_config)?, RequestType::CreateSession) + .await? + } + Err(e) => return Err(e), + }; let realtime = response .headers() .get(REALTIME_SESSION_HEADER) diff --git a/tests/v0_execute_wiremock.rs b/tests/v0_execute_wiremock.rs index c2afcec4..404dde5f 100644 --- a/tests/v0_execute_wiremock.rs +++ b/tests/v0_execute_wiremock.rs @@ -1681,6 +1681,88 @@ async fn execute_with_cloudfetch_disabled_supports_paged_arrow_results() { ); } +#[tokio::test] +async fn cloudfetch_disabled_falls_back_to_inline_when_warehouse_rejects_can_cloud_download() { + use wiremock::matchers::body_string_contains; + // Reyden rejects the paged-inline session conf at CreateSession; the + // session must still open and request INLINE results instead. + let server = MockServer::start().await; + Mock::given(method("POST")) + .and(path("/api/2.0/sql/warehouses/test_wh/sessions")) + .and(body_string_contains("can_cloud_download")) + .respond_with(ResponseTemplate::new(400).set_body_json(json!({ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Invalid session params: [INVALID_CONF_VALUE] The value 'false' in the \ + config \"can_cloud_download\" is invalid. SQLSTATE: 22022", + }))) + .with_priority(1) + .expect(1) + .mount(&server) + .await; + Mock::given(method("POST")) + .and(path("/api/2.0/sql/warehouses/test_wh/sessions")) + .respond_with( + ResponseTemplate::new(200) + .set_body_string(r#"{"session_id":"sess-test","warehouse_id":"test_wh"}"#), + ) + .with_priority(2) + .expect(1) + .mount(&server) + .await; + mount_delete_session(&server).await; + mount_close_any_statement(&server).await; + mount_execute( + &server, + succeeded_inline_body("stmt-inline", &int64_batch("n", vec![7])), + ) + .await; + + let mut result = ResultConfig::default(); + result.cloudfetch_enabled = false; + let session = open_session_with_result(&server, result).await; + let mut stmt = session.statement(); + stmt.spec().sql("SELECT 7 AS n"); + let mut exec = stmt.execute().await.expect("inline execute"); + let batches = drain(exec.result_stream_mut()).await; + assert_eq!(batches.len(), 1); + exec.close().await.expect("close"); + assert_eq!(recorded_execute_disposition(&server).await, "INLINE"); + session.close().await.expect("close session"); +} + +#[tokio::test] +async fn cloudfetch_disabled_surfaces_other_create_session_errors() { + let server = MockServer::start().await; + Mock::given(method("POST")) + .and(path("/api/2.0/sql/warehouses/test_wh/sessions")) + .respond_with(ResponseTemplate::new(400).set_body_json(json!({ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Invalid session params: [INVALID_CONF_VALUE] TIMEZONE is invalid.", + }))) + .expect(1) + .mount(&server) + .await; + let mut result = ResultConfig::default(); + result.cloudfetch_enabled = false; + let error = match Session::builder() + .connection( + ConnectionConfig::from_http_path(server.uri(), "/sql/1.0/warehouses/test_wh").unwrap(), + ) + .auth(AuthConfig::Pat { + token: "dapi_test_token".into(), + identity_federation_client_id: None, + }) + .result(result) + .open() + .await + { + Ok(_) => panic!("unrelated CreateSession rejection must surface"), + Err(error) => error, + }; + assert_eq!(error.http_status, Some(400)); + assert!(error.message.contains("TIMEZONE"), "{error}"); +} + #[tokio::test] async fn execute_with_cloudfetch_disabled_rejects_external_links_without_downloading() { let server = MockServer::start().await; From 0c41855a22711c47d7ad8f5c4485a09ad5a61735 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Fri, 13 Nov 2026 19:47:50 +0000 Subject: [PATCH 2/3] test(session): pin the can_cloud_download rejection match Only an HTTP 400 that names can_cloud_download (case-insensitive) switches the session to INLINE; other statuses and unrelated 400s do not. Signed-off-by: Vu Anh Phung Co-authored-by: Isaac --- src/client/sea.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/client/sea.rs b/src/client/sea.rs index ea6999bd..c2a0fb70 100644 --- a/src/client/sea.rs +++ b/src/client/sea.rs @@ -2476,6 +2476,32 @@ mod tests { } } + #[test] + fn rejects_can_cloud_download_requires_http_400_and_names_the_setting() { + let rejection = |status: u16, message: &str| { + Error::from_http_status(status).message(format!("HTTP {status}: {message}")) + }; + let reyden = r#"[INVALID_CONF_VALUE] The value 'false' in the config "can_cloud_download" is invalid."#; + assert!(rejects_can_cloud_download(&rejection(400, reyden))); + assert!(rejects_can_cloud_download(&rejection( + 400, + "CAN_CLOUD_DOWNLOAD is not supported" + ))); + for status in [401, 403, 404, 429, 500, 503] { + assert!( + !rejects_can_cloud_download(&rejection(status, reyden)), + "HTTP {status} must not trigger the INLINE fallback" + ); + } + assert!(!rejects_can_cloud_download(&rejection( + 400, + "[INVALID_CONF_VALUE] TIMEZONE is invalid" + ))); + let mut no_status = Error::invalid_argument().message(reyden); + no_status.http_status = None; + assert!(!rejects_can_cloud_download(&no_status)); + } + #[test] fn test_list_table_types() { let client = create_test_client(); From 6333a2c4828d6736da9692150384a892139a90e7 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Fri, 13 Nov 2026 20:17:27 +0000 Subject: [PATCH 3/3] fix(session): match only the can_cloud_download rejection and keep its error Fall back to INLINE only when the 400 rejects the can_cloud_download conf itself (INVALID_CONF_VALUE ... config "can_cloud_download"). If the retried CreateSession also fails, report both errors and leave the session's disposition unchanged. Signed-off-by: Vu Anh Phung Co-authored-by: Isaac --- src/client/sea.rs | 46 ++++++++++++++++++++++--------- tests/v0_execute_wiremock.rs | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/src/client/sea.rs b/src/client/sea.rs index c2a0fb70..dd1523fd 100644 --- a/src/client/sea.rs +++ b/src/client/sea.rs @@ -1068,13 +1068,13 @@ impl SeaRestTransport { } /// Whether a CreateSession error is the server rejecting the `can_cloud_download` -/// session conf (e.g. Reyden: `[INVALID_CONF_VALUE] ... "can_cloud_download"`). +/// session conf itself (Reyden: `[INVALID_CONF_VALUE] The value 'false' in the +/// config "can_cloud_download" is invalid`), not merely mentioning it. fn rejects_can_cloud_download(error: &Error) -> bool { + let message = error.message.to_ascii_lowercase(); error.http_status == Some(400) - && error - .message - .to_ascii_lowercase() - .contains("can_cloud_download") + && message.contains("invalid_conf_value") + && message.contains("config \"can_cloud_download\"") } /// Convert a parsed `GetChunksResponse` into the kernel-facing @@ -1199,10 +1199,23 @@ impl Transport for SeaRestTransport { "warehouse rejected can_cloud_download; using INLINE results for this session" ); session_config.retain(|key, _| !key.eq_ignore_ascii_case("can_cloud_download")); - self.inline_disposition.store(true, Ordering::Relaxed); - self.http_client + match self + .http_client .execute(build_request(session_config)?, RequestType::CreateSession) - .await? + .await + { + Ok(response) => { + self.inline_disposition.store(true, Ordering::Relaxed); + response + } + Err(mut retry_error) => { + retry_error.message = format!( + "{} (CreateSession retried without can_cloud_download after: {})", + retry_error.message, e.message + ); + return Err(retry_error); + } + } } Err(e) => return Err(e), }; @@ -2485,7 +2498,7 @@ mod tests { assert!(rejects_can_cloud_download(&rejection(400, reyden))); assert!(rejects_can_cloud_download(&rejection( 400, - "CAN_CLOUD_DOWNLOAD is not supported" + r#"[invalid_conf_value] The value 'false' in the config "CAN_CLOUD_DOWNLOAD" is invalid."# ))); for status in [401, 403, 404, 429, 500, 503] { assert!( @@ -2493,10 +2506,17 @@ mod tests { "HTTP {status} must not trigger the INLINE fallback" ); } - assert!(!rejects_can_cloud_download(&rejection( - 400, - "[INVALID_CONF_VALUE] TIMEZONE is invalid" - ))); + for other in [ + r#"[INVALID_CONF_VALUE] The value 'x' in the config "TIMEZONE" is invalid."#, + // Mentions the setting, but another conf is the one rejected. + r#"[INVALID_CONF_VALUE] The value 'x' in the config "TIMEZONE" is invalid. Params: can_cloud_download=false"#, + "can_cloud_download is not supported", + ] { + assert!( + !rejects_can_cloud_download(&rejection(400, other)), + "{other}" + ); + } let mut no_status = Error::invalid_argument().message(reyden); no_status.http_status = None; assert!(!rejects_can_cloud_download(&no_status)); diff --git a/tests/v0_execute_wiremock.rs b/tests/v0_execute_wiremock.rs index 404dde5f..29736f37 100644 --- a/tests/v0_execute_wiremock.rs +++ b/tests/v0_execute_wiremock.rs @@ -1763,6 +1763,58 @@ async fn cloudfetch_disabled_surfaces_other_create_session_errors() { assert!(error.message.contains("TIMEZONE"), "{error}"); } +#[tokio::test] +async fn cloudfetch_disabled_fallback_failure_reports_both_errors() { + use wiremock::matchers::body_string_contains; + let server = MockServer::start().await; + Mock::given(method("POST")) + .and(path("/api/2.0/sql/warehouses/test_wh/sessions")) + .and(body_string_contains("can_cloud_download")) + .respond_with(ResponseTemplate::new(400).set_body_json(json!({ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Invalid session params: [INVALID_CONF_VALUE] The value 'false' in the \ + config \"can_cloud_download\" is invalid. SQLSTATE: 22022", + }))) + .with_priority(1) + .expect(1) + .mount(&server) + .await; + Mock::given(method("POST")) + .and(path("/api/2.0/sql/warehouses/test_wh/sessions")) + .respond_with(ResponseTemplate::new(403).set_body_json(json!({ + "error_code": "PERMISSION_DENIED", + "message": "not allowed", + }))) + .with_priority(2) + .expect(1) + .mount(&server) + .await; + let mut result = ResultConfig::default(); + result.cloudfetch_enabled = false; + let error = match Session::builder() + .connection( + ConnectionConfig::from_http_path(server.uri(), "/sql/1.0/warehouses/test_wh").unwrap(), + ) + .auth(AuthConfig::Pat { + token: "dapi_test_token".into(), + identity_federation_client_id: None, + }) + .result(result) + .open() + .await + { + Ok(_) => panic!("a failed fallback CreateSession must surface"), + Err(error) => error, + }; + assert_eq!(error.http_status, Some(403)); + assert!(error.message.contains("not allowed"), "{error}"); + assert!( + error.message.contains("retried without can_cloud_download"), + "{error}" + ); + assert!(error.message.contains("INVALID_CONF_VALUE"), "{error}"); +} + #[tokio::test] async fn execute_with_cloudfetch_disabled_rejects_external_links_without_downloading() { let server = MockServer::start().await;