From ce7ede75aa1079d9c77eab5d9a736555edaad607 Mon Sep 17 00:00:00 2001 From: serversdown Date: Thu, 18 Jun 2026 06:04:02 +0000 Subject: [PATCH] fix: backfill skips hand extraction by default (prose->replay too lossy) The auto-extracted hands from narrative logs were garbage (mangled cards/positions, 'unknown' players). Seed sessions + recaps + villain dossiers only; hands come from clean shorthand going forward. --with-hands re-enables if ever wanted. Co-Authored-By: Claude Opus 4.8 (1M context) --- lyra/backfill.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lyra/backfill.py b/lyra/backfill.py index 8e269ea..aca08ce 100644 --- a/lyra/backfill.py +++ b/lyra/backfill.py @@ -79,8 +79,14 @@ def extract(block: str, backend: str = "cloud") -> dict | None: _real_handle = poker._real_handle # one canonical filter (lives in poker.py) -def seed(ex: dict, block: str) -> dict: - """Write one extracted session + its hands + villains to the DB. Returns a summary.""" +def seed(ex: dict, block: str, with_hands: bool = False) -> dict: + """Write one extracted session + villains (+ hands only if asked) to the DB. + + Hands are OFF by default: reconstructing a clean replayable hand from old + narrative prose is too lossy (mangled cards/positions). Sessions, their + original writeups (recap), and villain dossiers seed cleanly; hands are best + captured fresh from Brian's own shorthand going forward. + """ sid = poker.import_session( date=ex.get("date") or "2026-01-01", venue=ex.get("venue"), game=ex.get("game") or "NLH", stakes=ex.get("stakes"), fmt=ex.get("format") or "cash", @@ -88,10 +94,11 @@ def seed(ex: dict, block: str) -> dict: hours=ex.get("hours"), mood=ex.get("mood"), recap_md=block, ) n_hands = 0 - for h in ex.get("hands") or []: - hid = poker.store_hand_history(h, session_id=sid) - poker.link_hand_players(hid, h, session_id=sid) - n_hands += 1 + if with_hands: + for h in ex.get("hands") or []: + hid = poker.store_hand_history(h, session_id=sid) + poker.link_hand_players(hid, h, session_id=sid) + n_hands += 1 n_villains = 0 for v in ex.get("villains") or []: if _real_handle(v.get("name")): @@ -107,6 +114,7 @@ def main() -> int: args = sys.argv[1:] commit = "--commit" in args reset = "--reset" in args + with_hands = "--with-hands" in args # off by default — prose->hand replay is too lossy limit = None for i, a in enumerate(args): if a == "--dry" and i + 1 < len(args) and args[i + 1].isdigit(): @@ -127,7 +135,7 @@ def main() -> int: print(f" ! could not parse a block: {b[:60]!r}") continue if commit: - print(" seeded:", seed(ex, b)) + print(" seeded:", seed(ex, b, with_hands=with_hands)) else: print(f"\n=== {ex.get('date')} — {ex.get('venue')} {ex.get('stakes')} " f"({ex.get('format')}) net {ex.get('net')} ===")