AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
perf(chat): read only the start of each chat's last message for its preview (#441)
Rufusfa8628794cc4
diff --git a/packages/core/openexecutive/memory/session_store.py b/packages/core/openexecutive/memory/session_store.pyindex e0ded3ed..d99f1b1e 100644--- a/packages/core/openexecutive/memory/session_store.py+++ b/packages/core/openexecutive/memory/session_store.py@@ -198,7 +198,9 @@ def list_sessions(batch = last_ids[at:at + _IN_BATCH]marks = ",".join("?" * len(batch))for msg in conn.execute(- f"SELECT id, role, content FROM chat_messages WHERE id IN ({marks})", batch+ "SELECT id, role, substr(content, 1, ?) AS content FROM chat_messages "+ f"WHERE id IN ({marks})",+ [_PREVIEW_READ_CHARS, *batch],):last[msg["id"]] = msg# A chat-app conversation started with /new has a row before it has a@@ -218,6 +220,9 @@ def list_sessions(_PREVIEW_CHARS = 120+# How much of a last message the list reads: enough to fill the preview once+# Markdown marks are gone, without loading a long answer in full per chat.+_PREVIEW_READ_CHARS = 2000# Ids per IN (...) query, under SQLite's bound-parameter limit._IN_BATCH = 500# Markdown's marks, which read as noise in a one-line preview: a link keepsdiff --git a/packages/core/tests/unit/test_session_store.py b/packages/core/tests/unit/test_session_store.pyindex fe51d3ed..a08eccc5 100644--- a/packages/core/tests/unit/test_session_store.py+++ b/packages/core/tests/unit/test_session_store.py@@ -276,3 +276,24 @@ def test_list_sessions_preview_is_cut_at_a_word(db: Path) -> None:preview = list_sessions(OWNER, db_path=db)[0]["preview"]assert preview.endswith("word…")assert len(preview) <= 121+++def test_list_sessions_previews_every_chat_across_lookup_batches(+ db: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ import openexecutive.memory.session_store as store++ monkeypatch.setattr(store, "_IN_BATCH", 2)+ for n in range(5):+ create_session(f"b{n}", f"Chat {n}", "2024-01-01T00:00:00", caller_person_id=OWNER, db_path=db)+ save_message(f"b{n}", "assistant", f"Answer {n}", db_path=db)+ previews = {s["session_id"]: s["preview"] for s in list_sessions(OWNER, db_path=db)}+ assert previews == {f"b{n}": f"Answer {n}" for n in range(5)}+++def test_list_sessions_preview_reads_only_the_start_of_a_long_message(db: Path) -> None:+ create_session("big", "Big", "2024-01-01T00:00:00", caller_person_id=OWNER, db_path=db)+ save_message("big", "assistant", "Summary first. " + "x" * 500_000, db_path=db)+ preview = list_sessions(OWNER, db_path=db)[0]["preview"]+ assert preview.startswith("Summary first.")+ assert len(preview) <= 121