fix: prevent infinite loop on circular RV chains past MAX_DEPTH#127
Draft
Koan-Bot wants to merge 4 commits into
Draft
fix: prevent infinite loop on circular RV chains past MAX_DEPTH#127Koan-Bot wants to merge 4 commits into
Koan-Bot wants to merge 4 commits into
Conversation
Collaborator
|
@Koan-Bot rebase |
Contributor
Author
Rebase with requested adjustmentsBranch StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
b0d9c13 to
a2a8bb2
Compare
atoomic
approved these changes
Apr 29, 2026
rv_clone_iterative lacked cycle detection and hseen registration. A circular scalar-ref pair ($a = \$b; $b = \$a) embedded deeper than MAX_DEPTH caused the walk phase to loop forever. Additionally, cloned RVs were not stored in hseen, so shared references at depth > MAX_DEPTH were duplicated instead of shared. Fix: add CLONE_FETCH guard at entry (mirrors av/hv_clone_iterative), detect cycles during the walk via linear chain scan, handle circular chains with a two-phase rebuild (placeholder + close), and register every clone in hseen during rebuild. Co-Authored-By: Claude <noreply@anthropic.com>
The mixed array/hash test used $deep_target (2500 on Windows), but each mixed level has both an AV and HV, roughly doubling per-level stack consumption during Perl's recursive SvREFCNT_dec destruction. 2500 mixed levels ≈ 10000 C stack frames, exceeding Windows's 1 MB stack. Introduce $mixed_target (1250 on Windows) which keeps destruction depth comparable to 2500 pure-array levels while still exceeding MAX_DEPTH/2 (≈400 mixed levels) to exercise the iterative clone paths.
When rv_clone_iterative's walk phase finds a cached referent via CLONE_FETCH, it must still add the current RV to chain[] before breaking. Without this, the rebuild loop has zero entries and returns the bare referent clone (e.g. IV 42) instead of an RV wrapper, breaking shared-RV identity for the second path to the same reference. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
a2a8bb2 to
f03d383
Compare
install-with-cpm@v1 regressed on Perl 5.8-5.22 after a recent cpm update requiring Perl 5.24+. Bump to @v2 for action-based jobs and use direct `cpm install` in the Docker-based Linux matrix (where cpm is pre-installed). Matches the approach approved by @atoomic in PR garu#120. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
What
Fix infinite loop and missing hseen registration in
rv_clone_iterative.Why
A circular scalar-ref pair (
$a = \$b; $b = \$a) embedded deeper than MAX_DEPTHin a nested structure caused
rv_clone_iterativeto loop forever during its walkphase — the function lacked both cycle detection and the
CLONE_FETCHguard thatav_clone_iterativeandhv_clone_iterativealready have.Separately, cloned RVs were never stored in
hseen, so shared references atdepth > MAX_DEPTH were duplicated instead of shared (breaking reference identity).
How
CLONE_FETCHguard at function entry (mirrors av/hv iterative paths)referent, close the cycle, then apply deferred blessings
hseenviaCLONE_STOREduring rebuildTesting
New
t/24-iterative-rv-cycle.t(10 tests):alarm(10)to catch regressions as timeouts🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 272 insertions(+), 3 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline