Skip to content

fix(upload): replace recursive retry with iterative loop in upload_selected_params_workflow#1429

Open
yashhzd wants to merge 1 commit intoArduPilot:masterfrom
yashhzd:fix/upload-retry-callback-bug
Open

fix(upload): replace recursive retry with iterative loop in upload_selected_params_workflow#1429
yashhzd wants to merge 1 commit intoArduPilot:masterfrom
yashhzd:fix/upload-retry-callback-bug

Conversation

@yashhzd
Copy link
Contributor

@yashhzd yashhzd commented Mar 23, 2026

Summary

Fixes three bugs in the retry path of upload_selected_params_workflow (data_model_parameter_editor.py):

  1. Missing get_connection_progress_callback argument — the recursive retry call passed only 7 of 8 arguments, causing get_download_progress_callback to land in position 7 (get_connection_progress_callback's slot). On retry: connection progress showed wrong text, download progress was None.

  2. Unbounded recursion — each retry created a new stack frame, risking RecursionError on persistent FC communication issues.

  3. Redundant side effects on unwind_write_current_file() and _at_least_one_changed = False executed once per recursion depth, not once total.

Changes

Replace the recursive call with a while should_retry loop. All callback factories are correctly re-invoked each iteration. _write_current_file() runs exactly once after the loop exits.

Test plan

  • Upload parameters to FC, trigger a validation failure → click Retry → verify connection and download progress bars display correctly
  • Verify _write_current_file() is called exactly once after successful upload
  • Verify no RecursionError on repeated retries

Closes #1427

Signed-off-by: Yash Goel yashhzd@users.noreply.github.com

@yashhzd yashhzd requested a review from amilcarlucas as a code owner March 23, 2026 22:15
Copilot AI review requested due to automatic review settings March 23, 2026 22:15
@yashhzd yashhzd force-pushed the fix/upload-retry-callback-bug branch 2 times, most recently from 6fb52a7 to 4d83cd3 Compare March 23, 2026 22:20
Copy link
Contributor

Copilot AI left a comment

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 fixes the retry behavior in upload_selected_params_workflow by replacing a recursive retry call with an iterative loop, addressing incorrect callback argument ordering, unbounded recursion risk, and redundant side effects during recursion unwind.

Changes:

  • Replace recursive retry with a while should_retry loop.
  • Recreate progress callbacks each retry iteration and keep retry prompting in-loop.
  • Ensure _write_current_file() and _at_least_one_changed reset run exactly once after the loop completes.

logging_info(_("All parameters uploaded to the flight controller successfully"))
if should_retry:
continue
# If not retrying, continue without success message
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The comment “If not retrying, continue without success message” is misleading after the refactor: there is no continue in the non-retry branch, and execution will still fall through to later logic (e.g., diff export) before exiting the loop. Update the comment to reflect the actual control flow (e.g., “If not retrying, fall through without success message”) or restructure the branches to match the wording.

Suggested change
# If not retrying, continue without success message
# If not retrying, fall through without success message

Copilot uses AI. Check for mistakes.
@amilcarlucas
Copy link
Collaborator

  1. Is a bug, good catch
  2. Not really an issue. A user needs to click retry 1000 times to cause a crash.
  3. Is a bug good catch.

Anyway, good that you fixed all 3

amilcarlucas
amilcarlucas previously approved these changes Mar 23, 2026
@yashhzd
Copy link
Contributor Author

yashhzd commented Mar 23, 2026

  1. Is a bug, good catch
  2. Not really an issue. A user needs to click retry 1000 times to cause a crash.
  3. Is a bug good catch.

Anyway, good that you fixed all 3

thank you!

…lected_params_workflow

The recursive retry path had three bugs:

1. Missing get_connection_progress_callback argument — the download
   callback factory was passed in position 7 (where connection callback
   belongs), causing wrong progress text on retry and no download
   progress at all.

2. Unbounded recursion — each retry added a stack frame, risking
   RecursionError on persistent FC communication issues.

3. Redundant side effects — _write_current_file() and the
   _at_least_one_changed reset executed once per recursion depth
   on unwind, not just once.

Replace with a while loop that re-runs the entire upload/validate
cycle on retry. All callback factories are now correctly re-invoked
each iteration, _write_current_file() runs exactly once after the
loop exits.

Closes ArduPilot#1427

Signed-off-by: Yash Goel <yashhzd@users.noreply.github.com>
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.

Bug: Recursive retry in upload_selected_params_workflow passes wrong callback arguments

3 participants