Skip to content

Fix StrategyResult.resolve() mutating internal weights#18

Closed
dotsdl wants to merge 1 commit intomainfrom
fix/resolve-mutation
Closed

Fix StrategyResult.resolve() mutating internal weights#18
dotsdl wants to merge 1 commit intomainfrom
fix/resolve-mutation

Conversation

@dotsdl
Copy link
Copy Markdown
Member

@dotsdl dotsdl commented Mar 17, 2026

Summary

  • resolve() referenced self._weights directly, so each call normalized the dict in-place. A second call would double-normalize, producing wrong results.
  • Fix: copy the dict before modifying it.
  • Added tests for non-mutation and idempotency.

Test plan

  • test_resolve_does_not_mutate_weights — verifies weights unchanged after resolve()
  • test_resolve_is_idempotent — verifies two consecutive resolve() calls return the same result

🤖 Generated with Claude Code

resolve() operated on self.weights directly (a reference to self._weights),
so calling it would normalize the internal dict in-place. Subsequent calls
would double-normalize, producing incorrect results. Copy the dict first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dotsdl dotsdl requested a review from ianmkenney March 17, 2026 22:51
@ianmkenney
Copy link
Copy Markdown
Member

resolve() referenced self._weights directly, so each call normalized the dict in-place. A second call would double-normalize, producing wrong results.

To clarify, resolve mutates _weights, but repeated calls do not produce wrong results since normalizing normalized weights doesn't do anything.

Regardless closing in favor of #19

@ianmkenney ianmkenney closed this Mar 19, 2026
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.

2 participants