Ignore engine lines received after the command is finished - #1207
Open
Mukller wants to merge 3 commits into
Open
Ignore engine lines received after the command is finished#1207Mukller wants to merge 3 commits into
Mukller wants to merge 3 commits into
Conversation
Protocol.communicate() replaces a still-pending next_command by calling set_finished() on it. If that command had never left the NEW state (its awaiting task was cancelled before the previous command finished), the assertion in set_finished() raised AssertionError: CommandState.NEW, crashing the engine task (niklasf#1116). Allow CommandState.NEW in set_finished(): nothing was sent to the engine while the command was queued, so there is no active phase to unwind - surface the usual EngineError on its result instead. Also guard finished.set_result(), since communicate() cancels the finished future right before calling set_finished().
Engines may emit trailing output around the finishing line (e.g. info lines sent just before or after bestmove). When such a line arrives after the command already transitioned to DONE, BaseCommand._line_received raised AssertionError instead of discarding it (niklasf#1161).
Python 3.14 removed implicit event-loop creation, so constructing BaseCommand outside a running loop raised RuntimeError.
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.
Root cause
Engines commonly emit output around the finishing line — e.g.
infolines sent just before or afterbestmove. Depending on pipe timing, such a line can arrive after the command already processedbestmoveand transitioned toDONE. At that pointProtocol._line_received()still forwards the line to the current command, and the assertion inBaseCommand._line_received()raises:(#1161, reproducible with ordinary UCI engines; the reporter saw it regularly.)
Changes
BaseCommand._line_received()returns early when the command is alreadyDONE: there is no handler left to feed the line into, so trailing engine output is discarded instead of tripping an internal invariant. The assertion for genuinely unexpected states (NEW) stays in place.infoline without raising.Testing
python -m pytest test.py::EngineTestCase→ 28 passed, 11 skipped (binary-gated), including the new regression test.Refs #1161