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
24 changes: 20 additions & 4 deletions docs/apps-evaluate-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,26 @@ absolute local directory without symlink traversal.
assessor reads only fixed retained evidence through Apps; it does not prepare
a task, construct an execution target, launch a worker or access a network.

This first adapter exposes the production task family already supported by B
on main. It does not define a worker/profile or reinterpret frozen rules.
The separate real CPU profile delivery and full three-host integration remain
tracked by the parent Apps issue.
The [CPU smoke task](contracts/p1-cpu-smoke.md) supplies the worker and frozen
rules for the production example below.

## Opt-in production evidence

`evaluate execute --capture-evidence` composes the existing frozen P1 proof
projection with the Apps role reader and H capture lifecycle. Candidate and
report roles come from B-validated frozen metadata for its supported single
output recipe. B decides rules/proof content; H authenticates sources, retains
bytes and commits the record. Invalid UTF-8 and missing evidence retain their
existing separate claim outcomes. A source that H cannot capture keeps H's
zero-start fixed refusal and B can assess that record offline.

The switch is host assembly outside the saved request and both configuration
schemas. Without it, the existing execution path remains. Projection setup
and artifact reads happen only inside H's fresh callback. Registered replay,
conflict and in-progress requests do not invoke it. Enabling capture for an
already registered attempt returns the original facts; it cannot add proofs
to an old record or authorize another worker run. A separate new execution
requires an explicitly allocated attempt under the existing H contract.

## Outputs, errors and replay

Expand Down
4 changes: 4 additions & 0 deletions docs/apps-module-migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"src/inferrsi/apps/delivery/__init__.py",
"src/inferrsi/apps/handoff/bridge.py",
"src/inferrsi/apps/handoff/candidate_provider.py",
"src/inferrsi/apps/handoff/production_capture.py",
"src/inferrsi/apps/storage/artifact_reader.py",
"src/inferrsi/apps/views/attempt.py",
"src/inferrsi/apps/workflows/benchmark_compare.py",
Expand All @@ -37,6 +38,7 @@
"tests/test_apps_output.py",
"tests/test_apps_port_validation.py",
"tests/test_apps_prepare.py",
"tests/test_apps_production_cli.py",
"tests/test_apps_publication.py",
"tests/test_apps_replay.py",
"tests/test_benchmark_assessment.py",
Expand All @@ -62,6 +64,7 @@
"src/inferrsi/apps/artifact_reader.py",
"src/inferrsi/apps/cli/evaluate.py",
"src/inferrsi/apps/handoff/candidate_provider.py",
"src/inferrsi/apps/handoff/production_capture.py",
"src/inferrsi/apps/views/attempt.py",
"tests/check_installed.py",
"tests/test_apps_artifact_reader.py",
Expand Down Expand Up @@ -151,6 +154,7 @@
"tests/test_apps_execution_binding.py",
"tests/test_apps_generation_plan.py",
"tests/test_apps_module_migrations.py",
"tests/test_apps_production_cli.py",
"tests/test_benchmark_assessment.py",
"tests/test_benchmark_preparation.py",
"tests/test_harness_entry_verification.py",
Expand Down
16 changes: 13 additions & 3 deletions src/inferrsi/apps/cli/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def add_parser(commands) -> None:
command.add_argument("--record-ref", help="@<full RecordRef JSON file>")
command.add_argument("--scope")
command.add_argument("--primary-claim")
if action == "execute":
command.add_argument("--capture-evidence", action="store_true",
help="Retain the configured frozen P1 task's evidence")


def _object_file(path: Path) -> dict:
Expand Down Expand Up @@ -89,7 +92,7 @@ def _prepare_ports(config: dict) -> dict:
"validate_prepared": preparation.validate_prepared}


