Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e01949e
test: add V3 matched evaluation accounting
EvanProgramming Oct 21, 2026
93265da
test: account for matched task verification metrics
EvanProgramming Oct 21, 2026
9a94b32
test: add V3 matched evaluation controls
EvanProgramming Oct 21, 2026
8952842
feat: add matched V3 plan evaluation runner
EvanProgramming Oct 21, 2026
67d689f
fix: fail closed on incomplete matched workflows
EvanProgramming Oct 21, 2026
0193183
fix: harden V3 matched evaluation evidence
EvanProgramming Oct 21, 2026
5c3ee5b
fix: apply RMB cap to V3 evaluation costs
EvanProgramming Oct 21, 2026
39790c7
fix: stop matched run after provider errors
EvanProgramming Oct 21, 2026
d902a3e
fix: fail-stop V3 relay on transport errors
EvanProgramming Oct 21, 2026
49d6630
fix: ignore local relay client disconnects
EvanProgramming Oct 21, 2026
2fc0afb
test: normalize HTTP header names in provider coverage
EvanProgramming Oct 21, 2026
0abecc9
fix: keep streaming relay calls concurrent
EvanProgramming Oct 21, 2026
47ee773
fix: stop matched run on failed stream events
EvanProgramming Oct 21, 2026
f8268b4
fix: isolate concurrent CLI spinner display
EvanProgramming Oct 22, 2026
01763a6
fix: serialize CLI spinner output process-wide
EvanProgramming Oct 22, 2026
1e82817
fix: gate benchmark on sandbox and emit JSON results
EvanProgramming Oct 22, 2026
cb57fc9
test: allow delegated review to finish in CI
EvanProgramming Oct 22, 2026
a01fb70
fix: enforce matched benchmark evidence
EvanProgramming Oct 22, 2026
7a14d38
fix: keep V2 baseline compatible in evaluation
EvanProgramming Oct 22, 2026
3c9608c
fix: retain stale benchmark reservations across model changes
EvanProgramming Oct 22, 2026
f1a3826
feat: retain archived reservations in cohort reports
EvanProgramming Oct 22, 2026
a292374
test: handle shallow checkouts without V2 baseline
EvanProgramming Oct 22, 2026
6aa9e63
feat: pin matched benchmark to gpt-6-luna pricing
EvanProgramming Oct 22, 2026
fd142b2
fix: account for Panstar benchmark pricing
EvanProgramming Oct 22, 2026
29d7bec
fix: reconcile V3 benchmark reservation accounting
EvanProgramming Oct 22, 2026
552e89e
fix: normalize system messages in matched relay
EvanProgramming Oct 22, 2026
97d4df0
fix: stop relay at terminal response events
EvanProgramming Oct 22, 2026
7a6e3cc
fix: preserve cumulative benchmark spend across retries
EvanProgramming Oct 22, 2026
aa12e40
fix: mark incomplete benchmark workers inconclusive
EvanProgramming Oct 22, 2026
bbed941
fix: serialize parallel conversation journal appends
EvanProgramming Oct 22, 2026
e83a22a
fix: enforce the approved benchmark spend cap
EvanProgramming Oct 22, 2026
b0f6c9e
fix: make unknown benchmark settlement idempotent
EvanProgramming Oct 22, 2026
5ac77f0
fix: retry failed matched benchmark workers
EvanProgramming Oct 22, 2026
cbffab9
fix: carry forward cumulative benchmark exposure
EvanProgramming Oct 22, 2026
400c41e
fix: retain latest benchmark exposure
EvanProgramming Oct 22, 2026
33f029a
fix: update approved V3 evaluation spend cap
EvanProgramming Oct 22, 2026
09c6c93
fix: carry forward failed V3 benchmark exposure
EvanProgramming Oct 22, 2026
41a591a
fix: retain safe provider failure codes in benchmark
EvanProgramming Oct 22, 2026
40f4c81
fix: carry forward diagnostic benchmark exposure
EvanProgramming Oct 22, 2026
20984a1
fix: capture bounded HTTP provider error codes
EvanProgramming Oct 22, 2026
19b3ddf
fix: carry forward latest V3 provider holds
EvanProgramming Oct 22, 2026
e8efde8
docs: carry forward latest V3 benchmark reservation
EvanProgramming Oct 22, 2026
bd5fc23
docs: carry forward latest V3 benchmark hold
EvanProgramming Oct 22, 2026
e1209e9
fix: enforce cumulative benchmark spend cap
EvanProgramming Oct 22, 2026
ede7f5b
fix(benchmark): raise approved evaluation cap to twenty dollars
EvanProgramming Oct 22, 2026
d46b428
fix(benchmark): restore approved ten dollar cap
EvanProgramming Oct 22, 2026
e37e815
fix(benchmark): carry forward interrupted run exposure
EvanProgramming Oct 22, 2026
718cd2c
fix(benchmark): carry forward aborted candidate exposure
EvanProgramming Oct 22, 2026
a740594
fix: enforce cumulative evaluation spend cap
EvanProgramming Oct 23, 2026
166fe4b
fix: refresh benchmark budget exchange rate
EvanProgramming Oct 23, 2026
deee1c6
fix: run matched cohort with candidate worker
EvanProgramming Oct 23, 2026
dbdb83d
fix: enforce approved cumulative benchmark cap
EvanProgramming Oct 23, 2026
985f725
fix: use approved cumulative benchmark cap
EvanProgramming Oct 23, 2026
a4cba7c
fix: carry forward benchmark campaign reservations
EvanProgramming Oct 24, 2026
1f0be44
fix: account for all benchmark campaign exposure
EvanProgramming Oct 24, 2026
d85ce5e
fix: resume matched benchmark checkpoints
EvanProgramming Oct 24, 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
198 changes: 186 additions & 12 deletions benchmarks/prompt_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

