api.py: flush=True on graphiti-push log lines

The background daemon thread that pushes chat turns to Graphiti was using
default-buffered print(), so the success/failure lines never reached the
systemd journal — buffer never flushed because the thread keeps the
interpreter alive. The push itself worked (verified by Episodic nodes
appearing in the graph), just the log was silent.

Surgical fix: pass flush=True on the four print() calls inside _push_chat_turn_
to_graphiti's background worker. Now every push result lands in the journal
as it happens, giving real-time visibility into whether pushes are
succeeding, failing on non-200, hitting a network error, or raising
unexpectedly.

If we add more background-thread logging later, PYTHONUNBUFFERED=1 in the
service environment would solve it globally — but that's overkill for this
one site.
This commit is contained in:
2026-05-20 22:41:02 +00:00
parent f185ed60cb
commit 9d09d3fa14
+4 -4
View File
@@ -518,13 +518,13 @@ def _push_chat_turn_to_graphiti(conversation_id, user_message, assistant_message
# is empirically ~20 min wall-clock. We're patient; chat isn't.
r = requests.post(f"{GRAPHITI_URL}/episodes", json=payload, timeout=1800)
if r.status_code == 200:
print(f"[graphiti-push] turn ingested: {episode_name}")
print(f"[graphiti-push] turn ingested: {episode_name}", flush=True)
else:
print(f"[graphiti-push] non-200 ({r.status_code}) for {episode_name}: {r.text[:200]}")
print(f"[graphiti-push] non-200 ({r.status_code}) for {episode_name}: {r.text[:200]}", flush=True)
except requests.RequestException as e:
print(f"[graphiti-push] request failed: {e}")
print(f"[graphiti-push] request failed: {e}", flush=True)
except Exception as e:
print(f"[graphiti-push] unexpected error: {e}")
print(f"[graphiti-push] unexpected error: {e}", flush=True)
threading.Thread(target=_work, daemon=True).start()