OC-301e · Module 1

Plugin Lifecycle Management

3 min read

A plugin has a lifecycle: installation, activation, execution, deactivation, and removal. Each phase has specific requirements and failure modes. Installation copies the plugin code and validates its manifest. Activation registers the plugin with its extension points and allocates resources. Execution runs the plugin's code at the registered extension points. Deactivation unregisters the plugin and releases resources. Removal deletes the plugin code and cleans up any persistent state.

The critical phase is deactivation. A plugin that cannot be cleanly deactivated is a plugin that cannot be safely updated. If deactivating a plugin leaves orphaned event handlers, leaked resources, or dangling references, the system is in an inconsistent state that may not manifest until hours later. The lifecycle contract requires every plugin to implement a deactivate() function that reverses everything the activate() function did — no exceptions, no shortcuts.

Do This

  • Require every plugin to implement all lifecycle hooks: install, activate, deactivate, remove
  • Test deactivation as rigorously as activation — a plugin that cannot deactivate cleanly is defective
  • Validate the plugin manifest during installation — reject malformed manifests before they cause runtime errors

Avoid This

  • Allow plugins to skip lifecycle hooks — partial lifecycle implementation causes resource leaks
  • Test only the happy path (activate → execute) — deactivation and removal are where bugs hide
  • Allow plugins to register for extension points outside their manifest — undeclared behavior is unsafeable