Skip to content
Open
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
4 changes: 3 additions & 1 deletion skillopt_sleep/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from skillopt_sleep.harvest import format_harvest_note
from skillopt_sleep.harvest_sources import harvest_for_config, normalize_transcript_source
from skillopt_sleep.memory import ensure_skill_scaffold
from skillopt_sleep.mine import group_tasks_by_skill_hint, mine
from skillopt_sleep.mine import group_tasks_by_skill_hint, mine, normalize_task_split
from skillopt_sleep.multi_skill import (
BUDGET_REACHED,
SKIPPED,
Expand Down Expand Up @@ -906,6 +906,8 @@ def budget_exhausted() -> bool:
digests: List[SessionDigest] = []
if seed_tasks is not None:
tasks = seed_tasks
for task in tasks:
task.split = normalize_task_split(task)
n_sessions = 0
_progress(cfg, f"using {len(tasks)} seeded tasks")
else:
Expand Down
7 changes: 7 additions & 0 deletions skillopt_sleep/mine.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ def normalize_legacy_split(value: str) -> str:
return {"replay": "train", "holdout": "val"}.get(value, value)


def normalize_task_split(task: TaskRecord) -> str:
"""Keep dream tasks in training, including when reusing saved splits."""
if task.origin == "dream":
return "train"
return normalize_legacy_split(task.split or "train")


def mine(
digests: List[SessionDigest],
*,
Expand Down
4 changes: 2 additions & 2 deletions skillopt_sleep/tasks_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any, Dict, List, Tuple

from skillopt_sleep.judges import validate_checks
from skillopt_sleep.mine import assign_splits, normalize_legacy_split
from skillopt_sleep.mine import assign_splits, normalize_task_split
from skillopt_sleep.types import TaskRecord


Expand Down Expand Up @@ -48,7 +48,7 @@ def _normalize_tasks(
seed: int,
) -> List[TaskRecord]:
for task in tasks:
task.split = normalize_legacy_split(task.split or "train")
task.split = normalize_task_split(task)
if len(tasks) >= 2 and not any(task.split in {"val", "test"} for task in tasks):
tasks = assign_splits(tasks, holdout_fraction=holdout_fraction, seed=seed)
return tasks
Expand Down
55 changes: 55 additions & 0 deletions tests/test_consolidate_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
"""
from __future__ import annotations

import json
import os
import tempfile
import unittest

import pytest

from skillopt_sleep.__main__ import main
from skillopt_sleep.config import load_config
from skillopt_sleep.consolidate import _split
from skillopt_sleep.cycle import run_sleep_cycle
from skillopt_sleep.tasks_file import load_tasks_file, write_tasks_file
from skillopt_sleep.types import TaskRecord

Expand All @@ -18,6 +24,55 @@ def _ids(tasks):
return sorted(t.id for t in tasks)


@pytest.mark.parametrize("entrypoint", ["tasks-file", "seeded-cycle"])
def test_dream_tasks_cannot_enter_either_measured_split(tmp_path, entrypoint):
project = tmp_path / "project"
project.mkdir()
claude_home = tmp_path / ".claude"
assignments = [
("real-train", "train", "real"),
("real-validation", "val", "real"),
("real-test", "test", "real"),
("dream-validation", "holdout", "dream"),
("dream-test", "test", "dream"),
]
tasks = [
TaskRecord(
id=task_id, project=str(project), intent=f"Check {task_id}",
split=split, origin=origin, reference_kind="exact", reference=task_id,
)
for task_id, split, origin in assignments
]
if entrypoint == "tasks-file":
tasks_path = write_tasks_file(
str(tmp_path / "tasks.json"),
{"reviewed": True, "tasks": [task.to_dict() for task in tasks]},
)
assert main([
"dry-run", "--backend", "mock", "--project", str(project),
"--claude-home", str(claude_home), "--tasks-file", tasks_path,
]) == 0
else:
cfg = load_config(
backend="mock", invoked_project=str(project), projects="invoked",
claude_home=str(claude_home),
)
run_sleep_cycle(cfg, seed_tasks=tasks, dry_run=True)

(evidence,) = tmp_path.rglob("dryrun-*.jsonl")
events = [json.loads(line) for line in evidence.read_text(encoding="utf-8").splitlines()]
splits = {event["task_id"]: event["split"] for event in events if event["event"] == "task_ready"}
assert splits == {
"real-train": "train",
"real-validation": "val",
"real-test": "test",
"dream-validation": "train",
"dream-test": "train",
}
(test_score,) = (event for event in events if event["event"] == "held_out_score")
assert test_score["n_test"] == 1


class TestConsolidateSplit(unittest.TestCase):
def test_all_test_batch_does_not_leak_into_train_or_val(self):
tasks = [
Expand Down