Skip to content

fix(kernel): reclassify OAuth token-exchange failures as Unauthenticated (stack 5/8) - #28

Merged
msrathore-db merged 1 commit into
mainfrom
msrathore/kernel-oauth-error-class
May 26, 2026
Merged

msrathore-db merged 1 commit into
mainfrom
msrathore/kernel-oauth-error-class

Conversation

@msrathore-db

@msrathore-db msrathore-db commented May 16, 2026 •

Copy link
Copy Markdown
Collaborator

Stack

Linear stack of 8 PRs on databricks/databricks-sql-kernel landing the SEA-driver kernel-side enablement work. Merge in order from base ↑ to tip. The tip branch (msrathore/krn-status-fields, PR #23) is the single snapshot containing every kernel-side change in flight.

Pos PR Branch Scope
1/8 #26 kernel-async-public-api Remove block_on from ResultStream + Send-safety on Statement + rustls-tls + e2e test ported from #20
2/8 #27 kernel-napi-skeleton napi-rs binding crate skeleton: Cargo manifest + lib + error envelope + util + runtime + logger
3/8 #25 kernel-napi-classes Database / Connection / Statement / ResultStream napi classes
4/8 #29 kernel-napi-statement-validity StatementInner ValidityFlag fix propagated from sea-operation
5/8 #28 kernel-oauth-error-class Reclassify OAuth token-exchange failures as Error::unauthenticated() (2-line fix in auth/oauth/m2m.rs + u2m.rs)
6/8 #30 krn-connection-pool-default-bump Bump HttpConfig.pool_max_idle_per_host default from 10 → 100
7/8 #24 krn-tls-public-api Expose TlsConfig fields (custom_ca_cert + accept_self_signed + skip_hostname_verification) + stop discarding in session.rs
8/8 #23 krn-status-fields ← TIP Expose 5 status accessors on ExecutedStatement (num_modified_rows / progress / display_message / diagnostic_info / error_details_json)

Companion NodeJS stack (databricks/databricks-sql-nodejs): 8 PRs — root #378 (sea-abstraction) → #380 → #377 → #379 → #382 → #381 → #384 → #383 (tip).

Policy: new PRs always stack on the current tip. No sibling/parallel topology. No force-pushes on existing PRs unless absolutely necessary; if a PR's content is wrong, add a fix-up commit on top of the stack tip rather than rewriting history.


This PR is position 5/8.

Summary

Two-line fix. Changes Error::io() → Error::unauthenticated() in two OAuth token-exchange catch arms:

  • src/auth/oauth/m2m.rs:270
  • src/auth/oauth/u2m.rs:433

Why

The previous classification surfaced OAuth credential rejections as a generic IO error → downstream JS SeaErrorMapping decoder produced HiveDriverError. The correct semantics are AuthenticationError (typed). This 2-line change unblocks the NodeJS M2M bad-secret e2e at sea-auth-u2m@e7c979d (which now correctly raises instanceof AuthenticationError).

Deferred follow-up

Precise classification of oauth2::RequestTokenError subtypes (5xx token-endpoint failures, transport errors → NetworkError instead of Unauthenticated). Tracked as NF3-1 in the NodeJS round-3 review chain; non-blocking today because JS-side retry policy isn't yet wired through SEA.

Tracking

Co-authored-by: Isaac

@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 3bb3107 to 105d49b Compare May 17, 2026 13:15
@msrathore-db
msrathore-db changed the base branch from msrathore/kernel-async-public-api to msrathore/kernel-napi-statement-validity May 17, 2026 13:15
@msrathore-db msrathore-db changed the title fix(kernel): reclassify OAuth token-exchange failures as Unauthenticated fix(kernel): reclassify OAuth token-exchange failures as Unauthenticated (stack 5/8) May 17, 2026
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from edaebc0 to ddbad30 Compare May 20, 2026 10:36
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 105d49b to 5199c59 Compare May 20, 2026 10:36
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from ddbad30 to cccedf5 Compare May 20, 2026 16:55
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 5199c59 to 3333527 Compare May 20, 2026 16:55
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from cccedf5 to b77c150 Compare May 20, 2026 20:22
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 3333527 to f6a3a0e Compare May 20, 2026 20:22
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from b77c150 to b5d78e0 Compare May 21, 2026 00:03
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from f6a3a0e to 6db8e4d Compare May 21, 2026 00:03
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from b5d78e0 to ca82f09 Compare May 23, 2026 11:03
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 6db8e4d to f3505e7 Compare May 23, 2026 11:03
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from ca82f09 to 3f1673e Compare May 23, 2026 11:30
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from f3505e7 to fb8bcfb Compare May 23, 2026 11:30
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from 3f1673e to 1f6f57c Compare May 23, 2026 21:48
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from fb8bcfb to de6966d Compare May 23, 2026 21:48
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from 1f6f57c to 8ebabdf Compare May 24, 2026 15:54
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from de6966d to 5badf23 Compare May 24, 2026 15:54
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from 8ebabdf to 66220e0 Compare May 24, 2026 18:09
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 5badf23 to 4c83f26 Compare May 24, 2026 18:09
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from 66220e0 to 9c04b0b Compare May 24, 2026 18:43
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 4c83f26 to 185096c Compare May 24, 2026 18:43
@msrathore-db
msrathore-db marked this pull request as ready for review May 24, 2026 19:39
vikrantpuppala pushed a commit that referenced this pull request May 25, 2026
…tement + rustls-tls (stack 1/8) (#26)

## Stack

Linear stack of 8 PRs on `databricks/databricks-sql-kernel` landing the
**SEA-driver kernel-side enablement** work. Merge in order from base ↑
to tip. The tip branch (`msrathore/krn-status-fields`, PR
[#23](#23)) is
the single snapshot containing every kernel-side change in flight.

| Pos | PR | Branch | Scope |
|---|---|---|---|
| 1/8 |
[#26](#26) |
`kernel-async-public-api` | Remove `block_on` from ResultStream +
Send-safety on Statement + rustls-tls switch via Cargo features + e2e
test ported from
[#20](#20) |
| 2/8 |
[#27](#27) |
`kernel-napi-skeleton` | napi-rs binding crate skeleton (opts INTO
`tls-rustls` feature from creation) |
| 3/8 |
[#25](#25) |
`kernel-napi-classes` | Database / Connection / Statement / ResultStream
napi classes |
| 4/8 |
[#29](#29) |
`kernel-napi-statement-validity` | StatementInner ValidityFlag fix
propagated from sea-operation |
| 5/8 |
[#28](#28) |
`kernel-oauth-error-class` | Reclassify OAuth token-exchange failures as
`Error::unauthenticated()` |
| 6/8 |
[#30](#30) |
`krn-connection-pool-default-bump` | Bump
`HttpConfig.pool_max_idle_per_host` default 10 → 100 |
| 7/8 |
[#24](#24) |
`krn-tls-public-api` | Expose `TlsConfig` fields (custom_ca_cert +
accept_self_signed + skip_hostname_verification) |
| 8/8 |
[#23](#23) |
`krn-status-fields` **← TIP** | Expose 5 status accessors on
`ExecutedStatement` |

**Policy:** new PRs always stack on the current tip. No sibling/parallel
topology.

---

**This PR is position 1/8 (ROOT of the kernel stack).**

## Summary

Four commits in this PR. Two kernel correctness fixes that unblock async
consumers (napi, pyo3), a Cargo-feature-based TLS backend split to
preserve ODBC compatibility, plus a regression test for the block_on
fix:

- `49ffdcb` — `fix(kernel): remove block_on from ResultStream async
public surface` (305 LOC, 7 files). The previous `ResultStream`
accessors used `tokio::block_on` internally, which panics with "Cannot
start a runtime from within a runtime" when called from inside an
enclosing tokio runtime — exactly what napi-rs's `execute_tokio_future`
and PyO3's wrapper runtime do. Fix: make the `ResultReader` trait itself
`async` via `async_trait`. **This is Option 1 in [issue
#19](#19 —
the documented "right answer" — vs the Option 2 stopgap in [PR
#20](#20).
- `622a59a` — `krn-async-public-api: make Statement::execute/submit Send
and switch to rustls-tls` (137 LOC, 2 files). Made the futures Send +
switched reqwest's TLS backend to rustls-tls.
- `7c4755a` — `test(reader): port
cloudfetch_drain_does_not_nest_block_on from PR #20`. E2e regression
test (49 LOC) drains 1M rows from inside a `#[tokio::test(flavor =
"multi_thread")]`.
- `d96afd9` — `feat(config): make TLS backend selectable via Cargo
features` (NEW). Splits the prior unconditional rustls switch into two
opt-in features:
- `default = ["tls-native"]` — direct-Rust users, C-ABI / future ODBC
path get the historical `native-tls` backend.
- `tls-rustls` — napi-rs binding crate (added in next PR in this stack)
opts in to avoid OpenSSL-symbol clash with Node.js.

## Why the TLS-feature commit was needed

`622a59a` hardcoded rustls-tls because the napi binding loaded into Node
segfaults on OpenSSL 1.1 symbol clash. But that pre-empted the choice
for ODBC consumers who historically use native-tls. The new `d96afd9`
commit makes the backend configurable so each consumer picks its own.
**Default kept as native-tls** so existing direct-Rust callers + the
C-ABI / ODBC path see no behavior change.

Verified locally:
- `cargo check -p databricks-sql-kernel` (default tls-native): clean
- `cargo check --workspace` (kernel native-tls + napi rustls-tls in same
workspace): clean
- `cargo test --lib --workspace`: **376 passed / 0 failed**

Side benefit: the pre-existing PEM flake
`test_http_client_with_invalid_pem` (D-016 in the workflow) which was
failing on the rustls-tls build now passes on native-tls. CI default is
back to a fully-green state.

## Test plan

- `cargo test` — full lib tests still green (376 passing)
- `cargo clippy --all-targets -- -D warnings` clean
- Downstream napi binding builds against this surface; M2M e2e green at
`sea-auth-u2m@e7c979d` on databricks-sql-nodejs

## Tracking

- [PECOBLR-2670](https://databricks.atlassian.net/browse/PECOBLR-2670) —
Make the async interface for rust kernel
- [PECOBLR-2917](https://databricks.atlassian.net/browse/PECOBLR-2917) —
Fix napi binding SIGSEGV on concurrent openSession
- Parent epic:
[PECOBLR-2666](https://databricks.atlassian.net/browse/PECOBLR-2666)

Co-authored-by: Isaac

[PECOBLR-2670]:
https://databricks.atlassian.net/browse/PECOBLR-2670?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
msrathore-db added a commit that referenced this pull request May 25, 2026
…lope + util + runtime + logger (stack 2/8) (#27)

## Stack

Linear stack of 8 PRs on `databricks/databricks-sql-kernel` landing the
**SEA-driver kernel-side enablement** work. Merge in order from base ↑
to tip. The tip branch (`msrathore/krn-status-fields`, PR
[#23](#23)) is
the single snapshot containing every kernel-side change in flight.

| Pos | PR | Branch | Scope |
|---|---|---|---|
| 1/8 |
[#26](#26) |
`kernel-async-public-api` | Remove `block_on` from ResultStream +
Send-safety on Statement + rustls-tls + e2e test ported from
[#20](#20) |
| 2/8 |
[#27](#27) |
`kernel-napi-skeleton` | napi-rs binding crate skeleton: Cargo manifest
+ lib + error envelope + util + runtime + logger |
| 3/8 |
[#25](#25) |
`kernel-napi-classes` | Database / Connection / Statement / ResultStream
napi classes |
| 4/8 |
[#29](#29) |
`kernel-napi-statement-validity` | StatementInner ValidityFlag fix
propagated from sea-operation |
| 5/8 |
[#28](#28) |
`kernel-oauth-error-class` | Reclassify OAuth token-exchange failures as
`Error::unauthenticated()` (2-line fix in auth/oauth/m2m.rs + u2m.rs) |
| 6/8 |
[#30](#30) |
`krn-connection-pool-default-bump` | Bump
`HttpConfig.pool_max_idle_per_host` default from 10 → 100 |
| 7/8 |
[#24](#24) |
`krn-tls-public-api` | Expose `TlsConfig` fields (custom_ca_cert +
accept_self_signed + skip_hostname_verification) + stop discarding in
session.rs |
| 8/8 |
[#23](#23) |
`krn-status-fields` **← TIP** | Expose 5 status accessors on
`ExecutedStatement` (num_modified_rows / progress / display_message /
diagnostic_info / error_details_json) |

**Companion NodeJS stack** (`databricks/databricks-sql-nodejs`): 8 PRs —
root
[#378](databricks/databricks-sql-nodejs#378)
(sea-abstraction) →
[#380](databricks/databricks-sql-nodejs#380) →
[#377](databricks/databricks-sql-nodejs#377) →
[#379](databricks/databricks-sql-nodejs#379) →
[#382](databricks/databricks-sql-nodejs#382) →
[#381](databricks/databricks-sql-nodejs#381) →
[#384](databricks/databricks-sql-nodejs#384) →
[#383](databricks/databricks-sql-nodejs#383)
(tip).

**Policy:** new PRs always stack on the current tip. No sibling/parallel
topology. No force-pushes on existing PRs unless absolutely necessary;
if a PR's content is wrong, add a fix-up commit on top of the stack tip
rather than rewriting history.

---

**This PR is position 2/8.**

## Summary

Lands the napi-rs binding crate as a workspace member with
**infrastructure only**: no exported classes yet. ~442 LOC across 10
files.

**Files added:**
- `Cargo.toml` — workspace membership declaration
- `napi/Cargo.toml`, `napi/build.rs`, `napi/package.json`,
`napi/.gitignore` — crate manifest + napi-rs build glue
- `napi/src/lib.rs` — entry point declaring 4 infra modules (no class
modules yet); exports a smoke-test `version()` fn
- `napi/src/error.rs` — formatter for the `__databricks_error__:<json>`
napi error envelope decoded by the JS-side adapter
- `napi/src/util.rs` — shared helpers
- `napi/src/runtime.rs` — tokio multi-thread runtime helper
- `napi/src/logger.rs` — `tracing`-to-JS logger bridge stub

## Compilability

`cargo check -p databricks-sea-native` is clean. The crate compiles
standalone and exposes only the `version()` probe — the JS-side loader
would find a valid `.node` but no functional API yet. This split makes
the infra layer reviewable on its own; the next PR adds the user-facing
surface.

## Tracking

- [PECOBLR-2670](https://databricks.atlassian.net/browse/PECOBLR-2670) —
Make the async interface for rust kernel — napi crate skeleton
- Parent epic:
[PECOBLR-2666](https://databricks.atlassian.net/browse/PECOBLR-2666)

Co-authored-by: Isaac

[PECOBLR-2670]:
https://databricks.atlassian.net/browse/PECOBLR-2670?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
vikrantpuppala pushed a commit that referenced this pull request May 25, 2026
…in) (#66)

Re-targets
[#27](#27)
against `main`.

## What happened

PR #27 was stacked on PR #26's branch
(`msrathore/kernel-async-public-api`). When PR #26 squash-merged into
`main` (commit `f4a18ba`), PR #27's base was not re-pointed to `main`,
so merging PR #27 landed its content on the now-stale
`msrathore/kernel-async-public-api` branch (merge commit `b73a688`)
rather than on `main`. Result: the napi-skeleton content is not on
`main` despite #27 being marked as merged.

## What this PR does

Cherry-picks the squash commit from #27 (`b73a688`) onto a fresh branch
from current `main`. Content is identical to what #27 should have landed
— same 12 files, same `+3771 / -2` line counts.

## Review history

All review approval is on #27; this PR carries the identical diff.
Re-review is not required but pre-commit gate has been verified:

- `cargo fmt --all -- --check` — clean
- `cargo clippy --all-targets --locked -- -D warnings` — clean
- `cargo test --locked` — 14 / 14 pass
- `cargo build --release --locked` — clean

## Stack context

This is the second of an 8-PR kernel stack (PR #26 was the first;
#25/#29/#28/#30/#24/#23 follow). Each subsequent PR's base will need to
be updated to point at this PR's branch
(`msrathore/kernel-napi-skeleton-to-main`) once it merges to main,
mirroring the same re-target pattern.

## Files

- `.github/workflows/napi-checks.yml` — CI workflow for the napi crate
(fmt + clippy + test + release-build with `--locked`)
- `Cargo.toml` — root workspace tweak so the napi sub-crate's
standalone-workspace pattern works
- `napi/.gitignore`, `napi/Cargo.toml`, `napi/Cargo.lock`,
`napi/build.rs`, `napi/package.json` — crate manifest + napi-rs build
glue
- `napi/src/lib.rs` — crate root, `version()` napi export
- `napi/src/error.rs` — kernel `Error` → napi `Error` envelope mapper +
pyo3 field-parity guards
- `napi/src/util.rs` — `guarded()` panic-catching wrapper + `panic =
"abort"` compile-time guard
- `napi/src/runtime.rs` — captured tokio `Handle` accessor + PERF NOTE +
async-cleanup-hook TODO for PR #25
- `napi/src/logger.rs` — Round-3 logger bridge stub with inline design
sketch

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-napi-statement-validity branch from 9c04b0b to 4acde6a Compare May 25, 2026 19:20
@msrathore-db
msrathore-db requested a review from a team as a code owner May 25, 2026 19:20
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 185096c to 09472d7 Compare May 25, 2026 19:20
vikrantpuppala pushed a commit that referenced this pull request May 26, 2026
…3/8) (#25)

## Stack

Linear stack of 8 PRs on `databricks/databricks-sql-kernel` landing the
**SEA-driver kernel-side enablement** work. Merge in order from base ↑
to tip. The tip branch (`msrathore/krn-status-fields`, PR
[#23](#23)) is
the single snapshot containing every kernel-side change in flight.

| Pos | PR | Branch | Scope |
|---|---|---|---|
| 1/8 |
[#26](#26) |
`kernel-async-public-api` | Remove `block_on` from ResultStream +
Send-safety on Statement + rustls-tls + e2e test ported from
[#20](#20) |
| 2/8 |
[#27](#27) |
`kernel-napi-skeleton` | napi-rs binding crate skeleton: Cargo manifest
+ lib + error envelope + util + runtime + logger |
| 3/8 |
[#25](#25) |
`kernel-napi-classes` | Database / Connection / Statement / ResultStream
napi classes |
| 4/8 |
[#29](#29) |
`kernel-napi-statement-validity` | StatementInner ValidityFlag fix
propagated from sea-operation |
| 5/8 |
[#28](#28) |
`kernel-oauth-error-class` | Reclassify OAuth token-exchange failures as
`Error::unauthenticated()` (2-line fix in auth/oauth/m2m.rs + u2m.rs) |
| 6/8 |
[#30](#30) |
`krn-connection-pool-default-bump` | Bump
`HttpConfig.pool_max_idle_per_host` default from 10 → 100 |
| 7/8 |
[#24](#24) |
`krn-tls-public-api` | Expose `TlsConfig` fields (custom_ca_cert +
accept_self_signed + skip_hostname_verification) + stop discarding in
session.rs |
| 8/8 |
[#23](#23) |
`krn-status-fields` **← TIP** | Expose 5 status accessors on
`ExecutedStatement` (num_modified_rows / progress / display_message /
diagnostic_info / error_details_json) |

**Companion NodeJS stack** (`databricks/databricks-sql-nodejs`): 8 PRs —
root
[#378](databricks/databricks-sql-nodejs#378)
(sea-abstraction) →
[#380](databricks/databricks-sql-nodejs#380) →
[#377](databricks/databricks-sql-nodejs#377) →
[#379](databricks/databricks-sql-nodejs#379) →
[#382](databricks/databricks-sql-nodejs#382) →
[#381](databricks/databricks-sql-nodejs#381) →
[#384](databricks/databricks-sql-nodejs#384) →
[#383](databricks/databricks-sql-nodejs#383)
(tip).

**Policy:** new PRs always stack on the current tip. No sibling/parallel
topology. No force-pushes on existing PRs unless absolutely necessary;
if a PR's content is wrong, add a fix-up commit on top of the stack tip
rather than rewriting history.

---

**This PR is position 3/8.**

## ⚠️ Must merge together with PR #29

In isolation, this PR ships a known cancel-lifecycle bug: the first call
to `Statement.cancel()` from JS returns
`KernelError(InvalidStatementHandle)` instead of cancelling the
in-flight statement.

**Root cause** — `Connection::execute_statement`
(`napi/src/connection.rs:99-104`) builds a local kernel `Statement`,
awaits `stmt.execute()`, hands the resulting `ExecutedStatement` to the
JS-side `Statement` wrapper, then drops the parent kernel `Statement` at
end of the closure. The kernel's `Drop for Statement`
(`src/statement/mutable.rs:440-450`) calls `valid.invalidate()` on the
shared `ValidityFlag`. The next `Statement.cancel()` from JS reaches
`ExecutedStatement::cancel()` → `self.valid.check()` →
`KernelError(InvalidStatementHandle)`.

**Fix** — PR
[#29](#29) (next
in the stack) wraps the inner state in a `StatementInner { _parent:
KernelStatement, executed: ExecutedStatement }` struct that keeps the
parent alive for the wrapper's lifetime. With #29 applied, the cancel
lifecycle works correctly on the first call.

**Stack-merge policy** — these two PRs must merge as a pair (default
Github stacked-PR flow handles this). Do not merge #25 to main without
#29 in the same merge train. Reviewers approving #25 in isolation should
approve #29 as part of the same approval pass.

## Summary

Adds the four user-facing `#[napi]` classes that expose the kernel's v0
surface to JS consumers. ~504 LOC across 4 files plus a 4-line `lib.rs`
update to declare the new modules.

**Classes:**
- `Database` — `Database.open()` returns a Session handle
- `Connection` — `Connection.execute_statement()` returns a Statement
handle
- `Statement` — `fetchNextBatch()` / `schema()` / `cancel()` / `close()`
- `ResultStream` (internal) — used by Statement; not directly exposed

Results cross the FFI as Arrow IPC bytes (see `result.rs`); the TS
adapter decodes via `apache-arrow`.

Together with the skeleton PR
[#27](#27), this
delivers the full Round 2 napi surface.

## Test plan

- `cargo check -p databricks-sea-native` clean
- Downstream NodeJS `npm run build:native` produces a working `.node`
artifact against this stack
- Downstream OAuth M2M e2e green at `sea-auth-u2m@e7c979d` building
against this binding

## Tracking

- [PECOBLR-2670](https://databricks.atlassian.net/browse/PECOBLR-2670) —
Make the async interface for rust kernel — napi classes
- Parent epic:
[PECOBLR-2666](https://databricks.atlassian.net/browse/PECOBLR-2666)

Co-authored-by: Isaac

[PECOBLR-2670]:
https://databricks.atlassian.net/browse/PECOBLR-2670?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
vikrantpuppala pushed a commit that referenced this pull request May 26, 2026
…on (stack 4/8) (#29)

## Stack

Linear stack of 8 PRs on `databricks/databricks-sql-kernel` landing the
**SEA-driver kernel-side enablement** work. Merge in order from base ↑
to tip. The tip branch (`msrathore/krn-status-fields`, PR
[#23](#23)) is
the single snapshot containing every kernel-side change in flight.

| Pos | PR | Branch | Scope |
|---|---|---|---|
| 1/8 |
[#26](#26) |
`kernel-async-public-api` | Remove `block_on` from ResultStream +
Send-safety on Statement + rustls-tls + e2e test ported from
[#20](#20) |
| 2/8 |
[#27](#27) |
`kernel-napi-skeleton` | napi-rs binding crate skeleton: Cargo manifest
+ lib + error envelope + util + runtime + logger |
| 3/8 |
[#25](#25) |
`kernel-napi-classes` | Database / Connection / Statement / ResultStream
napi classes |
| 4/8 |
[#29](#29) |
`kernel-napi-statement-validity` | StatementInner ValidityFlag fix
propagated from sea-operation |
| 5/8 |
[#28](#28) |
`kernel-oauth-error-class` | Reclassify OAuth token-exchange failures as
`Error::unauthenticated()` (2-line fix in auth/oauth/m2m.rs + u2m.rs) |
| 6/8 |
[#30](#30) |
`krn-connection-pool-default-bump` | Bump
`HttpConfig.pool_max_idle_per_host` default from 10 → 100 |
| 7/8 |
[#24](#24) |
`krn-tls-public-api` | Expose `TlsConfig` fields (custom_ca_cert +
accept_self_signed + skip_hostname_verification) + stop discarding in
session.rs |
| 8/8 |
[#23](#23) |
`krn-status-fields` **← TIP** | Expose 5 status accessors on
`ExecutedStatement` (num_modified_rows / progress / display_message /
diagnostic_info / error_details_json) |

**Companion NodeJS stack** (`databricks/databricks-sql-nodejs`): 8 PRs —
root
[#378](databricks/databricks-sql-nodejs#378)
(sea-abstraction) →
[#380](databricks/databricks-sql-nodejs#380) →
[#377](databricks/databricks-sql-nodejs#377) →
[#379](databricks/databricks-sql-nodejs#379) →
[#382](databricks/databricks-sql-nodejs#382) →
[#381](databricks/databricks-sql-nodejs#381) →
[#384](databricks/databricks-sql-nodejs#384) →
[#383](databricks/databricks-sql-nodejs#383)
(tip).

**Policy:** new PRs always stack on the current tip. No sibling/parallel
topology. No force-pushes on existing PRs unless absolutely necessary;
if a PR's content is wrong, add a fix-up commit on top of the stack tip
rather than rewriting history.

---

**This PR is position 4/8.**

## Why this PR is structurally required (not redundant with PR #25)

Reviewers may notice this PR's diff against the new PR
[#25](#25) tip
looks like a follow-up nicety — it is not. It is a **correctness fix**
for a real lifecycle bug PR #25 ships in isolation.

**The bug** — PR #25's `Connection::execute_statement` builds a local
kernel `Statement`, awaits `stmt.execute()`, hands the resulting
`ExecutedStatement` to the JS-side `Statement` wrapper, then drops the
parent kernel `Statement` at end of the closure. The kernel's `Drop for
Statement` (`src/statement/mutable.rs:440-450`) calls
`valid.invalidate()` on the shared `ValidityFlag` between the parent and
the executed handle. The next `Statement.cancel()` from JS reaches
`ExecutedStatement::cancel()` → `self.valid.check()` →
`KernelError(InvalidStatementHandle)` — the **first** cancel call is
broken.

**The fix** — this PR wraps the inner state in `StatementInner {
_parent: KernelStatement, executed: ExecutedStatement }`, keeping the
parent alive for the JS wrapper's lifetime. The shared `ValidityFlag`
stays set, so cancel works on the first call.

**Stack-merge policy** — PR #25 and this PR must merge as a pair
(default Github stacked-PR flow handles this). The PR #25 description
carries a corresponding warning. Do not merge #25 to main without this
PR in the same merge train.

No new tests are added here — the closed-state assertions on PR #25's
`Statement::cancel()` pin the typed-error contract for the
parent-dropped case, and the cancel-after-completion idempotency tests
pin the JDBC contract. Both continue to pass on the merged state.
End-to-end cancel-during-fetch coverage is tracked as part of the
lock-shape refactor follow-up at
`sea-workflow/jira-candidates/2026-05-24-napi-cancel-during-fetch.md`.

## Summary

Ports the StatementInner ValidityFlag fix from the NodeJS sea-operation
worktree into the kernel-side napi crate (~89 LOC, 2 files). Adds the
parent-Statement-keep-alive wrapper to `napi::Statement`'s inner state
so the executed handle's `ValidityFlag` stays set for the JS wrapper's
lifetime.

The fix was originally authored downstream in the NodeJS worktree's
vendored napi copy; landing it on the kernel-side napi crate keeps the
two consistent until D-006 consolidation closes the vendoring gap.

## Test plan

- `cargo test` clean (24/24 lib tests pass against the merged PR #25 +
#29 state)
- Downstream NodeJS `sea-operation` feature already validates the fix in
JS-side unit tests

## Tracking

- [PECOBLR-2917](https://databricks.atlassian.net/browse/PECOBLR-2917) —
Fix napi binding SIGSEGV — StatementInner ValidityFlag
- Parent epic:
[PECOBLR-2666](https://databricks.atlassian.net/browse/PECOBLR-2666)

Co-authored-by: Isaac

[PECOBLR-2917]:
https://databricks.atlassian.net/browse/PECOBLR-2917?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
…nticated

Per src/kernel_error.rs:74-77 doc-comment, Unauthenticated is the
intended ErrorCode for "Server returned HTTP 401 (or OIDC discovery
rejected the token request)". M2M and U2M token-exchange paths were
using Error::io() (-> Internal), which is reserved for kernel-side
I/O / parsing failures. The misclassification caused authentication
failures to surface in NodeJS as HiveDriverError instead of
AuthenticationError (D-015).

Fix: m2m.rs:270 and u2m.rs:433 swap Error::io() -> Error::unauthenticated().
No kernel unit tests assert ErrorCode::Internal on these paths
(verified by grep) so no test updates are needed. The U2M test
`test_u2m_cache_miss_with_expired_refresh` asserts only `result.is_err()`,
which remains true.

Deferred (worth a follow-up): distinguish oauth2::RequestTokenError
subtypes so 5xx token-endpoint failures get NetworkError while
invalid_client / invalid_grant / unauthorized_client stay
Unauthenticated. The current change correctly handles the dominant
case (bad-credentials -> 400/401 from server) and matches the
existing kernel doc-comment intent.

Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
vikrantpuppala
vikrantpuppala previously approved these changes May 26, 2026
@msrathore-db
msrathore-db force-pushed the msrathore/kernel-oauth-error-class branch from 09472d7 to 17772cf Compare May 26, 2026 09:46
@msrathore-db
msrathore-db changed the base branch from msrathore/kernel-napi-statement-validity to main May 26, 2026 09:47
@msrathore-db
msrathore-db dismissed vikrantpuppala’s stale review May 26, 2026 09:47

The base branch was changed.

@msrathore-db
msrathore-db merged commit bda6dc2 into main May 26, 2026
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