fix(session): handle non-dict LLM responses in memory extraction#618
Merged
MaojiaSheng merged 2 commits intovolcengine:mainfrom Mar 15, 2026
Merged
Conversation
When using local Ollama models, parse_json_from_response may return a
list instead of the expected {"memories": [...]} dict, causing
AttributeError on .get(). Add type checking after parsing: wrap lists
as {"memories": data}, and fall back to {} for other unexpected types.
Closes volcengine#605
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
MaojiaSheng
approved these changes
Mar 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add defensive type checking in memory extraction to handle LLM responses that return a list instead of a dict. This fixes crashes when using local Ollama models.
Why this matters
When using OpenViking with local Ollama models (e.g.,
llama3.1:latest), memory extraction fails becauseparse_json_from_response()can return a list[{...}]instead of the expected{"memories": [{...}]}. The subsequentdata.get("memories", [])call throwsAttributeErrorsince lists don't have.get().isinstance(data, dict)checks in the merge bundle path (line 559), but the extraction path at line 296-301 lacks this guardChanges
In
openviking/session/memory_extractor.py, afterparse_json_from_response():datais a list, wrap it as{"memories": data}(treat the list as the memories array directly)datais neither dict nor list, log a warning and fall back to empty dictTesting
Added
tests/session/test_memory_extractor_response_types.pywith 6 test cases:Fixes #605
This contribution was developed with AI assistance (Claude Code).