fix(memory): wire limit kwarg through load_messages

Closes round-1 review finding perf-2 (minor).

Storage backends accept ``*, limit: int | None = None`` (see
:meth:`StorageBackend.load_messages` at storage/_protocol.py:146) but
the in-memory wrapper at memory.py:82-85 dropped the kwarg, so
callers that wanted to tail-load (e.g. ``session.resume`` against a
long-running coord with hundreds of wake rows + persisted reminder
JSON) were forced to pull every row through the wrapper anyway.

Wraparound is mechanical: signature widens, default leaves existing
callers unaffected.

(cherry picked from commit 885f6a9185)
This commit is contained in:
Patrick Buckley
2026-05-06 22:14:50 -07:00
parent eb9dd2402a
commit 0e2ea122eb
+8 -3
View File
@@ -79,10 +79,15 @@ def save_messages_bulk(rows: list[dict[str, Any]]) -> None:
log.warning("Failed to bulk-save %d messages", len(rows), exc_info=True)
def load_messages(ws_id: str) -> list[dict[str, Any]]:
"""Load messages for a workstream and reconstruct OpenAI message format."""
def load_messages(ws_id: str, *, limit: int | None = None) -> list[dict[str, Any]]:
"""Load messages for a workstream and reconstruct OpenAI message format.
*limit* tail-loads the most recent N rows when set; the storage
backend already accepts the kwarg. Used by callers that don't
need the full transcript (e.g. browsing a long-running coord).
"""
try:
return get_storage().load_messages(ws_id)
return get_storage().load_messages(ws_id, limit=limit)
except Exception:
log.warning("Failed to load messages for ws=%s", ws_id, exc_info=True)
return []