Skip to content
Merged
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@

### Changed

- For ordinary projects, import `prepare_project` and `execute_ordinary` from
`inferrsi.harness.executor`. The former `inferrsi.harness.project` operations
`prepare`, `steps`, `inspect_step` and `assess` are now `executor.prepare_project`,
`evaluator.project_steps`, `evaluator.inspect_project_step` and `evaluator.assess_project`.
Use `executor.validate_project` and `executor.PROJECT_DECISIONS` for the former
`project.validate` and `project.DECISIONS`. Import paired statistics and explanation helpers from `inferrsi.harness.evaluator`
in place of `inferrsi.harness.measurement`. Packaged tasks retain their own scoring rules.

- Import `prepare_task_protocol`, `run_task_protocol` and `TaskProtocolError` from
`inferrsi.harness.executor`. They replace `prepare`, `run` and `TaskProtocolError`
in the former `inferrsi.harness.task_protocol` module. Each operation uses the
frozen task resources and the same isolated child process protocol.

- Import the four-port AB/BA loop with `from inferrsi.harness.manager import run_experiment`.
The former `inferrsi.harness.runner` module was removed. The `inferrsi run` CLI and
`inferrsi.apps.legacy.run.run_experiment` continue to supply the four port bindings.
Expand Down
14 changes: 8 additions & 6 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ Each task retains its own protocol and task-specific code.
The [current-Agent optimization session](benchmarks/optimization-benchmarks.md) assembles
the first complete handoff for the Qwen task. `harness/optimization.py` controls
budget, attempts, feedback records, selection and independent final execution.
`harness/task_protocol.py` freezes a supplied resource directory and loads its
task-owned assessment protocol. `harness/optimization_session.py` assembles
execution and assessment; the CLI resolves task resources and injects knowledge
access and the capture callback from `apps/workflows/campaign.py`.
Harness Executor freezes a supplied resource directory with `prepare_task_protocol`
and starts its task-owned protocol in an isolated child with `run_task_protocol`.
The CLI resolves task resources and supplies the task assessor, knowledge access and
capture callback to `harness/optimization_session.py`.
The external Agent chooses and edits candidates between round submissions.
The same controller serves ordinary projects through `campaign start/round/final`
and packaged tasks through `benchmarks session`. The
[shared workflow and sequence diagram](guides/optimization-workflow-unification.md)
describe multi-file candidates, explicit acceptance inputs, stop rules and
dashboard projections from one control record. `harness/project.py` freezes
caller-provided checks and assesses their retained outputs. Ordinary optimization
dashboard projections from one control record. Harness Executor freezes caller-provided
project checks and runs the steps in order. Evaluator inspects each retained step before
execution continues and uses the same rule for the final AB/BA verdict. For packaged
tasks, Evaluator invokes the task assessor supplied by Apps. Ordinary optimization
does not import Benchmark. Benchmark supplies task definitions and specialized
rules, while Harness manages their execution and the complete optimization lifecycle.
Neither infers quality criteria from a natural-language goal.
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/module-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ registered consumers; this gate does not scan them.
#412 R3 retired the five temporary resource-loader declarations and their
`runtime resource loaders` blocker. Three of the five were removed:

- `harness.task_protocol` no longer loads task code. Each protocol operation
(`validate_arguments`, `arguments`, `assess`) runs `harness/protocol_child.py`
- Harness Executor supervises the frozen task protocol. Each operation
(`validate_arguments`, `arguments`, `assess`) runs `harness/executor/protocol_child.py`
as `python -I -B` in its own process group or Windows Job under a deadline, and
answers with one strict JSON envelope on a private copy of stdout. The child
imports only the standard library and compiles the exact protocol bytes it has
Expand Down
10 changes: 5 additions & 5 deletions docs/guides/optimization-workflow-unification.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ sequenceDiagram
Note over A,H: final 使用留存的最佳版本;工作区未提交修改不参与
end
C->>H: session_command:提交 round/final 参数
H->>H: evaluate_round:使用内部 execute / assess 适配函数
H->>H: evaluate_round:绑定 Executor 执行和 Evaluator 判定
H->>H: 核验文件、状态和预算,选择提交候选或留存最佳版本
H->>H: 保存到 rounds/… 或 final/…;state.pending 记录本次待完成尝试
H->>H: _session_execute → _project_execute → project.steps
H->>H: executor.execute_ordinary → evaluator.project_steps
Note over H: 根据固定配置生成基线/候选的质量、预热、交替测量命令
loop 按固定步骤采集;拒绝或异常时停止本次采集
H->>H: execute_trial → execute_command:运行质量/计时脚本,保存 result.json 和日志
H->>H: 留存状态、退出码、耗时;核对源码身份并记录 source_checks
H->>H: project.inspect_step:检查结果格式、质量字段和性能值,决定继续或拒绝
H->>H: evaluator.inspect_project_step:检查结果格式、质量字段和性能值,决定继续或拒绝
end
H->>H: 保存 execution.json;各步结果、日志和执行事实已落盘
H->>H: _settle:再次核验固定条件和候选身份
H->>H: _session_assess → project.assess:读取固定配置与留存结果,不重新测量
H->>H: evaluator.assess_ordinary → assess_project:读取固定配置与留存结果,不重新测量
H->>H: 核对完整性与质量,重算中位数/提升比例,比较门槛
Note over H: 产生 assessment:判定、指标、质量标记、证据引用和拒绝原因
H->>H: 写 observation.json;round 更新最佳候选,final 记录独立复测结论
Expand Down Expand Up @@ -152,7 +152,7 @@ Harness 没有常驻 Agent 驱动。Agent 逐次调用这些操作,代码在

