Skip to content

Commit 6ee4852

Browse files
committed
ruff
1 parent b1e7b1b commit 6ee4852

File tree

6 files changed

+27
-20
lines changed

6 files changed

+27
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,4 @@ libs/redis/docs/.Trash*
236236
TASK_MEMORY.md
237237
*.code-workspace
238238

239-
augment*.md
239+
augment*.md

agent_memory_server/cli.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def migrate_working_memory(batch_size: int, dry_run: bool):
119119

120120
from agent_memory_server.utils.keys import Keys
121121
from agent_memory_server.working_memory import (
122-
reset_migration_status,
123122
set_migration_complete,
124123
)
125124

@@ -149,7 +148,7 @@ async def run_migration():
149148
pipe.type(key)
150149
types = await pipe.execute()
151150

152-
for key, key_type in zip(keys, types):
151+
for key, key_type in zip(keys, types, strict=False):
153152
if isinstance(key_type, bytes):
154153
key_type = key_type.decode("utf-8")
155154

@@ -197,7 +196,7 @@ async def run_migration():
197196

198197
# Parse and prepare migration
199198
migrations = [] # List of (key, data) tuples
200-
for key, string_data in zip(batch_keys, string_data_list):
199+
for key, string_data in zip(batch_keys, string_data_list, strict=False):
201200
if string_data is None:
202201
continue
203202

@@ -222,7 +221,9 @@ async def run_migration():
222221
migrated += len(migrations)
223222
except Exception as e:
224223
# If batch fails, try one by one
225-
logger.warning(f"Batch migration failed, retrying individually: {e}")
224+
logger.warning(
225+
f"Batch migration failed, retrying individually: {e}"
226+
)
226227
for key, data in migrations:
227228
try:
228229
await redis.delete(key)
@@ -262,8 +263,7 @@ async def run_migration():
262263
)
263264
else:
264265
click.echo(
265-
"\nMigration completed with errors. "
266-
"Run again to retry failed keys."
266+
"\nMigration completed with errors. " "Run again to retry failed keys."
267267
)
268268

269269
asyncio.run(run_migration())

agent_memory_server/working_memory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def check_and_set_migration_status(redis_client: Redis | None = None) -> b
8989
# The counter will be managed differently in this mode
9090
_remaining_string_keys = -1
9191
return False
92-
elif key_type == "ReJSON-RL":
92+
elif key_type == "ReJSON-RL": # noqa: RET505
9393
json_keys_found += 1
9494

9595
if cursor == 0:
@@ -194,7 +194,7 @@ async def _migrate_string_to_json(
194194
end
195195
"""
196196
# Pass the JSON string as ARGV[1]
197-
migrated_val = await redis_client.eval(lua_script, 1, key, json.dumps(data))
197+
await redis_client.eval(lua_script, 1, key, json.dumps(data))
198198

199199
# Preserve TTL if it was set
200200
# Note: TTL is lost during migration since we deleted the key

tests/benchmarks/test_migration_benchmark.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def create_old_format_data(session_id: str, namespace: str) -> dict:
5656
@pytest.fixture
5757
async def cleanup_working_memory_keys(async_redis_client):
5858
"""Clean up all working memory keys before and after test."""
59+
5960
async def cleanup():
6061
cursor = 0
6162
deleted = 0
@@ -118,7 +119,7 @@ async def test_startup_scan_performance(
118119
print(f"✅ Created {KEY_COUNT:,} keys in {creation_time:.2f}s")
119120

120121
# Benchmark startup scan (with early exit)
121-
print(f"\n📊 Benchmarking startup scan (early exit on first string key)...")
122+
print("\n📊 Benchmarking startup scan (early exit on first string key)...")
122123
reset_migration_status()
123124

124125
start = time.perf_counter()
@@ -251,10 +252,12 @@ async def test_worst_case_single_string_key_at_end(
251252
await async_redis_client.set(string_key, json.dumps(string_data))
252253

253254
creation_time = time.perf_counter() - start
254-
print(f"✅ Created {KEY_COUNT:,} JSON keys + 1 string key in {creation_time:.2f}s")
255+
print(
256+
f"✅ Created {KEY_COUNT:,} JSON keys + 1 string key in {creation_time:.2f}s"
257+
)
255258

256259
# Benchmark startup scan - must scan all keys to find the string one
257-
print(f"\n📊 Benchmarking startup scan (worst case - string key at end)...")
260+
print("\n📊 Benchmarking startup scan (worst case - string key at end)...")
258261
reset_migration_status()
259262

260263
start = time.perf_counter()
@@ -297,7 +300,7 @@ async def test_migration_script_performance(
297300
print(f"✅ Created {KEY_COUNT:,} string keys in {creation_time:.2f}s")
298301

299302
# Benchmark migration (simulating what the CLI does)
300-
print(f"\n📊 Benchmarking pipelined migration...")
303+
print("\n📊 Benchmarking pipelined migration...")
301304
migrate_start = time.perf_counter()
302305

303306
# Scan and collect string keys
@@ -313,7 +316,7 @@ async def test_migration_script_performance(
313316
pipe.type(key)
314317
types = await pipe.execute()
315318

316-
for key, key_type in zip(keys, types):
319+
for key, key_type in zip(keys, types, strict=False):
317320
if isinstance(key_type, bytes):
318321
key_type = key_type.decode("utf-8")
319322
if key_type == "string":
@@ -323,7 +326,9 @@ async def test_migration_script_performance(
323326
break
324327

325328
scan_time = time.perf_counter() - migrate_start
326-
print(f" Scan completed in {scan_time:.2f}s ({len(string_keys):,} string keys)")
329+
print(
330+
f" Scan completed in {scan_time:.2f}s ({len(string_keys):,} string keys)"
331+
)
327332

328333
# Migrate in batches
329334
migrated = 0
@@ -338,7 +343,7 @@ async def test_migration_script_performance(
338343

339344
# Parse and migrate
340345
write_pipe = async_redis_client.pipeline()
341-
for key, string_data in zip(batch_keys, string_data_list):
346+
for key, string_data in zip(batch_keys, string_data_list, strict=False):
342347
if string_data is None:
343348
continue
344349
if isinstance(string_data, bytes):
@@ -352,7 +357,9 @@ async def test_migration_script_performance(
352357

353358
if migrated % 100000 == 0:
354359
elapsed = time.perf_counter() - migrate_start
355-
print(f" Migrated {migrated:,} keys ({migrated / elapsed:,.0f} keys/sec)")
360+
print(
361+
f" Migrated {migrated:,} keys ({migrated / elapsed:,.0f} keys/sec)"
362+
)
356363

357364
migrate_time = time.perf_counter() - migrate_start
358365
rate = migrated / migrate_time
@@ -369,4 +376,3 @@ async def test_migration_script_performance(
369376
if isinstance(key_type, bytes):
370377
key_type = key_type.decode("utf-8")
371378
assert key_type == "ReJSON-RL", f"Expected ReJSON-RL, got {key_type}"
372-

tests/test_working_memory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ async def test_backward_compatibility_string_to_json_migration(
436436
assert retrieved_again.session_id == session_id
437437

438438
@pytest.mark.asyncio
439-
async def test_check_and_set_migration_status_with_no_keys(self, async_redis_client):
439+
async def test_check_and_set_migration_status_with_no_keys(
440+
self, async_redis_client
441+
):
440442
"""Test migration status check when no working memory keys exist."""
441443
from agent_memory_server.working_memory import (
442444
check_and_set_migration_status,

tests/test_working_memory_strategies.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for working memory strategy integration."""
22

3-
import json
43
from unittest.mock import AsyncMock, MagicMock, patch
54

65
import pytest

0 commit comments

Comments
 (0)