fix(transports): send the envelope as the value of a kafka record #44
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 530 lines diff across 6 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.375
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #44"
general
weight: 0.35
kamilmysliwiec
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
ClientProxyTransportemits theOutboxEnvelopeasdataby default, and the envelope always has akey.ClientKafka's default serializer (KafkaRequestSerializer) takes any data with akeyor avalueas the Kafka record itself, so the envelope becomes the record, with anullvalue, and kafkajs sends only its key and headers. The broker acknowledges it and the relay deletes the row, but the id, topic, createdAt and payload never left the process: the consumer's@Payload()isnull(the raw Kafka message on NestJS 11). On a compacted topic, a keyed message is also a tombstone, which compaction then uses to delete the key's earlier records.What is the new behavior?
For a
ClientKafka, recognized bysubscribeToResponseOf()(aClientKafkaProxymethod no other Nest client has) so the package still never loads@nestjs/microservices, the default data is now{ key: message.key, value: envelope, headers: message.headers }, the Kafka mapping theforRootAsynce2e test passes astoPacket. The consumer's@Payload()is the envelope. Only the value changes: the record already carried the message's key and headers, so partitioning is the same. Other clients still get the envelope, and a customtoPacketis used as is, through aClientKafkatoo.The mapping is exported as
toKafkaRecord, so aClientKafkabehind anemit-only facade or a test double, which the detection can't see, opts in withtoPacket: toKafkaRecord. ThetoPacketJSDoc ties the Kafka default to the default serializer's key-or-value rule, says aClientKafkawith its ownserializergets the record asdatatoo, gives thetoPacketthat keeps the envelope for one that expects it, and warns that with the default serializerdatamust never be the envelope or a spread of it. A customtoPacketis called as the function it was given, not with the transport asthis.The Kafka test builds a
ClientKafkafrom its prototype (its NestJS 11 constructor loads kafkajs, which the repo doesn't install), runs the realKafkaRequestSerializeron what it emits and asserts the topic, key, value and headers of each record (NestJS 11 and 12 in CI). Further tests cover a customtoPacketthrough aClientKafka,toPacket: toKafkaRecordthrough a plain client, thethisof a customtoPacket, and the other Nest clients, which still get the envelope itself. Without the change, the Kafka test fails withvalue: nullfor both messages (run); with it, the suite passes (run).Does this PR introduce a breaking change?
A
ClientKafkawith its ownserializernow receives{ key, value: envelope, headers }asdatainstead of the envelope, so a serializer that expects the envelope (one that encodesdatawhole, or reads its fields) sees the record;toPacket: (message, envelope) => ({ pattern: message.topic, data: envelope })keeps the previous data. Through the default serializer only the record's value changes, fromnullto the envelope.Other information
Kafka is the only Nest transport whose serializer reads plain objects as records (RMQ, NATS and MQTT check
instanceoftheir record classes), so the other defaults are unaffected.The outbox docs page describes the default as
client.emit(topic, envelope); through aClientKafkait is nowemit(topic, { key, value: envelope, headers }). That line lives in nestjs/docs.nestjs.com, so it is not in this PR.