From 8e48f23e2872079fb139a4fd4c529a2082367b2d Mon Sep 17 00:00:00 2001 From: Jason Huebert Date: Fri, 16 Oct 2026 16:17:02 -0500 Subject: [PATCH 1/2] fix: keep ack retry pending when the packet pool refuses the resend A refused retry previously counted as sent (rtx) and dropped the reply, silently losing it. Retain the slot and retry after FLEET_ACK_RETRY_BACKOFF_MS, incrementing rtx only once the resend is queued. sendAlert() now reports the sender's result instead of always claiming success. Adds regression tests and documents the backoff. --- FLEET.md | 9 ++++--- examples/simple_repeater/FleetManager.cpp | 23 ++++++++++++----- test/test_fleet/test_fleet.cpp | 30 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/FLEET.md b/FLEET.md index 6778abe2..3ad31c89 100644 --- a/FLEET.md +++ b/FLEET.md @@ -256,9 +256,12 @@ exactly one reply per node. "Heard a repeat" proves a repeater relayed the reply; it does **not** prove the operator's companion received it — there is no end-to-end ack for flood group text. Each such miss is counted as `rtx` on the status line; a climbing `rtx` means replies are not being repeated — likely no -neighbouring repeater in range, or heavy loss. The retry is build-time tunable -(`FLEET_ACK_RETRY`, `FLEET_ACK_REPEAT_WINDOW_MS`), never persisted; build with -`FLEET_ACK_RETRY=0` to restore the single fire-and-forget send. +neighbouring repeater in range, or heavy loss. If the packet pool refuses an +initial send or retry, it is tried again after the configured backoff; `rtx` +increments only when the retry is queued. The retry is build-time tunable +(`FLEET_ACK_RETRY`, `FLEET_ACK_REPEAT_WINDOW_MS`, and +`FLEET_ACK_RETRY_BACKOFF_MS`), never persisted; build with `FLEET_ACK_RETRY=0` +to restore the single fire-and-forget send. ## Inline pauses (`!delay `) diff --git a/examples/simple_repeater/FleetManager.cpp b/examples/simple_repeater/FleetManager.cpp index 0fdc8f2e..66132caf 100644 --- a/examples/simple_repeater/FleetManager.cpp +++ b/examples/simple_repeater/FleetManager.cpp @@ -309,8 +309,17 @@ void FleetManager::serviceReplies() { // window elapsed with no repeater heard repeating the reply: one // byte-identical resend. Same ts => same packet hash, so every node that // already relayed attempt 1 suppresses this copy — no duplicate on air. - if (send_fn != NULL) { - send_fn(send_ctx, r.chan_secret, r.chan_hash, r.tx_ts, body, NULL); + if (send_fn == NULL) { + removeReply(i); + continue; + } + bool sent = send_fn(send_ctx, r.chan_secret, r.chan_hash, r.tx_ts, body, NULL); + if (!sent) { + // packet pool refused the retry: it was not sent, so retain the slot and + // try again after the same bounded backoff as an initial-send refusal. + r.deadline_ms = millis() + FLEET_ACK_RETRY_BACKOFF_MS; + i++; + continue; } reply_retries++; // the miss count: the first attempt drew no repeat removeReply(i); @@ -318,10 +327,13 @@ void FleetManager::serviceReplies() { } // first attempt: stamp it now, remember the ts and hash for a possible retry + if (send_fn == NULL) { + removeReply(i); + continue; + } uint32_t ts = time_fn ? time_fn(time_ctx) : 0; uint8_t hash[MAX_HASH_SIZE]; - bool sent = send_fn != NULL && - send_fn(send_ctx, r.chan_secret, r.chan_hash, ts, body, hash); + bool sent = send_fn(send_ctx, r.chan_secret, r.chan_hash, ts, body, hash); if (!sent) { // packet pool refused the send: no attempt used, try again shortly r.deadline_ms = millis() + FLEET_ACK_RETRY_BACKOFF_MS; @@ -363,8 +375,7 @@ void FleetManager::onHeardPacket(const mesh::Packet* packet) { bool FleetManager::sendAlert(const char* body) { if (!enabled || psk_len == 0 || send_fn == NULL) return false; uint32_t ts = time_fn ? time_fn(time_ctx) : 0; - send_fn(send_ctx, psk, chan_hash, ts, body, NULL); // one-shot: no retry - return true; + return send_fn(send_ctx, psk, chan_hash, ts, body, NULL); // one-shot: no retry } // ---------------------------------------------------------------- relay side diff --git a/test/test_fleet/test_fleet.cpp b/test/test_fleet/test_fleet.cpp index 4850aecf..db02d992 100644 --- a/test/test_fleet/test_fleet.cpp +++ b/test/test_fleet/test_fleet.cpp @@ -1089,6 +1089,30 @@ TEST_F(FleetHooksTest, AckSendRefusalUsesNoAttempt) { EXPECT_EQ(fleet.getReplyRetries(), (uint32_t)1); } +// A refused retry was not sent: keep the reply queued for retry and do not +// count it until the packet is actually accepted by the sender. +TEST_F(FleetHooksTest, AckRetryRefusalDoesNotConsumeRetry) { + deliver("!id k1\n!ack\nset a"); + ASSERT_TRUE(pass()); + g_mock_millis += env.jitter; + fleet.runScripts(ExecRecorder::fn, &env.rec); + ASSERT_EQ(env.sent.size(), (size_t)1); + + g_mock_millis += FLEET_ACK_REPEAT_WINDOW_MS; + env.next_send_fails = true; + fleet.runScripts(ExecRecorder::fn, &env.rec); + EXPECT_EQ(env.sent.size(), (size_t)1); + EXPECT_EQ(fleet.getReplyRetries(), (uint32_t)0); + EXPECT_EQ(fleet.getReplyCount(), 0); + EXPECT_EQ(fleet.getAwaitingCount(), 1); + + g_mock_millis += FLEET_ACK_RETRY_BACKOFF_MS; + fleet.runScripts(ExecRecorder::fn, &env.rec); + EXPECT_EQ(env.sent.size(), (size_t)2); + EXPECT_EQ(fleet.getReplyRetries(), (uint32_t)1); + EXPECT_EQ(fleet.getAwaitingCount(), 0); +} + #else // Off switch: the reply is dropped the instant the first send succeeds — @@ -1219,6 +1243,12 @@ TEST_F(FleetHooksTest, SendAlertUnwiredSenderIsSilent) { EXPECT_EQ(env.sent.size(), (size_t)0); } +TEST_F(FleetHooksTest, SendAlertReportsPacketPoolRefusal) { + env.next_send_fails = true; + EXPECT_FALSE(fleet.sendAlert("BATT RESUME 3700mV")); + EXPECT_EQ(env.sent.size(), (size_t)0); +} + TEST_F(FleetHooksTest, AlertIsNotAScript) { // the alert body does not start with "!id ", so a receiver counts it as // ordinary chat (noid) and never queues it From 9a22c97c2fe7c4f43d47dacb7645ed35eaaa9fd9 Mon Sep 17 00:00:00 2001 From: Jason Huebert Date: Fri, 16 Oct 2026 16:17:03 -0500 Subject: [PATCH 2/2] docs: refresh AGENTS.md test counts Filter 295->301, fleet 82->112, battery 44->50. --- AGENTS.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f691b6cf..90782e67 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -88,9 +88,9 @@ commit** — the guides are user-facing API documentation, not optional docs. drain). - `main.cpp` — serial CLI entry (upstream + fork's buffer-hardening lines). -**Tests:** `test/test_packet_filter/` (295 behavior-level cases: matching, +**Tests:** `test/test_packet_filter/` (301 behavior-level cases: matching, content rules, limiter, persistence upgrades, CLI surface, TinyRegex, -PatternMatch), `test/test_fleet/` (82 cases: runner grammar, tag targeting, +PatternMatch), `test/test_fleet/` (112 cases: runner grammar, tag targeting, acknowledgements, scheduling, persistence, CLI surface, the battery exemption contract), `test/test_battery_gate/`, and `test/test_mesh_clock/` (24 behavior-level cases). Test-only shims: @@ -281,8 +281,8 @@ FILTER.md: fails any release target whose `src/`/`examples/` code holds a frame >= 2 KB (formerly a filter-release.yml CI check) — keep new frames well under it. -- Pure refactors keep both suites green **unchanged** — the suites (295 filter, - 82 fleet, 44 battery) are the safety net that proves no behavior slipped. +- Pure refactors keep both suites green **unchanged** — the suites (301 filter, + 112 fleet, 50 battery) are the safety net that proves no behavior slipped. - Run both suites, then re-read the diff: ```