Fix Learner2D state rollback in BalancingLearner ask(tell_pending=False)#492
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix the failing GitHub Actions job "test (ubuntu-latest, 3.13)"
Fix Learner2D state rollback in BalancingLearner ask(tell_pending=False)
Jun 10, 2026
Key-level mutations (stack pops/inserts) are all that restore() needs to roll back; values are never mutated in place. A deepcopy of the full data dict would add O(npoints) allocation to every ask(tell_pending=False) call and to pickling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This addresses the failing
test (ubuntu-latest, 3.13)job caused bytest_balancing_learner[Learner2D-ring_of_fire-learner_kwargs2]. The failure came from state leaking acrossrestore(...)boundaries, eventually leavingLearner2Dwith too few points during stack fill.Root cause
Learner2D.__getstate__returned live mutable objects (_stack,data), so temporary mutations made duringBalancingLearner.ask(..., tell_pending=False)were not fully isolated.Code change
Learner2D.__getstate__now snapshots_stackanddatavia deep copies to guarantee rollback correctness when used withrestore(...).Regression coverage
Learner2Dstack/data are unchanged afterBalancingLearner.ask(1, tell_pending=False).Checklist
pre-commit run --all(first install usingpip install pre-commit)pytestpassedType of change
Check relevant option(s).