Skip to content

fix: defensive fixes for packet/routing related memory leakages - #11223

Open
t-miura wants to merge 17 commits into
meshtastic:developfrom
t-miura:fix/defensive-routing-memory-fixes
Open

fix: defensive fixes for packet/routing related memory leakages#11223
t-miura wants to merge 17 commits into
meshtastic:developfrom
t-miura:fix/defensive-routing-memory-fixes

Conversation

@t-miura

@t-miura t-miura commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This PR includes following fixes which applies to all platforms,
while it's part of enhancing supports trials on STM32WL platform.
some changes also requires updated test codes, and they're also in this PR as well.

acknoledgements: huge tnx for @ndoo and many others on Discord's #stm32

1. MeshBeaconBroadcastModule::sendBeaconPacket Packet Leak

  • Issue: router->send(p) was called directly in sendBeaconPacket(). When router->send(p) returned ERRNO_SHOULD_RELEASE (e.g. for non-LoRa destinations or duty cycle limit drops), sendBeaconPacket ignored the return code and failed to release p.
  • Fix: Updated src/modules/MeshBeaconModule.cpp to release p when router->send(p) returns ERRNO_SHOULD_RELEASE.

2. NextHopRouter::sniffReceived Relayed Packet Leak

  • Issue: NextHopRouter::sniffReceived allocated a relay copy meshtastic_MeshPacket *relay = packetPool.allocCopy(*p) and evaluated Router::send(relay) == ERRNO_OK. If Router::send returned ERRNO_SHOULD_RELEASE, relay was leaked.
  • Fix: Updated src/mesh/NextHopRouter.cpp] to capture the return code and call packetPool.release(relay) on ERRNO_SHOULD_RELEASE.

3. Static MemoryPool Safety & Double-Free Protection

  • Issue: Pointer arithmetic (p - pool) in static memory pool deallocation could lead to memory corruption if invalid or misaligned pointers were released or if a pointer was freed twice.
  • Fix: Hardened src/mesh/MemoryPool.h with pointer alignment validation (offset % sizeof(T) == 0) and double-free detection (if (!used[index]) return).

4. Fixing logging format on data size-related logs(can be separate PR)

  • Issue: Some logging lines were not working as excpected due to formatting error, mainly where that's related to data's size
  • Fix: on commit 7db47da , following modules's log format that wasn't quite right has been fixed:
    • src/mesh/MemoryPool.h
    • src/mesh/PhoneAPI.cpp
    • src/mesh/RadioInterface.cpp
    • src/modules/PositionModule.cpp

used Gemini 3.6 Flash via Antigravitiy 2.0, while it exhausted quota before finishing all task, had to do the rest by my own✋

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)
      • Wio-E5 (STM32WL)

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid, missing, oversized, or unavailable mesh packets to prevent crashes and safely release resources.
    • Prevented invalid memory-pool releases, including out-of-range, misaligned, and duplicate release attempts.
    • Improved recovery when radio transmissions cannot start or complete.
    • Fixed packet cleanup when queues are full or message delivery fails.
    • Added safer handling for unavailable routing and mesh interfaces.
    • Improved diagnostics for memory, packet, and transmission errors.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The changes add runtime validation for memory pools, radio packets, routing dependencies, queue operations, and local-node state. They also improve packet release handling, transmit failure cleanup, pointer logging, and radio safety tests.

Changes

Runtime safety and packet lifecycle

Layer / File(s) Summary
Allocator and pool validation
src/mesh/MemoryPool.h
MemoryPool validates ownership, alignment, release state, and slot selection. Allocation deleters use value-based std::function storage. Pointer logs use %p.
Routing and beacon cleanup
src/mesh/Router.cpp, src/modules/MeshBeaconModule.cpp
Routing validates missing modules, invalid payloads, allocation failures, and interfaces. Beacon paths release packets when Router::send() requests release.
Service and radio guardrails
src/mesh/MeshService.cpp, src/mesh/RadioInterface.cpp
Queue, local-node, router, packet, payload, and sender validation now returns explicitly and releases packets when required.
Transmit failure propagation and tests
src/mesh/RadioLibInterface.cpp, test/test_radio/test_main.cpp
Failed beginSending() results skip transmission and restore radio state. Tests cover oversized payloads, null routers, and full queues.
Log format corrections
src/mesh/PhoneAPI.cpp, src/modules/PositionModule.cpp
Size-based log values use explicit unsigned formatting and casts.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: thebentern, jp-bennett

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.74% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary changes: defensive fixes for packet leaks and routing-related memory safety.
Description check ✅ Passed The description explains the main fixes, affected areas, testing status, and device coverage with completed attestations.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@t-miura

t-miura commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mesh/MemoryPool.h`:
- Around line 153-162: Update pointer logging in the pool deallocation paths,
including the misalignment and double-free messages and the nearby LOG_HEAP
“Freeing” message, to use the %p format specifier and pass p or &pool[i] as
static_cast<void *>(...). Leave integer index formatting unchanged.

In `@src/mesh/RadioInterface.cpp`:
- Around line 1476-1480: Update the beginSending handling around sendingPacket
so an active transmission is never released. When sendingPacket is already set,
reject the newly supplied packet p and release p instead, preserving
sendingPacket for its completion path and maintaining the existing warning
behavior.

In `@test/test_radio/test_main.cpp`:
- Around line 374-380: Remove the packetPool.release(p) call from the test that
invokes testRadio->beginSending(p), since beginSending already releases
oversized packets; retain the result and getSendingPacket assertions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 936ccaec-27b0-4535-b85b-45a5505d2a0e

📥 Commits

Reviewing files that changed from the base of the PR and between 6be7d9c and 544ffbe.

📒 Files selected for processing (7)
  • src/mesh/MemoryPool.h
  • src/mesh/MeshService.cpp
  • src/mesh/NextHopRouter.cpp
  • src/mesh/RadioInterface.cpp
  • src/mesh/Router.cpp
  • src/modules/MeshBeaconModule.cpp
  • test/test_radio/test_main.cpp

Comment thread src/mesh/MemoryPool.h Outdated
Comment thread src/mesh/RadioInterface.cpp
Comment thread test/test_radio/test_main.cpp Outdated
t-miura and others added 2 commits July 26, 2026 18:13
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@t-miura

t-miura commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@t-miura
t-miura marked this pull request as ready for review July 26, 2026 11:00
@thebentern
thebentern requested a review from Copilot July 26, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens packet lifecycle handling across routing and radio paths to prevent memory leaks (notably around ERRNO_SHOULD_RELEASE), adds defensive null/invalid-state guards, and extends unit tests to cover the targeted leak scenarios—motivated by broader platform robustness needs (including STM32WL trials).

Changes:

  • Ensure packets are released when router->send() / Router::send() returns ERRNO_SHOULD_RELEASE in beacon broadcast and next-hop relay paths.
  • Add defensive checks in routing/radio/service code paths (null router/module/interface, invalid payload variants, oversize radio payloads) with appropriate cleanup.
  • Add/extend unit tests to validate oversized payload handling, null-router delivery cleanup, and queue-status behavior under full queues.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/test_radio/test_main.cpp Adds tests covering oversized send abort, null-router delivery release, and full queue-status queue behavior.
src/modules/MeshBeaconModule.cpp Releases beacon packets when router->send() indicates caller-owned cleanup (ERRNO_SHOULD_RELEASE).
src/mesh/Router.cpp Adds defensive checks (null routingModule, invalid payload variant handling, null interface handling, OOM warnings).
src/mesh/RadioInterface.cpp Adds defensive guards in receive/send paths and drops+releases invalid/oversized/overlapping sends.
src/mesh/NextHopRouter.cpp Fixes potential relay-copy leak when Router::send() returns ERRNO_SHOULD_RELEASE.
src/mesh/MeshService.cpp Hardens queue scanning/re-enqueue and ensures queue-status allocations are released on enqueue failure.
src/mesh/MemoryPool.h Hardens pool release behavior (misalignment/double-free detection) and adjusts UniqueAllocation deleter type/logging.

Comment thread src/mesh/MemoryPool.h
Comment on lines 56 to 60
/// Variations of the above methods that return std::unique_ptr instead of raw pointers.
using UniqueAllocation = std::unique_ptr<T, const std::function<void(T *)> &>;
using UniqueAllocation = std::unique_ptr<T, std::function<void(T *)>>;
/// Return a queable object which has been prefilled with zeros.
/// std::unique_ptr wrapped variant of allocZeroed().
UniqueAllocation allocUniqueZeroed() { return UniqueAllocation(allocZeroed(), deleter); }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, depends on how much it increases the stack/heap comsumption,
but i feel like re-inventing smaller wheel doesn't sound healthy...

Comment thread src/mesh/MemoryPool.h Outdated
Comment on lines +152 to +156
uintptr_t offset = reinterpret_cast<uintptr_t>(p) - reinterpret_cast<uintptr_t>(pool);
if (offset % sizeof(T) != 0) {
LOG_WARN("Pointer %p is misaligned inside static pool!", static_cast<void *>(p));
return;
}
Comment thread src/mesh/RadioInterface.cpp Outdated
Comment thread test/test_radio/test_main.cpp Outdated
Comment thread test/test_radio/test_main.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/mesh/RadioInterface.cpp (1)

1476-1480: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Abort startSend() after beginSending() drops the packet.

The beginSending() failure paths release p and return 0, but RadioLibInterface::startSend() still calls startTransmit() and later printPacket(..., txp) in the success path. Add an immediate failure check after beginSending() so it never transmits a zero-length buffer or log/access a freed packet; also preserve exactly-once ownership cleanup.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mesh/RadioInterface.cpp` around lines 1476 - 1480, Update
RadioLibInterface::startSend() to immediately detect a failed beginSending()
result and return before calling startTransmit() or accessing txp via
printPacket. Preserve the existing success path, and ensure packet ownership
cleanup occurs exactly once without releasing the packet again after
beginSending() has already released it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/mesh/RadioInterface.cpp`:
- Around line 1476-1480: Update RadioLibInterface::startSend() to immediately
detect a failed beginSending() result and return before calling startTransmit()
or accessing txp via printPacket. Preserve the existing success path, and ensure
packet ownership cleanup occurs exactly once without releasing the packet again
after beginSending() has already released it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 167bd282-1750-4605-a50c-b51d6e2a6ed1

📥 Commits

Reviewing files that changed from the base of the PR and between aff94df and 68d9177.

📒 Files selected for processing (2)
  • src/mesh/RadioInterface.cpp
  • test/test_radio/test_main.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/test_radio/test_main.cpp

@t-miura

t-miura commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

fix added for #11223 (review) , while it's outside of this PR, so now it's separated: #11229

Verification & Findings

  1. RadioInterface::beginSending() Error Behavior (src/mesh/RadioInterface.cpp):

    • beginSending(p) checks conditions such as active transmissions (sendingPacket != nullptr), unencrypted packet variants, oversized payload, or zero sender node number.
    • On any error, beginSending() logs the error, calls packetPool.release(p) to return packet ownership to the pool, and returns 0.
    • On success, beginSending() sets sendingPacket = p and returns numbytes > 0.
  2. Issue in RadioLibInterface::startSend() (src/mesh/RadioLibInterface.cpp):

    • Previously, RadioLibInterface::startSend() called size_t numbytes = beginSending(txp); without verifying if numbytes == 0.
    • If beginSending() failed (returned 0), startSend() proceeded to call iface->startTransmit((uint8_t *)&radioBuffer, 0).
    • Furthermore, on success return from startTransmit(), it called printPacket("Started Tx", txp)—causing a use-after-free access on txp, which had already been released by beginSending().

Changes Made

  1. RadioLibInterface.cpp:

    • Added an immediate if (numbytes == 0) return false; check following beginSending(txp).
    • Ensures startTransmit() and printPacket() are not invoked when beginSending() fails.
    • Prevents double-releasing txp because packet ownership cleanup occurred inside beginSending().
  2. SimRadio.cpp:

    • Added a corresponding if (numbytes == 0) return; check in SimRadio::startSend() to prevent accessing freed packet memory via packetPool.allocCopy(*txp).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mesh/RadioLibInterface.cpp`:
- Around line 775-777: Update the send flow around beginSending() so a zero-byte
result invokes the same TX-state cleanup and RX restart used by the
startTransmit() failure path after configHardwareForSend(). Preserve the
existing false return while ensuring TX power state is cleared before returning.

In `@src/platform/portduino/SimRadio.cpp`:
- Around line 210-212: Update SimRadio::startSend() to return a send-status
value consistent with RadioLibInterface::startSend(), propagating beginSending()
failure when it returns zero. In onNotify(), only call
RadioInterface::getPacketTime(txp) and schedule or log transmit airtime after
startSend() reports success, so released packets are not reused.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 41178263-6d5e-407c-adf5-28ea72692a56

📥 Commits

Reviewing files that changed from the base of the PR and between 68d9177 and 3b71d21.

📒 Files selected for processing (2)
  • src/mesh/RadioLibInterface.cpp
  • src/platform/portduino/SimRadio.cpp

Comment thread src/mesh/RadioLibInterface.cpp
Comment thread src/platform/portduino/SimRadio.cpp Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/platform/portduino/SimRadio.cpp`:
- Around line 188-194: Update SimRadio::startSend() to return true after the
successful transmission path so its caller-side status check is valid. Remove
the value-return from void SimRadio::unpackAndReceive(), leaving that function
without a returned value.
- Around line 210-216: Update the send path around beginSending and
packetPool.allocCopy in SimRadio so every failure releases txp when ownership
has been accepted and restores isReceiving before returning. Route both
failed-send branches through the existing send-completion or equivalent cleanup
mechanism, preserving normal handling when allocation succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d13333c9-356b-48a9-8105-c3a679825913

📥 Commits

Reviewing files that changed from the base of the PR and between 3b71d21 and 168a0a2.

📒 Files selected for processing (3)
  • src/mesh/RadioLibInterface.cpp
  • src/platform/portduino/SimRadio.cpp
  • src/platform/portduino/SimRadio.h

Comment thread src/platform/portduino/SimRadio.cpp Outdated
Comment thread src/platform/portduino/SimRadio.cpp Outdated
@t-miura
t-miura force-pushed the fix/defensive-routing-memory-fixes branch from 58b33c7 to 8231bca Compare July 26, 2026 12:27
Comment thread src/platform/portduino/SimRadio.cpp Outdated
@t-miura
t-miura force-pushed the fix/defensive-routing-memory-fixes branch from 8231bca to 832d2b7 Compare July 26, 2026 12:33
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@t-miura

t-miura commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mesh/RadioLibInterface.cpp`:
- Around line 776-780: Update the zero-byte handling in the sending flow around
beginSending() so completeSending(), power-monitor cleanup, and startReceive()
run only when no transmission is already active. Preserve the existing
sendingPacket and radio state when beginSending() returns 0 because another
packet is in progress, while retaining cleanup for genuine failures without an
active transmission.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8c589280-783b-428c-a522-688ddb165be0

