Skip to content

[Bugfix] Delete all bonds does not allow re-pairing.#404

Merged
h2zero merged 1 commit intomasterfrom
bugfix/delete-all-bonds
Mar 17, 2026
Merged

[Bugfix] Delete all bonds does not allow re-pairing.#404
h2zero merged 1 commit intomasterfrom
bugfix/delete-all-bonds

Conversation

@h2zero
Copy link
Owner

@h2zero h2zero commented Mar 17, 2026

This change iterates through each bond and unpairs it rather than just deleting the bond data in nvs, allowing a connected peer to rebond.

Summary by CodeRabbit

  • Improvements
    • Refined bond clearing mechanism with enhanced error detection and per-device diagnostics. Bond clearing operations now provide granular error reporting for each bonded device, delivering more informative failure messages. This improvement enables faster identification and resolution of issues during device bond management, enhancing overall system reliability.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Warning

Rate limit exceeded

@h2zero has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 37ea47a0-d9f8-43d0-b11e-c2cb75e5a089

📥 Commits

Reviewing files that changed from the base of the PR and between b0a3d05 and 7c4fe48.

📒 Files selected for processing (1)
  • src/NimBLEDevice.cpp
📝 Walkthrough

Walkthrough

Arr, matey! This change be replacin' the deleteAllBonds() implementation from a single ble_store_clear() call to iteratin' over bonded addresses and deletin' each bond individually, with enhanced error handlin' and per-address logging. The vessel's signature stays steady while the internals be refined, yarrr!

Changes

Cohort / File(s) Summary
Bond Deletion Implementation
src/NimBLEDevice.cpp
Refactored deleteAllBonds() from a monolithic ble_store_clear() call to iteratin' through bonded addresses and deletin' each bond separately. Improved error handlin' with per-address failure detection and logging. Returns false on first failure, true if all deletions succeed. Minor cosmetic line-wrappin' changes in initialization path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • Issue #1110: This PR be directly implementin' the suggested fix by replacin' ble_store_clear() with per-peer deletion logic, addressin' the same deleteAllBonds() behavior concern at the code level.

Poem

The bonds be broken, one by one, ⛓️
With logs to show each deed what's done,
No more the sweeping tide so vast,
Each error caught and held so fast, 🏴‍☠️
The fleet sails true with better grace!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main bugfix: changing delete all bonds behavior to allow re-pairing by iterating through bonds and unpairing each peer individually.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/delete-all-bonds
📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/NimBLEDevice.cpp (1)

632-638: Ahoy, sailor! Consider cachin' the address before ye walk the plank, arr!

The getBondedAddress(i) be called twice when a deletion fails - once fer the deleteBond() call on line 634, and again fer the error log on line 635. While this be only happenin' in the error path (a rare voyage indeed), ye could stash the address in a local variable fer cleaner seas:

🏴‍☠️ Proposed treasure map to cleaner code
 bool NimBLEDevice::deleteAllBonds() {
     int numBonds = NimBLEDevice::getNumBonds();
     for (int i = numBonds - 1; i >= 0; i--) {
-        if (!NimBLEDevice::deleteBond(NimBLEDevice::getBondedAddress(i))) {
-            NIMBLE_LOGE(LOG_TAG, "Failed to delete bond for address: %s", NimBLEDevice::getBondedAddress(i).toString().c_str());
+        NimBLEAddress addr = NimBLEDevice::getBondedAddress(i);
+        if (!NimBLEDevice::deleteBond(addr)) {
+            NIMBLE_LOGE(LOG_TAG, "Failed to delete bond for address: %s", addr.toString().c_str());
             return false;
         }
     }
     return true;
 }

The backwards iteration be a fine choice, matey! It keeps the indices shipshape as bonds be removed from the list. Yarrr! 🦜

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NimBLEDevice.cpp` around lines 632 - 638, Cache the bonded address into a
local variable before calling NimBLEDevice::deleteBond so you don't call
NimBLEDevice::getBondedAddress(i) twice on the error path; specifically, inside
the loop that uses NimBLEDevice::getNumBonds() and iterates i from numBonds-1
down to 0, assign auto addr = NimBLEDevice::getBondedAddress(i) then call
NimBLEDevice::deleteBond(addr) and, if it fails, log addr.toString().c_str() in
the NIMBLE_LOGE call and return false as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/NimBLEDevice.cpp`:
- Around line 632-638: Cache the bonded address into a local variable before
calling NimBLEDevice::deleteBond so you don't call
NimBLEDevice::getBondedAddress(i) twice on the error path; specifically, inside
the loop that uses NimBLEDevice::getNumBonds() and iterates i from numBonds-1
down to 0, assign auto addr = NimBLEDevice::getBondedAddress(i) then call
NimBLEDevice::deleteBond(addr) and, if it fails, log addr.toString().c_str() in
the NIMBLE_LOGE call and return false as before.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3581199e-63ae-4393-94b4-1f00191b2f07

📥 Commits

Reviewing files that changed from the base of the PR and between c731adc and b0a3d05.

📒 Files selected for processing (1)
  • src/NimBLEDevice.cpp

This change iterates through each bond and unpairs it rather than just deleting the bond data in nvs, allowing a connected peer to rebond.
@h2zero h2zero force-pushed the bugfix/delete-all-bonds branch from b0a3d05 to 7c4fe48 Compare March 17, 2026 00:34
@h2zero h2zero merged commit 22e7d6f into master Mar 17, 2026
66 checks passed
@h2zero h2zero deleted the bugfix/delete-all-bonds branch March 17, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant