Skip to content

fix(search): escape SQL LIKE wildcard characters in memory search - #30

Merged
laceyp99 merged 3 commits into
mainfrom
agent/issue-26-run-28680237657
Jul 5, 2026
Merged

laceyp99 merged 3 commits into
mainfrom
agent/issue-26-run-28680237657

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Related Links

Summary

This PR attempts to satisfy the linked issue while keeping the change scope limited to the issue requirements. Escaped SQL LIKE wildcard characters in free-text memory search so q treats %, _, and backslash literally while preserving case-insensitive substring matching.

Files changed

  • app/storage.py - added LIKE-pattern escaping and ESCAPE '\' clauses for q filters.
  • tests/unit/test_storage.py - added regression coverage for literal _, %, and backslash search terms.
  • README.md - documented literal wildcard behavior.
  • docs/data_object_schema.md - updated retrieval contract wording.

Validation

  • pytest tests/unit/test_storage.py - passed, 12 tests.
  • ruff check app/storage.py tests/unit/test_storage.py - passed.
  • ruff format --check app/storage.py tests/unit/test_storage.py - passed.
  • Attempted pytest tests/integration/test_memories_list.py; it hung before producing a first test result and was interrupted after about 90 seconds.

Risks

Low risk. The change is isolated to shared retrieval filtering. Existing behavior changes only for search strings containing SQL LIKE wildcard or escape characters.

Follow-up

Before merging, run the full CI suite or at least re-run the integration list tests in an environment where they complete normally.

Test Steps

  • Agent validation passed: ruff format --check ., ruff check ., and pytest
  • PR Review Workflow reviews the PR and the implementation.
  • Human reviewed the implementation
  • Human checked relevant edge cases
  • Human confirmed issue requirements are fully satisfied

Other Notes

This draft PR was created automatically. Human review is required before marking it ready for review or merging.

@laceyp99 laceyp99 changed the title Draft: Implement issue #26 fix(search): escape SQL LIKE wildcard characters in memory search Jul 4, 2026
@laceyp99
laceyp99 marked this pull request as ready for review July 4, 2026 06:08
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Author

Agent PR review

Validation

Validation passed: ruff format --check ., ruff check ., and pytest all completed successfully.

Summary

This PR updates memory free-text search to escape SQL LIKE wildcard characters, adds unit regression coverage, and documents that % and _ are treated literally.

Issues and risks

  • severity: medium

  • file or area: app/storage.py:180, tests/unit/test_storage.py:40

  • why it matters: q is documented as matching both content and tags, and the PR context says backslash should be literal too. Content search works, but tag search still operates on JSON-serialized tags. Tags containing backslash-plus-wildcard sequences, such as path\_literal, are serialized with doubled backslashes, so q=r"path\_" does not match the tag even though it matches equivalent content.

  • suggested fix: Search tags through json_each(memories.tags) for q as well, e.g. EXISTS (...) WHERE LOWER(json_each.value) LIKE ? ESCAPE '\', instead of LOWER(tags) LIKE .... Add regression tests for %, _, and backslash cases in tags.

  • severity: low

  • file or area: README.md:147, docs/data_object_schema.md:290

  • why it matters: The implementation escapes backslash and the PR context says backslash should be treated literally, but the docs only mention % and _. That leaves the retrieval contract ambiguous for callers.

  • suggested fix: Document backslash literal behavior too, if that is intended contract.

Test coverage

The PR adds unit coverage for literal _, %, and backslash searches in memory content. The review context reports ruff format --check ., ruff check ., and pytest passed, though the PR description also notes an earlier interrupted integration-list run.

Important missing coverage: tag-side q matching for wildcard and escape characters, especially tags containing backslashes; HTTP/MCP contract coverage for the same behavior would also be useful because those are the public retrieval surfaces.

Recommendation

Needs changes before merge.


This is an automated review. Please treat it as advisory; human review is still required.

@laceyp99

laceyp99 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Update summary

  • Addressed the agent review finding about tag-side q search by matching decoded tag values through json_each(memories.tags) instead of searching the JSON-serialized tags column.
  • Added regression coverage for literal _, %, and \ search terms in tags.
  • Updated the retrieval docs to state that %, _, and \ are treated literally.

Resolved in commit e2f5545 (fix(search): match q against decoded tags).

Testing

  • py -3.12 -m pytest tests/unit/test_storage.py - passed
  • py -3.12 -m ruff format --check . - passed
  • py -3.12 -m ruff check . - passed
  • py -3.12 -m pytest - passed

@laceyp99
laceyp99 merged commit 0b3b49c into main Jul 5, 2026
4 checks passed
@laceyp99
laceyp99 deleted the agent/issue-26-run-28680237657 branch July 5, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Escape wildcard characters in free-text memory search

2 participants