Skip to content

refactor: read the flag once per evaluation, in one place - #381

Open
abelonogov-ld wants to merge 2 commits into
mainfrom
andrey/one-flag-read-per-evaluation
Open

refactor: read the flag once per evaluation, in one place#381
abelonogov-ld wants to merge 2 commits into
mainfrom
andrey/one-flag-read-per-evaluation

Conversation

@abelonogov-ld

@abelonogov-ld abelonogov-ld commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

The ten variation methods each spelled out the same call to the hook runner around the same evaluation, and left the flag read to the evaluation itself. They now collapse onto a helper that does the read, so one place expresses the order of the read, the hooks and the evaluation, and what an evaluation is about to return can be described without reading the store a second time.

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.


Note

Overview
Refactors flag evaluation so all typed *Variation APIs go through a new evaluateWithHooks helper instead of duplicating hookRunner.withEvaluation calls.

Evaluation now snapshots the evaluation context and flag (getNonDeletedFlag) once before hooks run, then passes those into variationDetailInternal. Prerequisite walks reuse the same context and fetch each prereq flag at that layer instead of re-reading context inside the evaluator.

Intent: one ordered pipeline (read → hooks → evaluate) so a concurrent identify() cannot swap context mid-call and attribute the wrong context on evaluation events.

Reviewed by Cursor Bugbot for commit 6a7de48. Bugbot is set up for automated code reviews on this repo. Configure here.

The ten variation methods each spelled out the same call to the hook runner
around the same evaluation, and left the flag read to the evaluation itself.
They now collapse onto a helper that does the read, so one place expresses the
order of the read, the hooks and the evaluation, and what an evaluation is
about to return can be described without reading the store a second time.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abelonogov-ld
abelonogov-ld requested a review from a team as a code owner August 11, 2026 02:03

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7efd98c. Configure here.

evaluateWithHooks snapshotted the flag before hooks ran, but
variationDetailInternal still re-read the evaluation context when recording
events. An identify landing in between left the returned value from the prior
context's flag attributed to the new context. Both are now read together and
threaded through the evaluation so the series, the result and the events all
describe one pair.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant