From 8223db761d31cbc36518473e57a19605874f09fc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 18 Jul 2025 22:05:55 -1000 Subject: [PATCH 1/2] document --- esphome/components/api/api_connection.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index ba5a2678e5..bf5aca25c7 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -19,6 +19,8 @@ namespace api { // Keepalive timeout in milliseconds static constexpr uint32_t KEEPALIVE_TIMEOUT_MS = 60000; // Maximum number of entities to process in a single batch during initial state/info sending +// This was increased from 20 to 24 after removing the unique_id field from entity info messages, +// which reduced message sizes allowing more entities per batch without exceeding packet limits static constexpr size_t MAX_INITIAL_PER_BATCH = 24; // Maximum number of packets to process in a single batch (platform-dependent) // This limit exists to prevent stack overflow from the PacketInfo array in process_batch_ From 09705ca5269a80cee7ffc4d16b16733b1a9c17e3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 18 Jul 2025 22:11:13 -1000 Subject: [PATCH 2/2] guard --- esphome/components/api/api_connection.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index c829d25c83..53f1b2632f 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1671,6 +1671,10 @@ ProtoWriteBuffer APIConnection::allocate_batch_message_buffer(uint16_t size) { } void APIConnection::process_batch_() { + // Ensure PacketInfo remains trivially destructible for our placement new approach + static_assert(std::is_trivially_destructible::value, + "PacketInfo must remain trivially destructible with this placement-new approach"); + if (this->deferred_batch_.empty()) { this->flags_.batch_scheduled = false; return;