← Back to Pull requests

Fix #120: start and stop each server plugin only once #397

Closed
unknown closed this pull request without merging on Jul 31, 2026 00:25 UTC
View on GitHub
unknown unknown commented on Jul 29, 2026 19:46 UTC
Author

Summary

Fixes #120. A plugin whose class implements several of the plugin type interfaces was registered once per interface, so it was started and stopped multiple times.

Root cause

DefaultExtensionController.initPlugins() checks each loaded plugin against every plugin type in turn, and each of the eight branches adds the instance to the same serverPlugins collection:

if (serverPlugin instanceof ServicePlugin) { ... serverPlugins.add(servicePlugin); }
if (serverPlugin instanceof ChannelPlugin) { ... serverPlugins.add(channelPlugin); }
// ...six more

Because that collection was an ArrayList, a class implementing both ServicePlugin and ChannelPlugin ends up in it twice.

Note the issue title mentions close(); the methods actually affected are start() and stop() on ServerPlugin.

Impact beyond start/stop

The duplicate entries affect every consumer of that collection, not just shutdown:

  • startPlugins() / stopPlugins() invoke start() and stop() once per implemented interface instead of once per plugin. This is the shutdown noise reported in the issue.

  • AlertWorker builds its alertActionAcceptors list by iterating getServerPlugins() and filtering on instanceof AlertActionAcceptor, so a duplicated plugin is added repeatedly and its alert actions run once per implemented interface.

  • DefaultUsageController reports plugin usage from the same collection, so counts are inflated for multi-interface plugins.
  • Fix

    serverPlugins is now a Set, so a plugin registered for several interfaces is held once and the de-duplication is the natural behaviour of the collection. The eight registration calls are unchanged.

    LinkedHashSet rather than HashSet: initPlugins() deliberately loads plugins in descending plugin weight order, and preserving that order means they are started and stopped in the intended sequence.

    getServerPlugins() still returns List<ServerPlugin>, so the ExtensionController signature is unchanged for extensions. It now returns a copy rather than the live internal collection.

    Net change is 10 insertions and 2 deletions in one file.

    On testing

    The earlier revision of this PR routed the registrations through a de-duplicating helper and unit tested it. Following review that has been dropped in favour of the Set, and the tests went with it: they exercised the helper directly, and the invariant is now enforced by the collection type rather than by logic of our own.

    Testing this through initPlugins() instead is not really reachable from a unit test, since it requires plugin metadata loading plus database access via setPluginProperties. If you would like coverage here, I am happy to look at an integration-level test.

    Verified with ./gradlew :server:test (613 tests, 0 failures) and ./gradlew :donkey:test.

    Note on the failing check

    The FileReceiverTest > testPoll1 failure on the previous commit is unrelated to this change, which touches only plugin registration. The assertion at FileReceiverTest.java:133 counts files picked up by a poll, and it passes locally both in the full suite and across three consecutive isolated runs. Given the recent "Allow parallel tests" change, this looks like a timing-sensitive flake rather than a real regression.

    How to verify

    Build a plugin whose class implements two ServerPlugin sub-interfaces, for example ServicePlugin and ChannelPlugin, and log a line in stop(). Before this change the line appears twice on server shutdown; after it, once.

    Diff: 443 lines (+332 / -111) across 5 files Reviewer: NicoPiel Review duration: 1719m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 443 lines diff across 5 files
    0.45
    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.365
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #397"
    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: 45.3% (MEDIUM) · Higher = larger blast radius
    45.3%
    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: 17.9% · Safe to merge
    17.9%