Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions loopx/capabilities/explore/result_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def append_explore_result_events(
with exclusive_file_lock(log_path):
existing_by_id: dict[str, dict[str, Any]] = {}
if log_path.exists():
for line in log_path.read_text(encoding="utf-8").splitlines():
for line in log_path.read_text(encoding="utf-8").split("\n"):
try:
current = json.loads(line)
except json.JSONDecodeError:
Expand Down Expand Up @@ -546,7 +546,7 @@ def load_explore_result_events(
if not log_path.exists():
return []
events: list[dict[str, Any]] = []
for line in log_path.read_text(encoding="utf-8").splitlines():
for line in log_path.read_text(encoding="utf-8").split("\n"):
stripped = line.strip()
if not stripped:
continue
Expand Down Expand Up @@ -579,7 +579,7 @@ def load_explore_result_events_strict(
if not log_path.exists():
return []
events: list[dict[str, Any]] = []
for line_number, line in enumerate(log_path.read_text(encoding="utf-8").splitlines(), start=1):
for line_number, line in enumerate(log_path.read_text(encoding="utf-8").split("\n"), start=1):
stripped = line.strip()
if not stripped:
continue
Expand Down
2 changes: 1 addition & 1 deletion loopx/chat_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _read_json(path: Path) -> dict[str, Any]:

def _read_jsonl(path: Path) -> list[dict[str, Any]]:
try:
lines = path.read_text(encoding="utf-8").splitlines()
lines = path.read_text(encoding="utf-8").split("\n")
except OSError:
return []
rows: list[dict[str, Any]] = []
Expand Down
2 changes: 1 addition & 1 deletion loopx/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def latest_promotion_readiness_event(runtime_root: Path, goal_id: str | None = N
)
for index_path, current_goal_id, source in indexes:
try:
lines = index_path.read_text(encoding="utf-8").splitlines()
lines = index_path.read_text(encoding="utf-8").split("\n")
except OSError:
continue
for line in lines:
Expand Down
4 changes: 2 additions & 2 deletions loopx/domain_packs/issue_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def promote_issue_fix_feasibility_ledger_jsonl(
canonical_existing: dict[str, Any] | None = None
if path.exists():
for index, line in enumerate(
path.read_text(encoding="utf-8").splitlines(), start=1
path.read_text(encoding="utf-8").split("\n"), start=1
):
if not line.strip():
continue
Expand Down Expand Up @@ -530,7 +530,7 @@ def retain_issue_fix_repository_snapshot_jsonl(
path = Path(ledger_path)
existing_rows: list[dict[str, Any]] = []
if path.exists():
for line in path.read_text(encoding="utf-8").splitlines():
for line in path.read_text(encoding="utf-8").split("\n"):
try:
value = json.loads(line)
except (TypeError, ValueError):
Expand Down
2 changes: 1 addition & 1 deletion loopx/domain_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def upsert_domain_state_jsonl(
candidate = {**payload, "domain_state_key": key}
if path.exists():
for index, line in enumerate(
path.read_text(encoding="utf-8").splitlines(), start=1
path.read_text(encoding="utf-8").split("\n"), start=1
):
if not line.strip():
continue
Expand Down
2 changes: 1 addition & 1 deletion loopx/event_sourced_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class AppendOnlyStateEventStore:
def load(self) -> list[dict[str, Any]]:
events: list[dict[str, Any]] = []
if self.path.exists():
for line_number, line in enumerate(self.path.read_text(encoding="utf-8").splitlines(), start=1):
for line_number, line in enumerate(self.path.read_text(encoding="utf-8").split("\n"), start=1):
if not line.strip():
continue
try:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_event_sourced_state_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
make_state_event,
)

NEL = "\x85"


def test_load_observes_events_appended_by_another_store(tmp_path: Path) -> None:
event_log = tmp_path / "events.jsonl"
Expand Down Expand Up @@ -429,3 +431,30 @@ def test_concurrent_processes_publish_contiguous_batches(tmp_path: Path) -> None
if row["event_id"].startswith(f"{worker}-")
]
assert positions == list(range(positions[0], positions[0] + 3))


def test_load_reads_a_record_whose_value_carries_u0085(tmp_path: Path) -> None:
"""The event log is one JSON document per LF.

`json.dumps(..., ensure_ascii=False)` keeps U+0085 inside a value verbatim,
and `str.splitlines()` treats it as a line break, so a valid event arrived
as two fragments and `load()` raised `StateEventError`.
"""

event_log = tmp_path / "events.jsonl"
store = AppendOnlyStateEventStore(event_log)
event = make_state_event(
event_id="evt-raw-separator",
goal_id="goal-a",
event_type=TODO_ADDED,
refs={"todo_id": "todo_raw_separator"},
payload={"role": "agent", "title": f"Observe the durable event.{NEL}"},
recorded_at="2026-09-06T00:00:00Z",
)
event_log.write_text(
json.dumps(event, ensure_ascii=False) + "\n", encoding="utf-8"
)

loaded = store.load()

assert [item["event_id"] for item in loaded] == ["evt-raw-separator"]
Loading