fix(manifest): terminate reachability on recursive sums via List/tuple#17
Merged
Conversation
The reachability walker _contains_fun_via_structs propagated its cycle-guard (the _seen visited-type set) only when recursing into named struct fields and named sum-variant payloads, but reset it to empty when recursing into type arguments (List<Self>) and tuple elements. A recursive sum whose self-reference passed through List<Self> or a tuple (for example type Condition = ... | AllOf(List<Condition>)) therefore looped forever and raised RecursionError, taking down build_manifest and everything built on it: --manifest and the Wasm backend (compile_wat) both crashed, while --check was unaffected because it does not build the manifest. Forward the visited-set through every recursive branch so the traversal terminates. The fix only adds termination: the fun-bearing / capability result for every type that already terminated is unchanged, and no existing manifest or SBOM result changes. Adds regression tests for recursive sums via List, via tuple, and directly self-referential, plus an end-to-end build_manifest case on the policy-eval AllOf(List<Condition>) shape.
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.
Problem
_contains_fun_via_structsincapa/manifest/_reachability.py(the manifest reachability walker) propagated its cycle-guard (the_seenvisited-type set) only when recursing into named struct fields and named sum-variant payloads, but reset it to empty when recursing into type arguments (List<Self>) and tuple elements.A recursive sum type whose self-reference passes through
List<Self>or a tuple, for exampletherefore looped forever and raised
RecursionError. Becausebuild_manifest->compute_reachabilityruns for both--manifestand the Wasm backend (compile_wat), both crashed on such a program;--checkwas unaffected (it does not build the manifest). Raising the recursion limit does not help: the cycle is infinite.Discovered while dogfooding
--wasion the downstreampolicy-evalprogram (AllOf(List<Condition>)).Fix
Forward the current visited-set (
_seen) through every recursive branch, including the tuple-element and type-argument branches, so the traversal terminates the first time it revisits a type name. The struct-field and sum-payload branches already forwarded it and are unchanged.The fix only adds termination: the fun-bearing / capability result for every type that already terminated is identical, so no existing manifest or SBOM result changes. The sibling walker
_caps_via_typeneeds no change (it does not expand named structs/sums, so it cannot cycle).Validation
policy-evalnow both generates a manifest (python -m capa --manifest) and compiles to Wasm (python -m capa --wasm --transpile policy_eval.capa), both exit 0. (policy-evalitself was not modified.)tests/test_manifest.py(TestRecursiveTypeReachability): recursive sum viaList<Self>, via tuple, and directly self-referential all terminate and yield the correct (empty, not-unprovable) capability result; plus an end-to-endbuild_manifestcase on theAllOf(List<Condition>)shape.