feat(dotc1z): record decompressed db size on save (zstd FCS + Info log) #777
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 628 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #777"
general
weight: 0.35
arreyder
Summary
Two changes, one feature:
1. Producer side —
saveC1znow writes the decompressed db size into the zstd frame header (Frame_Content_Size / FCS) and logs it at Info alongside the resulting compressed size. Upstream-spec-compatible — every existing zstd decoder ignores FCS and continues to stream exactly as today.2. Consumer side — the dotc1z
decoderpeeks the frame header during init and exposesDeclaredDecodedSize() (uint64, bool). When the declared size already exceedsDecoderMaxDecodedSize, the firstReadreturnsErrMaxSizeExceededwith the exact declared size embedded in the message — no bytes decompressed, no decoder warmed up.Why
The hit today isn't at sync time — it's during grant expansion. Expansion materializes one grant per (member, inherited access) tuple from the annotations the connector emits, and on some tenants that's enough to push the c1z past the 3 GiB decoder cap (observed: >200 GB decompressed). When downstream reopens the post-expansion c1z, it trips
ErrMaxSizeExceededwith no signal about how much more data is in the stream. The only way to find the true size today is to download the c1z and re-decompress with a raised cap — operationally expensive, often not possible during an incident.saveC1zruns once perC1File.Close(), so the final post-expansion save records the final post-expansion size. With FCS now in the header, any reader can learn that size directly — either via the 14-byte frame header (no dependency on this SDK) or viaDeclaredDecodedSize()(this SDK). Fail-fast on cap means the next bad c1z reports its declared size in the error instead of a generic "cap exceeded".What changed
Producer (
pkg/dotc1z/file.go)ResetContentSize(outFile, dbSize)so the frame header carries FCS.ResetContentSizerequires the written byte count to equal the advertised size atClose(), so theio.Copyis replaced withio.CopyN(..., dbSize)to make that invariant explicit.c1z: savedat Info withdecompressed_bytes+compressed_bytesfor operational visibility.Consumer (
pkg/dotc1z/decoder.go)decodergrowsdeclaredSize/hasDeclaredSizefields populated lazily during init.ensureInit(), called from bothReadand the newDeclaredDecodedSize().ReadHeaderstrips the 5-byte C1ZF magic, wrap the post-magic reader inbufio.Readerso we canPeek(zstd.HeaderMaxSize)the zstd frame header without consuming those bytes — the zstd decoder reads them back from bufio's buffer when it starts.declaredSize > maxDecodedSize, init stores anErrMaxSizeExceeded-wrapped error with"declared decoded size N exceeds cap M". The pooled / fresh zstd decoder is never even constructed in this case.DeclaredDecodedSizereturns(0, false), andReadbehaves exactly as before.Tests
Producer:
TestSaveC1z_SetsFrameContentSize— decodes the frame header of a freshly-saved c1z, assertsheader.HasFCSandheader.FrameContentSize == dbSize.TestSaveC1z/TestLoadC1zsubtests pass (including the empty-db edge case).Consumer:
TestDecoder_DeclaredDecodedSize—DeclaredDecodedSizereturns exact FCS before anyRead;Readthen streams the full payload; second call is idempotent.TestDecoder_DeclaredDecodedSize_LegacyWithoutFCS— hand-built legacy c1z (C1ZF magic + zstd frame withoutResetContentSize) returns(0, false)and still decodes cleanly.TestDecoder_DeclaredSizeExceedsCap_FailsFast— cap set below declared size; firstReadreturnsErrMaxSizeExceededwith"declared decoded size"in the message; zero bytes produced.TestC1ZDecoder_WindowSizeExceeded(16 MiB random payload) — moved here fromTestC1ZDecoder, since FCS-aware SingleSegment frames make small-payload window-exceeded checks impossible. Preserves coverage ofErrWindowSizeExceeded.Compat
C1ZF\x00magic and zstd stream layout are unchanged; FCS is an optional field inside the zstd frame header.errors.Is(err, ErrMaxSizeExceeded)keep working. The message now carries the declared size when known.Follow-ups (separate PRs, not in scope)
DeclaredDecodedSize()in theErrMaxSizeExceededlog line at the fetch site so per-tenant c1z-growth is queryable; add an OTel metric (e.g.c1z.size.decompressed_byteshistogram) keyed on tenant.Inspecthelper ondotc1zthat returns FCS without constructing a decoder, so ops tooling can parse the 14-byte header without any zstd setup.🤖 Generated with Claude Code