Repository navigation
Description
Describe the desired outcome from the user's perspective
As a binding author composing a ModelTransform (#2325/#2326) into the value pipeline, I want the kafka cache storage layer's produce path to accept a transform whose output is a different length than the client's declared input, so that a transform is not structurally restricted to same-length rewrites.
What actually shipped, and a real gap it leaves open. The original plan below proposed a dedicated staging mechanism, explicitly diverging from the existing view: json conversion pattern so that only the transformed output would ever exist in the log. What shipped instead reuses that existing pattern: KafkaCachePartition.writeProduceEntryStart calls the transform's padding() (a statically-known upper bound on how much larger the output can get — computable exactly for a fixed per-layer overhead) and reserves that much extra space in segment.convertedFile(), the same side-file mechanism view: json already uses; if the actual output still exceeds the reserved padding, the entry is marked CACHE_ENTRY_FLAGS_ABORTED. This works and needed no new mmap staging area — but it means the untransformed input is also persisted, in the convertedFile() companion, for as long as that pattern's existing retention already keeps it. For a length-changing transform whose whole point is protecting the original bytes (rather than offering an alternate rendering the way view: json does), that's a real, unresolved question: does the untransformed input persisting anywhere at rest undermine the guarantee such a transform is meant to provide? This needs a real answer, not an assumption either way, before this issue is considered settled.
Acceptance criteria
Implementation layer
This lives in the shared kafka cache storage implementation — concretely KafkaCachePartition (the storage class) plus KafkaCacheModel (the ModelHandler/ModelPipeline wrapper), invoked from KafkaCacheClientProduceFactory's KafkaCacheClientProduceFan. Any binding that produces through this storage layer gets this behavior automatically, with no separate implementation of its own.
Why today's produce write path can't be reused unmodified
KafkaCachePartition.writeProduceEntryStart commits the value's length prefix and reserves its space eagerly, from the client's declared (deferred) length, before later fragments arrive — this is what makes concurrent multi-producer writes to one partition cheap: each stream's region is carved out, non-overlapping, at INIT time, with no separate per-stream buffer needed.
A length-changing transform breaks this structurally, not as an edge case: its output size is not known until the transform runs, and may differ from the declared length.
Resolution actually shipped
- A record whose transform is length-preserving (or absent) is unaffected — today's direct-to-mmap-log mechanism is untouched, at no cost and no behavior change.
- A record subject to a length-changing transform reserves
padding()extra bytes in the partition'sconvertedFile()side file (the same mechanismview: jsonuses for its converted rendering) and writes the transformed output there. If the transform's actual output still exceeds the reserved padding, the entry is markedCACHE_ENTRY_FLAGS_ABORTEDrather than attempting to grow the reservation. - This depends on
padding()being a real, exact upper bound for the installed transform — a transform that cannot state a static bound cannot use this path safely, and should be rejected at schema-resolution time rather than silently risking abort under load.
Still open — needs resolving
- Whether persisting the untransformed input in
convertedFile()is acceptable for a transform whose purpose is protecting those bytes, or whether the storage layer needs an explicit "output-only, no side-by-side original" mode distinct fromview: json's deliberate keep-both behavior. - Whether
CACHE_ENTRY_FLAGS_ABORTEDis the right outcome for a padding under-estimate, or whether that should be a startup-time rejection of the transform's declaredpadding()instead, so it never occurs on the data path at all.
Coverage
Unit and k3po coverage for: a record whose transform is absent or length-preserving following today's direct-to-mmap path unchanged; a record subject to a length-changing transform correctly reserving and using padding() space in convertedFile(); a transform whose actual output exceeds its declared padding() producing CACHE_ENTRY_FLAGS_ABORTED; and coverage for whichever resolution the two open questions above receive.
Additional context
Depends on #2325/#2326 (ModelTransform, the mechanism that can make a value's output length differ from its declared input length).
Activity
jfallows commentedon Aug 4, 2026
Two changes to the header composition this issue owns, from decisions taken since it was filed.
1. Three headers, not four —
zilla:efieldsis dropped.zilla:keyzilla:edekzilla:edata[block-count][offset|length] × NA field id is only interpretable with the schema that defines it, so
zilla:efieldswas either redundant (a consumer holding the schema derives the mapping by traversal) or unreadable (a consumer without it cannot interpret the ids). Neither the gateway nor the client deserializer consumed it — see #1680.options.encryption.headerstherefore has three entries.2. Descriptors arrive via
ModelVisitor.onBlock(int offset, int length), a default method added in #1680. The binding accumulates regions as the transform writes them and composeszilla:edataonce per message. Offsets are message-relative, so they remain valid across anOVERFLOWresume where the output buffer drains andtransform()is called again.Also relevant to this issue: the produce path is
parse → validate → encrypt → sink, with validation on plaintext (see #1689). AndModelPipeline.padding(...)is the existing hook for reserving ciphertext expansion — 28 bytes per region, plus the header bytes — which the binding must call before transforming.Generated by Claude Code
jfallows commentedon Aug 4, 2026
Padding reservation cannot be
28 × fieldCount— that under-reserves badly and will overflow the output buffer.28(12-byte IV + 16-byte GCM tag) is correct only forbytesfields, which carry raw ciphertext.stringfields carry base64, verified against Confluent'sEncryptionExecutor— standard RFC 4648 alphabet with=padding — so growth is multiplicative, not additive:Per encrypted
stringfield the on-wire length is4·ceil((p + 28)/3), wherepis the plaintext length — plus 5 more inside the base64 if the DEK-version prefix is present (registry mode with rotation enabled, see #1680).The difficulty is that
ModelPipeline.padding(data, index, length)is called before transforming, so per-field plaintext lengths are not yet known. The bound has to be derived from the payload length and the field count rather than measured:ceil(length / 3)beyond the original bytesceil(length / 3) + 44 × fieldCount + headerBytesis a safe conservative boundOver-reserving is cheap; under-reserving means an
OVERFLOWthe transform cannot recover from because the field no longer fits. The exact constant should be derived from the per-field formula above rather than copied from this comment.fieldCountcomes from the policy, which names the maximum number of encryptable fields for the resolved schema — so it is known atpadding(...)time without parsing.Also note the header bytes are now three, not four —
zilla:efieldsis dropped (#1680) — andzilla:edekis base64 of the EDEK, so its size depends on the KEK's wrap output rather than being fixed.Generated by Claude Code
[-]Implement produce-path encryption in kafka-cache-client[/-][+]Implement produce-path encryption in kafka cache storage[/+][-]Implement produce-path encryption in kafka cache storage[/-][+]Support length-changing model transforms in kafka cache storage's produce path[/+]fix(binding-kafka): size converted-value padding from full value length
feat(binding-kafka): make KafkaCacheModel.transform incremental
feat(binding-kafka): widen cache entry value field to reuse KafkaCach…
feat(binding-kafka): stream value transform output directly into logF…
feat(binding-kafka): delete convertedFile entirely (#1688)
fix(binding-kafka): size converted-value padding from full value length
feat(binding-kafka): make KafkaCacheModel.transform incremental
feat(binding-kafka): widen cache entry value field to reuse KafkaCach…
feat(binding-kafka): stream value transform output directly into logF…
feat(binding-kafka): delete convertedFile entirely (#1688)
feat(binding-kafka): stream value transforms directly into the cache,…