Skip to content
Draft
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
10 changes: 3 additions & 7 deletions artemis/config/attempt_lifecycle_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,19 @@ def record_attempt_manifest(
"""
try:
from artemis.config.attempt_manifest import (
TIER_MODELS,
ManifestAlreadyExistsError,
build_attempt_manifest,
store_attempt_manifest,
tier_for_provider_model,
)
import os

tier = None
for candidate_tier, (provider, model_name) in TIER_MODELS.items():
if llm_config.planner.provider == provider and llm_config.planner.model == model_name:
tier = candidate_tier
break
tier = tier_for_provider_model(llm_config.planner.provider, llm_config.planner.model)
if tier is None:
print(
f"Attempt manifest [{checkpoint}] skipped: planner "
f"{llm_config.planner.provider}/{llm_config.planner.model} does not match "
"a declared tier in attempt_manifest.TIER_MODELS."
"a declared route in artemis.config.attempt_manifest."
)
return

Expand Down
20 changes: 16 additions & 4 deletions artemis/config/attempt_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@
"sol": ("openai", "gpt-5.6-sol"),
"nova": ("anthropic", "claude-sonnet-5"),
}
TIER_MODEL_ALIASES: dict[tuple[str, str], Tier] = {
("openai", "gpt-6.1-sol"): "sol",
}


def tier_for_provider_model(provider: str | None, model: str | None) -> Tier | None:
"""Resolve a tier from an exact declared provider/model route."""
if provider is None or model is None:
return None
route = (provider, model)
for tier, canonical_route in TIER_MODELS.items():
if route == canonical_route:
return tier
return TIER_MODEL_ALIASES.get(route)


# Environment variables whose presence/value can influence LLMConfig
# resolution and must be captured (never their raw secret value) in the
Expand Down Expand Up @@ -272,10 +287,7 @@ def _llm_node_snapshot(llm: LLM | LLMWithFallback) -> dict[str, Any]:

def _node_tier(llm: LLM | LLMWithFallback) -> Tier | None:
"""Which declared tier (if any) this node's primary provider/model matches."""
for tier, (provider, model) in TIER_MODELS.items():
if llm.provider == provider and llm.model == model:
return tier
return None
return tier_for_provider_model(llm.provider, llm.model)


@dataclasses.dataclass(frozen=True)
Expand Down
17 changes: 10 additions & 7 deletions artemis/config/attempt_reconciliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
from pathlib import Path
from typing import Any, Literal

from artemis.config.attempt_manifest import TIER_MODELS, Tier, digest_of, read_stored_manifest
from artemis.config.attempt_manifest import (
TIER_MODELS,
Tier,
digest_of,
read_stored_manifest,
tier_for_provider_model,
)
from artemis.config.attempt_usage_reader import read_llm_usage_events
from artemis.runtime import trace_store

Expand Down Expand Up @@ -241,13 +247,10 @@ def _tier_of_provider_model(provider: str | None, model: str | None) -> Tier | N
Dict-based counterpart of ``attempt_manifest._node_tier`` (which takes an
``LLM``/``LLMWithFallback`` instance): this module only ever sees the
already-serialized ``config``/``would_resolve_to`` dicts a stored manifest
carries, never the original ``LLM`` objects, so it re-does the same
``TIER_MODELS`` lookup directly against those two plain strings.
carries, never the original ``LLM`` objects, so it uses the shared exact-route
resolver against those two plain strings.
"""
for tier, (tier_provider, tier_model) in TIER_MODELS.items():
if provider == tier_provider and model == tier_model:
return tier
return None
return tier_for_provider_model(provider, model)


def _manifest_expected_source(node_entry: dict[str, Any], manifest_tier: Tier | None) -> str | None:
Expand Down
76 changes: 76 additions & 0 deletions tests/unit/config/test_attempt_reconciliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,82 @@ def test_no_stored_manifest_returns_none_not_a_verdict(self, tmp_path, _isolate_
)
assert result is None

def test_gpt_61_sol_lifecycle_records_route_and_accepts_synthetic_receipts(
self, tmp_path, monkeypatch, _isolate_traces_dir
):
"""Offline synthetic lifecycle coverage for the selected Sol route."""
import json

from artemis.config import paths
from artemis.config.attempt_lifecycle_hooks import (
reconcile_and_store_verdict,
record_attempt_manifest,
)
from artemis.config.attempt_manifest import read_stored_manifest

trace_id = "trace-gpt-61-sol-synthetic"
api_base = "https://gateway.synthetic.invalid/v1"
traces_dir = tmp_path / "traces"
db_path = tmp_path / "synthetic-usage.db"
monkeypatch.setattr(trace_store, "TRACES_DIR", str(traces_dir))
monkeypatch.setattr(paths, "get_traces_dir", lambda: traces_dir)
monkeypatch.setattr(paths, "get_data_engine_db_path", lambda: db_path)
monkeypatch.delenv("ARTEMIS_FAKE_LLM", raising=False)

llm = LLMWithFallback(
provider="openai",
model="gpt-6.1-sol",
api_base=api_base,
fallback=LLM(provider="openai", model="gpt-6.1-sol", api_base=api_base),
)
config = LLMConfig(
**{node: llm for node in _REQUIRED_NODES},
utils=LLMConfigUtils(outputter=llm, hopper=llm),
)

storage = StorageManager(db_path, traces_dir)
storage.create_session(
SessionMetadata(session_id=trace_id, initial_goal="synthetic lifecycle test")
)
for node in _REQUIRED_NODES:
storage.create_trace(
TraceRecord(
trace_id=f"synthetic-usage-{node}",
session_id=trace_id,
type="llm_call",
name="llm_usage",
payload={
"node": node,
"source": "openai:gpt-6.1-sol",
"synthetic": True,
},
)
)

record_attempt_manifest(
trace_id=trace_id,
checkpoint="launch",
llm_config=config,
)

stored = read_stored_manifest(trace_id, "launch")
assert stored is not None, "selected Sol route must store a launch manifest"
manifest = json.loads(stored[0].decode("utf-8"))
assert manifest["tier"] == "sol"
assert manifest["fake_llm_enabled"] is False
for node in ("planner", "checker"):
entry = manifest["nodes"][node]
assert entry["resolved_tier"] == "sol"
assert entry["config"]["provider"] == "openai"
assert entry["config"]["model"] == "gpt-6.1-sol"
assert entry["config"]["api_base"] == api_base

reconcile_and_store_verdict(trace_id=trace_id)
verdict_path = traces_dir / trace_id / "attempt_reconciliation_verdict.json"
verdict = json.loads(verdict_path.read_text(encoding="utf-8"))
assert verdict["accepted"] is True
assert verdict["reason"] is None

def test_matching_usage_accepts_the_attempt(self, tmp_path, _isolate_traces_dir):
trace_id = "trace-accept"
manifest = _manifest(attempt_id=trace_id, trace_id=trace_id)
Expand Down
Loading