Compare commits

...

1 Commits

Author SHA1 Message Date
Alexander Whitestone
a69189110c fix: closes #674
Some checks failed
CI / test (pull_request) Failing after 58s
CI / validate (pull_request) Failing after 1m4s
Review Approval Gate / verify-review (pull_request) Failing after 10s
2026-04-21 21:36:06 -04:00
2 changed files with 39 additions and 2 deletions

View File

@@ -98,11 +98,17 @@ class TrajectoryLogger:
all_cycles = []
for traj_file in sorted(self.log_dir.glob("trajectory_*.jsonl")):
with open(traj_file) as f:
with open(traj_file, encoding="utf-8") as f:
for line in f:
line = line.strip()
if line:
if not line:
continue
try:
all_cycles.append(json.loads(line))
except json.JSONDecodeError:
# Skip truncated/corrupt lines so one bad append does not
# poison the entire export.
continue
# Quality filter — only keep cycles where the model actually
# produced meaningful thought (not just "Nothing has happened")

View File

@@ -0,0 +1,31 @@
import json
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent.parent
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from nexus.trajectory_logger import TrajectoryLogger
def test_export_for_training_skips_malformed_jsonl_lines(tmp_path):
logger = TrajectoryLogger(log_dir=tmp_path, system_prompt="System prompt")
logger.log_cycle(
perception="A useful perception",
thought="This is a sufficiently detailed thought for export.",
actions=["World responds with a tactical update."],
cycle_ms=42,
)
with logger.log_file.open("a", encoding="utf-8") as handle:
handle.write('{"id": "broken"\n')
output = logger.export_for_training(tmp_path / "training.jsonl")
exported_lines = output.read_text(encoding="utf-8").strip().splitlines()
assert len(exported_lines) == 1
exported_cycle = json.loads(exported_lines[0])
assert exported_cycle["id"].endswith("_cycle_0")
assert exported_cycle["message_count"] == 4