Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(data): refuse a single file for --format soup-serve and say when a (#1557)

vaputa251e9c2414eb
diff --git a/changelog.d/0.75.1/1557.fixed.md b/changelog.d/0.75.1/1557.fixed.md
new file mode 100644
index 00000000..00c5651e
--- /dev/null
+++ b/changelog.d/0.75.1/1557.fixed.md
@@ -0,0 +1 @@
+- Fix `soup data from-traces --format soup-serve` silently writing an empty output (exit 0, `Wrote 0 preference pair(s)`) when `--logs` pointed at a single file: the soup-serve reader wants the directory `soup serve --trace-log` writes, and a file is now refused with a message naming the option and the expected shape; a source that reads zero traces at all now says so ahead of the count line, so an empty output no longer reads the same as a completed harvest (#1530 by @vaputa in #1557).
diff --git a/docs/data.md b/docs/data.md
index d8b6f7f8..cdad0c55 100644
--- a/docs/data.md
+++ b/docs/data.md
@@ -550,8 +550,9 @@ soup data from-traces --logs ./logs/openai.jsonl \
--format openai --signal regenerations --output prefs.jsonl
# Soup-serve logs + user-edit signal (edited response wins over original).
-# `--logs` is a DIRECTORY of *.jsonl: the soup-serve parser reads a directory,
-# and returns nothing for a single file (#1440).
+# `--logs` is a DIRECTORY of *.jsonl (one per `soup serve` session): the
+# soup-serve format reads a directory; a single file is refused at the
+# CLI — read a single JSONL with --format langchain or openai instead (#1530).
soup data from-traces --logs ./traces \
--format soup-serve --signal user_edit --output prefs.jsonl
diff --git a/src/soup_cli/commands/data.py b/src/soup_cli/commands/data.py
index 5b0969de..fdd99bab 100644
--- a/src/soup_cli/commands/data.py
+++ b/src/soup_cli/commands/data.py
@@ -1990,7 +1990,12 @@ def unregister_data(
@app.command(name="from-traces")
def from_traces_cmd(
logs: str = typer.Option(
- ..., "--logs", help="Path to JSONL trace log (or directory for soup-serve)",
+ ..., "--logs",
+ help=(
+ "Trace source: a JSONL file for langchain/openai, or the directory "
+ "`soup serve --trace-log` writes for soup-serve (a single file is "
+ "refused)"
+ ),
),
format: str = typer.Option(
..., "--format", help="Trace format: langchain | openai | soup-serve",
@@ -2064,6 +2069,21 @@ def from_traces_cmd(
if not logs_path.exists():
console.print(f"[red]--logs not found: {logs}[/]")
raise typer.Exit(1)
+ if format == "soup-serve" and not logs_path.is_dir():
+ # #1530: the soup-serve reader walks a directory of *.jsonl logs (one
+ # per `soup serve` session); pointed at a single file it silently read
+ # nothing and the run ended in a green "Wrote 0 preference pair(s)",
+ # exit 0, and an empty output file a pipeline would train from.
+ # Refuse — the smaller of the two fixes the issue proposed — and name
+ # the option and the shape the reader expects.
+ console.print(
+ f"[red]--logs '{_escape(logs)}' is not a directory: --format "
+ "soup-serve reads the directory `soup serve --trace-log` writes "
+ "(one *.jsonl per session), not a single file. Point --logs at "
+ "that directory, or read a single JSONL with --format langchain "
+ "or openai.[/]"
+ )
+ raise typer.Exit(1)
output_path = Path(output)
if not _under_cwd(output_path):
@@ -2104,6 +2124,27 @@ def from_traces_cmd(
trace_list = list(trace_iter)
pairs = list(build_pairs(trace_list, signal=signal))
+ if not pairs and not trace_list:
+ # #1530: reading zero traces used to fall straight through to the same
+ # green "Wrote 0 preference pair(s)" as a completed harvest. Say so and
+ # name the path. The zero-pair EXIT CODE is a design question the
+ # maintainer has left open, so it is deliberately unchanged here.
+ if format == "soup-serve":
+ reason = "the directory holds no readable *.jsonl trace files"
+ elif logs_path.is_dir():
+ # The file readers never opened anything here, so "no line
+ # parsed" would misreport a shape problem as a content problem.
+ reason = (
+ f"--logs is a directory; --format {format} reads a "
+ "single JSONL file"
+ )
+ else:
+ article = "an" if format == "openai" else "a"
+ reason = f"no line parsed as {article} {format} record"
+ console.print(
+ f"[yellow]Read 0 trace(s) from --logs '{_escape(logs)}' as format "
+ f"{format}: {reason}. The output file will be empty.[/]"
+ )
if not pairs and trace_list:
# #1440: reading traces that match no pair mode used to print a normal
# green "Wrote 0 preference pair(s)" and exit 0, so an empty output file
diff --git a/tests/test_issue1530_from_traces_file_logs.py b/tests/test_issue1530_from_traces_file_logs.py
new file mode 100644
index 00000000..fc5c2977
--- /dev/null
+++ b/tests/test_issue1530_from_traces_file_logs.py
@@ -0,0 +1,185 @@
+"""#1530 — `--format soup-serve` must refuse a file, not harvest zero pairs.
+
+``parse_soup_serve`` returns nothing for a non-directory, so
+``soup data from-traces --logs session.jsonl --format soup-serve`` ended in a
+green ``Wrote 0 preference pair(s)``, exit 0, and an empty output file a
+pipeline would train from. The fix refuses the file at the CLI boundary (the
+smaller of the two changes the issue proposed) and, when a source reads zero
+traces at all, says so instead of falling through to the same green line.
+
+The zero-pair EXIT CODE is deliberately unchanged: whether an empty harvest
+should fail the command is a design question the maintainer has left open.
+"""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+from typer.testing import CliRunner
+
+from tests.conftest import strip_ansi
+
+
+def _runner(tmp_path, monkeypatch) -> CliRunner:
+ monkeypatch.chdir(tmp_path)
+ return CliRunner()
+
+
+def _write_jsonl(path: Path, rows) -> None:
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(
+ "".join(json.dumps(row, ensure_ascii=False) + "\n" for row in rows),
+ encoding="utf-8",
+ )
+
+
+def _from_traces(runner, logs: str, fmt: str, signal: str = "thumbs_up"):
+ from soup_cli.cli import app
+
+ return runner.invoke(app, [
+ "data", "from-traces", "--logs", logs, "--format", fmt,
+ "--signal", signal, "-o", "prefs.jsonl",
+ ])
+
+
+# --------------------------------------------------------------------------- #
+# The refusal: a single file under --format soup-serve
+# --------------------------------------------------------------------------- #
+
+
+def test_soup_serve_refuses_a_single_file_instead_of_writing_an_empty_output(
+ tmp_path, monkeypatch,
+):
+ """The headline: exit non-zero, name --logs, and say what shape it wants."""
+ runner = _runner(tmp_path, monkeypatch)
+ # Rows a user would swear are readable — the refusal is about the SHAPE
+ # (file vs directory), and losing the data to a green 0-pair line is the
+ # bug, so the records are valid soup-serve records.
+ _write_jsonl(
+ tmp_path / "session.jsonl",
+ [
+ {"id": "1", "prompt": "Q", "response": "Good", "signal": "thumbs_up"},
+ {"id": "2", "prompt": "Q", "response": "Bad", "signal": "thumbs_down"},
+ ],
+ )
+ result = _from_traces(runner, "session.jsonl", "soup-serve")
+ text = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code != 0, text
+ assert "is not a directory" in text, text
+ # The option and the expected shape are named, so the mistake is fixable.
+ assert "--logs 'session.jsonl'" in text, text
+ assert "soup serve --trace-log" in text, text
+ # The usable alternative for a single JSONL is named too.
+ assert "--format langchain" in text and "openai" in text, text
+ # Refused before anything was written.
+ assert not (tmp_path / "prefs.jsonl").exists()
+
+
+def test_a_real_soup_serve_directory_still_harvests(tmp_path, monkeypatch):
+ """Control: the refusal is scoped to files; a directory keeps pairing."""
+ runner = _runner(tmp_path, monkeypatch)
+ _write_jsonl(
+ tmp_path / "traces" / "t.jsonl",
+ [
+ {"id": "1", "prompt": "Q", "response": "Good", "signal": "thumbs_up"},
+ {"id": "2", "prompt": "Q", "response": "Bad", "signal": "thumbs_down"},
+ ],
+ )
+ result = _from_traces(runner, "traces", "soup-serve")
+ text = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code == 0, text
+ assert "Wrote 1 preference pair(s)" in text, text
+
+
+def test_single_files_still_read_for_langchain(tmp_path, monkeypatch):
+ """Control: only soup-serve refuses a file; langchain keeps reading one."""
+ runner = _runner(tmp_path, monkeypatch)
+ _write_jsonl(
+ tmp_path / "langchain.jsonl",
+ [{
+ "id": "1",
+ "inputs": {"prompt": "Q"},
+ "outputs": {"text": "A"},
+ "feedback": [{"key": "thumbs", "score": 1}],
+ }],
+ )
+ result = _from_traces(runner, "langchain.jsonl", "langchain")
+ text = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code == 0, text
+ assert "is not a directory" not in text, text
+
+
+# --------------------------------------------------------------------------- #
+# Zero traces read: said out loud, exit code untouched
+# --------------------------------------------------------------------------- #
+
+
+def test_an_empty_directory_says_it_read_nothing(tmp_path, monkeypatch):
+ runner = _runner(tmp_path, monkeypatch)
+ (tmp_path / "traces").mkdir()
+ result = _from_traces(runner, "traces", "soup-serve")
+ text = " ".join(strip_ansi(result.output).split())
+ # The zero-pair exit code is the maintainer's open question — unchanged.
+ assert result.exit_code == 0, text
+ assert "Read 0 trace(s)" in text, text
+ # The path is named, so the reader can see which --logs read nothing.
+ assert "--logs 'traces'" in text, text
+ assert "no readable *.jsonl trace files" in text, text
+
+
+def test_a_dir_holding_only_non_jsonl_files_also_says_it_read_nothing(
+ tmp_path, monkeypatch,
+):
+ """The parser walks *.jsonl only; a dir of .txt files is the same trap."""
+ runner = _runner(tmp_path, monkeypatch)
+ (tmp_path / "traces").mkdir()
+ (tmp_path / "traces" / "t.txt").write_text("not a trace\n", encoding="utf-8")
+ result = _from_traces(runner, "traces", "soup-serve")
+ text = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code == 0, text
+ assert "Read 0 trace(s)" in text, text
+
+
+def test_a_langchain_file_no_line_of_which_parses_says_it_read_nothing(
+ tmp_path, monkeypatch,
+):
+ """The file formats share the message, with their own reason."""
+ runner = _runner(tmp_path, monkeypatch)
+ (tmp_path / "garbage.jsonl").write_text("not json\nalso not json\n", encoding="utf-8")
+ result = _from_traces(runner, "garbage.jsonl", "langchain")
+ text = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code == 0, text
+ assert "Read 0 trace(s)" in text, text
+ assert "no line parsed as a langchain record" in text, text
+
+
+def test_a_directory_under_a_file_format_names_the_shape_not_the_content(
+ tmp_path, monkeypatch,
+):
+ """langchain/openai only read files; a directory read nothing at all.
+
+ Saying "no line parsed" there misreports a shape problem (directory where
+ a JSONL file belongs) as a content problem, so the reason names the shape.
+ """
+ runner = _runner(tmp_path, monkeypatch)
+ (tmp_path / "traces").mkdir()
+ result = _from_traces(runner, "traces", "langchain")
+ text = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code == 0, text
+ assert "Read 0 trace(s)" in text, text
+ assert (
+ "--logs is a directory; --format langchain reads a single JSONL file"
+ in text
+ ), text
+ assert "no line parsed" not in text, text
+
+
+def test_the_openai_reason_uses_the_right_article(tmp_path, monkeypatch):
+ """Review nit: 'a openai record' read badly; keep the grammar pinned."""
+ runner = _runner(tmp_path, monkeypatch)
+ (tmp_path / "garbage.jsonl").write_text("not json\n", encoding="utf-8")
+ result = _from_traces(runner, "garbage.jsonl", "openai")
+ text = " ".join(strip_ansi(result.output).split())
+ assert result.exit_code == 0, text
+ assert "no line parsed as an openai record" in text, text