Repository navigation
Treat memory tag filters as literal LIKE substrings - #355
Merged
Merged
Conversation
EntryFilter.tag was wrapped in LIKE %"tag"% without escaping, so foo_bar also matched fooXbar and 100% also matched 1000 on /mem entries tag= and GET /v1/memory/entries?tag=. Escape \, %, and _ and pair the browse filter and FTS tag-boost predicate with ESCAPE '\'. Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
This was referenced Sep 18, 2026
…scape # Conflicts: # CHANGELOG.md
tylerreckart
marked this pull request as ready for review
September 21, 2026 12:58
tylerreckart
enabled auto-merge (squash)
September 21, 2026 12:58
…scape # Conflicts: # CHANGELOG.md
…scape # Conflicts: # CHANGELOG.md
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.
Problem
EntryFilter.tag(/mem entries tag=andGET /v1/memory/entries?tag=) wraps the tag inLIKE %"tag"%against the serialized tags JSON.%,_, and\\were not escaped, so they were SQL wildcards.A filter for
foo_baralso matchedfooXbar. A filter for100%also matched1000. Snake_case tags are common; this is a hardWHEREin browse mode, so the wrong entries are returned (and in FTS mode the wrong rows get the tag boost).This is the same LIKE-literal class as lesson search, but a separate filter and SQL site. Not SQL injection (the pattern is bound).
Fix
Escape
\\,%, and_in the tag and pair both the browseAND tags LIKE ?predicate and the FTS tag-boostCASE WHEN e.tags LIKE ?withESCAPE '\\'. Unescaped ASCII tags without those characters are unchanged. JSON quote wrapping around the token is unchanged.Helper is named
escape_like_wildcards(local to the memory-entry TU) so it does not collide with the lesson-search helper on #353.Tests
unit_memory_entries—foo_bardoes not matchfooXbar;100%does not match1000; a JSON-encoded backslash still matches when escaped. Suite 25/25 locally (142 assertions) + ASan/UBSan.Independently mergeable against
main(0456350). Code hunks auto-merge with #321–#354, including #330 (exact_conversationinlist_entries) and #353 (like_literal+search_lessons). CHANGELOG[Unreleased]sibling-conflicts after the first of those merges, same as the rest of the series.Backward-compatible for tags without
%/_/\\. Callers that relied on_as “any character” will see fewer rows — that was the bug.Note
Low Risk
Localized SQL filter fix with tests and docs; behavior change only for tags containing
%,_, or\.Overview
Memory
tag=filters now match literal tag substrings, fixing false positives where SQLiteLIKEtreated%,_, and\as wildcards./mem entries tag=andGET /v1/memory/entries?tag=build a%"tag"%pattern against serialized tags JSON. Unescaped patterns letfoo_barmatchfooXbarand100%match1000. The change addsescape_like_wildcards/tag_like_patternintenant_store.cppand appliesLIKE … ESCAPE '\'in both browse hard filters and FTS tag-boostCASE WHENclauses.Docs and changelog note literal semantics;
unit_memory_entriescovers underscore, percent, and backslash cases. Tags without those characters behave as before; callers who accidentally relied on_as “any character” will see fewer rows.Reviewed by Cursor Bugbot for commit 3e06630. Bugbot is set up for automated code reviews on this repo. Configure here.