BUG-HUNT: [error-handling] YAML template engine fails on deferred rendering with unhashable key error #7113

Open
opened 2026-04-10 07:52:17 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Branch: bugfix/m3-error-handling-yaml-template-deferred-rendering
  • Commit Message: fix(actor): handle Jinja2 syntax in deferred YAML template rendering
  • Milestone: Backlog (no milestone — see backlog note below)
  • Parent Epic: TBD — orphan flag posted in comment

Background and Context

The YAMLTemplateEngine in src/cleveragents/actor/yaml_template_engine.py supports inline Jinja2 templates in YAML configuration files. When no rendering context is provided (deferred rendering mode), the engine's _simple_template_extraction() method attempts to parse the raw Jinja2 template syntax directly as YAML. This causes a yaml.constructor.ConstructorError with "found unhashable key" because Jinja2 {{ variable }} syntax is not valid YAML.

Current Behavior

When YAMLTemplateEngine.load_string() is called with a template containing Jinja2 variables and no context is provided, _simple_template_extraction() attempts to parse the raw template as YAML, raising:

yaml.constructor.ConstructorError: found unhashable key

Reproduction:

engine = YAMLTemplateEngine()
result = engine.load_string('key: {{ value }}')  # No context provided
# Raises: ConstructorError: found unhashable key

Location:

  • File: src/cleveragents/actor/yaml_template_engine.py
  • Function: _simple_template_extraction()
  • Lines: ~200–210

Expected Behavior

When no context is provided, the engine should gracefully handle Jinja2 syntax by either:

  1. Returning a placeholder structure indicating deferred rendering is needed, or
  2. Extracting template variable names for later validation, or
  3. Returning a structured response indicating template variables were found without raising an exception.

Acceptance Criteria

  • YAMLTemplateEngine.load_string('key: {{ value }}') with no context does not raise ConstructorError
  • Deferred rendering returns a structured result (placeholder or variable list) instead of raising
  • Existing rendering-with-context behaviour is unchanged
  • All nox stages pass with coverage ≥ 97%

Supporting Information

  • Related: _simple_template_extraction() at lines ~200–210 of src/cleveragents/actor/yaml_template_engine.py
  • The fix should detect Jinja2 syntax ({{ ... }}, {% ... %}) before attempting YAML parsing, or wrap the YAML parse in a try/except that returns a deferred-rendering sentinel

Subtasks

  • Investigate _simple_template_extraction() and identify all code paths that parse raw Jinja2 as YAML
  • Implement Jinja2 syntax detection before YAML parsing (or graceful fallback)
  • Return structured deferred-rendering response when no context is provided
  • Tests (Behave): Add BDD scenarios for deferred rendering with Jinja2 variables
  • Tests (Robot): Add integration test for load_string with no context
  • Tests (ASV): Add benchmark for deferred rendering path
  • Verify coverage ≥ 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors
  • Await TDD issue creation and link this issue as blocked by TDD issue

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass.
  • Coverage ≥ 97%.

Backlog note: This issue was discovered during autonomous operation on milestone v3.2.0. It does not block milestone completion and has been placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: Acting on behalf of: Bug Hunting | Agent: new-issue-creator

## Metadata - **Branch**: `bugfix/m3-error-handling-yaml-template-deferred-rendering` - **Commit Message**: `fix(actor): handle Jinja2 syntax in deferred YAML template rendering` - **Milestone**: Backlog (no milestone — see backlog note below) - **Parent Epic**: TBD — orphan flag posted in comment ## Background and Context The `YAMLTemplateEngine` in `src/cleveragents/actor/yaml_template_engine.py` supports inline Jinja2 templates in YAML configuration files. When no rendering context is provided (deferred rendering mode), the engine's `_simple_template_extraction()` method attempts to parse the raw Jinja2 template syntax directly as YAML. This causes a `yaml.constructor.ConstructorError` with "found unhashable key" because Jinja2 `{{ variable }}` syntax is not valid YAML. ## Current Behavior When `YAMLTemplateEngine.load_string()` is called with a template containing Jinja2 variables and no context is provided, `_simple_template_extraction()` attempts to parse the raw template as YAML, raising: ``` yaml.constructor.ConstructorError: found unhashable key ``` **Reproduction**: ```python engine = YAMLTemplateEngine() result = engine.load_string('key: {{ value }}') # No context provided # Raises: ConstructorError: found unhashable key ``` **Location**: - File: `src/cleveragents/actor/yaml_template_engine.py` - Function: `_simple_template_extraction()` - Lines: ~200–210 ## Expected Behavior When no context is provided, the engine should gracefully handle Jinja2 syntax by either: 1. Returning a placeholder structure indicating deferred rendering is needed, or 2. Extracting template variable names for later validation, or 3. Returning a structured response indicating template variables were found without raising an exception. ## Acceptance Criteria - [ ] `YAMLTemplateEngine.load_string('key: {{ value }}')` with no context does not raise `ConstructorError` - [ ] Deferred rendering returns a structured result (placeholder or variable list) instead of raising - [ ] Existing rendering-with-context behaviour is unchanged - [ ] All nox stages pass with coverage ≥ 97% ## Supporting Information - Related: `_simple_template_extraction()` at lines ~200–210 of `src/cleveragents/actor/yaml_template_engine.py` - The fix should detect Jinja2 syntax (`{{ ... }}`, `{% ... %}`) before attempting YAML parsing, or wrap the YAML parse in a try/except that returns a deferred-rendering sentinel ## Subtasks - [ ] Investigate `_simple_template_extraction()` and identify all code paths that parse raw Jinja2 as YAML - [ ] Implement Jinja2 syntax detection before YAML parsing (or graceful fallback) - [ ] Return structured deferred-rendering response when no context is provided - [ ] Tests (Behave): Add BDD scenarios for deferred rendering with Jinja2 variables - [ ] Tests (Robot): Add integration test for `load_string` with no context - [ ] Tests (ASV): Add benchmark for deferred rendering path - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors - [ ] Await TDD issue creation and link this issue as blocked by TDD issue ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass. - Coverage ≥ 97%. > **Backlog note:** This issue was discovered during autonomous operation on milestone v3.2.0. It does not block milestone completion and has been placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: Acting on behalf of: Bug Hunting | Agent: new-issue-creator
Author
Owner

⚠️ Orphan Issue — Parent Epic Required

This issue was created by an automated agent and could not be automatically linked to a parent Epic. No Epic for the actor/yaml_template_engine module was found in the open issues.

Action required: A maintainer must:

  1. Identify or create the appropriate parent Epic for the YAMLTemplateEngine / actor configuration module.
  2. Link this issue as a child that blocks the parent Epic using Forgejo's dependency system (this issue → blocks → parent Epic).

Per CONTRIBUTING.md, orphan issues are not permitted. This issue must be linked before it can be moved to State/Verified.


TDD Workflow Note: Per CONTRIBUTING.md Bug Fix Workflow, a corresponding TDD: issue (Type/Testing) must be created before this bug fix begins. Once created, this issue should be set to blocked by the TDD issue. The caller noted: "After verification, a TDD issue will test that deferred rendering properly handles template syntax without raising unhashable key errors."


Automated by CleverAgents Bot
Supervisor: Acting on behalf of: Bug Hunting | Agent: new-issue-creator

⚠️ **Orphan Issue — Parent Epic Required** This issue was created by an automated agent and could not be automatically linked to a parent Epic. No Epic for the `actor/yaml_template_engine` module was found in the open issues. **Action required:** A maintainer must: 1. Identify or create the appropriate parent Epic for the `YAMLTemplateEngine` / actor configuration module. 2. Link this issue as a child that **blocks** the parent Epic using Forgejo's dependency system (this issue → blocks → parent Epic). Per CONTRIBUTING.md, orphan issues are not permitted. This issue must be linked before it can be moved to `State/Verified`. --- **TDD Workflow Note:** Per CONTRIBUTING.md Bug Fix Workflow, a corresponding `TDD:` issue (`Type/Testing`) must be created before this bug fix begins. Once created, this issue should be set to **blocked by** the TDD issue. The caller noted: *"After verification, a TDD issue will test that deferred rendering properly handles template syntax without raising unhashable key errors."* --- **Automated by CleverAgents Bot** Supervisor: Acting on behalf of: Bug Hunting | Agent: new-issue-creator
Author
Owner

Verified — Bug: YAML template engine fails on deferred rendering with unhashable key. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Bug: YAML template engine fails on deferred rendering with unhashable key. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#7113
No description provided.