Repository navigation
Request compressed API responses (zstd/gzip) and decode them transparently - #458
Conversation
|
/lc-review |
There was a problem hiding this comment.
AI Code Review Summary
Found 1 Medium issue: a likely flaky memory assertion in the new tests. I found no correctness problems in _http_compression.py or in the client.py changes. I checked how decode errors move through _rest_call, request(), _call_jwt_endpoint and the search poll loop. ResponseDecodeError has no status code, so is_transient does not retry it.
General Feedback
- test-time-budget: No
test-time-budgetcheck run exists for this commit. The base branchmasterdoes not require it in branch protection or in rulesets, and this PR does not add or change anything that creates the check. So this check does not block the review. - Low: the decoded size has no cap. A response with a very high compression ratio can grow to any size in memory. Before this PR, memory was limited by the bytes sent on the wire. Every caller targets the first-party API over TLS, so this is not a blocker. A cap tied to a sane maximum page size would be a cheap safety net.
Blast Radius
Client._rest_calland_call_jwt_endpointnow sendAccept-Encodingand decode bodies on every request. That covers everylimacharlie.sdk.*class, the search, AI and replay services reached throughalt_root, the JWT endpoint and every CLI command built on them.- New public API:
Client(compressed_responses=...),limacharlie.errors.ResponseDecodeError(a subclass ofApiError) and theLC_NO_RESPONSE_COMPRESSIONenvironment variable. - Behaviour change for callers of
raw_request(): a 2xx body that cannot be decoded now raisesResponseDecodeErrorinstead of returning(code, data). - Packaging: new optional extra
zstd, anddevnow pulls inzstandard. - Code that mocks
urlopenand returns objects withContent-Encodingheaders but without matching bodies will now go through the decoder.
This review was generated automatically by Claude Code.
|
/lc-review |
There was a problem hiding this comment.
AI Code Review Summary
I re-reviewed the PR at 9c98675. The earlier Medium finding (the flaky tracemalloc test) is fixed. I found one new Low issue, so the verdict is APPROVED.
General Feedback
- test-time-budget: No
test-time-budgetcheck run exists for this commit.masterdoes not require the check in branch protection or in rulesets. This PR does not change anything that creates the check. It does not block this review. - Low, still open from the last review: the decoded size has no cap. A body with a very high compression ratio can use any amount of memory. A cap tied to a sane maximum page size would be a cheap safety net.
Blast Radius
- Every request made through
Client._rest_calland_call_jwt_endpointnow sendsAccept-Encodingand decodes the body. That covers alllimacharlie.sdk.*classes,request()/raw_request(), services reached throughalt_root(search and others), and every CLI command built on them. - New public surface:
Client(compressed_responses=...),limacharlie.errors.ResponseDecodeError(anApiErrorsubclass) andLC_NO_RESPONSE_COMPRESSION. raw_request()can now raiseResponseDecodeErroron a 2xx response.- Packaging: new
zstdextra.devnow installszstandard. - Downstream tests that mock
urlopenwith aContent-Encodingheader but a plain body will now hit the decoder.
This review was generated automatically by Claude Code.
|
/lc-review |
There was a problem hiding this comment.
AI Code Review Summary
I re-reviewed the PR at a849696. The earlier Low finding is fixed: a body cut exactly at a member or frame boundary is now caught. I found no new issues.
General Feedback
- test-time-budget: This commit has no
test-time-budgetcheck run.masterdoes not require the check, either in branch protection or in rulesets. This PR does not change anything that creates the check, so it does not block this review. - Low, still open from earlier reviews: the decoded size has no cap. A body with a very high compression ratio can use any amount of memory. A cap tied to a sane maximum page size would be a cheap safety net.
Blast Radius
- Every request made through
Client._rest_calland_call_jwt_endpointnow sendsAccept-Encodingand decodes the body. That covers alllimacharlie.sdk.*classes,request()andraw_request(), services reached throughalt_root, and every CLI command built on them. - New public surface:
Client(compressed_responses=...),limacharlie.errors.ResponseDecodeError(anApiErrorsubclass) andLC_NO_RESPONSE_COMPRESSION. raw_request()can now raiseResponseDecodeErroron a 2xx response. That includes a compressed body that falls short of itsContent-Length.- Packaging: new
zstdextra.devnow installszstandard. - Downstream tests that mock
urlopenwith aContent-Encodingheader but a plain body will now go through the decoder.
This review was generated automatically by Claude Code.
…arently The client sent no Accept-Encoding of its own, so urllib asked for "identity" and every response, including multi-megabyte search result pages, crossed the wire uncompressed. Every request made through Client (API calls, raw_request, the JWT endpoint, the search API and the CLI built on them) now sends Accept-Encoding and decodes the body by the response's Content-Encoding: - "zstd, gzip" when a Zstandard decoder is importable: the standard library's compression.zstd on Python 3.14+, else the optional zstandard package (new "zstd" extra). Otherwise "gzip", from the standard library. - gzip, x-gzip, zstd, stacked codings and identity are decoded while the body streams in, into one buffer, so peak memory matches an uncompressed read. - A truncated or corrupt stream, or a coding the client did not ask for, raises the new ResponseDecodeError (an ApiError) instead of returning a partial body. An error response whose body cannot be decoded still raises the exception for its status code. - Client(compressed_responses=False) or LC_NO_RESPONSE_COMPRESSION=1 turns the request header off. A caller's own Accept-Encoding is kept. Signed-URL downloads (artifacts, payloads, exports, installers) keep reading raw bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tracemalloc traces every thread, including the in-process test server's handler thread. Compressing the reply inside the traced window could leave the compressed body alive at the client's peak on a busy runner and fail the bound for reasons unrelated to decoding. Both replies are now built up front, so the server thread only sends existing bytes while tracing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ames A connection that closes early exactly at a gzip member or zstd frame boundary looks like a clean end to the decoder, so the first members were returned as the whole body. http.client still records the Content-Length shortfall; read_body now raises ResponseDecodeError when it is non-zero, as an uncompressed read raises IncompleteRead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a849696 to
1066046
Compare
|
/lc-review |
There was a problem hiding this comment.
AI Code Review Summary
I re-reviewed the PR at 1066046. The branch was rebased, so the earlier fixes are now in 0bd04c8 (memory test replies built before tracing) and 1066046 (Content-Length shortfall check). Both are present and correct. I found no new High or Medium issues.
What I checked again on this commit:
ResponseDecodeErrorsubclassesApiError, notValueError. So theexcept ValueErrorin_rest_calldoes not turn it into{}. It propagates, and_is_transient_poll_errordoes not retry it.- In
_call_jwt_endpoint, a decode error on a 2xx is wrapped asAuthenticationErrorby the existingexcept Exception. That matches how other JWT read failures are reported. read_bodychecksfp.lengthafter decoding. This catches a cut that lands exactly on a member or frame boundary.
General Feedback
- test-time-budget: No
test-time-budgetcheck run exists for this commit.masterdoes not require the check in branch protection or in rulesets, and this PR does not change anything that creates it. So it does not block this review. - Low, still open from earlier reviews: the decoded size has no cap. A body that compresses very well can grow to any size in memory. Before this PR, memory was bounded by the bytes on the wire. A cap tied to a sane maximum page size would be a cheap safety net.
- Low: the
zstdextra has nopython_version < \"3.14\"marker. The comment inpyproject.tomland the docs say 3.14+ needs nothing extra, butpip install limacharlie[zstd](anddev) still installszstandardthere. It is harmless because the stdlib decoder is chosen first. Add the marker if the extra is meant only for 3.10-3.13.
Blast Radius
- Every request through
Client._rest_calland_call_jwt_endpointnow sendsAccept-Encodingand decodes the body. That covers alllimacharlie.sdk.*classes,request()/raw_request(), services reached throughalt_root(search and others), and every CLI command built on them. - New public API:
Client(compressed_responses=...),limacharlie.errors.ResponseDecodeError(anApiErrorsubclass) andLC_NO_RESPONSE_COMPRESSION. raw_request()can now raiseResponseDecodeErroron a 2xx response, including a compressed body that falls short of itsContent-Length.- Packaging: new
zstdextra, anddevnow installszstandard. - Downstream tests that mock
urlopenand return aContent-Encodingheader with a plain body will now go through the decoder and may fail.
This review was generated automatically by Claude Code.
A compressed response could expand without bound: a few kilobytes on the wire with an extreme compression ratio could inflate to gigabytes before anything noticed, where an uncompressed response is bounded by the bytes actually received. read_body now enforces a decoded-size limit while decoding, on every layer of the decoder chain. Exceeding it raises ResponseDecodeError naming the limit and how to change it, after at most the limit plus one decode step of output, never a partial body. The zstandard package's decompressobj has no output limit, so its input is fed in pieces sized from the remaining budget and the densest zstd expansion (an RLE block). - Default 1 GiB: the largest API responses, search result pages, decode to a few hundred megabytes at most, and other decoded responses are smaller or paged. - LC_MAX_DECODED_RESPONSE_BYTES=<bytes> or Client(max_decoded_response_bytes=...) changes it; 0 or a negative value removes it; a non-integer value warns and keeps the default. - Uncompressed responses are not limited, exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… requires The Search API accepts `event`, `detection` and `audit` in a request's stream field and answers HTTP 400 to anything else. The SDK docstrings and the `search run`, `search estimate` and `search saved-create` help named the detection stream `detect`, so following them failed. - Docstrings and CLI help now name `detection`. - Search.execute, validate, estimate and `search saved-create` send `detect` (any case) as `detection` through search_stream(), so scripts and saved queries that used the documented name keep working. Every other value is passed through for the server to validate. - Outputs, Spout and firehose keep `detect`, the correct name there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Resolved in 209365a: the review summary point that the decoded size has no cap. A compressed response may now decode to at most 1 GiB (LC_MAX_DECODED_RESPONSE_BYTES or Client(max_decoded_response_bytes=...) to change it, 0 to remove it), enforced while decoding on every layer, so a high-ratio stream raises ResponseDecodeError with bounded memory; uncompressed responses are unchanged. |
|
/lc-review |
There was a problem hiding this comment.
AI Code Review Summary
I re-reviewed the PR at edfc573. This review covers the two commits added since the last one: 209365a (decoded-size limit) and edfc573 (detect is sent as detection). I found no High or Medium issues and one new Low issue.
What I checked in the new code:
_LimitedReaderwraps every decoder layer.GzipFile.read(n)andZstdFile.read(n)return at mostnbytes, so the stdlib paths stop within one 256 KiB step of the limit._ZstandardReader._piece_sizekeeps eachdecompress()call under about 1 MiB of overshoot near the limit. With the default 1 GiB limit, input is fed in 16 KiB pieces. This costs a little extra per call but is fine.- When the limit is hit on an error response,
_read_error_bodyreplaces the body, so the status code still raises. When it is hit on a search page, the error reaches the caller asSearchError, and it is not retried, becauseResponseDecodeErrorhas no status code. - The bomb memory tests build their replies before
tracemalloc.start(), so the server thread only sends bytes that already exist inside the traced window. search_stream()is applied inexecute,validate(whichestimateuses too) andsaved-create. Saved queries that already storedetectalso work, because they go throughexecute.
General Feedback
- test-time-budget: No
test-time-budgetcheck run exists for this commit.masterdoes not require it in branch protection or in rulesets (both lists are empty). This PR does not change anything that creates the check, so it does not block this review. - Low, still open: the
zstdextra has nopython_version < \"3.14\"marker, solimacharlie[zstd]anddevstill installzstandardon 3.14+, where the docs say nothing extra is needed. This does no harm, because the stdlib decoder is chosen first. - The earlier Low point about a missing decoded-size cap is fixed in 209365a.
Blast Radius
- Every request through
Client._rest_calland_call_jwt_endpointnow sendsAccept-Encodingand decodes the body. That covers alllimacharlie.sdk.*classes,request()/raw_request(), services reached throughalt_root, and every CLI command built on them. - New public API:
Client(compressed_responses=..., max_decoded_response_bytes=...),ResponseDecodeError,LC_NO_RESPONSE_COMPRESSION,LC_MAX_DECODED_RESPONSE_BYTES,limacharlie.sdk.search.search_streamandSEARCH_STREAMS. - Behaviour changes: a compressed body larger than 1 GiB decoded now raises.
raw_request()can raiseResponseDecodeErroron a 2xx. Searchstream="detect"is rewritten todetection, and saved queries created with--stream detectnow storedetection. - Packaging: new
zstdextra, anddevnow installszstandard. - Downstream tests that mock
urlopenwith aContent-Encodingheader and a plain body will now go through the decoder.
This review was generated automatically by Claude Code.
…he size-limit env in tests Python 3.14+ decodes zstd with the standard library, so the zstd extra (and dev through it) no longer installs zstandard there. The compression tests clear LC_MAX_DECODED_RESPONSE_BYTES as well, so a value set on a developer machine or runner cannot change what the default-limit tests see. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Resolved in 97c52d8: the review summary point that the zstd extra installs zstandard on Python 3.14+. It now carries python_version < '3.14', so the extra (and dev) installs nothing there, where the standard-library decoder is used. |
|
/lc-review |
There was a problem hiding this comment.
AI Code Review Summary
I re-reviewed the PR at 97c52d8. One commit was added since the last review (edfc573). It changes pyproject.toml, tests/unit/test_client_response_compression.py and tests/unit/test_packaging.py. I found no new issues. Both open Low points are fixed.
- The
zstdextra now haspython_version < '3.14'. On 3.14+,limacharlie[zstd]anddevno longer installzstandard, which matches the docs. On 3.14 thezstandardtest arm is now skipped by_importable(). That is expected:compression.zstdcovers 3.14, andzstandardstays covered on 3.10-3.13.test_packaging.pyasserts the marker is present. _isolatenow clearsLC_MAX_DECODED_RESPONSE_BYTES, so an environment value can no longer change the limit tests.
General Feedback
- test-time-budget: This commit has no
test-time-budgetcheck run.masterrequires no status checks, in branch protection or in rulesets (both lists are empty). This PR does not change anything that creates the check, so it does not block this review.
Blast Radius
- Every request through
Client._rest_calland_call_jwt_endpointnow sendsAccept-Encodingand decodes the body. That covers alllimacharlie.sdk.*classes,request()/raw_request(), services reached throughalt_root, and every CLI command built on them. - New public API:
Client(compressed_responses=..., max_decoded_response_bytes=...),ResponseDecodeError,LC_NO_RESPONSE_COMPRESSION,LC_MAX_DECODED_RESPONSE_BYTES, andsearch_stream/SEARCH_STREAMS. - Behaviour changes:
- A compressed body that decodes to more than 1 GiB now raises.
raw_request()can raiseResponseDecodeErroron a 2xx response.- A search sent with
stream="detect"is now sent asdetection.
- Packaging: there is a new
zstdextra. It installszstandardonly on Python below 3.14, anddevpulls it in. - Downstream tests that mock
urlopenand return aContent-Encodingheader with a plain body will now go through the decoder.
This review was generated automatically by Claude Code.
Summary
The SDK and CLI now ask the API for compressed responses and decode them before returning. Return values, parsed JSON and error messages are unchanged; only the bytes on the wire shrink. On a synthetic 142 MiB search result page, the wire size drops 4.6x with gzip and 5.2x with zstd, and the download time over a throttled link drops by the same factor.
Accept-Encoding: zstd, gzipwhen a Zstandard decoder is importable (the standard library on Python 3.14+, or the optionalzstandardpackage on 3.10-3.13), elseAccept-Encoding: gzip.Content-Encoding, while they stream in, with the same peak memory as an uncompressed read.Client(compressed_responses=False)orLC_NO_RESPONSE_COMPRESSION=1.limacharlie[zstd], installszstandardfor Python 3.10-3.13.LC_MAX_DECODED_RESPONSE_BYTES/Client(max_decoded_response_bytes=...)change it), so a response with an extreme compression ratio cannot exhaust memory. Uncompressed responses are not limited.detection, as the Search API requires. The SDK docstrings and CLI help named itdetect, which the API rejects with HTTP 400;detectis now sent asdetection.Background
Clientsends requests withurllib.request.urlopenand set noAccept-Encodingof its own, sohttp.clientsentAccept-Encoding: identityand the API always answered uncompressed. JSON responses compress well, and the largest of them, search result pages, can be very large. Every caller paid the full uncompressed transfer, which dominates the run time on a slow link.The API compresses a response when the client asks: it negotiates gzip and zstd, honours q-values, and picks zstd when both are offered with equal weight. It does not produce
brordeflate, so the client does not ask for them.Implementation
All requests made through
Clientshare one code path, so the change sits in two places:Client._add_accept_encoding()Accept-Encodingto every request built by_rest_call(all SDK calls,request(),raw_request()) and_call_jwt_endpoint. A caller that sets its ownAccept-Encodinginextra_headerskeeps it.Client._read_body()/_read_error_body()HTTPErrorbodies throughlimacharlie._http_compression.read_body().limacharlie/_http_compression.py(new, private):content_codings()collects everyContent-Encodingheader line, case-insensitively, droppingidentityand empty elements.read_body()removes the codings last-applied first (RFC 9110 8.4), so stacked codings and multiple header lines work. With no coding it returnsfp.read()unchanged.gzip.GzipFile: multi-member streams, CRC-32 and length checks,EOFErroron truncation.compression.zstd.ZstdFileon Python 3.14+. Before 3.14 it uses thezstandardpackage when installed, through a small frame loop overdecompressobj(). The package's ownstream_readerreturns a truncated frame's prefix as the whole body with no error, so the loop tracks frame boundaries itself, starts each frame from the previous one'sunused_data(which also consumes skippable frames), and raises when the input ends inside a frame. Azstandardtoo old to reportdecompressobj().eofis not used.BytesIO, whose bytes are returned without a final copy. The compressed body is never held in full.compression.zstdreturn at most the requested bytes per read, so they stop within one 256 KiB step of the limit. Thezstandardpackage'sdecompressobj()returns all the output of its input, so that input is fed in pieces of at most (limit - decoded so far) / 65,536 bytes. 65,536 is above the densest zstd expansion (an RLE block: 4 bytes to 128 KiB), so one piece cannot overshoot the limit by more than about 1 MiB.Errors:
ResponseDecodeError, never a partial bodyContent-LengthResponseDecodeError: urllib's sized reads return short silently, so a cut inside a member or frame is caught by the stream's end marker, and a cut exactly between members or frames by the unmetContent-Lengthbr,deflate,zstdwith no decoder)ResponseDecodeErrornaming itResponseDecodeErrornaming the limit andLC_MAX_DECODED_RESPONSE_BYTES, after at most the limit plus one decode step of outputResponseDecodeErrorsubclassesApiError, so existingexcept ApiErrorhandlers keep catching it. It is not retried: the search poll loop treats it as non-transient.Entry points covered: every
limacharlie.sdk.*class (they all callClient.request/raw_request), the search API (Search.executeinitiate, page polls and cancel,validate,estimate, query listing), the JWT endpoint, and every CLI command built on them (limacharlie api,search run, ...). All of these send thelc-cli/<version>User-Agent, except the JWT endpoint, which sends urllib's default User-Agent as before.Search stream names: the Search API accepts
event,detectionandauditin a request'sstreamfield and answers HTTP 400 to anything else.Search.execute,validate,estimateandsearch saved-createnow senddetect, in any case, asdetection(limacharlie.sdk.search.search_stream()), and pass every other value through for the server to validate. Their docstrings and thesearch run,search estimateandsearch saved-createhelp now namedetection. Outputs, Spout and firehose keepdetect, which is the correct name in those APIs.Left as they are, deliberately:
firehose).requests(OAuth, spout):requestsalready negotiates and decodes compression itself.Architecture
flowchart LR A[SDK / CLI call] --> B[Client._rest_call] B -->|Accept-Encoding| C[(API)] C -->|Content-Encoding: zstd / gzip / none| D[_http_compression.read_body] D -->|decoded bytes| E[json.loads / text, unchanged] D -->|truncated, corrupt, unsupported| F[ResponseDecodeError]Client-only change. No server change is needed.
Backward Compatibility
Client.__init__gains two keyword arguments,compressed_responses: bool | None = Noneandmax_decoded_response_bytes: int | None = None, appended last.ResponseDecodeErrorwhere it was returned before; no API response comes near that size. Uncompressed responses are never limited.stream="detect"in a search now works (sent asdetection) where it failed with HTTP 400. No other stream value changes.limacharlie.errors.ResponseDecodeError(ApiError).raw_request()still returns(status, data)for every HTTP status, but a 2xx body that cannot be decoded raisesResponseDecodeErrorrather than being returned truncated or as{}.{}(the JSON parse of gzip bytes failed silently) before.Accept-Encodingkeep working: an absent oridentityContent-Encodingis read as before.Configuration and opt-out
Client(compressed_responses=False)Accept-Encoding(urllib then sendsidentity)None: on unless the env var is setLC_NO_RESPONSE_COMPRESSION=10,false,no,offand empty read as unsetpip install 'limacharlie[zstd]'zstandarddecoder on Python 3.10-3.13 so zstd is requestedLC_MAX_DECODED_RESPONSE_BYTES=<bytes>0or negative removes the limit; a non-integer warns and keeps the defaultClient(max_decoded_response_bytes=<bytes>)None: environment or 1 GiBDocumented in
doc/sdk/README.md(Compressed Responses),README.md,doc/authentication.mdandCHANGELOG.md.Performance
Fixture: a synthetic search-like JSON page, 142.1 MiB, 178,522 event rows with repeated hosts, paths and command lines and random per-row ids and hashes. It is served by a local Go HTTP server that negotiates gzip and zstd the way the API does. Real pages compress better than this fixture, because its random ids and hashes do not compress. Linux x86-64 laptop, arms interleaved, separate process per run. master is
origin/mastermeasured with the identical harness; the opt-out arm on this branch measured the same as master.Wire size:
Download over a link throttled to 10 MiB/s,
raw_response=True, 3 runs each, median [min-max]:The time saved scales with the link: on a slower link the saving is larger in absolute seconds and the ratio stays at the wire-size ratio.
Memory for the same page, unthrottled:
Decoding adds no memory over an uncompressed read: both end holding the body as bytes and as text. With full JSON parsing the RSS growth is 817 MiB on master, 805 MiB gzip and 806 MiB zstd (3 runs each, identical across runs).
Decoding cost (
tests/microbenchmarks/test_response_compression_microbenchmark.py, 6.7 MB page): gzip 14.1 ms (about 480 MB/s decoded), zstd 5.6 ms (about 1.2 GB/s) on Python 3.11; gzip 16.1 ms, zstd 5.0 ms on 3.14. That CPU is the cost of this change: about 0.5 s more client CPU per 142 MiB page with gzip and about 0.25 s with zstd. On an unthrottled loopback link, where the transfer costs nothing, a page therefore takes longer than on master (0.17 s master, about 0.5 s zstd, about 0.9 s gzip, including the server compressing it). Over any real network link the saved transfer time is much larger.Testing
tests/unit/test_client_response_compression.pydrives the realClient,Searchand CLI over real sockets to anhttp.serveron 127.0.0.1. The server records every request's headers and answers with what the test chose. Every test runs three times: withcompression.zstd, withzstandard, and with no zstd decoder. Each case is produced by hiding modules from the SDK's import (aNoneentry insys.modules) and re-importing its compression module; no SDK code is replaced.raw_request, the JWT endpoint, a caller-supplied header, the opt-out by argument and by environment (truthy and falsy values), and the argument overriding the environment.identitylabels, stacked codings in one header and across header lines, multi-member gzip, zstd single and multi-frame, skippable frames before and after, frames with and without checksum, zstd over gzip, empty bodies labelled gzip or zstd, chunked transfer in 3-byte pieces, CSV viaraw_response, non-ASCII text, a server that ignoresAccept-Encoding, and an opted-out client receiving gzip anyway.ResponseDecodeErrorand never a partial body: truncated, missing trailer, bad CRC, bad length, trailing garbage, corrupt deflate data, not gzip; for zstd truncated, missing checksum byte, header only, truncated last frame, truncated skippable frame, bad checksum, corrupt block, trailing garbage, not zstd; a connection closed early underContent-Length, inside a member or frame and exactly between two (on 2xx and error responses); unsupported codings (br,deflate,compress,snappy,gzip, br;zstdwith no decoder). Decode errors are not retried.Retry-After, 401 that refreshes the JWT and retries, 504 retried, 500 with an undecodable body still raisingApiErrorwith status 500, and a compressed JWT endpoint error.OrganizationandSearch, checking every call (org URL lookup, initiate, both polls, cancel) carried the header, the rows round-trip, and the wire was less than half the JSON. A corrupt page surfaces asSearchErrorcaused byResponseDecodeErrorafter one poll.limacharlie search runend to end, checking every request (JWT, URL lookup, search calls) and thelc-cli/User-Agent, and the opt-out by environment.gzip, gzip; a body exactly at the limit decodes and one byte more fails; identity bodies above the limit are untouched; the environment variable raising, lowering and removing the limit (0, negative), an empty value, and invalid values (lots,1.5e9,1GB,0x10) warning and keeping the default; the constructor argument overriding the environment; an oversized error body keeping its status code; and an oversized search page surfacing asSearchError.tests/unit/test_search_stream_names.py: against a local search API that accepts onlyevent,detectionandaudit,Search.execute,validateandestimateand the CLI'ssearch runsenddetectionfor bothdetectionanddetect,eventandauditpass through, no stream sends no field,search saved-create --stream detectstoresdetection, and the help ofsearch run,estimateandsaved-createnamesdetection.tests/unit/test_packaging.py:zstandardis never a hard dependency, thezstdextra exists and installs it only below Python 3.14 (3.14+ uses the standard library), anddevpulls it in so CI covers that decoder on 3.10-3.13.Full suite (
pytest tests/unit/ tests/microbenchmarks/): 5,567 passed on Python 3.10 and 3.11, 5,685 passed on 3.14. The skips on 3.10-3.13 are thecompression.zstdruns, which need 3.14.End-to-end testing
Run against the production LimaCharlie API with a test organization, through
api.limacharlie.io, the JWT endpoint and the organization's search API host. Read-only calls only. Each arm ran in its own virtualenv, and master is the current release code (origin/master) with the identical harness. A wrapper aroundurllib'surlopenrecorded each request'sAccept-Encoding, each response'sContent-EncodingandContent-Length, and the body bytes read from the socket. It changed no SDK logic.Accept-Encodingsentidentity)compression.zstdzstd, gzipzstandardzstandardzstd, gzipgzipcompressed_responses=False(SDK),LC_NO_RESPONSE_COMPRESSION=1(CLI)identity)Encodings observed:
zstdwhen offeredzstd, gzip,gzipwhen offeredgzip, and no coding to master and the opt-out arm.limacharlie api ontology -H 'Accept-Encoding: gzip': the server answers gzip. Master prints{}. Every branch arm, including the opt-out arm, prints the decoded JSON.Correctness, branch vs master:
Search.execute, 5 query shapes, 16 runs per shape (3 per arm, 1 for master on 3.11): row count and the sha256 of the sorted canonical rows were identical in all 16. Facets and timeline items, and the summedeventsScanned,bytesScannedandeventsMatched, were identical too. For every shape except the aggregation the row order was identical as well; the aggregation's row order differs between runs on master itself.limacharlie search run(paginated event search, aggregation, invalid query): identical rows, facets and timeline, exit codes and error text in every arm.Error paths, all identical to master (exception class, status code, message):
AuthenticationError(401).NotFoundError.execute(SearchError), and the same error result fromvalidate.sensor getgives the same exit code and stderr.The server sent these error bodies uncompressed (they are under 1 KiB). Compressed error bodies are covered by the unit tests above.
Bytes on the wire (median of the runs; ratio vs master on the same Python):
zstandard), 3.11The largest single search page was 6.4 MiB uncompressed, 0.68 MiB as zstd and 1.08 MiB as gzip.
Wall time, client CPU and peak RSS. Each figure is the median [min-max]; n=3, except master on 3.11, which is a single run. With n=3 the p99 equals the max.
zstandard), 3.11zstandard), 3.11zstandard), 3.11How to read these numbers:
Not covered end to end: batch search mode (the SDK does not select a search mode, and the test organization defaults to interactive), and a compressed 4xx/5xx body from the real server.
Rollback
LC_NO_RESPONSE_COMPRESSION=1, orClient(compressed_responses=False)in code. No reinstall needed.LC_MAX_DECODED_RESPONSE_BYTES=<larger>or0to remove it.zstandardon Python 3.10-3.13 to fall back from zstd to gzip.limacharlie, or revert this commit and release.Watch after rollout
ResponseDecodeError, "Failed to decode the ... response body" or "decodes to more than": should be none. Something re-encoding responses in between (a proxy sendingbr) or a broken stream would show here.Related PRs
limacharlie[zstd]extra, the opt-out and the decoded-size limit; to merge after the release that contains this change.🤖 Generated with Claude Code