Skip to content

Commit 4ca48d5

Browse files
author
peco-engineer-bot[bot]
committed
learn: retrospective learnings
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent 543777a commit 4ca48d5

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Learning journal 2026-12-01
2+
3+
### 2026-12-01: Security / error messages — Redact URIs in errors, including urlsplit failures and chained exceptions
4+
**Context:** In PR #1071, `_connection_uri` validation put the raw URI in its ValueError. Review then found three more leaks: `urlsplit` itself raises with the netloc when it hits a fullwidth slash, the parse error was chained through `__context__`, and a redactor that cut at the first `/` before removing userinfo still exposed part of a password that contained `/`.
5+
**Rule:** Never echo a user-supplied URI or hostname in an exception: show only the scheme and host[:port], show only the scheme when the value contains `@` or `%40`, wrap `urlsplit`/`.port` in try/except and raise the sanitized error outside the except block (or `from None`), and add tests that the secret is missing from the message, `__cause__` and `__context__`.
6+
7+
### 2026-12-01: Backend contracts and configuration — Run new override validation only when the override is set
8+
**Context:** In PR #1071, `_split_host(server_hostname)` ran before the `port is None` early return. Kernel connections that never set `_port` started rejecting hosts like `h.io:0` or `None`, which had passed through unchanged on main.
9+
**Rule:** Put validation added for a new optional override after the check that the override is unset, so connections that don't use it behave exactly as before, and add pass-through tests for odd inputs on the unset path.
10+
11+
### 2026-12-01: Backend contracts and configuration — Pre-flight guards must mirror the downstream resolver's precedence
12+
**Context:** In PR #1071, the OAuth origin guard treated `auth_type='databricks-oauth'` + `access_token` as OAuth and treated a custom `credentials_provider` as OAuth. The kernel auth bridge resolves the first to PAT and rejects the second with NotSupportedError, so callers got misleading errors.
13+
**Rule:** Make a client-side guard that predicts a downstream routing decision follow that resolver's exact precedence order, so it never pre-empts the real error, and add one test row per precedence branch on both the guarded and the skipped side.
14+
15+
### 2026-12-01: Backend contracts and configuration — Host overrides change which host receives credentials and token exchange
16+
**Context:** In PR #1071, a maintainer noted that the kernel wraps every auth provider in FederationProvider and uses the connection host. With `_connection_uri`, a foreign-issuer JWT passed as `access_token` is therefore POSTed to the URI host's /oidc/v1/token. Thrift does that exchange at `server_hostname`.
17+
**Rule:** When a connection option can redirect the target host, list every credential flow (PAT, OAuth, token federation exchange) and check which host receives raw credentials on each backend before you classify a credential as safe to send cross-origin.
18+
19+
### 2026-12-01: Verification — Assert resolved endpoint values reach the backend constructor
20+
**Context:** In PR #1071, no mocked `connect()` test checked that the resolved `kernel_host`/`kernel_http_path` were passed to KernelDatabricksClient, so reverting to `server_hostname=server_hostname` would have passed every test that runs without the wheel.
21+
**Rule:** When a session resolves or rewrites connection arguments, assert the final values on the mocked backend constructor's `call_args.kwargs` through `databricks.sql.connect`, not just in the resolver helper.

‎.claude/knowledge/lessons.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Lessons
22

3-
<!-- distilled-through: 2026-11-18 -->
3+
<!-- distilled-through: 2026-12-01 -->
44

