Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5a0d5e3
refactor(knowledge): build the recipe journal and KB writes from name…
Oct 19, 2026
c061f93
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 19, 2026
db3caec
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 19, 2026
20d0823
refactor(knowledge): merge a session's result into the live Recipe ro…
Oct 19, 2026
3ae9281
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
e420134
chore(metrics): lower the recipe journal's module-lines baseline afte…
Oct 20, 2026
47ff719
test(common): pin that a recorded measurement keeps a non-finite value
Oct 20, 2026
6658097
refactor(knowledge): delete five single-use units instead of moving them
Oct 20, 2026
db77fa1
test(common): pin the three inputs recorded_float and to_float disagr…
Oct 20, 2026
b005658
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
a69d8e5
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
2403ced
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
7e071de
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
28712f5
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
f9fa9c1
docs(knowledge): collapse the added helpers' docstrings to their summ…
Oct 20, 2026
dd913a0
chore(metrics): lower the module-lines baseline the docstring collaps…
Oct 20, 2026
fc74dc2
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
73a39a6
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 20, 2026
f0397f3
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 21, 2026
c151c71
refactor(knowledge): restore the units the ceiling never asked to change
Oct 21, 2026
fd848e0
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 21, 2026
54a5521
refactor(recipe-journal): delete the three sibling modules and their …
Oct 21, 2026
e37c399
refactor(recipe-journal): bring _record_fact_per_variant back under t…
Oct 21, 2026
a4e5f4b
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 21, 2026
cfa441e
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 22, 2026
b932fe6
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 22, 2026
00e5c40
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 22, 2026
9775393
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 22, 2026
cd7e73b
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 22, 2026
81ca18e
refactor(knowledge): delete what recipe_journal derived, coerced and …
Oct 22, 2026
cd6db85
refactor(knowledge): give the config timeline and the recipe attribut…
Oct 22, 2026
6aa2db1
Merge remote-tracking branch 'origin/main' into refactor/chenyi/cc20-…
Oct 22, 2026
feda1ad
chore(metrics): follow recipe_journal down to its split length
Oct 22, 2026
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
13 changes: 1 addition & 12 deletions scripts/code_metrics_baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ cognitive-complexity src/hyperloom/orchestrator/kernel/conc_sweep.py::_sweep_one
cognitive-complexity src/hyperloom/orchestrator/kernel/conc_sweep.py::run_conc_sweep 60
cognitive-complexity src/hyperloom/orchestrator/kernel/forge_fusion.py::_normalize_manifest 44
cognitive-complexity src/hyperloom/orchestrator/kernel/request_handlers.py::_resolve_forge_server_log 49
cognitive-complexity src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator._build_recipe_attrs_from_state 41
cognitive-complexity src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator._collect_attempt_provenance 34
cognitive-complexity src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator._collect_workload_tags 37
cognitive-complexity src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator.finalize_recipe_and_journal 48
cognitive-complexity src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator.kb_amend_recipe 49
cognitive-complexity src/hyperloom/orchestrator/knowledge/recipe_journal.py::_record_config_attempts 36
cognitive-complexity src/hyperloom/orchestrator/loop/writeback.py::WritebackCollaborator._drain_agent_keep_outbox 34
cognitive-complexity src/hyperloom/orchestrator/loop/writeback.py::WritebackCollaborator._keep_patch_sources 42
cognitive-complexity src/hyperloom/orchestrator/loop/writeback.py::WritebackCollaborator._promote_baseline 96
Expand Down Expand Up @@ -348,11 +342,6 @@ function-lines src/hyperloom/orchestrator/kernel/request_handlers.py::_run_forge
function-lines src/hyperloom/orchestrator/kernel/request_handlers.py::_run_forge_gemm_tuning 117
function-lines src/hyperloom/orchestrator/kernel/request_handlers.py::_run_integrate_rebaseline_with_lock_retry 106
function-lines src/hyperloom/orchestrator/kernel/request_handlers.py::integrate_handler 157
function-lines src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator._build_recipe_attrs_from_state 99
function-lines src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator._record_fact_per_variant 114
function-lines src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator.finalize_recipe_and_journal 211
function-lines src/hyperloom/orchestrator/knowledge/recipe_journal.py::RecipeJournalCollaborator.kb_amend_recipe 127
function-lines src/hyperloom/orchestrator/knowledge/recipe_journal.py::_record_config_attempts 136
function-lines src/hyperloom/orchestrator/knowledge/recipe_kb/local_store.py::LocalRecipeStore.put_recipe 102
function-lines src/hyperloom/orchestrator/knowledge/remote_recipe/client.py::RemoteRecipeClient.read 95
function-lines src/hyperloom/orchestrator/knowledge/remote_recipe/client.py::RemoteRecipeClient.write_if_better 82
Expand Down Expand Up @@ -491,7 +480,7 @@ module-lines src/hyperloom/orchestrator/actions/executors/roofline.py 1303
module-lines src/hyperloom/orchestrator/kernel/apply_kernel_patch.py 2656
module-lines src/hyperloom/orchestrator/kernel/conc_sweep.py 1429
module-lines src/hyperloom/orchestrator/kernel/request_handlers.py 4690
module-lines src/hyperloom/orchestrator/knowledge/recipe_journal.py 1671
module-lines src/hyperloom/orchestrator/knowledge/recipe_journal.py 1269
module-lines src/hyperloom/orchestrator/loop/coordinator.py 1337
module-lines src/hyperloom/orchestrator/loop/dispatcher.py 1453
module-lines src/hyperloom/orchestrator/loop/intent_router.py 1409
Expand Down
13 changes: 13 additions & 0 deletions src/hyperloom/common/coerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def to_float(value: Any, default: _T | None = None) -> float | _T | None:
return result if math.isfinite(result) else default


