OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: Memory extraction fails when prefetched metadata contains datetime

Open Terryli246 opened this issue 4 weeks ago • 0 comments

Issue Origin

Observed or reproduced in a real environment

Bug Description

Long-term memory extraction can fail during eager prefetch when a memory's metadata contains created_at or updated_at. MemoryFileUtils.read() parses those fields into Python datetime objects, and MemoryReadTool.execute() returns them in its result. add_tool_call_pair_to_messages() then passes the result to json.dumps() without a datetime serializer, raising TypeError before extraction can proceed.

Steps to Reproduce

  1. Read a memory whose MEMORY_FIELDS includes an ISO 8601 created_at or updated_at field using MemoryReadTool.
  2. Pass the returned metadata to add_tool_call_pair_to_messages, as eager prefetch does.
  3. Observe the serialization failure below.

Expected Behavior

Prefetched metadata is serialized to JSON and extraction proceeds, with timestamps represented as ISO 8601 strings.

Actual Behavior

The long-term extraction step fails with TypeError: Object of type datetime is not JSON serializable. In one local deployment, 13 session commit tasks failed with this error on 2026-11-03. The corresponding archives were retained; recovery of their extraction has not been verified.

Minimal Reproducible Example

from openviking.session.memory.utils.memory_file_utils import MemoryFileUtils
from openviking.session.memory.tools import add_tool_call_pair_to_messages

raw = 'Example\n\n<!-- MEMORY_FIELDS\n{"created_at":"2026-11-03T12:34:56+08:00"}\n-->'
result = MemoryFileUtils.read(raw, uri='viking://test.md').to_metadata()
add_tool_call_pair_to_messages([], 1, 'read', {'uri': 'viking://test.md'}, result)

Error Logs

Phase 2 step long_term failed: Object of type datetime is not JSON serializable
session_extract_context_provider.py: _append_structured_read_result
session/memory/tools.py: add_tool_call_pair_to_messages -> json.dumps
TypeError: Object of type datetime is not JSON serializable

OpenViking Version

0.5.3; the same unguarded json.dumps was present on main at 5760af6ff41fdc7b74056a7b408807ee7cdbc9b1 (source inspection only).

Python Version

3.13.15

Operating System

macOS

Model Backend

Other

Additional Context

Locally, reusing the existing _serialize_datetime JSON default in add_tool_call_pair_to_messages made an isolated test using MemoryReadTool pass and still rejects unsupported object types. The patched server has not yet been restarted or verified end-to-end, so this is not a claim of a live fix.

Related open PR #4648 changes the prefetch message format for a different issue. Its current diff also calls json.dumps on the complete prefetched memory data without a datetime default; it may need to account for this case as well. I have not run that PR.

Terryli246 avatar Nov 03 '26 15:11 Terryli246