fix(memory): resolve partial IDs beyond the first 1000 records

This commit is contained in:
Ehsan-hash
2026-10-22 00:38:56 -07:00
parent e995eb9f1d
commit 017c9a5511
2 changed files with 74 additions and 1 deletions
+1 -1
View File
@@ -598,7 +598,7 @@ def show_memory(
# If not found with exact ID, try partial match
if mem is None:
# Query all and filter by prefix
all_memories = asyncio.run(store.query(MemoryFilter(limit=1000)))
all_memories = asyncio.run(store.query(MemoryFilter()))
matches = [m for m in all_memories if m.id.startswith(memory_id)]
if len(matches) == 0:
+73
View File
@@ -165,6 +165,79 @@ class TestMemoryShow:
assert result.exit_code == 0
assert "TypeScript" in result.output
def test_show_by_partial_id_beyond_default_query_limit(
self, runner: CliRunner, temp_db: str
) -> None:
"""Show a unique partial ID when the match is older than 1,000 rows."""
store = SQLiteMemoryStore(temp_db)
filler_start = datetime(2024, 1, 1)
memories = [
Memory(
id=f"filler-{index:04d}",
content=f"Filler memory {index}",
user_id="test-user",
created_at=filler_start + timedelta(days=index),
valid_from=filler_start + timedelta(days=index),
)
for index in range(1000)
]
memories.append(
Memory(
id="legacy-target-memory",
content="Legacy target outside the first page",
user_id="test-user",
created_at=datetime(2020, 1, 1),
valid_from=datetime(2020, 1, 1),
)
)
asyncio.run(store.save_batch(memories))
result = runner.invoke(main, ["memory", "show", "--db-path", temp_db, "legacy-target-"])
assert result.exit_code == 0
assert "Legacy target outside the first page" in result.output
def test_show_by_partial_id_reports_ambiguity_beyond_default_query_limit(
self, runner: CliRunner, temp_db: str
) -> None:
"""Report ambiguity when matching IDs span beyond the first 1,000 rows."""
store = SQLiteMemoryStore(temp_db)
filler_start = datetime(2024, 1, 1)
memories = [
Memory(
id=f"filler-{index:04d}",
content=f"Filler memory {index}",
user_id="test-user",
created_at=filler_start + timedelta(days=index),
valid_from=filler_start + timedelta(days=index),
)
for index in range(1000)
]
memories.extend(
[
Memory(
id="shared-prefix-old",
content="Older matching memory",
user_id="test-user",
created_at=datetime(2020, 1, 1),
valid_from=datetime(2020, 1, 1),
),
Memory(
id="shared-prefix-new",
content="Newer matching memory",
user_id="test-user",
created_at=datetime(2026, 1, 1),
valid_from=datetime(2026, 1, 1),
),
]
)
asyncio.run(store.save_batch(memories))
result = runner.invoke(main, ["memory", "show", "--db-path", temp_db, "shared-prefix-"])
assert result.exit_code != 0
assert "Ambiguous ID 'shared-prefix-'" in result.output
def test_show_json_output(self, runner: CliRunner, populated_db: str) -> None:
"""Show memory as JSON."""
result = runner.invoke(