diff --git a/.claude/knowledge/journal/2026-12-04.md b/.claude/knowledge/journal/2026-12-04.md new file mode 100644 index 00000000..35c05444 --- /dev/null +++ b/.claude/knowledge/journal/2026-12-04.md @@ -0,0 +1,21 @@ +# Learning journal 2026-12-04 + +### 2026-12-04: Security / local files — Validate then reopen by path is a symlink TOCTOU +**Context:** PR #520's Volume PUT/GET checked a resolved path against allowed_paths, then reopened it by name, once per retry and again at publish. A symlink swapped into the gap could read or write outside the allowed roots. The fix keeps the validated handle, reads it by offset on retries, and after opening re-resolves the path and requires the same device and inode. +**Rule:** After validating a local path against allowed roots, do all I/O through the handle you opened and confirm it still matches the path (re-resolve, then compare dev/inode); never reopen the path by name for retries, redirects or publish. + +### 2026-12-04: Async lifecycle and FFI — Shared once-completion must latch an abandoned non-idempotent transfer +**Context:** In PR #520 the Volume completion was shared through a OnceCell. If the waiting future was dropped mid-transfer, nothing was cached, so another result stream could rerun a PUT or REMOVE that storage had already applied. The fix sets a started flag, so later calls return Cancelled. +**Rule:** When several waiters share a once-only side effect, latch a 'started' state before the work begins so that dropping one waiter mid-flight can never let another waiter re-run a non-idempotent operation. + +### 2026-12-04: HTTP and protocol — Idle timeouts need progress signals and a zero-means-unlimited rule +**Context:** In PR #520 the storage idle timeout counted only file-read progress. A byte-backed upload never signalled progress, so a large upload that was still moving failed as stalled. A zero timeout ran `sleep(0)` inside `select!`, which raced the work and failed transfers at random. +**Rule:** For an idle (no-progress) timeout, send every upload source in chunks that each count as progress, and treat a zero duration as no limit instead of passing it to sleep inside select!. + +### 2026-12-04: HTTP and protocol — Keep gzip decoding on presigned-storage GETs for cross-cloud parity +**Context:** In PR #520 reviewers asked several times for `no_gzip()` on the Volume storage client. The author kept decoding. GCS decompresses gzip objects itself when the request lacks `Accept-Encoding: gzip`, so turning decoding off would write different bytes on GCP than on AWS and Azure. All three Thrift drivers also decode. +**Rule:** Keep reqwest gzip decoding enabled for presigned cloud-storage downloads so GCS, AWS and Azure write identical files, and match the Thrift drivers' staging behavior before changing content-encoding handling. + +### 2026-12-04: Public API and bindings — Put new internal options on crate-private envelopes, not public exhaustive structs +**Context:** PR #511 added `lz4_compression` to the public, exhaustively constructible `ExecuteParams`. That broke struct literals, including an integration test that had to be edited. The field was moved to the crate-private `ExecutionParams`. +**Rule:** Carry new per-request options on a crate-private struct; adding a field to a public, non-#[non_exhaustive] struct breaks downstream struct literals. diff --git a/.claude/knowledge/lessons.md b/.claude/knowledge/lessons.md index 637c1121..1458a6f6 100644 --- a/.claude/knowledge/lessons.md +++ b/.claude/knowledge/lessons.md @@ -1,9 +1,9 @@ # Lessons - + ## Public API and bindings -- L-0001 (4×, #250 #184 #372): Preserve public Rust compatibility: non-exhaustive structs need external builders, public enums need fallback arms, and breaking 1.x type changes require a major release. +- L-0001 (5×, #511 #250 #184): Preserve public Rust compatibility: non-exhaustive structs need external builders, public enums need fallback arms, new internal per-request options go on crate-private structs (not public exhaustive ones), and breaking 1.x type changes require a major release. - L-0002 (2×, #246 #248): At FFI boundaries, define empty versus absent explicitly. Validate coupled config values together before mutating state, and test null/empty inputs. - L-0003 (2×, #247 #361): napi Rust identifiers determine published TypeScript names; choose cross-binding spelling before release and sync generated index.d.ts when Rust docs or defaults change. - L-0004 (1×, #262): Use napi u32 for JS-number duration/size options, widen inside Rust, and document its range; u64/usize expose BigInt and differ from Python/C. @@ -49,6 +49,9 @@ - L-0040 (2×, #401): Parse large responses from bytes and borrow attachments instead of UTF-8/string/Vec copies. Test escaped JSON too, since it exercises the owned deserializer path. - L-0041 (1×, #380): SEA DELETE /api/2.0/sql/sessions/{id} requires warehouse_id in the query; omitting it returns 400 and leaks the session until idle expiry. - L-0042 (1×, #436): Enforce explicit CloudFetch opt-out on response paths too; reject external links consistently on first and continuation pages when the server violates the disabled capability. +- L-0138 (1×, #518): Classify proxy/credential auth rejections as non-retryable in both the retry loop and the exported retryable flag; pin matched error strings and assert exactly one attempt is made. +- L-0139 (1×, #520): Idle (no-progress) timeouts must see progress from every upload source, so chunk byte-backed bodies too; treat zero as unlimited rather than sleep(0) inside select!, which races the work. +- L-0140 (1×, #520): Keep reqwest gzip decoding on for presigned cloud-storage GETs: GCS decompresses itself without Accept-Encoding: gzip, so no_gzip() makes GCP bytes differ from AWS/Azure; match Thrift drivers' staging. ## Async lifecycle and FFI - L-0043 (4×, #261 #299 #300): Provide best-effort Drop cleanup as well as explicit close. Recover poisoned cleanup locks and retain identifiers after failed close RPCs so idempotent cleanup can retry. @@ -72,6 +75,7 @@ - L-0061 (1×, #466): Coalesce requests without holding locks across network calls: key attempts, share same-key errors/results, recheck after different-key waits, and detach work from individual waiter cancellation. - L-0062 (1×, #431): A non-consuming peek buffers errors as well as data for the next read. Test one-shot-error-then-EOF; optional enrichment must not silently turn server success into execution failure. - L-0063 (1×, #451): Cached terminal ExecuteResponse payloads must be complete and take-once. Clear on error, close, Drop, owner release, timeout and fresh status polls; document how terminal observations retain inline results. +- L-0141 (1×, #520): When waiters share a once-only non-idempotent side effect (OnceCell), latch a started state before the work begins so a dropped waiter mid-flight cannot let another rerun it; later calls return Cancelled. ## Arrow results and metadata - L-0064 (2×, #301 #373): Empty catalog/pattern semantics vary by metadata operation; test short-circuit ordering and avoid turning an empty request into catalog=None (all catalogs). GetFunctions accepts meaningful empty catalogs. @@ -97,7 +101,7 @@ ## Verification and CI - L-0082 (2×, #184 #314): README Rust blocks are untested unless included as crate docs; verify external imports/builders explicitly. Public rustdoc must not link to private anchors. -- L-0083 (4×, #259 #279 #322): Isolate fallback/error sources and assert exact codes, SQLSTATE and distinctive nonzero values; generic Err or zero/default-only checks miss the wrong path. +- L-0083 (5×, #524 #259 #279): Isolate fallback/error sources and assert exact codes, SQLSTATE and distinctive nonzero values; for latencies inject known wiremock delays and assert derived lower bounds. Generic Err or zero/default/>=0 checks miss the wrong path. - L-0084 (2×, #261 #353): Drive protocol changes through real transport/exporter/provider routing with wiremock, asserting paths, payloads and failure behavior; helper-only or capturing-fake tests bypass wiring. - L-0085 (5×, #263 #291 #331): Wiremock cannot establish server parity or capability acceptance. Capture real fixtures or add ignored tests/v0_*_e2e.rs warehouse coverage, including unsupported-server behavior. - L-0086 (2×, #293 #312): Sequence concurrency tests so operations truly overlap and bound both client/server waits. A fixed mock accept-count wait can otherwise hang on a missing retry. @@ -109,6 +113,11 @@ - L-0092 (2×, #333 #429): Keep required checks always present. Compute path changes from BASE...HEAD with full history and include standalone workspaces plus their root path dependencies. - L-0093 (1×, #429): repository_dispatch 204 only acknowledges delivery. Sender-owned checks need cancellation/failure completion and stale-check expiry; list check runs with filter: all. - L-0094 (2×, #411 #412 #473): Regenerate dependency pins on the normal toolchain with a healthy registry. Inspect every lockfile for unrelated downgrades/checksum drift and validate locked builds. +- L-0136 (2×, #518 #501): Enforce transitive bug-fix floors as direct manifest minimums (default-features = false); lockfiles and comments don't bind downstream. When widening a range, add a CI leg pinning the declared floor. +- L-0137 (1×, #525): Gate fail-on-missing-secret CI steps with if: github.actor != 'dependabot[bot]'; Dependabot same-repo PRs get no Actions secrets but still need credential-free build/test coverage. ## Review follow-up [phase=review,followup] - L-0095 (1×, #257): Before claiming a review finding is already fixed or a symbol exists, reread HEAD and cite its current lines; remembered or partial source reads waste review rounds. + +## Local files and security +- L-0142 (1×, #520): After validating a local path against allowed roots, do all I/O via the opened handle (read by offset on retries) and re-resolve to compare dev/inode; never reopen by name for retries or publish (symlink TOCTOU).