BUG-HUNT: [consistency] YAMLTemplateEngine._postprocess_rendered_yaml() contains mutually exclusive conditions — YAML fixup logic is dead code #6420

Open
opened 2026-04-09 21:02:03 +00:00 by HAL9000 · 1 comment
Owner

Bug Report: [consistency] Contradictory guard conditions in _postprocess_rendered_yaml make the multi-value YAML line fixup logic unreachable

Severity Assessment

  • Impact: The _postprocess_rendered_yaml method in YAMLTemplateEngine is intended to fix malformed YAML lines that result from Jinja2 template rendering (e.g., key: value1 other_key: value2). Due to a logical contradiction in the guard conditions, the inner fixup block never executes. This means that Jinja2-rendered YAML with inline multi-value lines that need splitting will fail to parse, causing actor config loading to crash instead of being silently repaired.
  • Likelihood: Medium — triggered whenever a Jinja2-rendered actor YAML produces a line with a colon-bearing value that needs splitting (the exact scenario the method was designed to handle).
  • Priority: Medium

Location

  • File: src/cleveragents/actor/yaml_template_engine.py
  • Function: YAMLTemplateEngine._postprocess_rendered_yaml
  • Lines: 128–143

Description

The _postprocess_rendered_yaml method walks through rendered YAML lines and applies a fixup for lines where a value appears to embed extra key-value pairs. The two conditions guarding the fixup are mutually exclusive:

  • Outer guard (line 133): ":" not in value_part — only enters this block if the value portion has no colon.
  • Inner guard (line 135): any(":" in w for w in value_words[1:]) — only enters the fixup if at least one word after the first contains a colon.

Since value_part is the joined string of all value_words, if any element of value_words[1:] contains a colon, then value_part also contains a colon — making the outer guard False. Therefore, the inner condition can never be True while the outer condition is True.

The inner if block (lines 136–142) is dead code.

Evidence

# yaml_template_engine.py, lines 128-143
if ":" in line and line.count(":") == 1:
    parts = line.split(":", 1)
    if len(parts) == 2:
        key_part = parts[0]
        value_part = parts[1].strip()
        if value_part and " " in value_part and ":" not in value_part:  # ← A: no colon in value
            value_words = value_part.split()
            if len(value_words) > 1 and any(":" in w for w in value_words[1:]):  # ← B: colon in words
                # A says value_part has no colon, so no word in value_part has a colon
                # B requires a word with a colon → A and B are mutually exclusive
                # This block is DEAD CODE — it never executes ←
                fixed_lines.append(f"{key_part}: {value_words[0]}")
                remaining = " ".join(value_words[1:])
                indent = len(key_part) - len(key_part.lstrip())
                fixed_lines.append(f"{' ' * indent}{remaining}")
                continue

Verification:

# The line the method was meant to fix:
line = "  key: value1 other_key: value2"
parts = line.split(":", 1)
value_part = parts[1].strip()   # "value1 other_key: value2"
# Outer guard: ":" not in value_part → ":" in "value1 other_key: value2" → True → guard fails
# → The fixup block is never reached for ANY line that actually needs fixing

The method is supposed to handle lines like key: value1 other_key: value2, but those lines have a colon in value_part, which is exactly what the outer guard prevents entering.

Expected Behavior

The _postprocess_rendered_yaml method should successfully split lines like key: value1 other_key: value2 into two separate YAML lines during post-processing of Jinja2-rendered templates.

Actual Behavior

The fixup logic never executes. The outer condition ":" not in value_part ensures that any line containing a colon in its value (precisely the lines needing fixing) is skipped. The method falls through to fixed_lines.append(line) for all such lines, leaving malformed YAML unchanged.

When the downstream yaml.safe_load() encounters such a malformed line, the _fix_common_yaml_issues() fallback may or may not handle it correctly, but the intent of _postprocess_rendered_yaml to proactively fix this case is completely defeated.

Suggested Fix

Remove the contradictory outer guard and replace with a condition that matches the actual intent — lines with exactly one colon BUT with value content that itself contains a colon after the first word:

# yaml_template_engine.py — corrected logic
if ":" in line:
    parts = line.split(":", 1)
    if len(parts) == 2:
        key_part = parts[0]
        value_part = parts[1].strip()
        # Fix: check for embedded key-value pairs (colon IN value, after first word)
        if value_part and " " in value_part:
            value_words = value_part.split()
            if len(value_words) > 1 and any(":" in w for w in value_words[1:]):
                fixed_lines.append(f"{key_part}: {value_words[0]}")
                remaining = " ".join(value_words[1:])
                indent = len(key_part) - len(key_part.lstrip())
                fixed_lines.append(f"{' ' * indent}{remaining}")
                continue
fixed_lines.append(line)

Category

consistency

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: bug-hunter

## Bug Report: [consistency] Contradictory guard conditions in _postprocess_rendered_yaml make the multi-value YAML line fixup logic unreachable ### Severity Assessment - **Impact**: The `_postprocess_rendered_yaml` method in `YAMLTemplateEngine` is intended to fix malformed YAML lines that result from Jinja2 template rendering (e.g., `key: value1 other_key: value2`). Due to a logical contradiction in the guard conditions, the inner fixup block **never executes**. This means that Jinja2-rendered YAML with inline multi-value lines that need splitting will fail to parse, causing actor config loading to crash instead of being silently repaired. - **Likelihood**: Medium — triggered whenever a Jinja2-rendered actor YAML produces a line with a colon-bearing value that needs splitting (the exact scenario the method was designed to handle). - **Priority**: Medium ### Location - **File**: `src/cleveragents/actor/yaml_template_engine.py` - **Function**: `YAMLTemplateEngine._postprocess_rendered_yaml` - **Lines**: 128–143 ### Description The `_postprocess_rendered_yaml` method walks through rendered YAML lines and applies a fixup for lines where a value appears to embed extra key-value pairs. The two conditions guarding the fixup are **mutually exclusive**: - **Outer guard (line 133)**: `":" not in value_part` — only enters this block if the value portion has **no** colon. - **Inner guard (line 135)**: `any(":" in w for w in value_words[1:])` — only enters the fixup if at least one word after the first **contains** a colon. Since `value_part` is the joined string of all `value_words`, if any element of `value_words[1:]` contains a colon, then `value_part` also contains a colon — making the outer guard `False`. Therefore, the inner condition can **never** be `True` while the outer condition is `True`. The inner `if` block (lines 136–142) is **dead code**. ### Evidence ```python # yaml_template_engine.py, lines 128-143 if ":" in line and line.count(":") == 1: parts = line.split(":", 1) if len(parts) == 2: key_part = parts[0] value_part = parts[1].strip() if value_part and " " in value_part and ":" not in value_part: # ← A: no colon in value value_words = value_part.split() if len(value_words) > 1 and any(":" in w for w in value_words[1:]): # ← B: colon in words # A says value_part has no colon, so no word in value_part has a colon # B requires a word with a colon → A and B are mutually exclusive # This block is DEAD CODE — it never executes ← fixed_lines.append(f"{key_part}: {value_words[0]}") remaining = " ".join(value_words[1:]) indent = len(key_part) - len(key_part.lstrip()) fixed_lines.append(f"{' ' * indent}{remaining}") continue ``` **Verification**: ```python # The line the method was meant to fix: line = " key: value1 other_key: value2" parts = line.split(":", 1) value_part = parts[1].strip() # "value1 other_key: value2" # Outer guard: ":" not in value_part → ":" in "value1 other_key: value2" → True → guard fails # → The fixup block is never reached for ANY line that actually needs fixing ``` The method is supposed to handle lines like `key: value1 other_key: value2`, but those lines have a colon in `value_part`, which is exactly what the outer guard **prevents** entering. ### Expected Behavior The `_postprocess_rendered_yaml` method should successfully split lines like `key: value1 other_key: value2` into two separate YAML lines during post-processing of Jinja2-rendered templates. ### Actual Behavior The fixup logic never executes. The outer condition `":" not in value_part` ensures that any line containing a colon in its value (precisely the lines needing fixing) is skipped. The method falls through to `fixed_lines.append(line)` for all such lines, leaving malformed YAML unchanged. When the downstream `yaml.safe_load()` encounters such a malformed line, the `_fix_common_yaml_issues()` fallback may or may not handle it correctly, but the intent of `_postprocess_rendered_yaml` to proactively fix this case is completely defeated. ### Suggested Fix Remove the contradictory outer guard and replace with a condition that matches the actual intent — lines with exactly one colon BUT with value content that itself contains a colon after the first word: ```python # yaml_template_engine.py — corrected logic if ":" in line: parts = line.split(":", 1) if len(parts) == 2: key_part = parts[0] value_part = parts[1].strip() # Fix: check for embedded key-value pairs (colon IN value, after first word) if value_part and " " in value_part: value_words = value_part.split() if len(value_words) > 1 and any(":" in w for w in value_words[1:]): fixed_lines.append(f"{key_part}: {value_words[0]}") remaining = " ".join(value_words[1:]) indent = len(key_part) - len(key_part.lstrip()) fixed_lines.append(f"{' ' * indent}{remaining}") continue fixed_lines.append(line) ``` ### Category consistency ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail` to prove the bug exists before fixing it. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
HAL9000 added this to the v3.2.0 milestone 2026-04-09 21:09:48 +00:00
Author
Owner

🔁 Duplicate Detection — Additional Evidence from Bug Hunt Cycle 2 Batch 2 Worker 12

This issue was independently rediscovered during Bug Hunt Cycle 2, Batch 2, Worker 12 (working directory: /tmp/bug-hunt-cycle-2-batch2-worker12) under the category [data-flow].

Additional Evidence Provided by Worker 12

The worker identified the same contradictory logic but framed it from a data-flow / content-corruption perspective, highlighting that the dead code path was intended to protect valid YAML content containing URLs, JSON strings, or other legitimate colon usage:

Impact Examples (valid YAML that could be affected by a misguided fix):

description: "Visit the documentation at https://example.com for more info"
webhook_url: "Send alerts to team@company.com using this endpoint"

Worker 12's Evidence Snippet (lines ~105-125, slightly different line reference):

if ":" in line and line.count(":") == 1:
    parts = line.split(":", 1)
    if len(parts) == 2:
        key_part = parts[0]
        value_part = parts[1].strip()
        if value_part and " " in value_part and ":" not in value_part:  # NO colons
            value_words = value_part.split()
            if len(value_words) > 1 and any(":" in w for w in value_words[1:]):  # Checking for colons!
                # This condition can never be true - contradictory logic
                fixed_lines.append(f"{key_part}: {value_words[0]}")
                remaining = " ".join(value_words[1:])
                indent = len(key_part) - len(key_part.lstrip())
                fixed_lines.append(f"{' ' * indent}{remaining}")
                continue

Suggested Fix (Worker 12)

Three options proposed:

  1. Remove the contradictory condition entirely
  2. Rewrite the logic to properly detect and fix actual YAML formatting issues
  3. Add comprehensive tests to validate the post-processing behavior

This corroborates the original finding. No new issue was created — this comment supplements the existing report.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: new-issue-creator

## 🔁 Duplicate Detection — Additional Evidence from Bug Hunt Cycle 2 Batch 2 Worker 12 This issue was independently rediscovered during **Bug Hunt Cycle 2, Batch 2, Worker 12** (working directory: `/tmp/bug-hunt-cycle-2-batch2-worker12`) under the category **[data-flow]**. ### Additional Evidence Provided by Worker 12 The worker identified the same contradictory logic but framed it from a **data-flow / content-corruption** perspective, highlighting that the dead code path was *intended* to protect valid YAML content containing URLs, JSON strings, or other legitimate colon usage: **Impact Examples** (valid YAML that could be affected by a misguided fix): ```yaml description: "Visit the documentation at https://example.com for more info" webhook_url: "Send alerts to team@company.com using this endpoint" ``` **Worker 12's Evidence Snippet** (lines ~105-125, slightly different line reference): ```python if ":" in line and line.count(":") == 1: parts = line.split(":", 1) if len(parts) == 2: key_part = parts[0] value_part = parts[1].strip() if value_part and " " in value_part and ":" not in value_part: # NO colons value_words = value_part.split() if len(value_words) > 1 and any(":" in w for w in value_words[1:]): # Checking for colons! # This condition can never be true - contradictory logic fixed_lines.append(f"{key_part}: {value_words[0]}") remaining = " ".join(value_words[1:]) indent = len(key_part) - len(key_part.lstrip()) fixed_lines.append(f"{' ' * indent}{remaining}") continue ``` ### Suggested Fix (Worker 12) Three options proposed: 1. Remove the contradictory condition entirely 2. Rewrite the logic to properly detect and fix actual YAML formatting issues 3. Add comprehensive tests to validate the post-processing behavior This corroborates the original finding. No new issue was created — this comment supplements the existing report. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#6420
No description provided.