Skip to content

memory.ask treats slug underscores as LIKE wildcards #1032

Closed

Description

@zlareb1

Component

Memory and search

Describe what's wrong

memory.ask looks up a bridge subject's memory keys with a LIKE pattern that leaves _ unescaped.

bridge_rows_by_key sets the pattern to % + key_slug(bridge) + %. key_slug lowercases the name and turns every non-alphanumeric run into _. The docstring gives Carlos Gómez to carlos_g_mez, which is the literal key the extractor writes. The pattern is not passed through an escape.

ClickHouse LIKE treats _ as one character and % as any string. %carlos_g_mez% matches the literal key carlos_g_mez and also carlosagamez. The read is already restricted to the caller's identity (memory_identity_where), so the extra rows are inside that scope. They are still rows the subject filter did not mean to select.

On commit 5fbc62c, key_slug("Carlos Gómez") returned carlos_g_mez. A local model of LIKE ( _ one character, % any string) matched both carlos_g_mez and carlosagamez. ClickHouse was not queried. like_contains in the code index does escape \\, % and _.

Does it reproduce on the latest release or main?

Yes

How to reproduce

Auth on or off. One namespace, two active memories under the same identity:

  • memory_key carlos_g_mez_citizen_of, value the fact you want
  • memory_key carlosagamez_citizen_of, value a different fact

Ask a question whose bridge entity is Carlos Gómez (a follow-up that takes the key-slug path in bridge_rows_by_key).

Both keys match memory_key LIKE '%carlos_g_mez%'. The second key is not the slug.

Expected behavior

The pattern matches keys that contain the slug as literal text, including the underscores key_slug inserted. % and _ in the slug are escaped, as like_contains does for a symbol name. A key that differs by one character in an underscore's place does not match.

Environment

Source: ClickHouse/loom main, commit 5fbc62c21a, package version 1.3.0
Python: 3.14.6
Platform: macOS arm64
LOOM_STORAGE_AUTHORITY: clickhouse (the default)
ClickHouse: not queried

How this was found

An AI tool found it, and I have not reproduced it myself

Additional context

The slug and the pattern match were checked in process. memory.ask was not called against a server, so there is no returned hit list.

Redaction

  • I removed tokens, keys, passwords and personal or customer data from everything above.

Activity

  1. added
    bug
    on Nov 20, 2026
  2. self-assigned this
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions