Skip to content

Circular include cycle detection missing in non-recursive preprocess path #553

@Serhan-Asad

Description

@Serhan-Asad

Bug Description

Circular <include> tags cause an infinite loop when using the default (non-recursive) preprocess path. The process hangs forever, spamming "Processing XML include" messages until manually killed.

Reproduction

mkdir /tmp/circ-test && cd /tmp/circ-test && git init
echo '<include>b.txt</include>' > a.txt
echo '<include>a.txt</include>' > b.txt
echo '<include>a.txt</include>' > circular_python.prompt
timeout 10 pdd preprocess circular_python.prompt
# Process hangs, spams "Processing XML include" until timeout kills it

Root Cause

process_include_tags() in preprocess.py has a while prev_text != current_text convergence loop (line 295). The _seen set for cycle detection is only populated inside the if recursive: block (lines 272-274). In the non-recursive path, _seen is never updated, so the cycle check at line 226 (if resolved in _seen) never triggers.

The same issue exists in process_backtick_includes() (line 200-205).

Context

PR #528 (merged, fix for #521) added cycle detection for the recursive path. This is a follow-up — the non-recursive (default) path was not covered by that fix.

Expected Behavior

pdd preprocess should detect the circular include and raise a ValueError("Circular include detected: ...") instead of looping forever. Same behavior as the recursive path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions