From 8bd4a2965e9c7c1319d58a9e7a6c0b9d92693fa8 Mon Sep 17 00:00:00 2001 From: chenjunwen Date: Sat, 9 May 2026 22:31:04 +0800 Subject: [PATCH] fix(memory): skills template None value causes empty content - skills.yaml: use |default(0, true) to handle None values in Jinja2 template (default() only replaces undefined, not None) - content.py: log and raise on template rendering failure instead of silently swallowing the exception (results in empty content) Co-Authored-By: Claude Opus 4.7 --- openviking/prompts/templates/memory/skills.yaml | 2 +- openviking/session/memory/utils/content.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/openviking/prompts/templates/memory/skills.yaml b/openviking/prompts/templates/memory/skills.yaml index 0358ce517..5ea8c21ea 100644 --- a/openviking/prompts/templates/memory/skills.yaml +++ b/openviking/prompts/templates/memory/skills.yaml @@ -7,7 +7,7 @@ enabled: true content_template: | Skill: {{ skill_name }} - - Success rate: {{ ((success_count|default(0) / (total_executions|default(1) if total_executions|default(0) > 0 else 1)) * 100)|round|int }}% ({{ success_count|default(0) }}/{{ total_executions|default(0) }}) + - Success rate: {{ ((success_count|default(0, true) / (total_executions|default(1, true) if total_executions|default(0, true) > 0 else 1)) * 100)|round|int }}% ({{ success_count|default(0, true) }}/{{ total_executions|default(0, true) }}) - Best for: {{ best_for|default('N/A') }} - Recommended flow: {{ recommended_flow|default('N/A') }} - Key dependencies: {{ key_dependencies|default('N/A') }} diff --git a/openviking/session/memory/utils/content.py b/openviking/session/memory/utils/content.py index be9152672..664312dbb 100644 --- a/openviking/session/memory/utils/content.py +++ b/openviking/session/memory/utils/content.py @@ -76,9 +76,11 @@ def serialize_with_metadata( jinja_template = env.from_string(content_template) content = jinja_template.render(**template_vars).strip() - except Exception: - # If template rendering fails, use content as-is - pass + except Exception as e: + from openviking.telemetry import tracer + + tracer.error(f"Template rendering failed, skipping write: {e}") + raise # Clean metadata - remove None values and memory_type clean_metadata = {k: v for k, v in metadata.items() if v is not None and k != "memory_type"}