两个优化入口都调用 `harness.optimization_session.session_command`,使用同一个 `harness.optimization` 控制器。AB/BA 与题包使用 `evaluate_round`;显式 service_reuse 使用该控制器内的 `service_command` 和模式分支,共用锁及单一控制记录。执行与评测适配也在 Harness 内;普通项目整个生命周期不导入 Benchmark。

题库 `start` 由 CLI 经 `benchmark.registry` 定位资源目录,再交给 `harness.task_protocol.prepare` 固化;后续从冻结目录加载题包自己的 `optimization.py`,无需再次查询注册表。专用协议检查仍属于题包。两类 `assess` 都只读留存结果,不重新测量。KnowledgeReader 与 `apps/workflows/campaign.py` 的记录回调由 CLI 注入,Harness 不直接导入 Benchmark 或目标 Knowledge 模块,也不经记录模块间接引入知识实现。
题库 `start` 由 CLI 经 `benchmark.registry` 定位资源目录,再交给 `harness.executor.prepare_task_protocol` 固化;后续从冻结目录加载题包自己的 `optimization.py`,无需再次查询注册表。专用协议检查仍属于题包。两类 `assess` 都只读留存结果,不重新测量。KnowledgeReader 与 `apps/workflows/campaign.py` 的记录回调由 CLI 注入,Harness 不直接导入 Benchmark 或目标 Knowledge 模块,也不经记录模块间接引入知识实现。

本次交付可以分成三块:**Benchmark 的优化题目、Harness 的优化管理与验收、Harness 与宿主协作的新会话派发和回收**。第三块不改变第二块的生命周期;新会话仍自行 start 到 final。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"results/summary.json": "df3029cfcaacb91018b6c931017b059b99a80633116586f9446fe82e31986132",
"results/trials.jsonl": "6bd39719a5c0d794b1c5e04403b03789ae5ca42e0c9c74694200bdb6355a0756",
"validator/README.md": "c224e3d864829d5c1a2f8bc4e4c89e36834409d4ce78fc1fa7dc59f6f739fdd3",
"validator/check.py": "83b89ce30d89c8dd68e7092403ec5b62d965a9a9587caa65fcd0b541def5d3fd"
"validator/check.py": "33463b8c9ec1a4d845a71cc6711057ecae015dfda602a0735cfe73f2ba031c86"
}
6 changes: 3 additions & 3 deletions evidence/qwen-vats-gvo-910b1-20261124/validator/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from statistics import geometric_mean

from inferrsi.benchmark.registry import task_resources
from inferrsi.harness import task_protocol
from inferrsi.harness.executor import run_task_protocol
from inferrsi.harness.executor import candidates
from inferrsi.harness.manager.search.work_control import WorkControl
from inferrsi.harness.records import RunStoreReader
Expand Down Expand Up @@ -112,7 +112,7 @@ def main(completed, failed, historical_driver=None):
path = historical_driver or completed.parent.parent / "config/run.py"
require(sha(path) == expected_hash, name)
protocol_hash = spec["packaged_task_sha256"]["optimization.py"]
settings = task_protocol.run(
settings = run_task_protocol(
task, protocol_hash, "validate_arguments", arguments=plan["sampling"]
)
expected = [(arm, seed) for seed, arms in plan["blocks"] for arm in arms]
Expand Down Expand Up @@ -179,7 +179,7 @@ def main(completed, failed, historical_driver=None):
folder = measure.parents[1]
raw = read(measure)
execution = read(folder / "execution/execution.json")
assessment = task_protocol.run(
assessment = run_task_protocol(
task,
protocol_hash,
"assess",
Expand Down
2 changes: 2 additions & 0 deletions src/inferrsi/apps/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def _round_provider(plan):


def _optimization_session(args, *, task_source=None, report_metadata=None):
from ...harness.executor import assess_packaged_task
from ...harness.optimization_session import session_command
from ...knowledge.ranking_policy import managed_ranking_policy

Expand All @@ -47,6 +48,7 @@ def _optimization_session(args, *, task_source=None, report_metadata=None):
external_project = freeze_project(args.repo if args.project_task else None)
return session_command(
args, task_source=task_source, prepare_context=prepare_context,
assess_packaged=assess_packaged_task,
ranking_policy_for=managed_ranking_policy,
knowledge_reader=KnowledgeReader() if args.session_action == "knowledge" else None,
external_knowledge=settings, external_project=external_project,
Expand Down
4 changes: 2 additions & 2 deletions src/inferrsi/apps/workflows/benchmark_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
from inferrsi.benchmark.summary import POLICY, supported_policy
from inferrsi.benchmark.summary import comparison as metrics_comparison
from inferrsi.harness import agent_sessions, optimization
from inferrsi.harness.executor import run_task_protocol
from inferrsi.harness.optimization_session import _runtime_identity
from inferrsi.harness.records.artifact_primitives import digest, file_lock, sha256
from inferrsi.harness.records.atomic_json import atomic_write_json
from inferrsi.harness.records.knowledge_capture import verify_capture
from inferrsi.harness.task_protocol import run as protocol_operation
from inferrsi.knowledge.catalog import SCENARIO_ALIASES
from inferrsi.knowledge.context_projection import assemble_context_text
from inferrsi.knowledge.knowledge_operations import KnowledgeReader
Expand Down Expand Up @@ -237,7 +237,7 @@ def prepare(args):
for name in config["tasks"]:
resource = Path(str(task_resources(name)))
manifest = _object(resource / "task.json")
settings = protocol_operation(resource, sha256(resource / "optimization.py"),
settings = run_task_protocol(resource, sha256(resource / "optimization.py"),
"validate_arguments",
arguments=shlex.split(config["task_arguments"][name]))
task_settings[name] = {"settings": settings, "files": _manifest(resource),
Expand Down
8 changes: 2 additions & 6 deletions src/inferrsi/apps/workflows/benchmark_operations.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
"""Resolve packaged tasks at the application boundary and launch their entries."""

import subprocess
import sys
from pathlib import Path

from inferrsi.benchmark.registry import task_resources
from inferrsi.harness import optimization_session
from inferrsi.harness.executor import runtime_environment
from inferrsi.harness.executor import benchmark_command, runtime_environment


def run_task(name: str, arguments: list[str]) -> int:
entry = task_resources(name).joinpath("benchmark.py")
if not entry.is_file():
raise ValueError(f"Missing benchmark.py entry for task: {name}")
return subprocess.call(
[sys.executable, str(Path(optimization_session.__file__).resolve()),
str(entry), *arguments],
benchmark_command(entry, arguments),
env=runtime_environment(),
)
27 changes: 14 additions & 13 deletions src/inferrsi/apps/workflows/search_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
from inferrsi.apps.workflows.improvement import assessment
from inferrsi.benchmark.improvement import SelectionPolicy, holdout_accepts
from inferrsi.benchmark.registry import task_resources
from inferrsi.harness import task_protocol
from inferrsi.harness.executor import candidates, runtime_environment
from inferrsi.harness.executor import (
TaskProtocolError,
benchmark_command,
candidates,
prepare_task_protocol,
run_task_protocol,
runtime_environment,
)
from inferrsi.harness.executor.trials.external import execute_trial
from inferrsi.harness.records.artifact_primitives import digest, sha256
from inferrsi.harness.records.atomic_json import atomic_write_json
Expand All @@ -25,7 +31,7 @@ class EngineEvaluator:

def __init__(self, package, frozen, *, arguments, python=sys.executable, prefix=()):
self.frozen = Path(frozen).resolve()
self.plan = task_protocol.prepare(
self.plan = prepare_task_protocol(
Path(str(task_resources(package))), self.frozen, arguments
)
self.python, self.prefix = python, tuple(prefix)
Expand Down Expand Up @@ -55,12 +61,11 @@ def evaluate(self, candidate, check, output, deadline):
self._check_resources()
output.mkdir(parents=True)
candidates.retain(candidate / "candidate.py", output / "candidate.py")
from inferrsi.harness import optimization_session

execution = None
cleanup = True
try:
args = task_protocol.run(
args = run_task_protocol(
self.frozen,
self.plan["frozen_files"]["optimization.py"],
"arguments",
Expand All @@ -69,12 +74,8 @@ def evaluate(self, candidate, check, output, deadline):
output=output / "measurement",
settings=self.plan["evaluation_settings"],
)
command = (
*self.prefix,
self.python,
str(Path(optimization_session.__file__).resolve()),
str(self.frozen / "benchmark.py"),
*args,
command = benchmark_command(
self.frozen / "benchmark.py", args, python=self.python, prefix=self.prefix,
)
environment = runtime_environment()
environment["PYTHONDONTWRITEBYTECODE"] = "1"
Expand All @@ -89,7 +90,7 @@ def evaluate(self, candidate, check, output, deadline):
)
cleanup = execution["cleanup_verified"]
self._check_resources(during=True)
assessed = task_protocol.run(
assessed = run_task_protocol(
self.frozen,
self.plan["frozen_files"]["optimization.py"],
"assess",
Expand All @@ -98,7 +99,7 @@ def evaluate(self, candidate, check, output, deadline):
settings=self.plan["evaluation_settings"],
execution=execution,
)
except task_protocol.TaskProtocolError as error:
except TaskProtocolError as error:
if error.kind != "timeout":
raise
# Retain a real timeout as INCONCLUSIVE even when no time remains
Expand Down
12 changes: 8 additions & 4 deletions src/inferrsi/harness/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ measurement and assessment rules.
[path, JSON and diagnostic limits](records/service_io.py).
- [`optimization_session.py`](optimization_session.py) connects session
commands to the budget and recovery logic in [`optimization.py`](optimization.py).
[`task_protocol.py`](task_protocol.py) prepares task protocol packages and runs
their operations in a subprocess with source hash and response checks.
[Executor](executor/__init__.py) exposes `prepare_task_protocol` to freeze task resources
and `run_task_protocol` to run their operations in an [isolated child](executor/protocol_child.py).
For an ordinary project, `prepare_project` freezes the checks and `execute_ordinary` runs each
allowed step before the shared deadline. [Evaluator](evaluator/__init__.py) checks each
completed step before Executor launches the next process.
- [Skill trials](executor/skill_evaluation.py) execute commands and retain their results.
The [artifact sandbox](executor/artifact_sandbox.py) captures
and replays submitted artifacts.
Expand Down Expand Up @@ -66,8 +69,9 @@ The agent chooses a hypothesis and edits a candidate between rounds.
- **Executor** owns the retained candidate, task runner and [service lifecycle](project_service.py),
including measurement collection, process ownership and cleanup.
- **Evaluator** uses the frozen rules and stage receipts to decide the next stage or verdict.
[_session_assess](optimization_session.py) dispatches packaged tasks to their protocol
assessor and project trials to the [AB/BA assessor](project.py). Service screening is
`assess_ordinary` dispatches packaged tasks to the frozen task assessor supplied by Apps.
For AB/BA projects, `assess_project` rereads retained evidence with the same
`inspect_project_step` rule used during execution. Service screening is
diagnostic. [Service evaluation](project_service.py) uses formal samples and quality evidence.

New plans freeze the ranking ID, scoring version and all effective weights. Ordinary
Expand Down
35 changes: 35 additions & 0 deletions src/inferrsi/harness/evaluator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Assess ordinary attempts against frozen rules and retained evidence."""

from ._measurement import (
CONFIDENCE,
DIRECTIONS,
METHOD,
MIN_PAIRS,
explain,
gate_speedup,
interval_rank,
median_interval,
min_pairs,
paired_speedups,
paired_statistics,
profile_evidence,
relative_mad,
validate_mechanism,
)
from ._project import assess_project, inspect_project_step, project_steps

__all__ = [
"CONFIDENCE", "DIRECTIONS", "METHOD", "MIN_PAIRS", "assess_ordinary", "assess_project",
"explain", "gate_speedup",
"inspect_project_step", "interval_rank", "median_interval", "min_pairs", "paired_speedups",
"paired_statistics", "profile_evidence", "project_steps", "relative_mad", "validate_mechanism",
]


def assess_ordinary(root, directory, plan, execution, mechanism=None, *, assess_packaged):
"""Read project evidence or delegate to the packaged task's supplied assessor."""
if plan["task_source"] == "project":
return assess_project(
directory, plan["evaluation_settings"], execution, mechanism=mechanism,
)
return assess_packaged(root, directory, plan, execution)
Loading
Loading