fix: activate plugin hooks before RegisterPlugin calls Register - #337
Open
abelonogov-ld wants to merge 1 commit into
Open
fix: activate plugin hooks before RegisterPlugin calls Register#337abelonogov-ld wants to merge 1 commit into
abelonogov-ld wants to merge 1 commit into
Conversation
RegisterPlugin merged a plugin's hooks into the pipeline only after Register returned, so the same plugin saw different hook behaviour depending on whether it was configured via ConfigurationBuilder.Plugins or registered at runtime. Add the hooks first, matching construction-time registration and the iOS, Android, and Flutter SDKs. A plugin whose Register throws now keeps its hooks, as a configured plugin's do; the executor disposes them with the client, so DisposePluginHooks is no longer needed. RegisterPlugin had no test coverage, so add tests for the ordering, the metadata and hooks it passes on, and both failure paths. Co-authored-by: Cursor <cursoragent@cursor.com>
tanderson-ld
approved these changes
Aug 25, 2026
| } | ||
| } | ||
|
|
||
| private void DisposePluginHooks(IList<Hook> pluginHooks) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LdClient.RegisterPluginmerged a plugin's hooks into the live pipeline only afterRegisterreturned. Construction-time registration does the opposite:GetPluginHooksfeeds theExecutorconstructor beforeRegisterPluginsruns. The result was that the same plugin saw different hook behaviour depending on how it was registered, which a plugin author has no way to reason about — and which matters for plugins like observability that support both paths.This reorders
RegisterPluginto add the hooks first. The previous ordering was deliberate and documented as a deviation, so this is a behaviour change rather than a bug fix in the narrow sense:Registermakes.Registerthrows now keeps its hooks, exactly as a configured plugin's do.Executor.Disposealready disposes every hook in the pipeline when the client is disposed, so the hooks are still cleaned up andDisposePluginHooksis no longer needed.GetHooksthrowing is unchanged: the plugin is not registered and contributes no hooks.This brings .NET in line with the iOS, Android, and Flutter SDKs, which all activate plugin hooks before
register.Test plan
RegisterPluginhad no test coverage, so this adds it:RegisterPluginRegistersPluginAndItsHooks— the client and environment metadata reach the plugin, and its hooks go liveRegisterPluginRunsTheRegisteringPluginsOwnHooks— a plugin that evaluates a flag insideRegistersees its own hook fire, and it keeps firing afterwardsRegisterPluginKeepsHooksWhenRegisterThrows— hooks stay live whenRegisterthrows, and the exception does not propagateRegisterPluginDoesNotRegisterPluginWhoseGetHooksThrows—Registeris not reachedRegisterPluginRejectsNullPluginNote
Overview
LdClient.RegisterPluginnow merges plugin hooks into the live pipeline before callingRegister, aligning runtime registration with plugins added viaConfigurationBuilder.Plugins(hooks first, then register). Flag evaluations and identify calls made insideRegistertherefore invoke that plugin’s hooks, matching iOS/Android/Flutter.If
Registerthrows, hooks remain active (same as a configured plugin whoseRegisterfails); the previousDisposePluginHookspath on register failure is removed—cleanup happens when the client disposes the hook executor.GetHooksfailures still abort registration with no hooks added.Adds
RegisterPlugintest coverage (hooks live, hooks duringRegister,Register/GetHooksfailures, null rejection) plus supporting test plugins.Reviewed by Cursor Bugbot for commit 1c0c83b. Bugbot is set up for automated code reviews on this repo. Configure here.