Skip to content

feat(session): add session routing headers - #357

Closed
aakash-saravanan-db wants to merge 5 commits into
mainfrom
aakash-saravanan_data/fast-path-session-routing-headers
Closed

aakash-saravanan-db wants to merge 5 commits into
mainfrom
aakash-saravanan_data/fast-path-session-routing-headers

Conversation

@aakash-saravanan-db

@aakash-saravanan-db aakash-saravanan-db commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • negotiate real-time direct routing by sending x-databricks-realtime-direct-routing: true on CreateSession
  • treat x-databricks-realtime-session: true as the server acknowledgement that enables x-databricks-realtime-direct-routing: true on current-session follow-up requests
  • derive x-databricks-dbsql-session-id from CreateSessionResponse.session_id and attach it to current-session follow-up requests
  • keep detached statement requests on the standard route across lazy CloudFetch and inline continuation readers
  • prevent caller-provided headers from overriding the session routing contract

Testing

  • cargo +stable fmt --all -- --check
  • cargo +stable clippy --all-targets -- -D warnings
  • cargo +stable test (964 unit tests plus all non-ignored integration and doc tests)

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — a clean, well-tested change that threads SessionAttribution through the reader/link-fetcher/inline paths and negotiates routing headers correctly. The hardcoded Current attribution in cancel_statement/close_statement is safe because those are only reached on owning handles, and the execute_impl header-skip correctly blocks caller override without dropping the kernel's own routing headers. One low-severity maintainability note about the cross-direction header-name mapping.

Comment thread src/client/sea.rs Outdated

impl SessionRoutingHeaders {
fn from_response(headers: &HeaderMap) -> Self {
let direct_routing_enabled = headers

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The direct_routing_enabled flag is derived from the response header x-databricks-realtime-session (REALTIME_SESSION_HEADER), but the flag then gates emitting a differently-named request header x-databricks-realtime-direct-routing (REALTIME_DIRECT_ROUTING_HEADER) in follow_up_request (line 237). Reading only from_response, it looks like the field should map to the direct-routing header of the same stem. This is intentional per the Fast Path design (the server acknowledges direct routing via realtime-session, and the client echoes realtime-direct-routing on follow-ups), but the three near-identical header names crossing between request and response directions make the mapping easy to misread during future edits. Consider a one-line comment on the field or from_response noting that the realtime-session response header is what activates sending realtime-direct-routing on subsequent requests.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — one low readability note. The routing/session-ID header negotiation is threaded cleanly: attribution flows through readers, lazy CloudFetch link fetches, and inline continuation; detached statements correctly suppress session-owned routing headers; cancel/close hardcoding Current is safe given attached handles refuse those operations; and the managed-header skip prevents caller override without duplicating the kernel's negotiated values. Test coverage (wiremock lifecycle, independent-header cases, detached suppression, unit-level attribution preservation) is thorough. The only nit is the uncommented request/response header asymmetry in SessionRoutingHeaders::from_response.

Comment thread src/client/sea.rs Outdated

impl SessionRoutingHeaders {
fn from_response(headers: &HeaderMap) -> Self {
let direct_routing_enabled = headers

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The direct_routing_enabled flag is derived from the response's x-databricks-realtime-session header, yet in follow_up_request it gates emission of a different header, x-databricks-realtime-direct-routing: true. This request/response header asymmetry (server acknowledges via realtime-session, kernel then echoes direct-routing on follow-ups) is the intended handshake per the design doc, but it is entirely uncommented here. A future maintainer reading from_response will reasonably expect the flag to be sourced from the direct-routing header and may "fix" the perceived mismatch, breaking routing. Consider a one-line comment on the direct_routing_enabled assignment explaining that the server signals acceptance via REALTIME_SESSION_HEADER while follow-ups must send REALTIME_DIRECT_ROUTING_HEADER.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — a clean, well-tested implementation of session routing headers. All session-owned request sites (create/delete session, execute, status polling, chunk fetches, cancel/close, metadata) correctly attach the negotiated headers via follow_up_request, detached paths correctly suppress them, and the removed blanket InlineChunkSource impl has no remaining users. One low note about the cancel/close attribution asymmetry (safe today, but worth documenting).

Comment thread src/client/sea.rs
.http_client
.inner()
.request(Method::POST, &url)
.follow_up_request(Method::POST, &url, SessionAttribution::Current)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — cancel_statement and close_statement hardcode SessionAttribution::Current while every other follow-up RPC (get_statement_status, get_result_chunks, get_inline_chunk, fetch_completed_result, statement_status) threads attribution through the trait. This is safe today: per the detached-adopt contract in session.rs (a non-owning attach never fires close_statement, doesn't drop-cancel, and cancel() returns an error), only session-owned statements ever reach these two methods, so Current is always correct. Flagging as a latent inconsistency: if detached statements ever gain close/cancel capability, these paths would attach the negotiated x-databricks-dbsql-session-id / direct-routing headers to a statement that may belong to a different session. Consider a brief comment documenting why Current is hardcoded here, or threading attribution for symmetry.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Medium · 1 Low

Solid, well-tested change — routing-header propagation is verified across the full session-owned lifecycle (execute/status/chunks/inline/cancel/close/delete), detached statements are verified to omit the headers, and caller-override protection is covered. Two minor points: (1) medium — the PR description says x-databricks-realtime-session is "propagated" on follow-ups, but the code only uses it as a boolean gate and re-sends x-databricks-realtime-direct-routing instead; worth confirming the header contract against the design doc. (2) low — the dbsql-session-id emptiness check trims but the stored value doesn't.

Comment thread src/client/sea.rs

if let Some(headers) = self.session_routing_headers.get() {
if headers.direct_routing_enabled {
builder = builder.header(REALTIME_DIRECT_ROUTING_HEADER, "true");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium — The PR description says the negotiated x-databricks-realtime-session header is propagated on follow-up requests, but the implementation never echoes that header's value. Instead, from_response collapses x-databricks-realtime-session to a boolean gate (eq_ignore_ascii_case("true")) and follow-ups re-send x-databricks-realtime-direct-routing: true — a different header. Only x-databricks-dbsql-session-id is propagated verbatim.

If the server-issued x-databricks-realtime-session value is actually a routing token that must be echoed back (not merely a boolean ack), the current code silently drops it and direct routing would break. Please confirm against the Drivers Fast Path design that (a) x-databricks-realtime-session is a boolean acknowledgement, and (b) re-asserting x-databricks-realtime-direct-routing: true on follow-ups (rather than echoing the negotiated header) is the intended contract. If the intent is truly to echo the header, the value is being lost here.

Comment thread src/client/sea.rs Outdated
.and_then(|value| value.to_str().ok())
.is_some_and(|value| value.eq_ignore_ascii_case("true"));
let dbsql_session_id = headers
.get(DBSQL_SESSION_ID_HEADER)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The empty-check trims (!value.trim().is_empty()) but the stored/propagated value is the untrimmed value.cloned(). A server response whose x-databricks-dbsql-session-id carries leading/trailing whitespace would pass the non-empty check and then be forwarded with the whitespace intact on every follow-up request, which could produce a mismatched routing key. Consider storing the trimmed value (build a fresh HeaderValue from value.to_str().trim()) so the check and the stored value agree. Minor — reqwest rarely surfaces OWS-padded header values — but the check/store asymmetry is worth tightening.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — one low-severity note. The session-routing-header contract (negotiate on CreateSession, echo x-databricks-dbsql-session-id, gate x-databricks-realtime-direct-routing on the server ack, keep detached statement requests off the route, and reject caller overrides) is implemented consistently across all current-session request sites and backed by solid wiremock coverage. The only observation is that the new fallible steps in create_session run after the server has minted the session, slightly widening an existing orphan-on-error window (F1).

Comment thread src/client/sea.rs
"Failed to parse session response: {e} - body: {body}"
))
})?;
let dbsql_session_id = HeaderValue::try_from(session_response.session_id.as_str())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — Two new fallible steps run after the server has already minted the session (the POST /sessions succeeded): HeaderValue::try_from(session_id) (line 1122) and session_routing_headers.set(...) (returns Err on line 1135). If either returns Err, create_session propagates the error and the just-created server-side session is orphaned — the caller in Session::build never receives a session_id, so it cannot issue a DeleteSession to clean it up.

In practice both are effectively unreachable (session IDs are UUID-shaped ASCII, so HeaderValue::try_from won't fail; set() only fails on a second create, which Session::build never does), and the pre-existing text()/serde_json parsing steps already sit on this same error path — so this widens an existing orphan-on-error window rather than introducing a new failure class. Worth a note only: consider deriving/validating dbsql_session_id before or immediately from the response without failing the whole call (e.g. store None and skip the header) so a session mint is never wasted.

@aakash-saravanan-db
aakash-saravanan-db deleted the aakash-saravanan_data/fast-path-session-routing-headers branch October 2, 2026 17:10

This branch was previously deployed

1 inactive deployment
azure-prod — 9726b924 Deployed Sep 23, 2026 by oss-reviewer-bot[bot] via followup #1578
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant