Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions loopx/chat_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,9 @@ def flush_events(self, session_id: str, turn_id: str) -> int:
try:
with exclusive_file_lock(path, agent_id="loopx-chat", operation="append_chat_events"):
rows = self._event_rows_locked(session_id, turn_id)
# Allocate after the last persisted sequence and append under the
# same file lock: row order stays strictly increasing by sequence.
# Compaction preserves this order but may leave sequence gaps.
sequence = int(rows[-1].get("sequence") or 0) if rows else 0
for event in pending:
sequence += 1
Expand Down Expand Up @@ -1355,6 +1358,8 @@ def events_after(self, session_id: str, turn_id: str, event_id: str | None) -> l
if rows is None:
with exclusive_file_lock(path, agent_id="loopx-chat", operation="read_chat_events"):
rows = self._event_rows_locked(session_id, turn_id)
# Relies on the sequence ordering maintained by flush_events and compaction;
# gaps are valid, but inserting or rewriting rows must preserve that order.
start = bisect_right(
rows,
after,
Expand Down