Skip to content

fix: clarify evaluation context propagation between hook stages - #465

Open
CloudedKarma wants to merge 4 commits into
open-feature:mainfrom
CloudedKarma:fix/329-hook-context-propagation
Open

CloudedKarma wants to merge 4 commits into
open-feature:mainfrom
CloudedKarma:fix/329-hook-context-propagation

Conversation

@CloudedKarma

@CloudedKarma CloudedKarma commented Nov 30, 2026 •

Copy link
Copy Markdown

This PR

Clarifies how evaluation context updates returned by before hooks are merged and propagated throughout the hook evaluation lifecycle.

The existing wording leaves ambiguity regarding when context updates must be merged and which evaluation context subsequent hook stages should receive. This can result in implementations passing the original evaluation context to subsequent hooks while only providing the accumulated context to the provider during flag resolution.
This PR:

Updates Requirement 4.3.4 to require incremental merging of evaluation context before subsequent hook invocations or flag resolution.

Updates Requirement 4.3.5 to require subsequent before, after, error, and finally hooks to receive the current merged evaluation context in dynamic-context implementations.

Clarifies context preservation when a before hook returns no evaluation context.

Clarifies that updates returned by previously completed before hooks remain available when a subsequent before hook terminates abnormally.

References existing evaluation context merge precedence and multi-provider context isolation documentation.

Preserves the existing requirement identifiers.

Regenerates specification.json.

Six Gherkin conformance scenarios have been added to cover:

Incremental evaluation context accumulation across multiple before hooks.

Context propagation to error and finally hooks following failed flag resolution.

Context preservation when a before hook returns no evaluation context.

Preservation of previously returned context when a subsequent before hook fails.

Context preservation when an after hook fails.

Isolation of hook-generated context updates between evaluations.

Related Issues

Related to #329.

Related pull request: #459.

Notes

A separate local proof-of-concept implementation was created using the Python SDK to investigate the reported behavior and validate the proposed requirements.

Five of the six proposed conformance scenarios failed against the original Python SDK implementation. After implementing incremental context merging and propagation in the local reference implementation, all six scenarios passed.

Additional tests verified:

Targeting-key and attribute precedence.

Context propagation across API, client, invocation, and provider hook registration levels.

Before, after, and finally hook execution ordering.

Hook data isolation.

Preservation of original evaluation contexts.

Synchronous and asynchronous client evaluation behavior.

The Python SDK proof-of-concept implementation is not included in this specification pull request.

I am aware of the overlapping proposal in #459. This contribution provides an alternative approach by clarifying the existing requirements and supplying additional conformance scenarios and local implementation evidence.

The following pre-existing validation issues were identified in the upstream baseline and left unchanged to avoid unrelated modifications:

25 violations from the local recursive Markdown linting command.

Four existing specification parser unit test failures.

Existing Prettier formatting inconsistencies unrelated to the proposed changes.

All testing was performed locally on Windows. GitHub Actions validation remains pending.

Follow-up Tasks

Coordinate implementation of the new Gherkin step definitions across applicable SDKs.

Determine the preferred approach for filtering unsupported conformance scenarios.

Confirm the preferred organization of the normative requirements, including whether to clarify existing requirements or introduce a new requirement identifier.

Coordinate any necessary SDK implementation changes.

The six new scenarios use a proposed @hook-context-propagation capability tag alongside the applicable specification requirement tags. This enables selective execution or exclusion but does not automatically configure existing SDK runners to skip unsupported scenarios.

Multi-provider context isolation is referenced in the proposed wording but has not been independently tested.

The asynchronous tests exercise the asynchronous client evaluation lifecycle using a synchronous recording provider through the SDK's asynchronous adapter. Native asynchronous providers and concurrent asynchronous evaluations were not independently tested.

Maintainer feedback on the proposed wording, error-path behavior, and conformance test integration would be appreciated before this PR is considered ready for merging.

How to test

The specification changes can be validated using the repository's existing Makefile targets:
make parse
make lint
make markdown-toc
git diff --check

The generated specification.json and table of contents should remain synchronized.

The new conformance scenarios can be selected in a compatible Behave test environment using:

behave --tags="@hook-context-propagation"

The corresponding step definitions must be implemented in the SDK test runner before executing these scenarios.

The following results were obtained using the separate local Python SDK proof of concept and specification validation tools:

Test Result
Original Python SDK pytest suite 215/215 passed
Modified Python SDK pytest suite with extended tests 218/218 passed
Original SDK context propagation scenarios 1/6 passed
Modified SDK synchronous conformance scenarios 6/6 passed
Modified SDK asynchronous conformance scenarios 6/6 passed
Synchronous Gherkin steps 51/51 passed
Asynchronous Gherkin steps 51/51 passed
Repository parser pytest suite 5/5 passed
Repository parser Ruff formatting Passed
Repository parser Ruff linting Passed
Repository parser mypy validation Passed
Specification JSON generation Passed
Specification JSON linting Passed
Modified Markdown linting Passed
Modified documentation links 13/13 passed
Full Markdown link checker Passed
Table-of-contents synchronization Passed
Git whitespace validation Passed

Signed-off-by: CloudedKarma <117319672+CloudedKarma@users.noreply.github.com>
Signed-off-by: CloudedKarma <117319672+CloudedKarma@users.noreply.github.com>
Signed-off-by: CloudedKarma <117319672+CloudedKarma@users.noreply.github.com>
Signed-off-by: CloudedKarma <117319672+CloudedKarma@users.noreply.github.com>
@CloudedKarma
CloudedKarma requested a review from a team as a code owner November 30, 2026 07:37
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Requirements 4.3.4 and 4.3.5 now define incremental merging of context returned by before hooks and its propagation to later hooks and flag resolution. New Gherkin scenarios cover success, failures, missing context returns, and evaluation isolation.

Changes: Hook context propagation

Layer / File(s) Summary
Define incremental context propagation
specification/sections/04-hooks.md, specification.json
Requirements 4.3.4 and 4.3.5 specify that returned context is merged before subsequent hooks or flag resolution. Later hooks receive the current merged context.
Specify context propagation scenarios
specification/assets/gherkin/hooks.feature
New scenarios cover accumulated context, provider and hook failures, hooks that return no context, and isolation between evaluations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

  • open-feature/spec#459: Adds a requirement and Gherkin coverage for propagation of context returned by a before hook.

Suggested reviewers: toddbaert, beeme1mr, kripa-sindhu-007

Merge Risk: Minimal · up to 821cf

This PR clarifies how evaluation context passes between hook stages and adds conformance scenarios. It changes only the specification text, JSON, and feature file, so nothing runs in production. SDKs will need to add step definitions or filter the new scenarios, which the author has listed as follow-up work.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: clarifying how evaluation context returned by before hooks is propagated between hook stages. It matches the changes to Requirements 4.3.4 and 4.3.5 and the new Gherki…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is specific and related to the changeset. It states that the PR clarifies how before-hook evaluation context is merged and propagated. It maps the changes to Requirements 4.3.4 and 4.3…
Full details: Title check

Explanation

The title names the main change: clarifying how evaluation context returned by before hooks is propagated between hook stages. It matches the changes to Requirements 4.3.4 and 4.3.5 and the new Gherkin scenarios. The 'fix:' prefix is a conventional-commit label and does not reduce clarity.

Full details: Description check

Explanation

The description is specific and related to the changeset. It states that the PR clarifies how before-hook evaluation context is merged and propagated. It maps the changes to Requirements 4.3.4 and 4.3.5, the six added Gherkin scenarios, the regenerated specification.json, and the validation commands. It also lists the known limitations, the untested areas, and the follow-up tasks.

Finishing Touches

Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dd2ad1de-d2f9-44b6-927c-844d8f7a0607
Commits

Reviewing files that changed from the base of the PR and between b489ba9 and 821cf34.

Files selected for processing: 3

  • specification.json
  • specification/assets/gherkin/hooks.feature
  • specification/sections/04-hooks.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

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