fix: reject cyclic predicate definitions, guard evaluation depth#60
Merged
Conversation
A predicate redefinition could introduce a reference cycle that only becomes visible after the fact (e.g. define q: is p, then define p: is q), since each `define` only checks that the referenced name exists at that moment, not what it eventually resolves to. Evaluating such a cycle recursed forever and raised a bare RecursionError instead of a structured LiminateResult. Add a static cycle check in analyzer._check_define that walks the reference graph of a predicate body being (re)defined and rejects it if the walk reaches the name being defined. As a defensive backstop, cap predicate evaluation depth in the interpreter at 64 so any cycle the analyzer misses still surfaces as ERROR_SEMANTIC rather than a raw exception.
rmichaelthomas
force-pushed
the
fix/cyclic-predicate-rejection
branch
from
July 20, 2026 07:10
9542647 to
354f48c
Compare
This was referenced Jul 20, 2026
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.
Summary
define q: is pthendefine p: is q), since eachdefineonly checks that the referenced name exists right now, not what it eventually resolves to.RecursionErrorinstead of a structuredLiminateResult— this crashed callers like seshat-app's_validate_agreement_source, which callsliminate.run()unwrapped.analyzer.py):_check_definenow walks the reference graph of a (re)defined predicate body via a new_check_predicate_definition_cycle/_find_predicate_cycle, reusing the visited-set pattern from_composition_void_result_verb. Reaching the name being defined raises_SemanticErrornaming the loop (e.g.Definition 'p' refers back to itself through 'q'. A definition can't depend on itself.). Runs after the existing forward-declaration check, so a first-everdefine p: is pstill hits the original "I don't know a definition" error, unshadowed.interpreter.py, defensive backstop): a_predicate_eval_depthContextVar (mirroring the existing_in_action_blocktoken pattern) caps predicate-evaluation recursion at 64, raising_RuntimeError(→ERROR_SEMANTIC) on overflow, so any cycle the analyzer misses still produces a structured result rather than a raw exception.tests/test_define.py; full suite 1661 passed (1654 baseline + 7 new), zero regressions, vocabulary unchanged at 61 words.Test plan
pytest tests/test_define.py -v— 40 passedpytest tests/— 1661 passed, zero regressions🤖 Generated with Claude Code