fix: initialize `_devices_supported` in `Plugin.__init__` #878
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 356 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #878"
general
weight: 0.35
yarda
What
_devices_supportedis created in_init_devices(), which runs only frominit_devices()and only when_devices_initedisFalse. Three methods read it without checking whether that has happened:| method | line |
| :--- | :--- |
|
assign_free_devices()|tuned/plugins/base.py:168||
release_devices()|tuned/plugins/base.py:186||
_run_for_each_device()|tuned/plugins/base.py:204|Any plugin reaching one of them before
init_devices()has run raises:In
units/manager.py:create(),init_devices()andassign_free_devices()are called per instance in the same loop, so an exception part way through leaves the instances already created to be torn down by plugins whoseinit_devices()was never reached. Each of those raises again during cleanup, viacleanup()->destroy_instances()->_destroy_instance()->release_devices().Why it is worth fixing
The exceptions are caught and logged as
BUG: Unhandled exception in destroy_all: ..., the daemon continues, and it then reports:The settings owned by the failed plugins are silently not applied while the daemon reports success. Nothing downstream can tell the difference. On 2.27.0 this hit four plugins in a single run --
sysfs,sysctl,scsi_hostandcpu-- and the only visible symptom was that[sysfs]entries in the profile never took effect; the daemon's own status said the rofile had been applied.Reproducing
Rapid repeated profile switching is what triggered it in the field (a second profile-management daemon was switching profiles underneath TuneD). It is simpler to provoke directly: construct a plugin, create an instance, and destroy it without calling
init_devices()-- which is what the two tests added here do.test_destroy_instance()does not catch it because it callsinstance.plugin.init_devices()explicitly before destroying, which primes the attribute. The new tests take the path that does not.The change
One line, beside
_devices_initedin the constructor, so the invariant lives in one place:Guarding each of the three readers on
_devices_initedinstead would work equally well and is arguably more explicit about the invariant. That seemed the larger change for the same result -- happy to switch if you prefer it.Tests
Both new tests fail on unmodified master with the
AttributeErrorabove and pass with the change. Full suite: 136 tests before, 138 after, all passing.Tested against master (2.28.0-rc.1); originally observed on 2.27.0 with Python 3.13.