From 2f833e445b048939e25339296fdc8ea6a55c4d00 Mon Sep 17 00:00:00 2001 From: matthew-pilot Date: Sat, 30 May 2026 01:04:28 +0000 Subject: [PATCH 1/2] test(dataexchange): assert data absent when IncludeBase64=true (PILOT-269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing test only checked data_b64 presence but never verified that data was absent when IncludeBase64 is enabled — which is the 2× payload blowup described in the ticket. This commit will FAIL until the fix in service.go is applied. --- zz_more_test.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/zz_more_test.go b/zz_more_test.go index cd86cd4..d1883ba 100644 --- a/zz_more_test.go +++ b/zz_more_test.go @@ -5,6 +5,7 @@ package dataexchange import ( "bytes" "context" + "encoding/base64" "encoding/binary" "encoding/json" "errors" @@ -252,12 +253,25 @@ func TestService_SaveInboxMessage_WritesJSON(t *testing.T) { if msg["type"] != "TEXT" { t.Errorf("type = %v, want TEXT", msg["type"]) } - if msg["data"] != "hello" { - t.Errorf("data = %v, want hello", msg["data"]) - } - _, hasB64 := msg["data_b64"] - if hasB64 != b64 { - t.Errorf("has data_b64 = %v, want %v", hasB64, b64) + if b64 { + // When IncludeBase64 is true, data_b64 is the canonical field; + // data must NOT be present to avoid 2× payload blowup. + if _, hasRaw := msg["data"]; hasRaw { + t.Errorf("data = %v, want absent when IncludeBase64=true", msg["data"]) + } + b64Val, hasB64 := msg["data_b64"] + if !hasB64 { + t.Error("data_b64 missing when IncludeBase64=true") + } else if b64Val != base64.StdEncoding.EncodeToString([]byte("hello")) { + t.Errorf("data_b64 = %v, want %q", b64Val, base64.StdEncoding.EncodeToString([]byte("hello"))) + } + } else { + if msg["data"] != "hello" { + t.Errorf("data = %v, want hello", msg["data"]) + } + if _, hasB64 := msg["data_b64"]; hasB64 { + t.Error("data_b64 present when IncludeBase64=false") + } } }) } From 91134b9b8b1869acb7b327a295bb4cb4f75dcf35 Mon Sep 17 00:00:00 2001 From: matthew-pilot Date: Sat, 30 May 2026 01:04:39 +0000 Subject: [PATCH 2/2] fix(dataexchange): omit raw data field when IncludeBase64 is true (PILOT-269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When IncludeBase64=true, saveInboxMessage stored both the raw string(frame.Payload) as 'data' AND its base64 encoding as 'data_b64', effectively doubling the JSON payload size. For a max 256MiB frame, this produced ~683MiB of JSON (256MiB raw + 341MiB base64 + overhead). Fix: omit 'data' when 'data_b64' is present — IncludeBase64 operators get the lossless base64 representation without the duplicate. Closes PILOT-269 --- service.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index 4b7d524..3d84160 100644 --- a/service.go +++ b/service.go @@ -263,12 +263,13 @@ func (s *Service) saveInboxMessage(frame *Frame, from protocol.Addr) error { msg := map[string]interface{}{ "type": TypeName(frame.Type), "from": from.String(), - "data": string(frame.Payload), "bytes": len(frame.Payload), "received_at": ts.Format(time.RFC3339Nano), } if s.cfg.IncludeBase64 { msg["data_b64"] = base64.StdEncoding.EncodeToString(frame.Payload) + } else { + msg["data"] = string(frame.Payload) } data, err := json.Marshal(msg) if err != nil {