Skip to content

fix: resolve list-of-models clip defaults at read time - #740

Open
WeAreResilience wants to merge 1 commit into
awslabs:devfrom
WeAreResilience:fix/list-clip-default-read-time
Open

WeAreResilience wants to merge 1 commit into
awslabs:devfrom
WeAreResilience:fix/list-clip-default-read-time

Conversation

@WeAreResilience

Copy link
Copy Markdown

Pull Request

Issue Reference

Closes #691

Description of Changes

An unset clip_under_threshold on a list of models is resolved when the field is read. explain(), to_json_schema() and to_stickler_config() report the value the list scores with.

Changes Made

  • Removed the deferred-settlement registry, its lock, the os.register_at_fork hook and the weakref.finalize finalizers.
  • Added ConfigurationHelper.model_list_clip, and used it from get_comparison_info, _model_list_export_metadata, the scalar and primitive-list exporters, and StructuredListComparator._list_clip.
  • An unset clip on List[Union[A, B]], Sequence[A], List[Any], a bare List[Optional[A]], a bare List[Annotated[A, ...]] and a forward reference (List["Item"]) reports False and scores with clipping off.

Why These Changes Are Needed

Settling the default when the class is defined cannot see a forward reference, and several spellings of a list of models were never rewritten. explain() then reported the global default True while the score kept partial credit. Reading the default at use removes the per-class state and makes those reports match the score.

Testing

  • Unit tests added/updated

  • Integration tests added/updated

  • Manual testing completed

  • All existing tests pass

  • uv run pytest tests/ -n 4 -q --tb=line — 7497 passed, 14 skipped, 1 xfailed, 391 warnings, in 66.92s. pyproject.toml also adds -v --tb=short.

  • uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line — 58 passed, 3 warnings. The shapes measured for fix(415): honour clip_under_threshold on List[StructuredModel] fields #627 (the repro both ways, an unset List[StructuredModel], Optional and List | None, every spelling including an explicit True, JSON Schema and Stickler-config round trips, and the 1.0.x export cases) still score as before. An unset list of models still scores 1/3 on the repro pair; an explicit True still scores 0.0.

  • uv run ruff check . — all checks passed.

  • No type checker is configured in pyproject.toml, the Makefile, or .github/workflows/lint.yaml. CI lint is uv run ruff check. ruff format --check already fails on these model files on unmodified dev, so unrelated lines were left as they were.

Mutation proof

The new parity tests fail on unmodified base (dev at 8d7cc65) and pass with the fix. Each mutation was applied to the finished tree, the named test was run, and the tree was restored. uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line then passed again (58 passed).

  • BASE. New parity tests against unmodified upstream/dev (8d7cc6525438861369677c388c1e90da28b5c024), with only src/stickler/structured_object_evaluator/models/{configuration_helper,structured_model,structured_list_comparator,json_schema_field_converter}.py checked out from that commit.
    uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "explain_matches or unrecognised_list_exports or bare_list_of_models_spellings or forward_referenced_list_reports or deferred_clip_registry"
    — 8 failed, 3 passed, 47 deselected. test_explain_matches_the_score_for_an_unrecognised_list_of_models failed for UnionList, AnyList and SequenceList (assert True is False). test_bare_list_of_models_spellings failed for BareOptionalElement and BareAnnotatedElement. test_an_unrecognised_list_exports_the_clip_it_scores_with failed for SequenceList and AnyList. test_the_deferred_clip_registry_is_gone failed because _DEFERRED_CLIP_CLASSES was present.

  • M1. model_list_clip returned True when is_list_of_structured_models was false, and True for a bare annotation.
    uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "explain_matches_the_score_for_an_unrecognised_list_of_models or bare_list_of_models_spellings"
    — caught by test_explain_matches_the_score_for_an_unrecognised_list_of_models (UnionList, AnyList, SequenceList; assert True is False) and by test_bare_list_of_models_spellings for BareOptionalElement and BareAnnotatedElement.

  • M2. apply_model_list_clip returned the raw metadata, so to_json_schema() and to_stickler_config() skipped resolution.
    uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "forward_referenced_list_exports or unrecognised_list_exports"
    — caught by test_a_forward_referenced_list_exports_and_round_trips_its_default (assert True is False on the schema clip) and by test_an_unrecognised_list_exports_the_clip_it_scores_with for SequenceList and AnyList.

  • M3. Removed the read-time override in get_comparison_info and skipped export resolution, leaving the class-definition amendment as the only writer.
    uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "forward_referenced_list_reports_the_default"
    — caught by test_a_forward_referenced_list_reports_the_default_it_scores_with (assert True is False).

  • M4. Re-added _DEFERRED_CLIP_CLASSES and an os.register_at_fork hook.
    uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "deferred_clip_registry_is_gone"
    — caught by test_the_deferred_clip_registry_is_gone (_DEFERRED_CLIP_CLASSES was present).

Reviewers

@sromoam @digalaviz

Checklist

  • Code follows the project's coding standards
  • Self-review of code completed
  • Documentation updated (if applicable)
  • CHANGELOG.md entry added under [Unreleased], or not needed because
    nothing user-visible changed (see RELEASING.md)
  • Tests added/updated for new functionality
  • All CI checks are passing
  • Ready for review

Additional Notes

An unset List[Any] reports False on every path. A list of non-model values in that field therefore keeps a below-threshold element's partial score, where it previously contributed 0.0. Scores for a list of models are unchanged. List[Union[A, B]] is still refused by both exporters, which have no type for a union with a model arm; explain() and the score agree.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

An unset clip_under_threshold on a list of models is resolved when the
field is read, so explain(), to_json_schema() and to_stickler_config()
agree with the score for List[Union[A, B]], Sequence[A], List[Any], a
bare List[Optional[A]], a bare List[Annotated[A, ...]] and a forward
reference. The deferred-settlement registry, its lock, the fork hook
and the per-class finalizers are removed.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve the List[StructuredModel] clip default where it is read, and drop the deferred-settlement registry

1 participant