import argparse
import json
import hashlib
import os
import sys
import time
from pathlib import Path
from types import SimpleNamespace

Expand All @@ -13,40 +16,211 @@ def main():
parser.add_argument("--source", required=True)
parser.add_argument("--workspace", required=True)
parser.add_argument("--url", required=True)
parser.add_argument("--model", default="deepseek-v4-flash")
parser.add_argument("--protocol", choices=("chat", "responses"), default="chat")
parser.add_argument("--scenario", default="")
parser.add_argument("--process-marker", default="")
parser.add_argument("--prompt-file", required=True)
parser.add_argument("--plan-file")
parser.add_argument("--result", required=True)
args = parser.parse_args()
workspace_root = Path(args.workspace).resolve()
sys.path.insert(0, args.source)
from openkyrozen.app.bootstrap import build_application
from openkyrozen.providers import ProviderConfig
from openkyrozen.providers.openai import OpenAICompatProvider
from openkyrozen.providers.openai import OpenAICompatProvider, OpenAIResponsesProvider
application = build_application(surface="cli")
runtime = application.runtime
try:
runtime._set_workspace_root(args.workspace)
runtime.set_interaction_mode("agent")
config = ProviderConfig(provider="deepseek", api_key="benchmark-local",
base_url=args.url, model_simple="deepseek-v4-flash",
model_complex="deepseek-v4-flash")
provider_name = "openai" if args.protocol == "responses" else "deepseek"
config = ProviderConfig(provider=provider_name,
api_key=os.environ.get("KYROZEN_BENCHMARK_API_KEY", "benchmark-local"),
base_url=args.url, model_simple=args.model,
model_complex=args.model)
runtime._provider_config = config
runtime.llm_provider = OpenAICompatProvider(config)
runtime.DEEPSEEK_MODEL_SIMPLE = runtime.DEEPSEEK_MODEL_COMPLEX = "deepseek-v4-flash"
# Only isolate optional services; leave planning, tools, recovery, receipts,
# completion and CLI rendering on their actual production paths.
provider_type = OpenAIResponsesProvider if args.protocol == "responses" else OpenAICompatProvider
runtime.llm_provider = provider_type(config)
runtime._default_turn.provider = runtime.llm_provider
runtime.DEEPSEEK_MODEL_SIMPLE = runtime.DEEPSEEK_MODEL_COMPLEX = args.model
# Keep production planning, tools, recovery, receipts and completion active.
runtime.dispatch_learning_cycle = lambda **kwargs: None
runtime._plugin_runtime_for_surface = lambda *args: SimpleNamespace(
turn_start=lambda **kwargs: None, turn_end=lambda **kwargs: None)
events = []
receipts = []
cli_chat = runtime.chat
started = time.monotonic()
first_delta_ms = None