def _execute_ports(config: dict, storage: dict) -> dict:
def _execute_ports(config: dict, storage: dict, *, capture_evidence: bool = False) -> dict:
from ...harness.api import Harness, LocalCpuTarget
from ...harness.run_store import RunStore
from ..storage.artifact_reader import ArtifactReader
Expand All @@ -110,11 +113,17 @@ def _execute_ports(config: dict, storage: dict) -> dict:
if item["namespace"] == storage["harness_namespace"]), None)
if mount is None or mount["kind"] != "harness_sqlite":
raise ValueError("execute requires the configured Harness SQLite mount")
capture = None
if capture_evidence:
from ..handoff.production_capture import PreparedCapture

capture = PreparedCapture(storage)

def execute(spec):
# Opening a writable Store is an execution effect. Defer it until Apps
# has verified the saved request/preparation, and preserve PublicError.
harness = Harness(RunStore.from_mount(mount), target, artifact_reader=reader)
harness = Harness(RunStore.from_mount(mount), target, artifact_reader=reader,
evidence_capture=capture)
return harness.execute(spec)

return {"execute_harness": execute}
Expand Down Expand Up @@ -173,7 +182,8 @@ def dispatch(args) -> int:
if args.evaluate_action == "prepare":
ports = _prepare_ports(_runtime(args.runtime_config))
elif args.evaluate_action == "execute":
ports = _execute_ports(_runtime(args.runtime_config), storage)
ports = _execute_ports(_runtime(args.runtime_config), storage,
capture_evidence=args.capture_evidence)
else:
# Offline assessment ignores target/worker configuration entirely.
ports = _assess_ports()
Expand Down
36 changes: 36 additions & 0 deletions src/inferrsi/apps/handoff/production_capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Compose the frozen B projection only when H invokes fresh evidence capture."""

from copy import deepcopy

from ...harness.errors import PublicError
from ..storage.archive import read_prepared
from ..storage.artifact_reader import ArtifactReader
from .evidence_capture import EvidenceCapture


class PreparedCapture:
"""Trusted host adapter; constructing it performs no task or artifact reads."""

def __init__(self, storage_config: dict):
self._storage = deepcopy(storage_config)

def capture(self, phase, facts, *, artifacts):
# H never invokes this callback for registered replay/conflict/in-progress.
from ...benchmark.proofs import ProofError, ProofProjector

prepared = read_prepared(self._storage, facts["prepared_ref"])
reader = ArtifactReader(self._storage)
with reader.open(prepared["protocol"]) as stream:
protocol = stream.read()
try:
projector = ProofProjector(prepared, protocol)
# B's supported P1 validator fixes the single-output recipe. Apps
# takes role names from that validated metadata, not task names.
adapter = EvidenceCapture(
projector.project,
candidate_role=prepared["candidate_contract"]["input_role"],
report_role=prepared["recipe"]["outputs"][0]["role"],
)
return adapter.capture(phase, facts, artifacts=artifacts)
except ProofError as error:
raise PublicError(error.code, stage="evidence_capture", message=str(error)) from error
1 change: 1 addition & 0 deletions tests/check_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ def _inventory(root, prefix):
capture_output=True, text=True, check=True,
)
assert "--request" in help_result.stdout and "--output-id" in help_result.stdout
assert ("--capture-evidence" in help_result.stdout) == (evaluate_action == "execute")
for canonical in ("inferrsi.apps.views.summary_chart",
"inferrsi.apps.workflows.benchmark_operations",
"inferrsi.apps.integrations.mindie.project",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_apps_evaluate_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ def test_request_cannot_supply_runtime_authority(evaluation, tmp_path, capsys, m
configured = []
original = cli._execute_ports

def observe(trusted, storage):
def observe(trusted, storage, **options):
configured.append(deepcopy(trusted))
return original(trusted, storage)
return original(trusted, storage, **options)

monkeypatch.setattr(cli, "_execute_ports", observe)
command = arguments(tmp_path, "execute", request, config, runtime)
Expand Down
Loading
Loading