Skip to content

fix(memory): quote FTS5 queries to handle hyphens and special chars#427

Merged
marcusquinn merged 3 commits intomainfrom
feature/t139
Feb 7, 2026
Merged

fix(memory): quote FTS5 queries to handle hyphens and special chars#427
marcusquinn merged 3 commits intomainfrom
feature/t139

Conversation

@marcusquinn
Copy link
Owner

Summary

  • Fixes memory-helper.sh recall crashing with Runtime error near line 1: no such column: edit when queries contain hyphens (e.g., pre-edit)
  • FTS5 interprets - as the NOT operator; wrapping queries in double quotes makes them literal phrase searches
  • All existing query types (single words, multi-word, embedded quotes, single quotes) continue to work correctly

Root Cause

SQLite FTS5 has special syntax characters: - (NOT), * (prefix), OR, AND, etc. The previous code escaped quotes but didn't protect against operator interpretation. A query like pre-edit was parsed as pre NOT edit, and since edit isn't a column name, FTS5 threw an error.

Fix

Wrap the escaped query in FTS5 double quotes ("pre-edit") which tells FTS5 to treat the entire string as a literal phrase. Embedded double quotes are already escaped by doubling them (""), which is the FTS5 convention.

Testing

Verified manually:

  • recall "pre-edit" - no longer crashes (was: no such column: edit)
  • recall "pre-edit-check" - handles multiple hyphens
  • recall "memory" - normal queries still work
  • recall 'test "quoted" value' - embedded double quotes work
  • recall "it's a test" - single quotes work
  • Stored and recalled a hyphenated memory end-to-end
  • ShellCheck: zero violations

Closes #398

memory-helper.sh recall failed on hyphenated queries like "pre-edit"
because FTS5 interprets hyphens as the NOT operator. Wrapping the query
in double quotes makes FTS5 treat it as a literal phrase search.

Closes #398
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/t139

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the memory-helper.sh recall command by fixing a critical issue where FTS5 queries containing special characters, such as hyphens, would lead to application crashes. The core change involves modifying how search terms are processed, specifically by enclosing them in double quotes to compel FTS5 to interpret them as literal phrases rather than its internal operators. This change significantly improves the reliability and usability of the memory recall feature for complex search terms.

Highlights

  • FTS5 Query Fix: Resolves a crash in memory-helper.sh recall when queries contain hyphens, which FTS5 previously misinterpreted as the NOT operator.
  • Literal Phrase Search: Implements wrapping FTS5 queries in double quotes to ensure they are treated as literal phrase searches, correctly handling special characters.
  • Compatibility: Ensures that all existing query types, including single words, multi-word phrases, and those with embedded single or double quotes, continue to function as expected.
Changelog
  • .agents/scripts/memory-helper.sh
    • Updated the cmd_recall function to correctly prepare FTS5 queries.
    • The query escaping logic was modified to first escape embedded double quotes by doubling them, and then wrap the entire query in double quotes to enforce literal phrase matching, thereby preventing misinterpretation of special FTS5 syntax characters like hyphens.
  • TODO.md
    • Marked task t135.6 P1-C: Fix CI workflow code-quality.yml issues as completed with a completion date of 2026-02-07.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Feb 7, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 25 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Feb 7 06:12:01 UTC 2026: Code review monitoring started
Sat Feb 7 06:12:01 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 25
Sat Feb 7 06:12:02 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Sat Feb 7 06:12:04 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 25
  • VULNERABILITIES: 0

Generated on: Sat Feb 7 06:12:06 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a bug in memory-helper.sh where FTS5 queries containing hyphens would fail. The fix correctly wraps the query string in double quotes to ensure it's treated as a literal phrase by FTS5, which is the correct approach. The change is well-explained and effectively resolves the described issue. I have one minor suggestion to improve code readability in the shell script. The change in TODO.md is just a task status update.

Comment on lines 543 to +545
local escaped_query="${query//"'"/"''"}"
escaped_query="${escaped_query//\"/\"\"}"
# Escape embedded double quotes for FTS5 (double them), then wrap in quotes
escaped_query="\"${escaped_query//\"/\"\"}\""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and to avoid re-assigning to escaped_query, you could use an intermediate variable with a more descriptive name. This makes the purpose of each escaping step clearer and the code easier to follow.

Suggested change
local escaped_query="${query//"'"/"''"}"
escaped_query="${escaped_query//\"/\"\"}"
# Escape embedded double quotes for FTS5 (double them), then wrap in quotes
escaped_query="\"${escaped_query//\"/\"\"}\""
local query_sql_escaped="${query//'/'/''}"
# Escape embedded double quotes for FTS5 (double them), then wrap in quotes
local escaped_query="\"${query_sql_escaped//\"/\"\"}\""

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2026

@marcusquinn marcusquinn merged commit 5a4598d into main Feb 7, 2026
15 checks passed
marcusquinn added a commit that referenced this pull request Feb 7, 2026
marcusquinn added a commit that referenced this pull request Feb 7, 2026
…elpers (t135.3) (#433)

* chore: mark t139 complete in TODO.md (#427)

* chore: mark t135.14 complete in TODO.md (#426)

* fix: add SQLite WAL mode + busy_timeout to supervisor, memory, mail helpers (t135.3)

Add db() wrapper function to all three helpers that sets busy_timeout=5000ms
on every SQLite connection via '.timeout 5000' dot-command. This prevents
'database is locked' errors during concurrent access by parallel agents.

Changes per helper:
- supervisor-helper.sh: Add db() wrapper, replace 106 sqlite3 calls, add
  WAL migration in ensure_db() for pre-existing databases
- memory-helper.sh: Add db() wrapper, replace 63 sqlite3 calls, add WAL
  PRAGMA to init_db() and WAL migration in ensure_db()
- mail-helper.sh: Add db() wrapper, replace 36 sqlite3 calls, add WAL
  migration in ensure_db() for pre-existing databases

WAL mode is persistent (set once per DB), but busy_timeout is per-connection
and must be set each time. The db() wrapper ensures every sqlite3 invocation
gets the timeout. Tested: 20/20 concurrent writes succeed with fix vs 9/20
without.

* chore: sync version to 2.105.3 across all files
marcusquinn added a commit that referenced this pull request Feb 7, 2026
…432)

* chore: mark t139 complete in TODO.md (#427)

* chore: mark t135.14 complete in TODO.md (#426)

* fix: add ShellCheck enforcement to CI code-quality workflow (t135.6.3)

- Add ShellCheck lint step to framework-validation job
- Enforces error-severity violations that fail the build
- Iterates all git-tracked .sh files with gcc output format
- Mark t135.6 subtasks complete (t135.6.1/t135.6.2 done in PR #423)
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.

aidevops update output overwhelms tool buffer on large updates, losing session summary

1 participant