Fix mutable default arguments in core and plugins#194
Conversation
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 Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
|
Thanks for this pull request! I'll read up more on the link you included... |
|
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. |
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 indiagnosis.pywhereused_mnemonics=[]accumulates state across recursivewalkdown()calls.Changes
Replaced mutable defaults with
Noneand added initialization guards in:onair/src/ai_components/onair/src/reasoning/onair/src/systems/plugins/All modified files pass
python -m py_compile.