Skip to content

fix(core): merge strategy and per-call sampling requirements - #1744

Open
ajbozarth wants to merge 1 commit into
generative-computing:mainfrom
ajbozarth:issue-1698-sampling-requirement-resolution
Open

ajbozarth wants to merge 1 commit into
generative-computing:mainfrom
ajbozarth:issue-1698-sampling-requirement-resolution

Conversation

@ajbozarth

@ajbozarth ajbozarth commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Pull Request

Issue

Fixes #1698

Description

SamplingStrategy._merge_requirements resolved strategy-level and per-call requirements by supersede rather than merge: when the strategy had its own requirements they won outright and the per-call list was silently dropped (and when it had none, the per-call list was used). The two lists were never combined. This contradicted both the method name and the sample() requirements docstring, which have described the lists as "merged with global requirements" since sampling was first added — a quiet correctness footgun where a requirement the caller configured could go unenforced with no error or warning.

This changes _merge_requirements to return the union of both lists (deduplicated, order-preserving), so every requirement configured on the strategy or at the call site is enforced. Because Requirement has no value equality, deduplication is by object identity: two distinct Requirement instances are always kept and validated, and a real duplicate only arises when the same instance appears in both lists (where which copy is kept is immaterial). The strategy class docstrings (SamplingStrategy, BaseSamplingStrategy, BaseMBRDSampling) are aligned with the merge semantics.

Because this changes released behavior for act() / aact() / instruct() / sample() that has shipped for ~13 months, it was split out of #1697 into its own issue (#1698) and reviewed before implementing.

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code was added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Inverted the existing test_global_requirements_override_per_call (now test_global_and_per_call_requirements_are_merged) to assert both lists are evaluated, and added test_merged_requirements_dedup_shared_instance covering identity-based deduplication of a requirement present in both lists.

Attribution

  • AI coding assistants used

Adding a new component, requirement, sampling strategy, or tool?

If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.

  • Component
  • Requirement
  • Sampling Strategy
  • Tool

_merge_requirements resolved strategy-level and per-call requirements by
supersede: when the strategy had its own requirements they won outright and
the per-call list was dropped, so a requirement the caller configured could
go unenforced with no error. This contradicted both the method name and the
sample() docstring, which described the two lists as merged.

Union the two lists instead (deduplicated, order-preserving) so every
requirement configured on the strategy or at the call site is enforced, and
align the strategy class docstrings with the merge semantics.

Closes generative-computing#1698

Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
@ajbozarth
ajbozarth requested a review from a team as a code owner October 16, 2026 19:19
@ajbozarth ajbozarth added area/requirement Requirement base class, validation, repair loops area/sampling SamplingStrategy, SamplingResult, ModelOption, generation options labels Oct 16, 2026
@ajbozarth ajbozarth added area/requirement Requirement base class, validation, repair loops area/sampling SamplingStrategy, SamplingResult, ModelOption, generation options labels Oct 16, 2026
@ajbozarth ajbozarth self-assigned this Oct 16, 2026
@github-actions github-actions Bot added the bug Something isn't working label Oct 16, 2026
@ajbozarth
ajbozarth requested a review from jakelorocco October 16, 2026 19:26
@generative-computing generative-computing deleted a comment from github-actions Bot Oct 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/requirement Requirement base class, validation, repair loops area/sampling SamplingStrategy, SamplingResult, ModelOption, generation options bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sampling requirement resolution supersedes instead of merging, contradicting long-standing docstrings

1 participant