fix(memory): handle JSON-string tags from LLM serialization (v1.2.1) - #52
Merged
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: xlabtg#51
LLMs sometimes serialize array arguments as a JSON string (e.g. '["rules","github"]' instead of ["work","urgent"]). The external validation layer rejects these with "tags: must be array" before the plugin ever runs, causing the intermittent failure. - Add coerceToArray() helper that parses a JSON-string into an array, or treats a plain string as a single-element array - Use coerceToArray() in parseTags() so memory_store and memory_update handle string-typed tags inputs gracefully - Use coerceToArray() in memory_search tag filter normalization - Widen the JSON Schema for every `tags` parameter from `type: "array"` to `oneOf: [array, string]` so the validator accepts both forms - Add three new tests covering JSON-string tags in memory_store (two cases) and memory_search Fixes xlabtg#51 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
konard
marked this pull request as ready for review
March 26, 2026 07:16
This reverts commit b15fc51.
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
🤖 Models used:
📎 Log file uploaded as Gist (943KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
Author
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
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
Fixes #51
Root Cause
The error
tags: must be arrayoccurs because LLMs sometimes serialize array arguments as a JSON-encoded string instead of a proper JSON array:The external validation layer in
@mariozechner/pi-aichecks the JSON Schema before callingexecute, so the plugin never had a chance to handle this gracefully. The issue is intermittent because LLMs don't do this consistently — they sometimes pass a real array, sometimes a string.Fix
Two complementary changes:
Schema widened — Each
tagsparameter schema is changed fromtype: "array"tooneOf: [array, string], so the validator accepts both forms and letsexecuterun.coerceToArray()helper added — Normalises a JSON string, plain string, or proper array to a plain JS array before processing. Used inparseTags()(formemory_store/memory_update) and inmemory_searchtag filter normalisation.Tests Added
memory_store— accepts tags as a JSON-encoded string'["rules", "github"]'memory_store— accepts tags as a single plain string"work"memory_search— accepts tags filter as a JSON-encoded string'["github"]'All 62 tests pass.
This PR was created automatically by the AI issue solver