Skip to content

fix(telemetry): emit delete session from C ABI close - #300

Merged
jay-xiao446 merged 2 commits into
mainfrom
jay-xiao446/fix/telemetry-cabi-session-close-delete
Aug 28, 2026
Merged

jay-xiao446 merged 2 commits into
mainfrom
jay-xiao446/fix/telemetry-cabi-session-close-delete

Conversation

@jay-xiao446

@jay-xiao446 jay-xiao446 commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Change kernel_session_close() to drive the awaited Session::close() path so C ABI consumers emit and flush DELETE_SESSION telemetry.
  • Update the C ABI header/session comments to describe the awaited close contract.
  • Add C ABI regression coverage for CREATE_SESSION + DELETE_SESSION export on close.
  • Remove the now-unused Session::initiate_delete() wrapper so -D warnings CI builds stay clean.

RCA

Covers RCA 03: Go kernel happy path fully drained results and emitted CREATE_SESSION / EXECUTE_STATEMENT, but missed DELETE_SESSION because the Go kernel backend closes through the C ABI and the C ABI used fire-and-forget Session::initiate_delete().

Stack

Flow

sequenceDiagram
    participant Go as Go driver CloseSession
    participant CABI as kernel_session_close
    participant Rust as Session::close
    participant Server as SEA DeleteSession
    participant Telemetry as Telemetry runtime

    Go->>CABI: kernel_session_close(session)
    CABI->>Rust: block_on_ffi(Session::close)
    Rust->>Server: DeleteSession
    Server-->>Rust: success
    Rust->>Telemetry: emit DELETE_SESSION
    Rust->>Telemetry: finish/flush
    CABI-->>Go: KernelStatusCode::Success
Loading

Tests

  • cargo +stable fmt --all -- --check
  • cargo test kernel_session_close_exports_delete_session_telemetry --lib --locked
  • cargo test is_open_flips_true_to_false_on_delete --lib --locked
  • cargo clippy --all-targets -- -D warnings
  • cargo test c_abi --lib --locked
  • cargo test telemetry --lib --locked

@jay-xiao446
jay-xiao446 requested a review from a team as a code owner August 26, 2026 22:56
@jay-xiao446

Copy link
Copy Markdown
Collaborator Author

RCA: Go kernel happy path missed DELETE_SESSION

Symptom

The Go driver kernel happy-path flow completed successfully and fully drained SELECT id FROM range(1000000), but kernel-owned telemetry emitted only:

  • CREATE_SESSION
  • EXECUTE_STATEMENT

The expected kernel DELETE_SESSION row was missing. The Thrift baseline emitted DELETE_SESSION, so this was a kernel lifecycle telemetry parity gap.

Repro flow

sequenceDiagram
    participant App as Go app
    participant Go as Go SQL driver
    participant Backend as Kernel backend
    participant CABI as C ABI
    participant Kernel as Kernel session
    participant Telemetry as Kernel telemetry

    App->>Go: connect
    Go->>Backend: UseKernel=true
    Note over Go: Go wrapper telemetry disabled for kernel path
    Backend->>CABI: open session with kernel telemetry config
    CABI->>Kernel: Session::open
    Kernel->>Telemetry: CREATE_SESSION
    App->>Go: execute + drain result
    Kernel->>Telemetry: EXECUTE_STATEMENT
    App->>Go: close connection
    Go->>Backend: CloseSession
    Backend->>CABI: kernel_session_close(session)
    CABI->>Kernel: initiate_delete() only
    Note over Kernel,Telemetry: Before this PR, no DELETE_SESSION telemetry was emitted or flushed
Loading

Root cause

The Go kernel backend closes sessions through kernel_session_close(). That C ABI close path consumed the session handle and called Session::initiate_delete().

Session::initiate_delete() only spawns a fire-and-forget server-side DeleteSession; it does not emit OperationType::DeleteSession and does not call telemetry finish(). The awaited Rust close path, Session::close(self), is the path that emits DELETE_SESSION telemetry and flushes the final batch.

Because the Go wrapper disables its own driver telemetry when UseKernel=true, there was no wrapper-side DELETE_SESSION event to compensate. The close event must come from the kernel.

Fix

This PR changes the existing C ABI close function to consume the boxed Session and drive the awaited Rust close path through block_on_ffi:

sequenceDiagram
    participant Go as Go KernelBackend.CloseSession
    participant CABI as kernel_session_close
    participant Rust as Session::close
    participant Server as Statement Execution API
    participant Telemetry as Telemetry runtime

    Go->>CABI: kernel_session_close(session)
    CABI->>Rust: block_on_ffi(move || session.close())
    Rust->>Server: DeleteSession
    alt DeleteSession succeeds
        Rust->>Telemetry: emit DELETE_SESSION
        Rust->>Telemetry: finish().await
        CABI-->>Go: Success
    else DeleteSession fails
        Rust->>Telemetry: emit DELETE_SESSION with error
        Rust->>Telemetry: finish().await
        Note over Rust: Drop fallback still schedules best-effort delete retry
        CABI-->>Go: mapped KernelStatusCode
    end
Loading

The public C ABI header is updated to describe kernel_session_close() as an awaited close. This keeps the Go API unchanged while giving C ABI consumers the same lifecycle telemetry contract as Rust/PyO3/NAPI close.

Regression coverage

Added kernel_session_close_exports_delete_session_telemetry, which:

  1. Opens a kernel Session against a mock SEA session server with telemetry enabled and a capturing exporter.
  2. Boxes the session as a kernel_session_t handle.
  3. Calls kernel_session_close() from a native test thread.
  4. Asserts exported telemetry operations are exactly CREATE_SESSION and DELETE_SESSION for the session id.

Local validation

  • cargo +stable fmt --all -- --check
  • cargo test kernel_session_close_exports_delete_session_telemetry --lib --locked
  • cargo test c_abi --lib --locked
  • cargo test telemetry --lib --locked

@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.

@jay-xiao446

Copy link
Copy Markdown
Collaborator Author

CI follow-up: all compile-bearing failures had the same root cause, Session::initiate_delete became dead code after the C ABI close path moved to awaited Session::close(). I removed that unused wrapper and kept the existing is-open test by calling the inner drop helper directly. Local validation now includes cargo clippy --all-targets -- -D warnings, plus the targeted regression, C ABI filter, telemetry filter, and fmt check.

@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: Jay Xiao <jay.xiao@databricks.com>
Signed-off-by: Jay Xiao <jay.xiao@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.

✅ No issues identified by the review bot.

@jay-xiao446
jay-xiao446 added this pull request to the merge queue Aug 28, 2026
Merged via the queue into main with commit 74ff258 Aug 28, 2026
18 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — 839fd179 Deployed Aug 28, 2026 by jay-xiao446 via followup #1233
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.

2 participants