← Back to Pull requests

fix: initialize `_devices_supported` in `Plugin.__init__` #878

Closed
unknown closed this pull request without merging on Sep 10, 2026 17:00 UTC
View on GitHub
unknown unknown commented on Aug 19, 2026 08:29 UTC
Author

What

_devices_supported is created in _init_devices(), which runs only from init_devices() and only when _devices_inited is False. 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:

AttributeError: '<Name>Plugin' object has no attribute '_devices_supported'.
Did you mean: '_devices_inited'?

In units/manager.py:create(), init_devices() and assign_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 whose init_devices() was never reached. Each of those raises again during cleanup, via cleanup() -> 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:

static tuning from profile '<profile>' applied

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_host and cpu -- 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 calls instance.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_inited in the constructor, so the invariant lives in one place:

self._devices_inited = False
self._devices_supported = False

Guarding each of the three readers on _devices_inited instead 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 AttributeError above 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.

Diff: 356 lines (+267 / -89) across 4 files Reviewer: yarda Review duration: 32191m
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
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.5% (MEDIUM) · Higher = larger blast radius
42.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.8% · Safe to merge
16.8%