📥 Commits

Reviewing files that changed from the base of the PR and between 3b71d21 and 832d2b7.

📒 Files selected for processing (4)
  • src/mesh/MemoryPool.h
  • src/mesh/RadioLibInterface.cpp
  • src/platform/portduino/SimRadio.cpp
  • src/platform/portduino/SimRadio.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/platform/portduino/SimRadio.h
  • src/platform/portduino/SimRadio.cpp
  • src/mesh/MemoryPool.h

@t-miura

t-miura commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

Jorropo and others added 4 commits July 26, 2026 22:25
checkov/CKV_SECRET_6 flags the commented-out "large4cats" example, which
is the public default credential for the meshtastic.org MQTT broker rather
than a real secret. Ignore the file in .trunk/trunk.yaml so the example
config stays free of lint-suppression comments.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@t-miura

t-miura commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

updated heap-freeing logs to align with #11374, that's much simpler and works just fine!
this pr will add double-free / misalignment detection on top of that PR's changes.

@t-miura
t-miura marked this pull request as draft August 11, 2026 02:37
fix test_radio code, fix QueStatus packet sending with proper clean-up
@t-miura
t-miura force-pushed the fix/defensive-routing-memory-fixes branch from df86a4e to c9ecb42 Compare August 11, 2026 02:39
@t-miura

t-miura commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
test/test_radio/test_main.cpp (1)

401-403: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the decorative test banner.

This three-line banner does not explain a non-obvious reason. Remove it.

As per coding guidelines: “Keep code comments minimal—one or two lines maximum—and comment only when the reason is not obvious.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/test_radio/test_main.cpp` around lines 401 - 403, Remove the three-line
decorative comment banner above the verification and stress tests, leaving the
surrounding test code unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/mesh/MeshService.cpp`:
- Around line 182-184: In the failed re-enqueue branch of
getNodenumFromRequestId, increment fromNum after packetPool.release(p) so
observers are notified of the dropped phone-bound packet, matching sendToPhone()
and reconcilePendingRxTimes().

In `@src/mesh/RadioLibInterface.cpp`:
- Around line 776-782: Update the rejected-send flow around beginSending() and
the numbytes == 0 branch so beacon-switch state is cleared and the radio is
restored before beginSending() releases txp. Ensure the fix handles a null
sendingPacket, clears the beacon sidecar entry, and invokes the existing radio
restoration path instead of relying on sendingPacket being present.

In `@test/test_radio/test_main.cpp`:
- Around line 417-420: The tests around beginSendingPublic() and
deliverToReceiverPublic() currently verify only return values and packet state;
add memaudit::snapshot() assertions for the pktpool(live) baseline before packet
allocation and confirm it is restored after each rejected-packet path at
test/test_radio/test_main.cpp lines 417-420, 429-433, and 441-450. Update all
three listed sites as applicable, while leaving the existing QueueStatus
eviction coverage unchanged.

---

Nitpick comments:
In `@test/test_radio/test_main.cpp`:
- Around line 401-403: Remove the three-line decorative comment banner above the
verification and stress tests, leaving the surrounding test code unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f0d0c174-032d-4d2e-ab0a-19a26eb4659f

📥 Commits

Reviewing files that changed from the base of the PR and between b8dee13 and 14e1947.

📒 Files selected for processing (9)
  • src/mesh/MemoryPool.h
  • src/mesh/MeshService.cpp
  • src/mesh/PhoneAPI.cpp
  • src/mesh/RadioInterface.cpp
  • src/mesh/RadioLibInterface.cpp
  • src/mesh/Router.cpp
  • src/modules/MeshBeaconModule.cpp
  • src/modules/PositionModule.cpp
  • test/test_radio/test_main.cpp

Comment thread src/mesh/MeshService.cpp
Comment thread src/mesh/RadioLibInterface.cpp
Comment thread test/test_radio/test_main.cpp
@t-miura

t-miura commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Pull request that fixes bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants