Skip to content

Enforce bootloader discovery deadline - #2140

Open
amilcarlucas wants to merge 1 commit into
masterfrom
bootloader_discovery
Open

amilcarlucas wants to merge 1 commit into
masterfrom
bootloader_discovery

Conversation

@amilcarlucas

Copy link
Copy Markdown
Collaborator

Description

Reject bootloader discovery when legacy external-flash fallback finishes after the global enumeration deadline. Reboot the held bootloader through the existing recovery path instead of allowing firmware upload to proceed after the discovery budget has expired.

Add a regression test covering a delayed legacy bootloader response, deadline exhaustion, safe reboot, and prevention of flash writes.

Checklist

  • Run pre-commit checks locally
  • Verified by a human programmer
  • All commits are signed off (use git commit --signoff)
  • Code follows our coding standards
  • Documentation updated if needed
  • No breaking changes or properly documented

Testing

Describe how you tested these changes:

  • Unit tests pass
  • Integration tests pass
  • Manual testing performed
  • Tested on flight controller hardware

Copilot AI balanced review requested due to automatic review settings September 30, 2026 17:40
@amilcarlucas amilcarlucas added the AIReview Request an automated AI review; picked up by the reviewprs sweep label Sep 30, 2026

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Enforces the global bootloader discovery deadline by rejecting legacy-fallback identification that finishes too late, and adds a regression test to ensure the held bootloader is safely rebooted and flashing does not proceed.

Changes:

  • Add a post-identification check to fail discovery if the global enumeration deadline has expired.
  • Add a regression test simulating a slow legacy bootloader response that exhausts the discovery budget.
File Description
ardupilot_methodic_configurator/​backend_flightcontroller_bootloader.py Rejects late bootloader discovery attempts after the global deadline is exceeded.
tests/​test_backend_flightcontroller_bootloader.py Adds a regression test for deadline exhaustion during legacy fallback and verifies safe reboot/no flash writes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 822 to 827
info = client.identify(deadline=attempt_deadline)
if self._clock() >= deadline:
msg = _("bootloader discovery deadline expired")
raise BootloaderProtocolError(msg)
_restore_transport_timeout(transport, self._timeout)
return client, info
Comment on lines +823 to +825
if self._clock() >= deadline:
msg = _("bootloader discovery deadline expired")
raise BootloaderProtocolError(msg)
Comment on lines +390 to +398
return super().write(data)

def read(self, size: int = 1) -> bytes:
if self.requests and self.requests[-1][:1] == bl.GET_DEVICE:
body = self.requests[-1][1:-1]
if body in {bl.INFO_BOARD_ID, bl.INFO_BOARD_REV, bl.INFO_FLASH_SIZE} and self._reply:
now[0] += 0.1
return super().read(size)

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

☂️ Code Coverage

current status: ✅

Overall Coverage

Statements Covered Coverage Threshold Status
31875 30637 96% 89% 🟢

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: dcc6ee9 by action🐍

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

     4 files   -      1       4 suites   - 1   50m 10s ⏱️ - 10m 31s
10 685 tests  -      2  10 619 ✅  -      2   4 💤 ± 0  62 ❌ ± 0 
42 524 runs   - 10 602  42 394 ✅  - 10 535  68 💤  - 30  62 ❌  - 37 

For more details on these failures, see this check.

Results for commit dcc6ee9. ± Comparison against base commit 05cc87e.

This pull request removes 3 and adds 1 tests. Note that renamed tests count towards both.
tests.test_vehicle_components_schema ‑ test_json_schema[json_file13]
tests.test_vehicle_components_schema ‑ test_json_schema[json_file31]
tests.test_vehicle_components_schema ‑ test_json_schema[json_file7]
tests.test_backend_flightcontroller_bootloader ‑ test_discovery_does_not_continue_after_legacy_fallback_exceeds_global_deadline

♻️ This comment has been updated with latest results.

@AP-Review

AP-Review commented Sep 30, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-09-30)

Automated review note — AI-generated (Claude), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head c71289f98e.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2140/1.html#prMethodicConfigurator-2140

Thanks. Rejecting identification that completes after the discovery deadline looks right, and the new test covers it.

One problem on the new path (https://github.com/ArduPilot/MethodicConfigurator/pull/2140/files#diff-c70ba4e2c02221763c9b3aa2459177b4b9c861b23571197bfac7e7c484f537a9R823): the deadline error goes into the recovery handler, which always calls abort_before_erase(expect_ack=True). A revision-2 bootloader reboots without an ACK. With a late legacy rev-2 board, the device does reboot, but the user gets 'could not confirm reboot ... power-cycle', bootloader_rebooted is not set, and upload_apj_firmware skips the automatic reconnect. info is known at that point, so passing expect_ack=info.protocol_revision != 2 there (as BootloaderClient.upload does) would fix it. Keep expect_ack=True when identify itself failed.

Smaller suggestion: the new raise skips _restore_transport_timeout, so the reboot write runs with the shortened open timeout. Restoring the timeout at the start of the except block would cover this and the existing identify-failure path.

FYI, pre-EXTF bootloaders that appear in the last ~2 s of the 15 s window will now always be rejected, because identify() waits out the deadline on the INSYNC/INVALID EXTF reply. Your test docstring suggests that is intended, so this is just a note.

Not checked: real hardware and serial timing.

Reject bootloader discovery when legacy external-flash fallback finishes
after the global enumeration deadline. Reboot the held bootloader through
the existing recovery path instead of allowing firmware upload to proceed
after the discovery budget has expired.

Add a regression test covering a delayed legacy bootloader response,
deadline exhaustion, safe reboot, and prevention of flash writes.
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head dcc6ee90ac.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2140/2.html#prMethodicConfigurator-2140

Still requesting changes: the revision-2 recovery bug is unchanged.
Nothing has been fixed since the last review: the new head dcc6ee9 is a rebase of c71289f with an identical patch.

Blocking

  1. backend_flightcontroller_bootloader.py:862 Late revision-2 board reported as needing a power-cycle (still open). Use expect_ack=info.protocol_revision != 2 for the deadline case, and keep True when identify() itself failed.

Should fix

  • Commit dcc6ee9: the DCO Signed-off-by trailer is missing, which CONTRIBUTING.md requires. git commit --amend --signoff fixes it.
Minor (2)

Copilot's >= and test-brittleness comments are not defects.

Not checked: real hardware and serial timing.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 45185854679

Coverage increased (+0.009%) to 96.147%

Details

  • Coverage increased (+0.009%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 31875
Covered Lines: 30647
Line Coverage: 96.15%
Relevant Branches: 9684
Covered Branches: 8834
Branch Coverage: 91.22%
Branches in Coverage %: No
Coverage Strength: 2.87 hits per line

💛 - Coveralls

This branch has not been deployed

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

Labels

AIReview Request an automated AI review; picked up by the reviewprs sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants