From 71bbe072202a6bacd1e9f6704d4a8f61eee987de Mon Sep 17 00:00:00 2001 From: serversdown Date: Fri, 3 Jul 2026 19:35:15 +0000 Subject: [PATCH] fix: scope a session's "her notes" to its own time window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HUD's notes list filtered journal/note entries by `created_at >= started_at` with no upper bound, so a *closed* session kept absorbing every note she wrote afterward — a session from last Saturday would show a note jotted 25 minutes ago. Cap the window at `ended_at` for closed sessions; live sessions (no end yet) stay open-ended as before. Co-Authored-By: Claude Opus 4.8 (1M context) --- lyra/poker.py | 7 ++++++- tests/test_poker.py | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lyra/poker.py b/lyra/poker.py index da42314..860ca2a 100644 --- a/lyra/poker.py +++ b/lyra/poker.py @@ -1298,12 +1298,17 @@ def hud(session_id: int | None = None) -> dict | None: for h in list_hands(sid) ] - # Notes she jotted during this session: journal/note entries since it started. + # Notes she jotted *during* this session: journal/note entries inside its + # [started_at, ended_at] window. A live session has no end yet, so it stays + # open-ended; without the upper bound a closed session would keep absorbing + # every note she writes long after it's over. started = s.get("started_at") or "" + ended = s.get("ended_at") or None notes = [ {"created_at": j["created_at"], "kind": j["kind"], "content": j["content"]} for j in memory.list_journal(kinds=("note", "journal")) if (j["created_at"] or "") >= started + and (ended is None or (j["created_at"] or "") <= ended) ][:20] stats = session_stats(sid) diff --git a/tests/test_poker.py b/tests/test_poker.py index 95ef400..36a979a 100644 --- a/tests/test_poker.py +++ b/tests/test_poker.py @@ -18,6 +18,27 @@ def lyra(tmp_path, monkeypatch): return poker +def test_hud_notes_scoped_to_session_window(lyra): + poker = lyra + from lyra import memory + sid = poker.start_session(venue="Meadows", stakes="1/3", buy_in=300) + s = poker.get_session(sid) + started = s["started_at"] + # A note written mid-session (>= started, before it ends) belongs to it. + conn = memory._connection() + with conn: + conn.execute("INSERT INTO journal (created_at, kind, content) VALUES (?,?,?)", + (started, "note", "villain 3 overfolds turn")) + poker.end_session(cash_out=540, session_id=sid) + # A note written well after the session closed must NOT show up on it. + with conn: + conn.execute("INSERT INTO journal (created_at, kind, content) VALUES (?,?,?)", + ("2999-01-01T00:00:00+00:00", "note", "thought from the far future")) + contents = [n["content"] for n in poker.hud(sid)["notes"]] + assert "villain 3 overfolds turn" in contents # inside the window + assert "thought from the far future" not in contents # after ended_at + + def test_session_lifecycle_and_net(lyra): poker = lyra sid = poker.start_session(venue="Meadows", stakes="1/3", buy_in=400)