Skip to content

Stop self-opaquing analysis when the shape stops changing - #624

Merged
johnml1135 merged 1 commit into
masterfrom
fix/623-selfopaquing-loop
Nov 27, 2026
Merged

johnml1135 merged 1 commit into
masterfrom
fix/623-selfopaquing-loop

Conversation

@johnml1135

@johnml1135 johnml1135 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Start here: AnalysisRewriteRule.cs. HermitCrab analysis could spin forever when a rewrite rule's output conflicts with its environment and the rule therefore reapplies its inverse in self-opaquing mode. With this change, self-opaquing reapplication stops once a pass leaves the shape unchanged, and keeps reapplying while the shape still changes.

The loop runs in IterativePhonologicalPatternRule, which reports success whenever it invokes the right-hand side, even when nothing changes. For the reduced rules in #623, the inverse stays eligible after an unchanged pass, so the old loop never ended. The new guard compares a full Shape snapshot using ValueEquals, not spelling, so it covers node features, optionality, Modified, boundaries and morph annotations. If a pass leaves the shape unchanged, the next pass would see the same state, so stopping cannot hide a later productive pass.

New regression tests cover the three reduced grammars from #623: segment t → d / _ a (parsing da), alpha-input nasal (parsing mp) and glottal (parsing -a). Each asserts the lexical analysis and has a timeout; all three hung before the fix. The tests also check generation. In these reduced feature systems, t/d and ʔ/- have identical feature structures, so generation prints the first spelling (ta, ʔa), while parse validation accepts either spelling. This is how these fixtures render, not a synthesis bug.

Fixes #623

Next: none planned. A separate fixture with a real feature contrast could strengthen generation coverage later.

Validation
  • HermitCrab tests, Release, Linux: 179 passed, 0 failed.
  • The old implementation, substituted in an isolated build, passes the same 176 existing tests with no outcome differences. The only new cases are the three regressions, and the old implementation fails them at the 15 s timeout.
  • CSharpier and comment hygiene are clean, and git diff --check is clean.
  • local_check.sh fails locally for reasons unrelated to this change: cmake is missing for the SentencePiece native build, and the Thot test WordAlignCorpus_DefaultIsTransductive(Eflomal) hit the inactivity timeout. Machine (910 passed, 3 skipped) and HermitCrab (179 passed) were green in the same run.
  • The full snapshot clone costs one allocation per pass and is not retained between passes.

🤖 Generated with Claude Code


This change is Reviewable

@claude

claude Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Verdict: approve.

What matters most: the new guard at src/SIL.Machine.Morphology.HermitCrab/PhonologicalRules/AnalysisRewriteRule.cs:177 is sound. Shape.ValueEquals compares the snapshot with the live shape by annotation feature structures, optionality and ranges. Ranges resolve through FreezableEqualityComparer to node index, so comparing against a clone does not always return false. Each pass stops no later than the old loop did, so this change can only end analysis sooner, never later. SelfOpaquingTests.IncompatibleEnvironmentTerminatesWithExpectedAnalysis is the test that proves it.

Counts: 0 Critical, 0 Important, 0 Low.

What I ran: dotnet test tests/SIL.Machine.Morphology.HermitCrab.Tests -c Release at head: 179 passed, 0 failed. gh pr checks 624: both Build checks (ubuntu-22.04, windows-latest), Create NuGet package and both advisory comment-hygiene reports pass; claude-review is pending.

Not verified: I did not rerun the three new cases against the old implementation; that is the author's claim that they hung. I did not confirm that an existing test drives a self-opaquing rule through two or more passes that each change the shape, which is the branch that keeps looping. The fix also does not guard against a rule that cycles between two shapes. I have no example of one, and the old code had the same exposure. I did not run --agent-strict.

Public API, target framework, package, sillsdev/machine.py parity: None verified changed.

Findings: none this round.

Reviewed at eebb57d

Repeated unapplication can match without changing the shape, leaving analysis in an infinite loop. Stop reapplying once the shape is unchanged.

Co-Authored-By: GPT-6.1 Terra <noreply@openai.com>
@johnml1135
johnml1135 force-pushed the fix/623-selfopaquing-loop branch from eebb57d to 7335c69 Compare November 27, 2026 16:00
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.80%. Comparing base (f9294f9) to head (7335c69).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #624      +/-   ##
==========================================
+ Coverage   75.76%   75.80%   +0.03%     
==========================================
  Files         457      457              
  Lines       39103    39108       +5     
  Branches     5459     5461       +2     
==========================================
+ Hits        29626    29644      +18     
+ Misses       8339     8335       -4     
+ Partials     1138     1129       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johnml1135
johnml1135 merged commit 51c163a into master Nov 27, 2026
8 checks passed
@johnml1135
johnml1135 deleted the fix/623-selfopaquing-loop branch November 27, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HermitCrab analysis can spin on simultaneous rewrites with incompatible environments

4 participants