55
## Backend contracts and configuration
66
- L-0001 (1×, log:2026-08-13): When changing cursor.description type_code strings, update every downstream conversion branch that matches them.
@@ -16,7 +16,7 @@
1616
- L-0011 (6×, #932 #925 #940): Gate optional Session kwargs through _kernel_session_accepts_kwarg and fail closed on introspection failure. Default-off options must preserve older wheels; explicit requirements need a released dependency floor and accurate support docs.
1717
- L-0012 (2×, #930): Verify flags against materialized values and cursor.description on each backend. Shared client-side conversion toggles differ from options handled only by a backend.
1818
- L-0013 (2×, #925 #933 #940): Test PyO3 kwarg filtering with fixed-signature fakes or real wheels; permissive MagicMock kwargs hide incompatible argument forwarding.
19-
- L-0014 (1×, #925): Paths mirroring a routing decision must reuse its predicate exactly; truthiness and identity checks can disagree for non-bool inputs.
19+
- L-0014 (2×, #1071 #925): Guards or paths mirroring a downstream routing decision must reuse its predicate and precedence order exactly so they never pre-empt the real error; test each precedence branch on guarded and skipped sides.
2020
- L-0015 (1×, #948): Preserve Thrift's implicit OAuth default on kernel routing only when no explicit credential shape already determines the auth flow.
2121
- L-0016 (1×, #948): After retries or fallback mutate kwargs, attribute failures and cleanup to the backend object that actually failed.
2222
- L-0017 (1×, #948): Scope recovery-marker error translation to the RPC the recovery layer handles; unrelated calls must retain meaningful errors.
@@ -26,6 +26,7 @@
2626
- L-0021 (1×, #985): SQL LIKE escape handling depends on preceding backslash-run parity; a one-character negative lookbehind cannot establish JDBC equivalence.
2727
- L-0022 (2×, #1066 #1026): Validate integer options at the Python boundary: reject bool explicitly plus non-int and out-of-range values, test True alongside 0, negative, None, str and float, and clamp large values before native conversion.
2828
- L-0048 (1×, #1066): Inject connector-derived session_conf defaults only when the user has not set the key under any letter case; copy rather than mutate the mapping, and test both override casings plus non-mutation.
29+
- L-0057 (1×, #1071): Place validation for a new optional override after the override-unset early return so non-users behave exactly as before; add pass-through tests for odd inputs on the unset path.
2930

3031
## Results and lifecycle
3132
- L-0023 (2×, #1019): Verify server metadata and forwarded configuration behavior with live tests and an opposite-setting positive control; fabricated metadata or forwarding-only unit tests cannot establish server behavior.
@@ -40,6 +41,8 @@
4041
- L-0032 (1×, #1022): KERNEL_REV changes CI source only. Shipping a kernel fix requires a released wheel and matching packaging floor/lock update, plus an in-repo E2E regression.
4142
- L-0033 (1×, #1020): Prove optional C acceleration actually executes and skip when unavailable. Choose input/output protocols separately and verify encoded bytes and nesting limits against the fallback.
4243
- L-0034 (1×, #1016): Carry sync result metadata into async get_execution_result. Read numModifiedRows from the existing terminal FINISHED_STATE status response via the shared helper, avoiding an extra RPC.
44+
- L-0053 (1×, #1078): Keep row-conversion fast paths memory-flat: stream per-row values via a generator, tolist() numpy object arrays in bounded chunks (not per-row views or one full tolist()), and report peak traced memory vs main with timings.
45+
- L-0054 (1×, #1078): When a fast path bypasses a class constructor, test it against the public factory for every input shape: type, repr, equality, pickle bytes, field identity, immutability, exact error messages and chunk-boundary counts.
4346

4447
## Logging and concurrency
4548
- L-0035 (2×, #924): pyo3-log caches effective logger levels. Reset its cache after relevant level changes/session setup and isolate cached state in tests.
@@ -57,3 +60,8 @@
5760
- L-0045 (1×, #1004): Recheck capability claims after tool upgrades; replacing version numbers inside old support statements does not validate them.
5861
- L-0046 (1×, #1013): Confirm targeted regression tests fail when their guarded check is removed; inject inputs where earlier sanitization cannot neutralize the case.
5962
- L-0047 (1×, #1045): Secret-bearing CI steps must run Python isolated or from a neutral directory, preventing checkout modules from shadowing trusted imports.
63+
- L-0058 (1×, #1071): When a session resolves or rewrites connection arguments, assert final values on the mocked backend constructor's call_args.kwargs via databricks.sql.connect, not only in the resolver helper.
64+
65+
## Security and error messages
66+
- L-0055 (1×, #1071): Never echo user URIs/hosts in errors: show scheme and host[:port] only (scheme only if @ or %40 present), raise sanitized errors outside except or from None, and test the secret is absent from message, __cause__ and __context__.
67+
- L-0056 (1×, #1071): When an option can redirect the target host, check which host receives raw credentials for every flow (PAT, OAuth, token federation exchange) on each backend before deeming a credential safe cross-origin.

0 commit comments

Comments
 (0)