def recorded_float(value: Any, default: float = 0.0) -> float:
"""Coerce a recorded value to ``float``, keeping ``inf``, ``nan`` and ``bool`` as they were recorded.

:func:`to_float` returns *default* for those three instead, which would
render a degenerate figure as one nobody can tell from a real measurement.
"""
try:
return float(value or default)
except (TypeError, ValueError):
return default


def to_int(value: Any, default: _T | None = None) -> int | _T | None:
"""Coerce *value* to ``int``, rejecting ``bool``, ``None``, and non-finite floats."""
if value is None or isinstance(value, bool):
Expand Down Expand Up @@ -116,6 +128,7 @@ def to_list(value: Any) -> list[Any]:

__all__ = [
"to_float",
"recorded_float",
"to_int",
"first_float",
"first_int",
Expand Down
31 changes: 31 additions & 0 deletions src/hyperloom/inference_optimizer/tests/test_coerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
first_int,
first_str,
optional_positive_int,
recorded_float,
to_float,
to_int,
to_list,
Expand Down Expand Up @@ -69,6 +70,36 @@ def test_custom_default(self):
assert to_float(None, default=-1.0) == -1.0


class TestRecordedFloat:
@pytest.mark.parametrize(
"value,expected",
[
(1, 1.0),
(1.5, 1.5),
("2.5", 2.5),
(-4, -4.0),
],
)
def test_parses(self, value, expected):
assert recorded_float(value) == expected

@pytest.mark.parametrize("value", [None, "", "abc", object(), [1]])
def test_absent_or_unparseable_reads_as_the_default(self, value):
assert recorded_float(value) == 0.0
assert recorded_float(value, -1.0) == -1.0

def test_infinity_survives_so_a_degenerate_measurement_stays_visible(self):
assert recorded_float(float("inf")) == math.inf
assert recorded_float("Infinity") == math.inf
assert math.isnan(recorded_float(float("nan")))

@pytest.mark.parametrize("value", [float("inf"), float("nan"), True])
def test_keeps_what_to_float_rejects(self, value):
"""The three inputs on which the two coercions disagree, so a swap is never silent."""
assert to_float(value, 0.0) == 0.0
assert recorded_float(value) != 0.0 or math.isnan(recorded_float(value))


class TestToInt:
@pytest.mark.parametrize(
"value,expected",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
recipe_canonical_id,
)
from hyperloom.orchestrator.knowledge.config import KnowledgeConfig
from hyperloom.orchestrator.knowledge.recipe_journal import (
recipe_attrs_from_state,
)
from hyperloom.inference_optimizer.breakdown.recorder import close_out as _close_out


Expand Down Expand Up @@ -433,7 +436,7 @@ def test_best_config_reads_stack_args_from_canonical_server_key(
}
]
ss.cumulative_gain_validated = 10.0
attrs = coord.recipe_journal._build_recipe_attrs_from_state()
attrs = recipe_attrs_from_state(coord.shared_state, coord.session_dir.name)
assert attrs["best_config"]["extra_server_args"] == ("--page-size 32 --schedule-policy lpm"), (
"stack-layer launch args must be read from the canonical "
"extra_server_args key; got "
Expand Down Expand Up @@ -557,7 +560,7 @@ def test_session_entry_carries_throughput_date_and_actions(
]
ss.cumulative_gain_validated = 7.5
ss.cumulative_gain_validated_stack_len = 2
attrs = coord.recipe_journal._build_recipe_attrs_from_state()
attrs = recipe_attrs_from_state(coord.shared_state, coord.session_dir.name)
sessions = attrs.get("sessions") or []
assert sessions, "no session entry emitted"
s = sessions[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from hyperloom.orchestrator.loop.coordinator import Coordinator
from hyperloom.orchestrator.state.objective import TargetGainObjective
from hyperloom.inference_optimizer.protocol.intent import Intent, IntentType
from hyperloom.orchestrator.knowledge.recipe_journal import (
workload_kb_tags,
)
from hyperloom.orchestrator.loop.dispatcher import HeldLeases


Expand Down Expand Up @@ -560,7 +563,7 @@ def test_collect_workload_tags(coord: Coordinator, monkeypatch) -> None:
"workload_mode": "serving",
}

assert coord.recipe_journal._collect_workload_tags() == {
assert workload_kb_tags(coord.shared_state) == {
"framework": "sglang",
"model_class": "moe",
"model_name": "Qwen3-32B",
Expand Down Expand Up @@ -591,19 +594,19 @@ def test_workload_tags_read_ep_from_the_env_only_without_a_shared_state_value(co
ss = coord.shared_state
ss.ep = 8

tags = coord.recipe_journal._collect_workload_tags()
tags = workload_kb_tags(coord.shared_state)
assert tags["ep"] == 8
assert tags["pp"] == 3

ss.ep = 0
assert coord.recipe_journal._collect_workload_tags()["ep"] == 2
assert workload_kb_tags(coord.shared_state)["ep"] == 2


def test_an_unparseable_or_non_positive_parallelism_env_is_not_tagged(coord: Coordinator, monkeypatch) -> None:
monkeypatch.setenv("EP", "two")
monkeypatch.setenv("PP", "0")

tags = coord.recipe_journal._collect_workload_tags()
tags = workload_kb_tags(coord.shared_state)
assert "ep" not in tags
assert "pp" not in tags

Expand All @@ -618,7 +621,7 @@ def test_workload_tags_survive_a_resumed_null_fingerprint_meta(coord: Coordinato
ss.stack_fingerprint_meta = None
ss.baseline_workload_extra = None

assert coord.recipe_journal._collect_workload_tags() == {"framework": "vllm"}
assert workload_kb_tags(coord.shared_state) == {"framework": "vllm"}


def test_unknown_and_empty_fingerprint_entries_are_not_tagged(coord: Coordinator, monkeypatch) -> None:
Expand All @@ -634,7 +637,7 @@ def test_unknown_and_empty_fingerprint_entries_are_not_tagged(coord: Coordinator
"image_digest": "sha256:abc",
}

tags = coord.recipe_journal._collect_workload_tags()
tags = workload_kb_tags(coord.shared_state)
assert tags == {"framework": "vllm", "image_digest": "sha256:abc"}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
)
from hyperloom.orchestrator.loop.coordinator import AdvisoryServices, Coordinator
from hyperloom.orchestrator.knowledge.recipe_kb import LocalRecipeStore, RecipeKB
from hyperloom.orchestrator.knowledge.recipe_journal import (
attempt_provenance,
recipe_attrs_from_state,
)


def _make_coordinator(tmp_path: Path) -> Coordinator:
Expand Down Expand Up @@ -67,7 +71,7 @@ def test_collect_attempt_provenance_maps_keep_and_revert(tmp_path):
},
)

kept, kept_by_gap, reverted = coord.recipe_journal._collect_attempt_provenance()
kept, kept_by_gap, reverted = attempt_provenance(coord.shared_state)
assert kept == {"mtp_on": "https://pr/123"}
assert kept_by_gap == {"gap.research_hint.0": "https://pr/123"}
assert len(reverted) == 1
Expand Down Expand Up @@ -106,7 +110,7 @@ def test_provenance_resolves_by_gap_id_when_name_mismatches(tmp_path):
},
)

attrs = coord.recipe_journal._build_recipe_attrs_from_state()
attrs = recipe_attrs_from_state(coord.shared_state, coord.session_dir.name)
row = next(x for x in attrs["what_worked"] if x["name"] == "k007")
assert row["source"] == "https://pr/777"

Expand Down Expand Up @@ -142,7 +146,7 @@ def test_build_recipe_attrs_sediments_source_and_revert(tmp_path):
},
)

attrs = coord.recipe_journal._build_recipe_attrs_from_state()
attrs = recipe_attrs_from_state(coord.shared_state, coord.session_dir.name)
ww = attrs["what_worked"]
mtp = next(x for x in ww if x["name"] == "mtp_on")
assert mtp["source"] == "https://pr/123"
Expand Down Expand Up @@ -174,7 +178,7 @@ def test_sediment_toggle_off_keeps_recipe_ephemeral(tmp_path):
},
)

attrs = coord.recipe_journal._build_recipe_attrs_from_state()
attrs = recipe_attrs_from_state(coord.shared_state, coord.session_dir.name)
mtp = next(x for x in attrs["what_worked"] if x["name"] == "mtp_on")
assert "source" not in mtp

Expand Down Expand Up @@ -219,7 +223,7 @@ def test_experience_rows_survive_the_kb_round_trip(tmp_path):
model="m",
hardware="h",
framework_name="f",
# Exactly what recipe_journal._build_recipe_attrs_from_state emits.
# Exactly what recipe_journal.recipe_attrs_from_state emits.
what_worked=[
{
"name": "mtp_on",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3126,7 +3126,7 @@ def test_remote_read_is_wired_into_cli_t0_and_close_write_remains() -> None:
fromlist=["_bootstrap_recipe_kb"],
)._bootstrap_recipe_kb
)
close_source = inspect.getsource(RecipeJournalCollaborator.finalize_recipe_and_journal)
close_source = inspect.getsource(RecipeJournalCollaborator._publish_remote_recipe)
assert "RemoteWarmRecipeAdapter" in bootstrap_source
assert "HyperloomRemoteKB.from_env().write" in close_source
assert "write_final_remote_recipe" not in close_source
Expand Down
Loading
Loading