Routing/transport/execution family (heavy-port lane factory-heavy-ro-exec, worktree rune-wave-rp): the 25 audit-named missing fns ported name-preserving to src/go/operator-deep/gaps_execution.go — both _build_model_router defs, _sorted_tool_names, _filter_safety_noise, _wire_auto_filer, _reconcile_guarded, _transport_for, _runtime_for_model, _capability_selection, _conversation_messages, _attach_runtime_objects, _apply_runtime_result, _ensure_canonical, _channel_for_task, _response_envelope, _context_broker, the six _contributor_* blocks, _execute_on_model with its nested _fold_attempt, _finalize_runtime_response, _log_token_usage. Frozen truth 72 rows (truth_execution.json, scripts/roexec_freeze.py — pinned clock/uuid/monotonic rig, journaling seam fakes, id-placeholder law) regenerated byte-identical x3 (sha256 866f958e); battery 72/72 + full operator-deep suite green; live parity frozen==regen (scripts/check_ro_exec_parity.py, exit 0); gofmt/vet/build clean; pytest 53 passed BOTH pins (RUNE_OPERATOR_CORE pin proven vacuous); audit rune_operator 29/68 PARTIAL -> 56/68 FULL (GO), wave 128/192. Evidence: verification/roexec-*.exit + summary-roexec.md (logs gitignored).
964 lines
44 KiB
Python
964 lines
44 KiB
Python
#!/usr/bin/env python3
|
|
"""roexec_freeze — frozen-truth generator for the rune_operator
|
|
routing/transport/execution family gap-close (#2479 dichotomy wave, GO
|
|
verdict, worktree rune-wave-rp).
|
|
|
|
Oracle: /mnt/workdrive/rune/src/rune/rune_operator.py — the 25 audit-named
|
|
missing fns of the family (both _build_model_router defs, the six
|
|
_contributor_* blocks, _context_broker, _execute_on_model, _fold_attempt,
|
|
_finalize_runtime_response, _log_token_usage, _transport_for,
|
|
_runtime_for_model, _capability_selection, _conversation_messages,
|
|
_attach_runtime_objects, _apply_runtime_result, _ensure_canonical,
|
|
_channel_for_task, _response_envelope, _sorted_tool_names,
|
|
_filter_safety_noise, _wire_auto_filer, _reconcile_guarded).
|
|
|
|
Determinism rig (truth laws):
|
|
* HOME="." inside a throwaway cwd — every derived path is repo-relative
|
|
* frozen clock via freeze_rigs.pin_clock patched into rune_operator AND
|
|
rune.tool_protocol (the _utc_now_iso default_factory reads the module
|
|
global at call time)
|
|
* uuid4().hex -> deterministic 1..n counter sequence (memory_consolidation
|
|
entry_id law)
|
|
* time.monotonic -> fixed 0.25 ladder (no wall clock in expected values);
|
|
TaskStateRecord.updated_at (a default_factory wall clock) is excluded
|
|
from import_record journals
|
|
* every seam (model_profiles, safety_override, capability_broker,
|
|
ContextBroker, LocalToolRuntime, transports, inference_trace,
|
|
model_routing, event_bus, failure_auto_filer, forge_client,
|
|
subsystem_health) replaced with journaling fakes BEFORE the cases run;
|
|
expected values carry the returned value + the observed side-effect
|
|
journal
|
|
* dict-order-bearing outputs (response envelope) are frozen as EXACT
|
|
json.dumps strings (insertion-order law); everything else compares
|
|
structurally
|
|
|
|
Writes src/go/operator-deep/truth_execution.json. Re-run twice; the file
|
|
must be byte-identical (regen law).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import dataclasses
|
|
import itertools
|
|
import json
|
|
import re
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
from types import SimpleNamespace as NS
|
|
|
|
WORKTREE = Path(__file__).resolve().parents[1]
|
|
ORACLE_SRC = Path("/mnt/workdrive/rune/src")
|
|
sys.path.insert(0, str(WORKTREE / "scripts"))
|
|
|
|
from freeze_rigs import pin_clock # noqa: E402
|
|
|
|
FROZEN_NOW = "2026-10-14T12:00:00"
|
|
TRUTH_OUT = WORKTREE / "src" / "go" / "operator-deep" / "truth_execution.json"
|
|
|
|
# ── the rig environment, BEFORE any rune import ─────────────────────────
|
|
_SCRATCH = tempfile.mkdtemp(prefix="roexec-freeze-")
|
|
os.chdir(_SCRATCH)
|
|
os.environ["HOME"] = "."
|
|
for var in list(os.environ):
|
|
if var.startswith("RUNE_"):
|
|
del os.environ[var]
|
|
sys.path.insert(0, str(ORACLE_SRC))
|
|
|
|
import rune.rune_operator as ro # noqa: E402
|
|
from rune import capability_broker, context_broker, event_bus, failure_auto_filer # noqa: E402
|
|
from rune import forge_client, inference_trace, memory_env, model_routing # noqa: E402
|
|
from rune import openai_compat_transport, subsystem_health, tool_protocol # noqa: E402
|
|
|
|
# ── deterministic clock / uuid / monotonic ──────────────────────────────
|
|
FrozenDT = pin_clock(FROZEN_NOW)
|
|
ro.datetime = FrozenDT
|
|
tool_protocol.datetime = FrozenDT
|
|
|
|
_SEQ = itertools.count(1)
|
|
|
|
|
|
class _U4:
|
|
def __init__(self, hex_: str) -> None:
|
|
self.hex = hex_
|
|
|
|
|
|
def _uuid4() -> _U4:
|
|
return _U4(f"{next(_SEQ):032x}")
|
|
|
|
|
|
ro.uuid = NS(uuid4=_uuid4)
|
|
|
|
_MONO = itertools.count(0)
|
|
ro.time = NS(monotonic=lambda: next(_MONO) * 0.25)
|
|
|
|
# ── the journal (every observable side effect) ──────────────────────────
|
|
J: list[str] = []
|
|
|
|
|
|
def journal(kind: str, **kw) -> None:
|
|
J.append(f"{kind}|{json.dumps(kw, ensure_ascii=False)}")
|
|
|
|
|
|
# ── seam fakes ──────────────────────────────────────────────────────────
|
|
FAKE_TOOLS = [
|
|
{"name": "read_file", "schema": {"type": "object"}},
|
|
{"name": "run_command", "schema": {"type": "object"}},
|
|
{"name": "find_capability", "schema": {"type": "object"}},
|
|
]
|
|
ro.tool_executor.TOOLS = FAKE_TOOLS
|
|
|
|
|
|
def _select_for_job(description, need_tools=False):
|
|
journal("broker_select", description=description, need_tools=need_tools)
|
|
mode = SELECT_MODE[0]
|
|
if mode == "raise":
|
|
raise RuntimeError("broker down")
|
|
if mode == "empty":
|
|
return {"tools": [], "names": []}
|
|
return {
|
|
"tools": [FAKE_TOOLS[0]],
|
|
"names": ["read_file"],
|
|
"reason": "matched read for file task",
|
|
"task_family": "code",
|
|
}
|
|
|
|
|
|
SELECT_MODE = ["ok"]
|
|
capability_broker.select_for_job = _select_for_job
|
|
|
|
subsystem_health.record_failure = lambda subsystem, exc, tier=1, context="": journal(
|
|
"health", subsystem=subsystem, detail=str(exc), tier=tier, context=context
|
|
)
|
|
subsystem_health.set_auto_filer = lambda filer: journal(
|
|
"set_auto_filer", filer=type(filer).__name__
|
|
)
|
|
|
|
ro.safety_override.SafetyOverride = lambda: NS(
|
|
get_params=lambda desc: {"tier": 0, "reason": "baseline"},
|
|
is_refusal=lambda text: text.startswith("REFUSE"),
|
|
report_outcome=lambda desc, text, meta: journal(
|
|
"override_outcome", tier=meta.get("tier"), refusal=text.startswith("REFUSE")
|
|
),
|
|
)
|
|
ro.safety_override.ESCALATION_TIERS = {
|
|
0: {"prefix": "", "suffix": "", "temperature": 0.7},
|
|
1: {"prefix": "[T1] ", "suffix": " //t1", "temperature": 0.5},
|
|
2: {"prefix": "[T2] ", "suffix": " //t2", "temperature": 0.3},
|
|
3: {"prefix": "[T3] ", "suffix": " //t3", "temperature": 0.1},
|
|
}
|
|
|
|
PROFILE_TIER = [2]
|
|
ro.model_profiles.get_or_create_profile = lambda model: NS(safety_tier=PROFILE_TIER[0])
|
|
ro.model_profiles.get_prompt_context = lambda model: (
|
|
None if not model or model.startswith("silent") else f"profile-context:{model}"
|
|
)
|
|
ro.model_profiles.record_interaction = lambda model, ok, topic: journal(
|
|
"interaction", model=model, ok=ok, topic=topic
|
|
)
|
|
|
|
|
|
class _Ollama:
|
|
def __init__(self, timeout: float = 300.0) -> None:
|
|
self.timeout = timeout
|
|
|
|
|
|
ro.OllamaChatTransport = _Ollama
|
|
openai_compat_transport.cloud_transport_for = lambda model, timeout=120: NS(
|
|
kind="cloud", provider=model.split("/", 1)[0], model=model, timeout=timeout
|
|
)
|
|
# is_cloud_pinned stays REAL (pure prefix rule — the single authority).
|
|
|
|
memory_env.rune_home = lambda: "./.rune"
|
|
model_routing.default_profiles_path = lambda: "./.rune/state/routing_profiles.json"
|
|
model_routing.update_profiles_from_traces = lambda path, records: (
|
|
journal("profiles_merge", path=str(path), count=len(records)) or {"merged": len(records)}
|
|
)
|
|
model_routing.save_profiles = lambda path, merged: journal("profiles_save", path=str(path))
|
|
|
|
event_bus._store_path = lambda: "./.rune/events.jsonl"
|
|
inference_trace.price_for = lambda model: 0.002 if model.startswith("Cloud/") else None
|
|
inference_trace.record_trace = lambda record: journal(
|
|
"trace_record", record=dataclasses.asdict(record)
|
|
)
|
|
|
|
|
|
def describe_transport(t) -> dict:
|
|
return {"kind": getattr(t, "kind", "ollama"), "timeout": getattr(t, "timeout", None),
|
|
"provider": getattr(t, "provider", None)}
|
|
|
|
|
|
class _FakeRuntime:
|
|
"""LocalToolRuntime stand-in: captures construction + scripted runs."""
|
|
|
|
built: list["_FakeRuntime"] = []
|
|
SCRIPT: list = []
|
|
|
|
def __init__(self, transport=None, executor=None, model="", tools=None) -> None:
|
|
self.built_transport = transport
|
|
self.transport = NS(
|
|
provider="fakeprov",
|
|
usage_calls=0, usage_prompt_tokens=0, usage_output_tokens=0,
|
|
usage_total_duration_ns=0, last_prompt_eval_count=42,
|
|
)
|
|
self.tool_names = tuple(t["name"] for t in (tools or []))
|
|
self.model = model
|
|
self.messages_seen: list | None = None
|
|
self.options_seen: dict | None = None
|
|
_FakeRuntime.built.append(self)
|
|
|
|
def run(self, messages, options=None, think=False):
|
|
self.messages_seen = [dict(m) for m in messages]
|
|
self.options_seen = dict(options or {})
|
|
scripted = _FakeRuntime.SCRIPT.pop(0)
|
|
self.transport.usage_calls += scripted.pop("usage_calls", 1)
|
|
self.transport.usage_prompt_tokens += scripted.pop("usage_prompt_tokens", 10)
|
|
self.transport.usage_output_tokens += scripted.pop("usage_output_tokens", 20)
|
|
self.transport.usage_total_duration_ns += scripted.pop("usage_total_duration_ns", 250_000_000)
|
|
self.transport.last_prompt_eval_count = scripted.pop("last_prompt_eval_count", 42)
|
|
return scripted["response"]
|
|
|
|
|
|
ro.LocalToolRuntime = _FakeRuntime
|
|
|
|
|
|
class _FakeSelector:
|
|
MODE = ["ok"]
|
|
|
|
def select_for_task(self, description: str):
|
|
journal("memory_select", description=description)
|
|
mode = _FakeSelector.MODE[0]
|
|
if mode == "raise":
|
|
raise RuntimeError("selector exploded")
|
|
if mode == "empty":
|
|
return NS(candidates_evaluated=5, selected_count=0, abstained=True,
|
|
types_queried=["memory"], blocks=[])
|
|
return NS(
|
|
candidates_evaluated=4, selected_count=2, abstained=False,
|
|
types_queried=["memory", "neurons"],
|
|
blocks=[NS(content="neuron: prefer local models"), NS(content=""), NS(content=" ")],
|
|
)
|
|
|
|
|
|
class _FakeBroker:
|
|
INSTANCES: list["_FakeBroker"] = []
|
|
MEMORY_SELECTOR: list = [_FakeSelector()]
|
|
|
|
def __init__(self, archive_path=None) -> None:
|
|
self.archive_path = archive_path
|
|
self.registrations: list[tuple] = []
|
|
self.memory_selector = _FakeBroker.MEMORY_SELECTOR[0]
|
|
_FakeBroker.INSTANCES.append(self)
|
|
|
|
def register_contributor(self, name, fn, bucket):
|
|
self.registrations.append((name, bucket, fn.__name__))
|
|
|
|
|
|
context_broker.ContextBroker = _FakeBroker
|
|
MEMORY_OFF = [False]
|
|
context_broker.memory_disabled = lambda: MEMORY_OFF[0]
|
|
context_broker.log_calibration = lambda estimated, served, model: journal(
|
|
"calibration", estimated=estimated, served=served, model=model
|
|
)
|
|
|
|
|
|
class _Log:
|
|
def exception(self, msg, *a) -> None:
|
|
journal("log_exception", message=msg % a if a else msg)
|
|
|
|
|
|
def _make_filer(client, spool):
|
|
journal("auto_filer", client=type(client).__name__, spool=str(spool))
|
|
return NS(kind="FailureAutoFiler", reconcile=lambda: journal("reconcile"))
|
|
|
|
|
|
failure_auto_filer.FailureAutoFiler = _make_filer
|
|
failure_auto_filer.JsonlSpool = lambda path: f"spool:{path}"
|
|
failure_auto_filer._LOG = _Log()
|
|
forge_client.create_forge_client = lambda: NS(kind="forge-client")
|
|
|
|
|
|
class _Thread:
|
|
SPECS: list[dict] = []
|
|
|
|
def __init__(self, target=None, args=(), daemon=False, name=None) -> None:
|
|
self.started = False
|
|
_Thread.SPECS.append({"target": target.__name__,
|
|
"args": [type(a).__name__ for a in args],
|
|
"daemon": daemon, "name": name})
|
|
|
|
def start(self) -> None:
|
|
self.started = True
|
|
|
|
|
|
__import__("threading").Thread = _Thread
|
|
|
|
|
|
# ── receiver construction ───────────────────────────────────────────────
|
|
TASK_STATE: dict[str, NS] = {}
|
|
WINDOW: list[dict] = []
|
|
|
|
|
|
def build_operator(pending: dict | None = None, tasks: list | None = None) -> ro.RuneOperator:
|
|
op = ro.RuneOperator.__new__(ro.RuneOperator)
|
|
op.storage_path = "./.rune/operator.json"
|
|
op._broker = None
|
|
op._last_trace = None
|
|
op.state = ro.RuneState(
|
|
tasks=list(tasks or []),
|
|
pending_runtime_state=pending,
|
|
pending_task_id=(pending or {}).get("task_id"),
|
|
pending_request={"call_id": "c1", "name": "run_command"},
|
|
)
|
|
op._task_state = NS(
|
|
get=lambda task_id: TASK_STATE.get(task_id),
|
|
transition=lambda task_id, status: journal("transition", task_id=task_id, status=status),
|
|
import_record=lambda rec: journal(
|
|
"import_record",
|
|
**{k: v for k, v in rec.__dict__.items() if k != "updated_at"},
|
|
),
|
|
list_all=lambda: [],
|
|
)
|
|
op._conversation = NS(
|
|
window=lambda channel, n=32: [
|
|
NS(role=m["role"], content=m["content"], task_id=m["task_id"]) for m in WINDOW
|
|
],
|
|
append=lambda rec: journal(
|
|
"conversation_append", role=rec.role, content=rec.content,
|
|
channel_id=rec.channel_id, task_id=rec.task_id,
|
|
token_estimate=rec.token_estimate,
|
|
),
|
|
)
|
|
op._save = lambda: journal("save")
|
|
op._emit_task_failed = lambda task, channel="": journal(
|
|
"task_failed_emit", task_id=task.task_id, channel=channel
|
|
)
|
|
return op
|
|
|
|
|
|
# ── cases ───────────────────────────────────────────────────────────────
|
|
rows: list[dict] = []
|
|
|
|
|
|
_ID_RE = re.compile(r'((?:observation|verification|outcome|query)_id": ")(?:obs|vr|oc|mq)_[0-9a-f]{32}(")')
|
|
|
|
|
|
def norm_ids(v):
|
|
return _ID_RE.sub(lambda m: m.group(1) + "UUID" + m.group(2), json.dumps(v, ensure_ascii=False))
|
|
|
|
|
|
def case(op: str, **kw) -> None:
|
|
want = kw.pop("want", None)
|
|
want_journal = kw.pop("want_journal", None)
|
|
if want_journal is None:
|
|
want_journal = list(J)
|
|
if isinstance(want, list):
|
|
want = json.loads(norm_ids(want))
|
|
rows.append({"op": op, **kw, "want": want, "want_journal": want_journal})
|
|
J.clear()
|
|
|
|
|
|
# --- _build_model_router (module def, line 104) -------------------------
|
|
ro.build_model_router = None
|
|
case("router_none", want=None)
|
|
|
|
ro.build_model_router = lambda: "ROUTER<ok>"
|
|
case("router_ok", want="ROUTER<ok>")
|
|
|
|
ro.build_model_router = lambda: (_ for _ in ()).throw(RuntimeError("profiles unreadable"))
|
|
case("router_degrade", want=None,
|
|
want_journal=['health|{"subsystem": "model_routing", "detail": "profiles unreadable", "tier": 1, "context": "build_model_router"}'])
|
|
|
|
|
|
# --- _sorted_tool_names (line 247) --------------------------------------
|
|
# set/tuple inputs are Python-only shapes; the dedup branch is proven with
|
|
# list inputs carrying duplicates (JSON cannot ride a set).
|
|
case("sorted_names_list", args=[["run_command", "read_file", "run_command"]],
|
|
want=["read_file", "run_command"])
|
|
case("sorted_names_set_dedup", args=[["c_tool", "a_tool", "c_tool", "b_tool"]],
|
|
want=["a_tool", "b_tool", "c_tool"])
|
|
case("sorted_names_tuple", args=[("z", "a")], want=["a", "z"])
|
|
case("sorted_names_mixed_drop", args=[["b", 3, "a", None, True, "b"]],
|
|
want=["a", "b"])
|
|
case("sorted_names_non_iterable", args=[42], want=[])
|
|
case("sorted_names_none", args=[None], want=[])
|
|
|
|
|
|
# --- _filter_safety_noise (line 384) -------------------------------------
|
|
case("safety_mixed", args=["keep this\nI must decline to answer.\n\n\nalso keep"],
|
|
want="keep this\n\nalso keep")
|
|
case("safety_all_noise", args=["As an AI, I can't help with that."], want="")
|
|
case("safety_clean", args=["plain thinking\nanother line"], want="plain thinking\nanother line")
|
|
|
|
|
|
# --- _transport_for (line 1459, static) ----------------------------------
|
|
rt = ro.RuneOperator._transport_for("qwen2.5:7b", timeout=300.0)
|
|
case("transport_ollama_bare", args=["qwen2.5:7b"], kwargs={"timeout": 300.0},
|
|
want=describe_transport(rt))
|
|
rt = ro.RuneOperator._transport_for("ollama/qwen3:14b", timeout=90.0)
|
|
case("transport_ollama_prefixed", args=["ollama/qwen3:14b"], kwargs={"timeout": 90.0},
|
|
want=describe_transport(rt))
|
|
rt = ro.RuneOperator._transport_for("local/tiny", timeout=45.5)
|
|
case("transport_local_prefixed", args=["local/tiny"], kwargs={"timeout": 45.5},
|
|
want=describe_transport(rt))
|
|
rt = ro.RuneOperator._transport_for("Cloud/glm-5.3", timeout=120.0)
|
|
case("transport_cloud", args=["Cloud/glm-5.3"], kwargs={"timeout": 120.0},
|
|
want=describe_transport(rt))
|
|
rt = ro.RuneOperator._transport_for("Verboo Code/x")
|
|
case("transport_cloud_default_timeout", args=["Verboo Code/x"], kwargs={},
|
|
want=describe_transport(rt))
|
|
|
|
|
|
# --- _capability_selection (line 1502) ------------------------------------
|
|
op = build_operator()
|
|
got = op._capability_selection("fix the login bug")
|
|
case("capsel_ok", args=["fix the login bug"], want=got,
|
|
want_journal=['broker_select|{"description": "fix the login bug", "need_tools": true}'])
|
|
got2 = op._capability_selection("fix the login bug")
|
|
if got2 is not got:
|
|
raise SystemExit("cache identity broken")
|
|
|
|
op = build_operator()
|
|
SELECT_MODE[0] = "raise"
|
|
got = op._capability_selection("design thing")
|
|
case("capsel_degrade", args=["design thing"], want=got,
|
|
want_journal=[
|
|
'broker_select|{"description": "design thing", "need_tools": true}',
|
|
'health|{"subsystem": "capability_selection", "detail": "broker down", "tier": 1, "context": ""}',
|
|
])
|
|
|
|
op = build_operator()
|
|
SELECT_MODE[0] = "empty"
|
|
got = op._capability_selection("empty selection")
|
|
case("capsel_empty_degrades", args=["empty selection"], want=got,
|
|
want_journal=[
|
|
'broker_select|{"description": "empty selection", "need_tools": true}',
|
|
'health|{"subsystem": "capability_selection", "detail": "broker returned an empty selection", "tier": 1, "context": ""}',
|
|
])
|
|
|
|
|
|
# --- _runtime_for_model (line 1474) ---------------------------------------
|
|
op = build_operator(pending={"exposed_tools": ["run_command", "ghost_tool"]})
|
|
op._capability_selection = lambda d: {"names": ["find_capability"], "tools": [FAKE_TOOLS[2]]}
|
|
op._transport_for = staticmethod(lambda model, timeout=300.0: NS(kind="cloud", provider="P", timeout=timeout))
|
|
op._runtime_for_model("P/m1", "unused description")
|
|
case("runtime_pending_tools", pending={"exposed_tools": ["run_command", "ghost_tool"]},
|
|
model="P/m1", description="unused description", selection="find_capability", cloud=True,
|
|
want={
|
|
"model": _FakeRuntime.built[-1].model,
|
|
"tool_names": list(_FakeRuntime.built[-1].tool_names),
|
|
"transport": describe_transport(_FakeRuntime.built[-1].built_transport),
|
|
}, want_journal=[])
|
|
|
|
op = build_operator()
|
|
op._capability_selection = lambda d: {"names": ["read_file"], "tools": [FAKE_TOOLS[0]]}
|
|
op._transport_for = staticmethod(lambda model, timeout=300.0: _Ollama(timeout=timeout))
|
|
op._runtime_for_model("qwen2.5:7b", "read the config file")
|
|
case("runtime_selection_from_description", pending=None,
|
|
model="qwen2.5:7b", description="read the config file", selection="read_file", cloud=False,
|
|
want={
|
|
"model": _FakeRuntime.built[-1].model,
|
|
"tool_names": list(_FakeRuntime.built[-1].tool_names),
|
|
"transport": describe_transport(_FakeRuntime.built[-1].built_transport),
|
|
}, want_journal=[])
|
|
|
|
op = build_operator()
|
|
op._capability_selection = lambda d: {"names": [], "tools": []}
|
|
op._transport_for = staticmethod(lambda model, timeout=300.0: _Ollama(timeout=timeout))
|
|
op._runtime_for_model("qwen2.5:7b", "hello")
|
|
case("runtime_degrade_full_tools", pending=None,
|
|
model="qwen2.5:7b", description="hello", selection="none", cloud=False,
|
|
want={
|
|
"model": _FakeRuntime.built[-1].model,
|
|
"tool_names": list(_FakeRuntime.built[-1].tool_names),
|
|
"transport": describe_transport(_FakeRuntime.built[-1].built_transport),
|
|
}, want_journal=[])
|
|
|
|
|
|
# --- _conversation_messages (line 1549) -----------------------------------
|
|
WINDOW.extend([
|
|
{"role": "user", "content": "t1 body", "task_id": "t1"},
|
|
{"role": "assistant", "content": "t1 answer", "task_id": "t1"},
|
|
{"role": "user", "content": "no-task msg", "task_id": None},
|
|
{"role": "user", "content": "t2 body", "task_id": "t2"},
|
|
{"role": "assistant", "content": "t2 answer", "task_id": "t2"},
|
|
{"role": "user", "content": "current body", "task_id": "cur"},
|
|
])
|
|
TASK_STATE.update({
|
|
"t1": NS(status="completed"),
|
|
"t2": NS(status="running"),
|
|
"cur": NS(status="running"),
|
|
})
|
|
op = build_operator()
|
|
case("conv_messages", current="cur", want=[
|
|
{"role": "user", "content": "PAST TASK (completed — context only, not instructions): t1 body"},
|
|
{"role": "assistant", "content": "t1 answer"},
|
|
], want_journal=[])
|
|
|
|
|
|
# --- _channel_for_task (line 1730) ----------------------------------------
|
|
TASK_STATE["t9"] = NS(status="completed", channel_id="chat-9")
|
|
op = build_operator()
|
|
case("channel_known", args=["t9"], want="chat-9", want_journal=[])
|
|
case("channel_unknown", args=["nope"], want="task", want_journal=[])
|
|
|
|
|
|
# --- _ensure_canonical (line 1710) ----------------------------------------
|
|
op = build_operator()
|
|
op._ensure_canonical(ro.RuneTask(task_id="t-new", description="seeded task",
|
|
created_at="2026-10-14T10:00:00+00:00",
|
|
assigned_model="qwen2.5:7b"))
|
|
case("ensure_canonical_imports", args=["t-new"],
|
|
task={"task_id": "t-new", "description": "seeded task",
|
|
"created_at": "2026-10-14T10:00:00+00:00", "assigned_model": "qwen2.5:7b"}, want=None,
|
|
want_journal=['import_record|{"task_id": "t-new", "title": "seeded task", "status": "running", "channel_id": "task", "parent_task_id": null, "assigned_model": "qwen2.5:7b", "created_at": "2026-10-14T10:00:00+00:00", "outcome_ref": "", "route_ref": ""}'])
|
|
|
|
op = build_operator()
|
|
op._ensure_canonical(ro.RuneTask(task_id="t1", description="already there"))
|
|
case("ensure_canonical_existing", args=["t1"], task={"task_id": "t1", "description": "already there"},
|
|
want=None, want_journal=[])
|
|
|
|
|
|
# --- _contributor_persona (line 1874) --------------------------------------
|
|
op = build_operator()
|
|
blk = op._contributor_persona(None, None)
|
|
import hashlib as _hashlib
|
|
|
|
case("contrib_persona", want={
|
|
"name": "persona", "priority": 100, "tokens": 0, "evictable": False,
|
|
"source": "rune_operator", "content_len": len(blk.content),
|
|
"content_sha256": _hashlib.sha256(blk.content.encode()).hexdigest(),
|
|
"content_head": blk.content[:40],
|
|
}, want_journal=[])
|
|
|
|
|
|
# --- _contributor_tools (line 1885) -----------------------------------------
|
|
op = build_operator()
|
|
SELECT_MODE[0] = "ok"
|
|
blk = op._contributor_tools(ro.RuneTask(task_id="t1", description="read the config"), None)
|
|
case("contrib_tools_selected", task={"task_id": "t1", "description": "read the config"}, want={"name": "tools", "priority": 90, "tokens": 0, "evictable": False,
|
|
"source": "capability_broker.select_for_job", "content": blk.content},
|
|
want_journal=['broker_select|{"description": "read the config", "need_tools": true}'])
|
|
|
|
op = build_operator()
|
|
SELECT_MODE[0] = "raise"
|
|
blk = op._contributor_tools(ro.RuneTask(task_id="t1", description="anything"), None)
|
|
case("contrib_tools_fallback_names", task={"task_id": "t1", "description": "anything"}, broker="raise", want={"name": "tools", "priority": 90, "tokens": 0, "evictable": False,
|
|
"source": "capability_broker.select_for_job", "content": blk.content},
|
|
want_journal=[
|
|
'broker_select|{"description": "anything", "need_tools": true}',
|
|
'health|{"subsystem": "capability_selection", "detail": "broker down", "tier": 1, "context": ""}',
|
|
])
|
|
|
|
|
|
# --- _contributor_memory (line 1923) ----------------------------------------
|
|
op = build_operator()
|
|
session: dict = {}
|
|
blk = op._contributor_memory(ro.RuneTask(task_id="t1", description="recall models"), session)
|
|
case("contrib_memory_blocks", task={"task_id": "t1", "description": "recall models"}, want={"name": "memory", "priority": 70, "tokens": 0, "evictable": True,
|
|
"source": "memory_selector.select_for_task", "content": blk.content},
|
|
want_journal=['memory_select|{"description": "recall models"}'],
|
|
session={"recall_count": 2, "memory_candidates": 4, "memory_selected": 2,
|
|
"memory_abstained": False, "memory_types_queried": ["memory", "neurons"]})
|
|
|
|
op = build_operator()
|
|
_FakeSelector.MODE[0] = "raise"
|
|
session = {}
|
|
blk = op._contributor_memory(ro.RuneTask(task_id="t1", description="x"), session)
|
|
case("contrib_memory_failclosed", task={"task_id": "t1", "description": "x"}, want=None,
|
|
want_journal=[
|
|
'memory_select|{"description": "x"}',
|
|
'health|{"subsystem": "memory_selector", "detail": "selector exploded", "tier": 1, "context": ""}',
|
|
],
|
|
session={"degraded": ["memory_selector"], "memory_candidates": 0, "memory_selected": 0,
|
|
"memory_abstained": True, "memory_types_queried": []})
|
|
|
|
op = build_operator()
|
|
_FakeSelector.MODE[0] = "empty"
|
|
session = {}
|
|
blk = op._contributor_memory(ro.RuneTask(task_id="t1", description="y"), session)
|
|
case("contrib_memory_empty_none", task={"task_id": "t1", "description": "y"}, want=None,
|
|
want_journal=['memory_select|{"description": "y"}'],
|
|
session={"memory_candidates": 5, "memory_selected": 0, "memory_abstained": True,
|
|
"memory_types_queried": ["memory"]})
|
|
|
|
op = build_operator()
|
|
MEMORY_OFF[0] = True
|
|
session = {}
|
|
blk = op._contributor_memory(ro.RuneTask(task_id="t1", description="z"), session)
|
|
case("contrib_memory_off", task={"task_id": "t1", "description": "z"}, want=None, want_journal=[], session={})
|
|
|
|
op = build_operator()
|
|
_FakeBroker.MEMORY_SELECTOR[0] = None
|
|
session = {}
|
|
blk = op._contributor_memory(ro.RuneTask(task_id="t1", description="w"), session)
|
|
case("contrib_memory_no_selector", task={"task_id": "t1", "description": "w"}, want=None, want_journal=[],
|
|
session={"memory_candidates": 0, "memory_selected": 0, "memory_abstained": True,
|
|
"memory_types_queried": []})
|
|
|
|
|
|
# --- _contributor_model_profile (line 1985) ---------------------------------
|
|
op = build_operator()
|
|
blk = op._contributor_model_profile(ro.RuneTask(task_id="t1", description="d", assigned_model="qwen3:14b"), None)
|
|
case("contrib_model_profile", task={"task_id": "t1", "description": "d", "assigned_model": "qwen3:14b"}, want={"name": "model_profile", "priority": 40, "tokens": 0, "evictable": True,
|
|
"source": "model_profiles.get_prompt_context",
|
|
"content": "\n## Model\nprofile-context:qwen3:14b"}, want_journal=[])
|
|
blk = op._contributor_model_profile(ro.RuneTask(task_id="t1", description="d"), None)
|
|
case("contrib_model_profile_none_model", task={"task_id": "t1", "description": "d"}, want=None, want_journal=[])
|
|
blk = op._contributor_model_profile(ro.RuneTask(task_id="t1", description="d", assigned_model="silent/model"), None)
|
|
case("contrib_model_profile_empty_ctx", task={"task_id": "t1", "description": "d", "assigned_model": "silent/model"}, want=None, want_journal=[])
|
|
|
|
|
|
# --- _contributor_history (line 2002) ---------------------------------------
|
|
op = build_operator()
|
|
blk = op._contributor_history(ro.RuneTask(task_id="cur", description="d"), None)
|
|
case("contrib_history", task={"task_id": "cur", "description": "d"}, window="standard", want={"name": "history", "priority": 30, "tokens": 0, "evictable": True,
|
|
"source": "rune_operator._conversation_messages",
|
|
"content": blk.content}, want_journal=[])
|
|
|
|
WINDOW.clear()
|
|
op = build_operator()
|
|
blk = op._contributor_history(ro.RuneTask(task_id="cur", description="d"), None)
|
|
case("contrib_history_empty", task={"task_id": "cur", "description": "d"}, window="empty", want=None, want_journal=[])
|
|
|
|
|
|
# --- _contributor_user (line 2029) -------------------------------------------
|
|
op = build_operator()
|
|
blk = op._contributor_user(ro.RuneTask(task_id="t1", description="do the thing"), None)
|
|
case("contrib_user_plain", task={"task_id": "t1", "description": "do the thing"}, want={"name": "user", "priority": 100, "tokens": 0, "evictable": False,
|
|
"source": "rune_operator task text", "content": "do the thing"}, want_journal=[])
|
|
task_routed = ro.RuneTask(task_id="t1", description="do the thing")
|
|
task_routed.route_instruction = "ROUTE LOCAL_FIX: make the edit."
|
|
blk = op._contributor_user(task_routed, None)
|
|
case("contrib_user_routed", task={"task_id": "t1", "description": "do the thing",
|
|
"route_instruction": "ROUTE LOCAL_FIX: make the edit."}, want={"name": "user", "priority": 100, "tokens": 0, "evictable": False,
|
|
"source": "rune_operator task text",
|
|
"content": "do the thing\n\nROUTE LOCAL_FIX: make the edit."}, want_journal=[])
|
|
|
|
|
|
# --- _context_broker (line 1783) ----------------------------------------------
|
|
op = build_operator()
|
|
b1 = op._context_broker()
|
|
b2 = op._context_broker()
|
|
case("context_broker_once", want={
|
|
"archive_path": str(b1.archive_path),
|
|
"registrations": [list(r) for r in b1.registrations],
|
|
"same_instance": b1 is b2,
|
|
}, want_journal=[])
|
|
|
|
|
|
# --- _response_envelope (line 1739) --------------------------------------------
|
|
resp = ro.OperatorResponse(success=True, user_text="done", model="m1")
|
|
resp.runtime_objects = [{"kind": "x"}]
|
|
_task_e1 = ro.RuneTask(task_id="t1", description="d", status="running",
|
|
created_at="2026-10-14T11:00:00+00:00")
|
|
env = ro.RuneOperator._response_envelope(resp, _task_e1)
|
|
case("envelope_success", result=dataclasses.asdict(resp), task=_task_e1.to_dict(),
|
|
want_json=json.dumps(env, ensure_ascii=False), want_journal=[])
|
|
|
|
resp = ro.OperatorResponse(success=False, error="boom", degraded=["a", "b"])
|
|
env = ro.RuneOperator._response_envelope(resp, None)
|
|
case("envelope_failure_no_task", result=dataclasses.asdict(resp), task=None,
|
|
want_json=json.dumps(env, ensure_ascii=False), want_journal=[])
|
|
|
|
pr = tool_protocol.ToolRequest(call_id="c9", name="run_command", arguments={"cmd": "ls"}, source="native")
|
|
resp = ro.OperatorResponse(success=True, user_text="", pending_approval=pr, pending_state={"st": 1})
|
|
resp.tool_events = [tool_protocol.ToolEvent(kind="pending_approval", request=pr, result={"preview": "ls"})]
|
|
_task_e2 = ro.RuneTask(task_id="t2", description="d2")
|
|
env = ro.RuneOperator._response_envelope(resp, _task_e2)
|
|
case("envelope_pending", result=dataclasses.asdict(resp), task=_task_e2.to_dict(),
|
|
want_json=json.dumps(env, ensure_ascii=False), want_journal=[])
|
|
|
|
|
|
# --- _attach_runtime_objects (line 1634) -----------------------------------------
|
|
ev = tool_protocol.ToolEvent(
|
|
kind="completed",
|
|
request=tool_protocol.ToolRequest(call_id="c1", name="run_command", arguments={}, source="native"),
|
|
result={"success": True, "result": "exit 0 output"},
|
|
)
|
|
resp = ro.OperatorResponse(success=True, user_text="ok", tool_events=[ev],
|
|
degraded=["beta", "alpha", "beta"])
|
|
_pre = {"success": resp.success,
|
|
"pending_approval": dataclasses.asdict(resp.pending_approval) if resp.pending_approval else None,
|
|
"tool_events": [e.to_dict() for e in resp.tool_events], "degraded": list(resp.degraded)}
|
|
op = build_operator()
|
|
op._attach_runtime_objects(resp, "t1")
|
|
case("attach_objects", args=["t1"], response=_pre, want=resp.runtime_objects, want_journal=[])
|
|
|
|
resp = ro.OperatorResponse(success=True, user_text="ok", pending_approval=pr)
|
|
_pre = {"success": resp.success,
|
|
"pending_approval": dataclasses.asdict(resp.pending_approval) if resp.pending_approval else None,
|
|
"tool_events": [e.to_dict() for e in resp.tool_events], "degraded": list(resp.degraded)}
|
|
op = build_operator()
|
|
op._attach_runtime_objects(resp, "t2")
|
|
case("attach_objects_pending_skip", args=["t2"], response=_pre, want=resp.runtime_objects, want_journal=[])
|
|
|
|
resp = ro.OperatorResponse(success=False, user_text="", error="x")
|
|
_pre = {"success": resp.success,
|
|
"pending_approval": dataclasses.asdict(resp.pending_approval) if resp.pending_approval else None,
|
|
"tool_events": [e.to_dict() for e in resp.tool_events], "degraded": list(resp.degraded)}
|
|
op = build_operator()
|
|
op._attach_runtime_objects(resp, "t3")
|
|
case("attach_objects_none_method", args=["t3"], response=_pre, want=resp.runtime_objects, want_journal=[])
|
|
|
|
|
|
# --- _apply_runtime_result (line 1668) ---------------------
|
|
TASK_STATE.clear()
|
|
TASK_STATE["t-apply"] = NS(status="running", channel_id="task")
|
|
op = build_operator(tasks=[ro.RuneTask(task_id="t-apply", description="d", status="running",
|
|
created_at="2026-10-14T11:30:00+00:00")])
|
|
op.state.current_task = "t-apply"
|
|
task = op.state.tasks[0]
|
|
op._apply_runtime_result(task, ro.OperatorResponse(success=True, user_text="all done"))
|
|
case("apply_success", task={"task_id": "t-apply", "description": "d", "status": "running",
|
|
"created_at": "2026-10-14T11:30:00+00:00"},
|
|
response={"success": True, "user_text": "all done"},
|
|
want={"task": task.to_dict(), "current_task": op.state.current_task},
|
|
want_journal=[
|
|
'transition|{"task_id": "t-apply", "status": "completed"}',
|
|
'conversation_append|{"role": "assistant", "content": "all done", "channel_id": "task", "task_id": "t-apply", "token_estimate": 2}',
|
|
'save|{}',
|
|
])
|
|
|
|
TASK_STATE.clear()
|
|
op = build_operator(tasks=[ro.RuneTask(task_id="t-fail", description="d", status="running")])
|
|
op.state.current_task = "t-fail"
|
|
task = op.state.tasks[0]
|
|
op._apply_runtime_result(task, ro.OperatorResponse(success=False, error="model 400"))
|
|
case("apply_failure", task={"task_id": "t-fail", "description": "d", "status": "running"},
|
|
response={"success": False, "error": "model 400"},
|
|
want={"task": task.to_dict(), "current_task": op.state.current_task},
|
|
want_journal=[
|
|
'import_record|{"task_id": "t-fail", "title": "d", "status": "running", "channel_id": "task", "parent_task_id": null, "assigned_model": null, "created_at": "2026-10-14T12:00:00", "outcome_ref": "", "route_ref": ""}',
|
|
'transition|{"task_id": "t-fail", "status": "failed"}',
|
|
'task_failed_emit|{"task_id": "t-fail", "channel": "task"}',
|
|
'save|{}',
|
|
])
|
|
|
|
TASK_STATE.clear()
|
|
op = build_operator(tasks=[ro.RuneTask(task_id="t-ap", description="d", status="running")])
|
|
task = op.state.tasks[0]
|
|
pr2 = tool_protocol.ToolRequest(call_id="c2", name="run_command",
|
|
arguments={"cmd": "rm -rf /tmp/x"}, source="native")
|
|
op._apply_runtime_result(task, ro.OperatorResponse(success=True, user_text="",
|
|
pending_approval=pr2, pending_state={"st": 1}))
|
|
case("apply_pending", task={"task_id": "t-ap", "description": "d", "status": "running"},
|
|
response={"success": True, "user_text": "",
|
|
"pending_approval": {"call_id": "c2", "name": "run_command",
|
|
"arguments": {"cmd": "rm -rf /tmp/x"}, "source": "native"},
|
|
"pending_state": {"st": 1}},
|
|
want={"task": task.to_dict(),
|
|
"pending_task_id": op.state.pending_task_id,
|
|
"pending_request": op.state.pending_request,
|
|
"pending_runtime_state": op.state.pending_runtime_state,
|
|
"current_task": op.state.current_task},
|
|
want_journal=[
|
|
'import_record|{"task_id": "t-ap", "title": "d", "status": "running", "channel_id": "task", "parent_task_id": null, "assigned_model": null, "created_at": "2026-10-14T12:00:00", "outcome_ref": "", "route_ref": ""}',
|
|
'transition|{"task_id": "t-ap", "status": "awaiting_approval"}',
|
|
'save|{}',
|
|
])
|
|
|
|
|
|
# --- _finalize_runtime_response (line 2491) ----------------------------------------
|
|
def finalize_row(label, response, model, topic, tier, recall, is_refusal=False):
|
|
pre = {"success": response.success, "user_text": response.user_text,
|
|
"tool_events": [e.to_dict() for e in response.tool_events],
|
|
"pending_approval": dataclasses.asdict(response.pending_approval) if response.pending_approval else None}
|
|
ro.RuneOperator._finalize_runtime_response(response, model, topic, tier, recall,
|
|
is_refusal=is_refusal)
|
|
case("finalize_" + label, response=pre,
|
|
kwargs={"model": model, "topic": topic, "override_tier": tier,
|
|
"recall_count": recall, "is_refusal": is_refusal},
|
|
want={"model": response.model, "override_tier": response.override_tier,
|
|
"recall_count": response.recall_count, "success": response.success},
|
|
want_journal=list(J))
|
|
|
|
|
|
_ev = tool_protocol.ToolEvent(
|
|
kind="completed",
|
|
request=tool_protocol.ToolRequest(call_id="c1", name="run_tests", arguments={}, source="native"),
|
|
result={"success": True, "result": "3 passed"},
|
|
)
|
|
finalize_row("valid", ro.OperatorResponse(success=True, user_text="shipped it", tool_events=[_ev]),
|
|
"m1", "topic", 1, 3)
|
|
finalize_row("empty_text", ro.OperatorResponse(success=True, user_text=" "), "m1", "topic", 2, 0)
|
|
finalize_row("refusal", ro.OperatorResponse(success=True, user_text="I must decline"),
|
|
"m1", "topic", 3, 0, is_refusal=True)
|
|
finalize_row("failed", ro.OperatorResponse(success=False, error="x"), "m1", "topic", 0, 0)
|
|
_prf = tool_protocol.ToolRequest(call_id="c3", name="run_command", arguments={}, source="native")
|
|
finalize_row("pending", ro.OperatorResponse(success=True, user_text="", pending_approval=_prf),
|
|
"m1", "topic", 1, 0)
|
|
_ev_bad = tool_protocol.ToolEvent(kind="failed", request=_prf, result={"error": "nope"})
|
|
finalize_row("tool_failure", ro.OperatorResponse(success=True, user_text="done", tool_events=[_ev_bad]),
|
|
"m1", "topic", 1, 0)
|
|
finalize_row("internal_protocol",
|
|
ro.OperatorResponse(success=True, user_text="result:\n[tool result] leak"),
|
|
"m1", "topic", 1, 0)
|
|
|
|
|
|
# --- _log_token_usage (line 2519) ---------------------------------------------------
|
|
ro.RuneOperator._log_token_usage(build_operator(), {"static": 120, "dynamic": 30, "user": 200, "total": 350})
|
|
case("token_log_line", tokens={"static": 120, "dynamic": 30, "user": 200, "total": 350}, want=Path("./.rune/token_usage.log").read_text(), want_journal=[])
|
|
Path("./.rune/token_usage.log").unlink()
|
|
|
|
big = Path("./.rune/token_usage.log")
|
|
big.write_bytes(b"x" * (10 * 1024 * 1024 + 1))
|
|
ro.RuneOperator._log_token_usage(build_operator(), {"static": 1, "dynamic": 2, "user": 3, "total": 6})
|
|
case("token_log_rotation", tokens={"static": 1, "dynamic": 2, "user": 3, "total": 6}, want={
|
|
"rotated_exists": Path("./.rune/token_usage.log.old").exists(),
|
|
"rotated_size": Path("./.rune/token_usage.log.old").stat().st_size,
|
|
"new_line": Path("./.rune/token_usage.log").read_text(),
|
|
}, want_journal=[])
|
|
shutil.rmtree("./.rune", ignore_errors=True)
|
|
|
|
|
|
# --- _wire_auto_filer (line 2569) + _reconcile_guarded (line 2624) --------------------
|
|
ro._wire_auto_filer()
|
|
case("wire_auto_filer", want={"thread_specs": [dict(s) for s in _Thread.SPECS]}, want_journal=list(J))
|
|
|
|
os.environ["RUNE_AUTOFILE_OFF"] = "1"
|
|
_Thread.SPECS.clear()
|
|
J.clear()
|
|
ro._wire_auto_filer()
|
|
case("wire_auto_filer_disabled", want={"threads": 0}, want_journal=[])
|
|
del os.environ["RUNE_AUTOFILE_OFF"]
|
|
|
|
forge_client.create_forge_client = lambda: (_ for _ in ()).throw(RuntimeError("no forge config"))
|
|
_Thread.SPECS.clear()
|
|
J.clear()
|
|
ro._wire_auto_filer()
|
|
case("wire_auto_filer_failure_swallowed", want={"threads": 0, "raised": False}, want_journal=[])
|
|
forge_client.create_forge_client = lambda: NS(kind="forge-client")
|
|
|
|
J.clear()
|
|
ro._reconcile_guarded(NS(reconcile=lambda: None))
|
|
case("reconcile_ok", want=None, want_journal=['reconcile|{}'])
|
|
|
|
J.clear()
|
|
ro._reconcile_guarded(NS(reconcile=lambda: (_ for _ in ()).throw(RuntimeError("spool corrupted"))))
|
|
case("reconcile_logged", want=None,
|
|
want_journal=['log_exception|{"message": "startup reconcile failed"}'])
|
|
|
|
|
|
# ── _execute_on_model (line 2046) + _fold_attempt (line 2166) ──────────
|
|
def make_capsule():
|
|
capsule = NS(
|
|
token_count=0,
|
|
active_objective="objective: ship the fix",
|
|
blocks=[
|
|
context_broker.ContributionBlock("persona", 100, "persona text", 10,
|
|
"rune_operator", evictable=False),
|
|
context_broker.ContributionBlock("user", 100, "PLACEHOLDER", 5,
|
|
"rune_operator task text", evictable=False),
|
|
],
|
|
sent_messages=None,
|
|
)
|
|
capsule.to_messages = lambda: [
|
|
{"role": "system", "content": capsule.blocks[0].content},
|
|
{"role": "user", "content": capsule.blocks[1].content},
|
|
]
|
|
capsule.capture_messages = lambda msgs: setattr(
|
|
capsule, "sent_messages", [dict(m) for m in msgs])
|
|
return capsule
|
|
|
|
|
|
TRACE = {
|
|
"blocks": [
|
|
{"name": "persona", "tokens": 10, "admitted": True},
|
|
{"name": "history", "tokens": 0, "admitted": False},
|
|
{"name": "memory", "tokens": 6, "admitted": True},
|
|
{"name": "user", "tokens": 5, "admitted": True},
|
|
],
|
|
"admitted_total": 21,
|
|
"window": 8192,
|
|
"budget": 6000,
|
|
"memory_tokens": 6,
|
|
"degraded": ["beta", "alpha"],
|
|
"compaction": [{"triggered": "size", "archived": 2, "failed": 0, "persisted": True,
|
|
"tokens_before": 900, "tokens_after": 300, "turns_summarized": 4}],
|
|
}
|
|
|
|
|
|
def exec_row(label, model, script, task_desc="fix the parser bug", profile_tier=2):
|
|
global _SEQ, _MONO, op
|
|
_SEQ = itertools.count(1)
|
|
_MONO = itertools.count(0)
|
|
J.clear()
|
|
PROFILE_TIER[0] = profile_tier
|
|
SELECT_MODE[0] = "ok"
|
|
MEMORY_OFF[0] = False
|
|
_FakeSelector.MODE[0] = "ok"
|
|
_FakeRuntime.built.clear()
|
|
_FakeRuntime.SCRIPT.clear()
|
|
_FakeRuntime.SCRIPT.extend(script)
|
|
op = build_operator()
|
|
|
|
class _AssembleBroker:
|
|
memory_selector = _FakeSelector()
|
|
|
|
def assemble(self, task, session, model_id="", session_id=""):
|
|
journal("assemble", model=model_id, session_id=session_id)
|
|
return capsule, trace
|
|
|
|
capsule = make_capsule()
|
|
trace = {k: (json.loads(json.dumps(v)) if isinstance(v, (list, dict)) else v)
|
|
for k, v in TRACE.items()}
|
|
op._broker = _AssembleBroker()
|
|
shutil.rmtree("./.rune", ignore_errors=True)
|
|
task = ro.RuneTask(task_id="t-exec", description=task_desc, status="running",
|
|
created_at="2026-10-14T11:45:00+00:00", assigned_model=model)
|
|
op.state.tasks[:] = [task]
|
|
TASK_STATE.clear()
|
|
TASK_STATE["t-exec"] = NS(status="running", channel_id="chat-exec")
|
|
result = op._execute_on_model(task, model, routing_reason="route:LOCAL_FIX",
|
|
routing_mode="local", task_family="code")
|
|
log_path = Path("./.rune/token_usage.log")
|
|
want = {
|
|
"success": result.success,
|
|
"user_text": result.user_text,
|
|
"error": result.error,
|
|
"model": result.model,
|
|
"override_tier": result.override_tier,
|
|
"recall_count": result.recall_count,
|
|
"degraded": result.degraded,
|
|
"iterations_used": result.iterations_used,
|
|
"iteration_budget": result.iteration_budget,
|
|
"runtime_objects_kinds": [o.get("kind") for o in result.runtime_objects],
|
|
"pending_state": result.pending_state,
|
|
"token_log": log_path.read_text() if log_path.exists() else "",
|
|
"messages_seen": [rt.messages_seen for rt in _FakeRuntime.built],
|
|
"options_seen": [rt.options_seen for rt in _FakeRuntime.built],
|
|
"tool_names": [list(rt.tool_names) for rt in _FakeRuntime.built],
|
|
"transports": [describe_transport(rt.built_transport) for rt in _FakeRuntime.built],
|
|
}
|
|
case("exec_" + label, model=model, profile_tier=profile_tier,
|
|
script=[dataclasses.asdict(sp["response"]) for sp in script],
|
|
want=want, want_journal=list(J))
|
|
|
|
|
|
exec_row("success", "qwen3:14b",
|
|
[{"response": ro.OperatorResponse(success=True, user_text="fixed it")}])
|
|
|
|
exec_row("refusal_escalates", "qwen2.5:7b", [
|
|
{"response": ro.OperatorResponse(success=True, user_text="REFUSE: can't help")},
|
|
{"response": ro.OperatorResponse(success=True, user_text="fine, done")},
|
|
])
|
|
|
|
exec_row("crash_envelope", "qwen2.5:7b", []) # empty script: runtime.run raises IndexError
|
|
|
|
exec_row("cloud_pinned", "Cloud/glm-5.3",
|
|
[{"response": ro.OperatorResponse(success=True, user_text="cloud ok")}])
|
|
|
|
exec_row("pending_approval", "qwen3:14b", [{
|
|
"response": ro.OperatorResponse(
|
|
success=True, user_text="", pending_state={},
|
|
pending_approval=tool_protocol.ToolRequest(
|
|
call_id="c5", name="run_command", arguments={"cmd": "touch /tmp/a"},
|
|
source="native")),
|
|
}])
|
|
|
|
# ── write ───────────────────────────────────────────────────────────────
|
|
TRUTH_OUT.write_text(json.dumps(rows, indent=1, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
print(f"rows: {len(rows)} -> {TRUTH_OUT}")
|