Skip to content

fix: ⚠️ correct execution order for the same level hooks #458

Merged
toddbaert merged 3 commits intomainfrom
rd/hooks-order
Jan 12, 2026
Merged

fix: ⚠️ correct execution order for the same level hooks #458
toddbaert merged 3 commits intomainfrom
rd/hooks-order

Conversation

@erka
Copy link
Member

@erka erka commented Jan 11, 2026

TODO: mention this PR in CHANGELOG.


This PR

  • fix the issue with hook execution order

Related Issues

closes #456

Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
@erka erka requested review from a team as code owners January 11, 2026 16:37
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @erka, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue concerning the execution order of hooks within the OpenFeature client. It standardizes the collection of various hook types and enforces the correct execution sequence, particularly for 'After', 'Error', and 'Finally' hooks, which now run in reverse order of their registration. This change ensures that the hook system behaves predictably and aligns with the intended design, improving the overall reliability of feature flag evaluations.

Highlights

  • Hook Execution Order Correction: The pull request addresses and fixes an issue where hooks at the same level were not executing in the correct order, specifically for 'After', 'Error', and 'Finally' hooks.
  • Standardized Hook Collection: The collection of hooks (global, client, invocation, provider) has been streamlined into a single hooks slice, replacing previous separate concatenations.
  • Reverse Execution for Specific Hooks: The afterHooks, errorHooks, and finallyHooks functions now explicitly iterate through the collected hooks in reverse order (Provider → Invocation → Client → API) to ensure proper execution flow.
  • Documentation and Test Updates: Comments have been added to the hook execution functions (beforeHooks, afterHooks, errorHooks, finallyHooks) to clearly state their intended execution order. Corresponding test cases in hooks_test.go have been updated to reflect these changes and ensure correct behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses an issue with the execution order of hooks. The changes ensure that after, error, and finally hooks are executed in the reverse order of before hooks, which aligns with the OpenFeature specification. The implementation has been simplified by consolidating hook collections into a single slice and iterating over it in reverse where necessary. The tests have been updated accordingly to validate the corrected behavior. The changes are well-implemented and improve the correctness and maintainability of the hook execution logic.

@codecov
Copy link

codecov bot commented Jan 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.21%. Comparing base (0c9d36c) to head (7c16d0d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #458      +/-   ##
==========================================
+ Coverage   83.12%   83.21%   +0.08%     
==========================================
  Files          27       27              
  Lines        2098     2097       -1     
==========================================
+ Hits         1744     1745       +1     
+ Misses        305      304       -1     
+ Partials       49       48       -1     
Flag Coverage Δ
e2e 83.21% <100.00%> (+0.08%) ⬆️
unit 83.21% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sahidvelji
Copy link
Contributor

There may be users relying on the current execution order, even though it doesn't align with the spec. Technically this is a breaking change and we'll want to call that out in the release notes.

Co-authored-by: Sahid Velji <sahidvelji@gmail.com>
Signed-off-by: Roman Dmytrenko <rdmytrenko@gmail.com>
@toddbaert
Copy link
Member

@sahidvelji agreed. It's obviously not "breaking" in a compilation sense, but it is in a behavioral sense. I would learn toward calling out in our release notes but not doing a breaking change version.

Reviewing now.

@toddbaert toddbaert self-requested a review January 12, 2026 20:13
@toddbaert
Copy link
Member

Yep... Looks good to me. Thanks @erka

Do you guys agree we can avoid a major version change here? Behavior would change (no compilation issues) but, in my opinion, it changes in an logical way, and it's certainly more consistent with our spec now.... on the other hand:https://m.xkcd.com/1172/

I'm inclined to just mention it in our notes in a very visible way.

@erka
Copy link
Member Author

erka commented Jan 12, 2026

I think it's just a bug fix. Someone could be affected but it's better now than later.

@toddbaert toddbaert changed the title fix: correct execution order for the same level hooks fix: ⚠️ correct execution order for the same level hooks Jan 12, 2026
@toddbaert toddbaert merged commit 4ee43eb into main Jan 12, 2026
8 checks passed
@toddbaert toddbaert deleted the rd/hooks-order branch January 12, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Hooks registered at the same level execute out of order

3 participants