def on_event(event):
nonlocal first_delta_ms
if hasattr(event, "kind") and hasattr(event, "payload"):
from openkyrozen.agent.events import runtime_event_as_legacy
event = runtime_event_as_legacy(event) or {}
elif hasattr(event, "as_dict"):
event = event.as_dict()
if not isinstance(event, dict):
return
if first_delta_ms is None and event.get("event") == "content":
first_delta_ms = round((time.monotonic() - started) * 1000, 2)
if event.get("event") == "tool_receipt":
receipt = event.get("tool_receipt", {})
args = receipt.get("args") or {}
args_hash = hashlib.sha256(json.dumps(args, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
path = args.get("path") or args.get("file_path") if isinstance(args, dict) else None
try:
target_path = Path(str(path)).resolve().relative_to(workspace_root).as_posix()
except (OSError, ValueError):
target_path = None
receipts.append({"action": receipt.get("action"), "args_hash": args_hash,
"target_path": target_path,
"background": isinstance(args, dict) and args.get("background") is True,
"success": receipt.get("success") is True,
"authorized": receipt.get("authorized") is True,
"error_code": (receipt.get("tool_error") or {}).get("code")})
events.append({"event": "tool_receipt", "action": receipt.get("action"),
"success": receipt.get("success") is True})
elif event.get("event") in {"tasks", "task_update", "working_plan", "subagent"}:
events.append({"event": event.get("event"),
"working_plan": event.get("working_plan"),
"tasks": event.get("tasks"),
"agent": event.get("agent"),
"status": event.get("status"),
"description": event.get("description")})
elif event.get("event") in {"interaction", "protocol_recovery", "protocol.recovery"}:
events.append({"event": event.get("event"), "interaction": event.get("interaction")})

runtime.chat = lambda session, message, **kwargs: cli_chat(
session, message, on_event=events.append, **kwargs)
session, message, on_event=on_event, **kwargs)
prompt = Path(args.prompt_file).read_text()
runtime._run_cli_chat(prompt, runtime._interaction_controller.state())
answer = next((m["content"] for m in reversed(runtime.short_term_memory)
if m["role"] == "assistant"), "")
initial_plan = json.loads(Path(args.plan_file).read_text()) if args.plan_file else []
initial_tasks = []
accepted_fingerprint = None
if isinstance(initial_plan, dict):
proposal = runtime._interaction_controller.propose_plan(initial_plan, original_input=prompt)
accepted, _ = runtime._interaction_controller.accept_plan(
runtime.tasks, plan_id=proposal["plan_id"], version=proposal["version"],
)
accepted_fingerprint = accepted.get("fingerprint")
initial_tasks = [f"{step['title']}: {step['description']}" for step in accepted["steps"]]
elif isinstance(initial_plan, list) and all(isinstance(item, str) for item in initial_plan):
initial_tasks = initial_plan
if initial_tasks:
if callable(getattr(runtime.tasks, "edit_plan", None)):
runtime.tasks.edit_plan(
complexity="complex", expected_revision=0,
operations=[{"op": "add", "ref": f"fixture-{index}", "task": {
"description": task, "acceptance": ["Complete the independent fixture objective."],
}} for index, task in enumerate(initial_tasks, 1)],
reason="Initialize the frozen matched evaluation plan.",
)
else:
runtime.tasks.add_ordered_plan(initial_tasks, task_id_prefix="fixture")
prompt = ("Initial working-plan task order:\n" + "\n".join(
f"{index}. {task}" for index, task in enumerate(initial_tasks, 1)
) + "\nUse update_plan when new evidence requires adding, cancelling, replacing, or reordering work.\n\n"
+ prompt)
else:
raise ValueError("benchmark initial plan must be a plan object or an array of task descriptions")
snapshot_working_plan = getattr(runtime.tasks, "working_plan_snapshot", None)
initial_working_plan = snapshot_working_plan() if callable(snapshot_working_plan) else None
if initial_working_plan:
events.append({"event": "working_plan", "working_plan": initial_working_plan})
if runtime.tasks.tasks:
events.append({"event": "tasks", "tasks": list(runtime.tasks.tasks)})
if accepted_fingerprint:
prompt = ("A Strategic Plan has already been accepted. Preserve its approved scope; use the working plan "
"for implementation changes, and request renewed approval for material scope changes.\n\n" + prompt)
answer = runtime.chat(runtime.current_session, prompt, clear_tasks=False, profile="auto")
manager = getattr(runtime.current_session, "process_manager", None)
handles = tuple(getattr(manager, "_handles", {}).values())
cancellations = sum(item["action"] == "stop_process" and item["success"] for item in receipts)
unique_calls = {(item["action"], item["args_hash"]) for item in receipts}
working_plan = snapshot_working_plan() if callable(snapshot_working_plan) else None
plan_snapshots = []
for event in events:
snapshot = event.get("working_plan")
if isinstance(snapshot, dict) and all(
(item.get("plan_id"), item.get("revision")) !=
(snapshot.get("plan_id"), snapshot.get("revision")) for item in plan_snapshots):
plan_snapshots.append(snapshot)
Comment thread
EvanProgramming marked this conversation as resolved.
if isinstance(working_plan, dict) and all(
(item.get("plan_id"), item.get("revision")) !=
(working_plan.get("plan_id"), working_plan.get("revision")) for item in plan_snapshots):
plan_snapshots.append(working_plan)
revisions = [int(item.get("revision", 0)) for item in plan_snapshots]
working_revisions = max(0, max(revisions) - min(revisions)) if revisions else 0
task_orders = []
for event in events:
items = event.get("tasks")
if isinstance(items, list):
order = tuple((item.get("id"), item.get("description")) for item in items if isinstance(item, dict))
if order and (not task_orders or order != task_orders[-1]):
task_orders.append(order)
task_revisions = max(0, len(task_orders) - 1)
plan_revisions = max(working_revisions, task_revisions)
unnecessary_churn = sum(
left.get("tasks") == right.get("tasks") and left.get("plan_id") == right.get("plan_id")
for left, right in zip(plan_snapshots, plan_snapshots[1:])
)
material_revisions = sum(
1 for event in events if event.get("event") == "interaction"
and isinstance(event.get("interaction"), dict)
and (event["interaction"].get("pending_plan") or {}).get("revision_materiality") == "material"
)
interaction_state = runtime._interaction_controller.state()
history = runtime._interaction_controller._history()
proposals = [event.get("payload", {}) for event in history
if event.get("event_type") == "interaction.plan_proposed"]
accepted_versions = {(event.get("payload", {}).get("plan_id"),
event.get("payload", {}).get("version")) for event in history
if event.get("event_type") == "interaction.plan_accepted"}
accepted_fingerprints = [proposal.get("fingerprint") for proposal in proposals
if (proposal.get("plan_id"), proposal.get("version")) in accepted_versions]
pending_material = (interaction_state.get("pending_plan") or {}).get("revision_materiality") == "material"
result = {"answer": answer, "tool_calls": sum(e.get("event") == "tool_receipt" for e in events),
"tool_actions": [e.get("action") for e in events if e.get("event") == "tool_receipt"],
"tool_receipts": receipts, "events": events,
"tool_successes": sum(e.get("event") == "tool_receipt" and e.get("success") is True for e in events),
"tasks": [t["status"] for t in runtime.tasks.tasks],
"task_records": [{"id": t["id"], "description": t["description"],
"status": t["status"],
"strategic_binding": (t.get("checkpoint") or {}).get("strategic_plan")}
for t in runtime.tasks.tasks],
"working_plan": working_plan,
"initial_plan_fingerprint": accepted_fingerprint,
"accepted_plan_fingerprints": accepted_fingerprints,
"material_plan_proposals": sum(item.get("revision_materiality") == "material" for item in proposals),
"pending_material_revision": pending_material,
"executing_plan_fingerprint": (interaction_state.get("executing_plan") or {}).get("fingerprint"),
"plan_revisions": plan_revisions,
"cancelled_tasks": sum(t["status"] == "cancelled" for t in runtime.tasks.tasks),
"material_revisions": material_revisions,
"unnecessary_churn": unnecessary_churn,
"duplicate_calls": len(receipts) - len(unique_calls),
"protocol_recovery": sum(event["event"] in {"protocol_recovery", "protocol.recovery"}
for event in events),
"processes_started": sum(item["action"] == "run_cmd" and item["background"] and item["success"]
for item in receipts),
"processes_cancelled": cancellations,
"processes_alive": sum(handle.process.poll() is None for handle in handles),
"process_pids": [handle.process.pid for handle in handles],
"process_marker_seen": any(args.process_marker and args.process_marker in handle.stdout
for handle in handles),
"first_delta_latency_ms": first_delta_ms,
"provider_error": "[LLM Error]" in answer}
bound_scope_active = bool(accepted_fingerprint and any(
task["status"] != "cancelled"
and (task.get("strategic_binding") or {}).get("fingerprint") == accepted_fingerprint
for task in result["task_records"]
))
result["accepted_scope_preserved"] = bool(
accepted_fingerprint and accepted_fingerprint in accepted_fingerprints
and bound_scope_active
)
Comment thread
EvanProgramming marked this conversation as resolved.
result["scope_preserved"] = bool(result["accepted_scope_preserved"] and not pending_material)
Path(args.result).write_text(json.dumps(result))
finally:
application.close()
Expand Down
Loading
Loading