Skip to content

Fix mutable default arguments in core and plugins#194

Open
stef41 wants to merge 1 commit into
nasa:mainfrom
stef41:fix-mutable-default-arguments
Open

Fix mutable default arguments in core and plugins#194
stef41 wants to merge 1 commit into
nasa:mainfrom
stef41:fix-mutable-default-arguments

Conversation

@stef41

@stef41 stef41 commented Apr 11, 2026

Copy link
Copy Markdown

Summary

14 function signatures across 9 files use mutable default arguments (=[], ={}), which is a well-known Python anti-pattern. Mutable defaults are evaluated once at function definition time and shared across all calls, so data from one invocation can silently persist into subsequent calls.

This is particularly concerning in the AI reasoning interfaces where _reasoning_plugins={}, _learner_plugins={}, and _planner_plugins={} are shared across instances, and in diagnosis.py where used_mnemonics=[] accumulates state across recursive walkdown() calls.

Changes

Replaced mutable defaults with None and added initialization guards in:

Component Files Fixes
onair/src/ai_components/ 2 2
onair/src/reasoning/ 2 3
onair/src/systems/ 2 4
plugins/ 3 5

All modified files pass python -m py_compile.

14 function signatures across 9 files use mutable default arguments
(=[], ={}). This anti-pattern causes the default object to be shared
across all calls, so data from one invocation can leak into the next.

Affected components:
- onair/src/ai_components/ (learners, planners interfaces)
- onair/src/reasoning/ (diagnosis, complex reasoning interface)
- onair/src/systems/ (vehicle_rep, telemetry_test_suite)
- plugins/ (reporter, csv_output, generic)
@codecov-commenter

codecov-commenter commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.78947% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.91%. Comparing base (16fe993) to head (fba1ba2).
⚠️ Report is 162 commits behind head on main.

Files with missing lines Patch % Lines
plugins/csv_output/csv_output_plugin.py 20.00% 2 Missing and 2 partials ⚠️
plugins/reporter/reporter_plugin.py 20.00% 2 Missing and 2 partials ⚠️
onair/src/reasoning/diagnosis.py 33.33% 1 Missing and 1 partial ⚠️
plugins/generic/generic_plugin.py 60.00% 0 Missing and 2 partials ⚠️
onair/src/systems/vehicle_rep.py 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #194      +/-   ##
===========================================
- Coverage   100.00%   98.91%   -1.09%     
===========================================
  Files           26       31       +5     
  Lines          970     1198     +228     
  Branches       136      182      +46     
===========================================
+ Hits           970     1185     +215     
- Misses           0        5       +5     
- Partials         0        8       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@the-other-james

Copy link
Copy Markdown
Contributor

Thanks for this pull request! I'll read up more on the link you included...
In the meantime, can you please create an issue and submit a contributors license agreement? Refer to the Contributing section in the readme.
Thank you!

@stef41

stef41 commented Apr 17, 2026

Copy link
Copy Markdown
Author

Thanks @the-other-james! I have created issue #197 for this fix.

I will download the Individual CLA, complete it, and email it to gsfc-softwarerequest@mail.nasa.gov with james.marshall-1@nasa.gov CCed as described in the contributing guide. I will follow up here once that is done.

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.

3 participants