Skip to content

fix(json): avoid ESP32-S3 discovery serialization crash under constrained heap #4899

Closed

Description

@zackees

Context

Physical USB validation for #4893 found a reproducible failure in fresh canonical
ESP32-S3 AutoResearch (Arduino 3.3.11, IDF 5.5.5, native USB Serial/JTAG).
The RPC smoke run receives discovery data with no usable methods. A subsequent
status/heapCheck/rpc.discover sequence crashes with StoreProhibited, EXCVADDR=0.

The decoded stack is fl::deque<char>::push_back →
SerializerVisitor::append_escaped → recursive JSON array serialization.
Immediately before discovery: free heap 34,452 B, largest block 14,324 B,
minimum free 8,468 B, intact heap, loop-task stack high-water 10,308 B.
The crash causes a reset and the device then returns to AutoResearch readiness.

src/fl/stl/json.cpp.hpp builds serialized output through a temporary
deque<char> before producing its return string. The S3 harness retains its
96,100-byte receiver buffer for the existing 3,000-LED capacity. Serialization
peak allocation/low-memory behavior needs investigation; the decoded crash
establishes the failing path but does not by itself prove the allocation cause.
C6 baseline RPC smoke passes; its smaller receive-buffer tier is a different
workload and cannot establish S3 parity.

Proposal

Repair serialization peak-memory use and failure handling while preserving the
complete discovery schema, receiver capacity and JSON wire representation.
Keep this focused repair within the USB validation work rather than hiding the
failure by skipping discovery or shrinking the S3 receive buffer.

Acceptance criteria

  • RED → GREEN: preserve the actual failing S3 RPC/crash trace and add a focused
    regression for the verified memory/serialization cause before changing code.
  • Full discovery/help plus repeated status and heap checks pass on the same
    physical S3 USB route, with unchanged receiver capacity and heap integrity.
  • Verify escaping, nested arrays/objects and representative large documents;
    run relevant native debug tests and existing lint.
  • Use matched fbuild bloat and runtime heap evidence for any production change.
  • Keep C6 USB RPC smoke passing and document any remaining memory limitation.

Decisions

Open questions

  • Which allocation fails and what peak-memory reduction is sufficient on the
    observed S3 heap? Investigate before selecting the implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions