Hotfix: canonicalizeSpotTrace corrupts traces with OR operators#149
Merged
Hotfix: canonicalizeSpotTrace corrupts traces with OR operators#149
Conversation
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.
Bug
Trace satisfaction Y/N questions were showing the wrong correct answer for formulas like s <-> v. A question with trace !s & v; cycle{s & !v} against formula (s <-> v) was displaying Yes as the correct answer when it should have been No.
Root Cause
Introduced in v1.9.10 (commit 4cc9cd4, PR #146).
canonicalizeSpotTrace calls _canonicalize_state directly on raw SPOT trace output. However, _canonicalize_state only understands &-separated literals — it has no awareness of | (OR) operators.
SPOT generates trace states that can contain ORs, e.g.:
The canonicalizer was:
Splitting on & → tokens like (s, v) | (!s, !v)
Stripping parentheses → s, v | !s, !v (garbled)
Reordering alphabetically → s & !v & v | !s (nonsensical)
This destroyed the OR structure, producing traces that no longer satisfied (or rejected) the original formula. Since the correctness label (Yes/No) was determined before canonicalization, but the displayed trace was the corrupted one, students saw wrong answers.
Fix
Added _resolve_ors_in_state() which calls choosePathFromWord (the existing OR-resolver via the LTL parser) on each trace state before canonicalizing. This is the same OR-resolution that NodeRepr.init already performs — canonicalizeSpotTrace was simply bypassing it.
Verification
Ran a 100-iteration simulation of question generation for s <-> v: 0 bugs (previously ~40% failure rate)
3 new regression tests added for OR-containing traces
Full test suite passes (4 pre-existing English translation failures unrelated to this change)
Changes
exerciseprocessor.py — added _resolve_ors_in_state, integrated into canonicalizeSpotTrace
test_trace_canonicalization.py — 3 new regression tests
version.html — bumped to 1.9.12
CHANGELOG.md — added bugfix entry