Skip to content

feat(c-abi): typed result-config setters for client-side result knobs - #227

Merged
vikrantpuppala merged 4 commits into
mainfrom
feat/c-abi-result-config
Aug 10, 2026
Merged

vikrantpuppala merged 4 commits into
mainfrom
feat/c-abi-result-config

Conversation

@vikrantpuppala

@vikrantpuppala vikrantpuppala commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes the C-ABI half of #226. The C ABI previously had no way to reach ResultConfig: KernelSessionConfig carried none, build_session never called .result(...), and the only client-side result knob an ODBC/Go host could influence was cloudfetch_max_chunks_in_memory — smuggled as a magic string through kernel_session_config_set_session_conf and intercepted by apply_client_result_overrides. So cloudfetch_enabled, complex_types_as_json, intervals_as_string, and the prefetch/inline windows were all unreachable from the C ABI (0/6 result knobs), leaving it behind its napi/pyo3 siblings and forcing callers to conflate client knobs with server session confs — the class of bug that produced #196.

Note: this description reflects the final shape of the PR. Earlier commits went through a grouped set_result_config and per-knob setters before landing on the generic key/value setter below — see the commit history / PR comments for the rationale.

Changes

New generic client-side result-config setter on the C ABI:

KernelStatusCode kernel_session_config_set_client_conf(
    KernelSessionConfig* config, const char* key, const char* value);
  • Client-side counterpart to set_session_conf (which carries server confs to the SEA wire). set_client_conf sets client-side knobs that tune how the kernel fetches/buffers/post-processes results and are never sent to the server.
  • Key/value, not a fixed positional signature — chosen so the ABI never churns as ResultConfig (which is #[non_exhaustive]) grows new knobs, and so a host can forward DSN attributes in a loop. Safety is recovered at runtime: unknown keys and unparseable values are rejected with InvalidArgument (+ stored error), not silently ignored.
  • Recognised keys map 1:1 onto ResultConfig: cloudfetch_enabled, cloudfetch_link_prefetch_window, cloudfetch_max_chunks_in_memory (clamped to CLOUDFETCH_MAX_CHUNKS_CEILING = 256 with a warn), inline_max_chunks_in_memory, complex_types_as_json, intervals_as_string. Booleans accept "true"/"false"; windows accept a positive integer. A server conf key (e.g. ANSI_MODE) is rejected here — the two channels stay separate (the Typed client-property surface for bindings: stop conflating client knobs with server session_conf #226 goal).

Kernel-side dispatch is an enum, not magic strings. The boundary string is parsed once via ClientConfKey::parse (case-insensitive) and ResultConfig::apply_client_conf matches on the enum exhaustively — adding a variant won't compile until the new knob is handled. ClientConfKey::as_str owns the canonical spellings in one place.

KernelSessionConfig now carries a ResultConfig (defaulted in _new), threaded through build_session via .result(...).

Legacy session_conf channel, unified. apply_client_result_overrides now sweeps session_conf for any recognised client key (via ClientConfKey::parse) and delegates to the same apply_client_conf validator, replacing the bespoke cloudfetch_max_chunks_in_memory parser. Semantics are last-writer-wins: a recognised client key left in session_conf is applied (overwriting a value set via set_client_conf) and then stripped so it can't reach the wire. This only matters if a host deliberately sets the same knob through both channels — set_client_conf itself never touches session_conf — and the outcome is simply "the session_conf value applies" (no corruption). CLOUDFETCH_MAX_CHUNKS_CEILING moved to config.rs next to ResultConfig.

Also in this PR — a breaking C-ABI symbol rename (intentional): kernel_session_config_set_token_cache → kernel_session_config_set_u2m_token_cache_config. The setter configures the U2M (browser-auth) token-cache policy (enable + passphrase), which PAT/M2M ignore; the old name hid that scope, and the _config suffix matches the other grouped policy setters. Applied consistently across the header, src/c_abi/session.rs, and docs (no dangling references). Breaks any host linking the old symbol name — acceptable pre-1.0 (no external consumers pinned).

Not in this PR (deferred, tracked in #226)

  • The typed enable_metric_view_metadata client property (kind-2 client-prop → server-conf mapping — currently callers must hand-type the dotted spark.sql.thriftserver.metadata.metricview.enabled key).
  • Completing napi/pyo3 to cover all 6 ResultConfig knobs (they currently expose 2).

Test plan

  • tests/v0_c_abi_result_config_wiremock.rs — behavioral proof: a session opened over the C ABI with set_client_conf("cloudfetch_enabled","false") makes every ExecuteStatement carry SEA disposition = INLINE; enabled / default carry INLINE_OR_EXTERNAL_LINKS. Plus rejection coverage: unknown key, server-conf key, and unparseable bool all return InvalidArgument.
  • tests/c/session_smoke.c — set_client_conf compiles + links against the cdylib, accepts valid keys, clamps an over-ceiling value, and rejects unknown/server/bad-bool/null.
  • Lib unit tests (src/config.rs, src/session.rs) — apply_client_conf per-key parsing/validation/clamping and unknown-key rejection; apply_client_result_overrides applies all six client keys from session_conf and strips them while leaving server params untouched.
  • cargo test, cargo clippy --all-targets -- -D warnings, cargo fmt all clean. (Run with --no-default-features --features tls-rustls in this env due to a local OpenSSL 3.x / native-tls linker mismatch unrelated to this change.)

Refs #226

This pull request and its description were written by Isaac.

The C ABI had no way to reach `ResultConfig`: `KernelSessionConfig`
carried none, `build_session` never called `.result(...)`, and the only
client-side result knob an ODBC/Go host could influence was
`cloudfetch_max_chunks_in_memory`, smuggled as a magic string through
`kernel_session_config_set_session_conf` and intercepted by
`apply_client_result_overrides`. So `cloudfetch_enabled`,
`complex_types_as_json`, `intervals_as_string`, and the prefetch/inline
windows were all unreachable from the C ABI — leaving it behind its napi
/ pyo3 siblings and forcing callers to conflate client knobs with
server session confs (the class of bug that produced #196).

This adds a typed client-side result-config surface to the C ABI:

- `kernel_session_config_set_result_config(cloudfetch_enabled,
  link_prefetch_window, max_chunks_in_memory, inline_max_chunks_in_memory)`
  — the CloudFetch / inline tuning group. A `0` on any usize field means
  "keep the kernel default", and `max_chunks_in_memory` is clamped to the
  existing `CLOUDFETCH_MAX_CHUNKS_CEILING` (256) with a warn.
- `kernel_session_config_set_complex_types_as_json(enabled)` and
  `kernel_session_config_set_intervals_as_string(enabled)` — the two
  flat-text rendering booleans (parity with napi/pyo3).

`KernelSessionConfig` now carries a `ResultConfig` (defaulted in
`_new`), and `build_session` threads it through `.result(...)`. These
knobs are client-side only and never reach the SEA wire.

The legacy `cloudfetch_max_chunks_in_memory` magic string still works as
a fallback, but the typed setter now wins:
`apply_client_result_overrides` skips the string value when the field
has already been moved off its default (still stripping the key so it
can't leak to the wire).

Deferred (tracked in #226): the typed `enable_metric_view_metadata`
client property (kind-2 client-prop → server-conf mapping) and
completing napi/pyo3 to cover all six ResultConfig knobs.

Tests:
- New `tests/v0_c_abi_result_config_wiremock.rs`: opening a session via
  the C ABI with `set_result_config(cloudfetch_enabled=false)` makes
  every ExecuteStatement carry `disposition = INLINE`; enabled / default
  carry `INLINE_OR_EXTERNAL_LINKS`. Proves the typed path reaches the
  wire.
- `tests/c/session_smoke.c`: new setters compile, link, accept valid
  input (incl. over-ceiling clamp), and null-guard the handle.
- New lib unit test: the typed setter wins over the legacy magic string,
  and the string key is still stripped.

Refs #226

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@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.

…n-cache

Addresses review feedback on the result-config surface:

- The split (grouped set_result_config for 4 CloudFetch/inline knobs +
  two separate boolean setters for complex_types_as_json /
  intervals_as_string) was inconsistent — all six are fields of the same
  ResultConfig. Fold complex_types_as_json and intervals_as_string into
  kernel_session_config_set_result_config as two trailing bool params, so
  the whole result config is set atomically in one call. Removes
  kernel_session_config_set_complex_types_as_json and
  kernel_session_config_set_intervals_as_string.

- Rename kernel_session_config_set_token_cache ->
  kernel_session_config_set_u2m_token_cache_config: the setter configures
  the U2M (browser-auth) token-cache POLICY (enable + passphrase), which
  PAT and M2M ignore — the old name implied a generic "token cache" and
  hid the U2M scope. The _config suffix aligns it with the other grouped
  policy setters (set_retry_config, set_result_config).

Breaking ABI changes (pre-1.0; no external consumers pinned yet). Header,
C smoke test, and the C-ABI wiremock test updated accordingly. The
grouped setter and renamed symbol both compile and link from C (verified
against the cdylib).

Refs #226

Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala

Copy link
Copy Markdown
Collaborator Author

Revised per review feedback (2nd commit):

  • Folded all 6 result knobs into one setter. The earlier split (grouped set_result_config for 4 CloudFetch/inline knobs + two standalone boolean setters) was inconsistent — all six are fields of the same ResultConfig. kernel_session_config_set_result_config now takes complex_types_as_json and intervals_as_string as two trailing bool params, and set_complex_types_as_json / set_intervals_as_string are removed. Result config is now set atomically in one call.
  • Renamed set_token_cache → set_u2m_token_cache_config. It configures the U2M (browser-auth) token-cache policy (enable + passphrase), which PAT/M2M ignore; the old name hid that scope. The _config suffix aligns it with set_retry_config / set_result_config.

Breaking ABI changes, but pre-1.0 with no external consumers pinned. Header, C smoke test, and C-ABI wiremock test updated; the grouped setter + renamed symbol both compile and link from C against the cdylib. Full suite + clippy + fmt green.

@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 — clean, well-tested addition. The typed ResultConfig C-ABI surface is wired correctly (field names match src/config.rs, builder threads .result(...) before apply_client_result_overrides runs at open, clamp/ceiling reuses the existing policy), the set_token_cache → set_u2m_token_cache_config rename is consistent across header/docs/impl with no dangling references, and coverage spans wiremock (wire disposition), C smoke, and a lib unit test. One low note on the default-value precedence heuristic.

Comment thread src/session.rs Outdated
}
// The typed setter takes precedence: if the field has already been moved
// off its default (by `kernel_session_config_set_result_config` or a
// direct `ResultConfig`), don't let the legacy magic string clobber it.

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 typed-setter-wins precedence uses "field != ResultConfig::default()" as the proxy for "the typed setter was applied." This conflates two distinct cases:

  1. A host calls kernel_session_config_set_result_config(...) but leaves max_chunks_in_memory = 0 (documented as "keep the kernel default"), so the field stays at 16. If that same host also passes the legacy cloudfetch_max_chunks_in_memory magic string, this guard sees the field still at its default and the legacy string wins — even though the caller explicitly used the typed path.
  2. A host explicitly sets the typed max_chunks_in_memory = 16 (== default); a stray legacy string then silently overrides it.

Both are narrow (a host would have to mix the typed setter with the legacy string on the same knob), and the behavior is documented, so this is a limitation rather than a clear bug. But since set_result_config already writes c.result unconditionally, an explicit "typed setter was called" flag on KernelSessionConfig would make precedence exact rather than value-inferred. Worth considering if the legacy channel is expected to survive alongside the typed one for a while.

Reworks the C-ABI client-result surface twice over, per review:

1. Signature that never churns. A flat positional set_result_config
   freezes its argument list, but ResultConfig is #[non_exhaustive] and
   expected to grow — every new knob would force a breaking signature
   change or a _v2. Replace it with a generic key/value setter:

     kernel_session_config_set_client_conf(config, key, value)

   This is the client-side counterpart to set_session_conf (server
   confs): the signature is stable as knobs are added, and a host that
   already has DSN / connection-string attributes can forward them in a
   loop. Safety is recovered at runtime — an unknown key or unparseable
   value is REJECTED with InvalidArgument (+ stored error), not silently
   ignored. Its own key set is client-only, so a server conf like
   ANSI_MODE passed here is rejected: the two channels stay separate,
   which is the point of #226.

2. Enum, not magic strings. The kernel-side dispatch is now a
   ClientConfKey enum (config.rs): the boundary string is parsed once via
   ClientConfKey::parse (case-insensitive) and apply_client_conf matches
   on the enum exhaustively — adding a variant won't compile until the
   new knob is handled, so a knob can't be silently forgotten. as_str()
   owns the canonical spellings in one place. The C-ABI boundary stays
   const char* (the wire format is strings) and C/test literals are
   unchanged — those are the real API input.

Also unifies the legacy path: apply_client_result_overrides now sweeps
session_conf for ANY recognised client key (via ClientConfKey::parse)
and delegates to the same validator, instead of the bespoke
cloudfetch_max_chunks_in_memory string parser. CLOUDFETCH_MAX_CHUNKS_CEILING
moved to config.rs next to ResultConfig.

Breaking ABI (pre-1.0). Header, C smoke test, and the C-ABI wiremock
test updated; set_client_conf's disposition-on-the-wire behaviour and
its reject-unknown-key / reject-bad-value paths are covered. Full suite
+ clippy + fmt green; C smoke test links and passes against the cdylib.

Refs #226

Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala

Copy link
Copy Markdown
Collaborator Author

Reworked again per review (3rd commit) — two related changes:

1. Generic set_client_conf(key, value) replaces the grouped set_result_config. The flat positional signature was frozen: since ResultConfig is #[non_exhaustive] and expected to grow, every future knob would force a breaking signature change or a _v2. The key/value shape keeps the signature stable as knobs are added, and lets a host forward DSN attributes in a loop. Safety is recovered at runtime — unknown keys and unparseable values are rejected with InvalidArgument (+ stored error), not silently ignored. Its key set is client-only, so a server conf like ANSI_MODE passed here is rejected: the client and server channels stay cleanly separate (the #226 goal).

2. ClientConfKey enum instead of magic strings. The C-ABI boundary is const char* (the wire format is strings, and that's what a real C caller passes), but the kernel now parses the key once into an exhaustive ClientConfKey enum and matches on it — adding a variant won't compile until the new knob is handled, so a knob can't be silently forgotten. as_str() owns the canonical spellings in one place.

Also unified the legacy path: apply_client_result_overrides now sweeps session_conf for any recognised client key via ClientConfKey::parse and delegates to the same validator (retiring the bespoke cloudfetch_max_chunks_in_memory string parser).

Breaking ABI, pre-1.0. Coverage: set_client_conf("cloudfetch_enabled","false") → disposition=INLINE on the wire; reject-unknown-key / reject-server-key / reject-bad-value; over-ceiling clamps. Full suite + clippy + fmt green; C smoke test links and passes against the cdylib.

@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 — the generic set_client_conf key/value surface, the exhaustive ClientConfKey enum, and the reworked apply_client_result_overrides are internally consistent and carry good wiremock + C-smoke coverage. Two doc-vs-code mismatches: committed doc comments (source and test) still name three typed setters (set_result_config / set_complex_types_as_json / set_intervals_as_string) that were never implemented after the refactor to the single generic setter. Note also that the PR description's claim that the "typed setter wins over the legacy magic string" (a guard that skips already-moved-off-default fields) is not actually implemented — apply_client_result_overrides unconditionally re-applies any recognized session_conf key onto config.result, so a key present in both channels resolves to the legacy value, not the typed one; harmless for typical C-ABI callers who use only one channel, but worth reconciling with the description.

Comment thread src/c_abi/session.rs Outdated
token_cache: TokenCacheConfig,
/// Client-side result-management knobs (CloudFetch / inline streaming
/// tuning, flat-text rendering). Populated by
/// `kernel_session_config_set_result_config`,

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 result field doc says it is "Populated by kernel_session_config_set_result_config, ..._set_complex_types_as_json, and ..._set_intervals_as_string", but none of those functions exist. The PR was refactored to a single generic kernel_session_config_set_client_conf(key, value) setter, and these three names were never implemented (a repo-wide grep finds them only inside doc comments). A reader of the source (or someone regenerating/consulting the header) will look for symbols that aren't there. Please update the doc to name the actual setter kernel_session_config_set_client_conf.

// limitations under the License.

//! C-ABI wiremock tests for the typed result-config surface
//! (`kernel_session_config_set_result_config`).

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 module doc and the open_session_c_abi helper doc reference kernel_session_config_set_result_config, which does not exist — the tests themselves correctly call kernel_session_config_set_client_conf. Same stale-name issue as the source doc; worth fixing so the test's stated intent matches the API it exercises.

Review bot flagged doc comments that still named three setters removed in
the refactor to the single generic `kernel_session_config_set_client_conf`:

- `KernelSessionConfig::result` field doc named
  `set_result_config` / `set_complex_types_as_json` / `set_intervals_as_string`.
- The C-ABI result-config wiremock test's module doc and
  `open_session_c_abi` helper doc named `set_result_config`.

All updated to name the actual `set_client_conf`. Docs only — no code or
behaviour change.

Refs #226

Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala

Copy link
Copy Markdown
Collaborator Author

Addressed the review-bot findings (commit bc9e25b):

  • 🟡 Medium — KernelSessionConfig::result doc named nonexistent setters (set_result_config / set_complex_types_as_json / set_intervals_as_string): fixed — now names the actual kernel_session_config_set_client_conf.
  • 🔵 Low — test module + open_session_c_abi helper docs named set_result_config: fixed the same way.
  • 🔵 Low — "typed-setter-wins" precedence heuristic on src/session.rs:972: this finding was against the 2nd-commit version. The 3rd commit removed that guard entirely — set_client_conf writes c.result only and never touches session_conf, so a C-ABI caller can't populate the same knob through both channels, and the value-inferred precedence no longer exists. The current PR description (3rd comment) also drops the "typed setter wins" claim, reconciling the description/code mismatch the later review noted.

Docs-only change; build + full suite + clippy + fmt still green.

@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

Sound, well-tested change that gives the C ABI a real path to ResultConfig — the wiremock disposition test is good end-to-end evidence and the field/key parity is guarded by a unit test. Two things to weigh: (1) an unrelated breaking rename of the kernel_session_config_set_token_cache C-ABI symbol is bundled in (F1), and (2) the legacy session_conf channel silently overrides typed set_client_conf values, contrary to the PR description (F2). Separately, note the PR description describes an entirely different API (set_result_config / set_complex_types_as_json / set_intervals_as_string) than the code actually implements (set_client_conf key/value) — the code is internally consistent, but the description is stale and should be reconciled before merge.

* EncryptedFileTokenCache (given the same passphrase). */
KernelStatusCode kernel_session_config_set_token_cache(KernelSessionConfig* config, bool enabled,
const char* passphrase);
KernelStatusCode kernel_session_config_set_u2m_token_cache_config(KernelSessionConfig* config,

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 — This PR renames an exported C-ABI symbol — kernel_session_config_set_token_cache → kernel_session_config_set_u2m_token_cache_config — in both the hand-maintained header and src/c_abi/session.rs:670. This is a breaking ABI change: any ODBC/Go host that links against the old symbol name will fail to resolve at load time.

The rename appears unrelated to this PR's stated purpose (client-side result-config knobs) and isn't mentioned in the PR description. If it's intentional, it deserves its own line in the changelog/description and a note that it breaks the previous symbol; if it slipped in from a rebase, it should be dropped from this PR. The rename itself is applied consistently (no dangling references to the old name remain), so this is a scoping/intent concern rather than a build break.

Comment thread src/session.rs
key = %spelling,
value = %value,
error = %e.message,
"ignoring invalid client-side result knob in session_conf; keeping current value",

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 — apply_client_result_overrides runs during Session::open (session.rs:254), after the C-ABI typed set_client_conf values have already been folded into config.result. For every recognised client key still present in session_conf, it calls config.result.apply_client_conf(&spelling, &value) unconditionally — so a value smuggled through the legacy session_conf bag silently overwrites a value the host explicitly set via the typed set_client_conf path.

The PR description claims the opposite ("typed setter wins ... apply_client_result_overrides now skips it when the field has already been moved off its default"), and the description also references a set_result_config unit test proving typed-wins — neither the skip logic nor that test exist in the diff. This is only reachable when a host sets the same knob through both channels, and the outcome is just "legacy value applies" (no corruption), hence low. Worth either implementing the documented precedence or correcting the doc/description so the actual last-writer-wins behavior is clear.

(Anchored to the nearest changed line — see the description for the exact location.)

@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Aug 10, 2026
@vikrantpuppala

Copy link
Copy Markdown
Collaborator Author

Addressed the latest review-bot findings — both were description↔code mismatches, now fixed by rewriting the PR description to match the final shape:

  • 🔵 Low — apply_client_result_overrides last-writer-wins vs. the "typed setter wins" claim (src/session.rs:948): correct catch. The old description text (and a set_result_config unit test) described a precedence guard that the 3rd commit removed. The description now states the actual semantics: last-writer-wins, and it only matters if a host deliberately sets the same knob through both set_client_conf and the legacy session_conf bag — set_client_conf never touches session_conf, so this can't arise for a normal caller, and the outcome is just "the session_conf value applies" (no corruption). No code change; the behavior is intentional and now documented accurately.
  • 🟡 Medium — set_token_cache → set_u2m_token_cache_config rename undocumented/possibly out-of-scope (include/databricks_kernel.h:374): the rename is intentional (the setter configures the U2M-only token-cache policy; the old name hid that scope). It's now called out explicitly in the description as a breaking symbol rename, with the rationale. Applied consistently, no dangling references.

Earlier doc-comment findings (stale set_result_config names in the result field doc and the test docs) were fixed in commit bc9e25b.

Merged via the queue into main with commit 7e4fe82 Aug 10, 2026
22 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — bc9e25b7 Deployed Aug 10, 2026 by oss-reviewer-bot[bot] via followup #242
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