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
33 changes: 23 additions & 10 deletions src/inferrsi/harness/manager/search/vats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from dataclasses import asdict, dataclass, replace
from itertools import combinations

from inferrsi.contracts.claim import Verdict
from inferrsi.harness.records.artifact_primitives import digest

from . import search_tree as tree
Expand Down Expand Up @@ -151,15 +152,27 @@ def menu(state, jobs, available, settings, snapshot):
extra.append(trial)
if not settings.bundled:
# Ablation: individual executable jobs, explicitly retaining incomplete evidence.
seeds = [
Action("verify", jobs=(job.job_id,), cost_ms=job.cost)
for job in jobs
if not job.prerequisites
and job.cost <= available
and job.candidate_id is not None
and job.check_id in tree.missing_checks(state, job.candidate_id)
]
extra = []
seeds = []
extra = (
sorted(
(
Action("verify", jobs=(job.job_id,), cost_ms=job.cost)
for job in jobs
if not job.prerequisites
and job.cost <= available
and job.candidate_id is not None
and tree.candidate_valid(state, job.candidate_id)
and not any(
item.verdict == Verdict.FAIL
for item in tree.evidence(state, job.candidate_id).values()
)
and job.check_id in tree.missing_checks(state, job.candidate_id)
),
key=lambda action: (action.cost_ms, action.jobs),
)
if len(state.attempts) < state.contract.max_attempts
else []
)
unions = []
parents = [
node
Expand Down Expand Up @@ -655,7 +668,7 @@ def prepared(state):
if time.time() >= claim["deadline"]:
raise ValueError("Preparation deadline exceeded")
if action.kind == "accept":
return self.finish("accept")
return self.finish("forced_accept" if forced else "accept")

def _continue_action(self):
from .verification_plans import Job
Expand Down
124 changes: 124 additions & 0 deletions tests/harness/test_vats_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,3 +1274,127 @@ def test_outer_loop_resume_reuses_trained_checkpoints_and_frozen_roots(runtime,
assert control.read("campaign") == before
with pytest.raises(ValueError, match="starting conditions"):
learn(control, "campaign", adapter, root, snapshot, settings, **(args | {"seed": 9}))


def test_unbundled_menu_enforces_attempts_candidate_validity_and_plan_cap():
from inferrsi.contracts.claim import Verdict
from inferrsi.harness.manager.search.vats import Action, menu
from inferrsi.harness.manager.search.verification_plans import Job

digest_hex = "a" * 64
ctx = tree.Context("task", "target", "env", "proto", "eval", "cfg", "qref")
prod = tree.Producer(digest_hex, digest_hex, digest_hex, digest_hex)

def root_receipts(search_id, root):
a1 = tree.Attempt(
"r-c1", "ek1", "res1", "l1", search_id, root.candidate_id, root.artifact_digest,
"c1", ctx,
)
a2 = tree.Attempt(
"r-c2", "ek2", "res2", "l2", search_id, root.candidate_id, root.artifact_digest,
"c2", ctx,
)
return (
tree.Receipt(a1, Verdict.PASS, digest_hex, None),
tree.Receipt(a2, Verdict.PASS, digest_hex, 1.0),
)

snap = Snapshot(drafter=(0.0,), policy=(0.0,) * 8, scorer=(0.0,), origin="test")
base_kw = dict(
search_ms=100, preparation_ms=1, draft_ms=1, max_steps=4, max_parents=1,
draft_depth=1, max_targets=2, max_jobs=8, max_plans=4,
)
bundled = Settings(**base_kw, bundled=True)
unbundled = Settings(**base_kw, bundled=False)

exhausted_contract = tree.Contract(
"s1", ctx, digest_hex, ("c1", "c2"), "c2", "maximize", 4, 3, 3
)
root1 = tree.Candidate("root", digest_hex, None, prod)
s_exhausted = tree.initialize(exhausted_contract, root1, root_receipts("s1", root1))
s_exhausted = tree.add_candidate(
s_exhausted, tree.Candidate("cand1", "b" * 64, "root", prod),
expected_revision=s_exhausted.revision,
)
att1 = tree.Attempt("a1", "eka1", "resa1", "la1", "s1", "cand1", "b" * 64, "c1", ctx)
s_exhausted = tree.register_attempt(s_exhausted, att1, expected_revision=s_exhausted.revision)
s_exhausted = tree.record_receipt(
s_exhausted, tree.Receipt(att1, Verdict.PASS, digest_hex, None),
expected_revision=s_exhausted.revision,
)
j1 = (Job("cand1:c2", 10, "cand1", "c2"),)
assert [a for a in menu(s_exhausted, j1, 100, unbundled, snap) if a.kind == "verify"] == []

dep = tree.Dependency("dep-a", 1)
inv_contract = tree.Contract("s2", ctx, digest_hex, ("c1", "c2"), "c2", "maximize", 5, 3, 10)
root2 = tree.Candidate("root", digest_hex, None, prod)
s_inv = tree.initialize(inv_contract, root2, root_receipts("s2", root2), dependencies=(dep,))
s_inv = tree.add_candidate(
s_inv, tree.Candidate("failed_cand", "b" * 64, "root", prod),
expected_revision=s_inv.revision,
)
s_inv = tree.add_candidate(
s_inv, tree.Candidate("stale_cand", "c" * 64, "root", prod, dependencies=(dep,)),
expected_revision=s_inv.revision,
)
s_inv = tree.add_candidate(
s_inv, tree.Candidate("valid_cand", "d" * 64, "root", prod),
expected_revision=s_inv.revision,
)
att2 = tree.Attempt("a2", "eka2", "resa2", "la2", "s2", "failed_cand", "b" * 64, "c1", ctx)
s_inv = tree.register_attempt(s_inv, att2, expected_revision=s_inv.revision)
s_inv = tree.record_receipt(
s_inv, tree.Receipt(att2, Verdict.FAIL, digest_hex, None),
expected_revision=s_inv.revision,
)
s_inv = tree.invalidate(s_inv, "dep-a", expected_revision=s_inv.revision)
j2 = (
Job("failed_cand:c2", 10, "failed_cand", "c2"),
Job("stale_cand:c1", 10, "stale_cand", "c1"),
Job("stale_cand:c2", 10, "stale_cand", "c2"),
Job("valid_cand:c1", 10, "valid_cand", "c1"),
)
assert [a.jobs for a in menu(s_inv, j2, 100, unbundled, snap) if a.kind == "verify"] == [
("valid_cand:c1",),
]

cap_contract = tree.Contract("s3", ctx, digest_hex, ("c1", "c2"), "c2", "maximize", 4, 3, 10)
root3 = tree.Candidate("root", digest_hex, None, prod)
s_cap = tree.initialize(cap_contract, root3, root_receipts("s3", root3))
s_cap = tree.add_candidate(
s_cap, tree.Candidate("cand1", "b" * 64, "root", prod),
expected_revision=s_cap.revision,
)
s_cap = tree.add_candidate(
s_cap, tree.Candidate("cand2", "c" * 64, "root", prod),
expected_revision=s_cap.revision,
)
j3 = (
Job("cand2:c2", 30, "cand2", "c2"),
Job("cand1:c2", 20, "cand1", "c2"),
Job("cand2:c1", 10, "cand2", "c1"),
Job("cand1:c1", 10, "cand1", "c1"),
)
assert len(menu(s_cap, j3, 100, bundled, snap)) == 4
unbundled_actions = menu(s_cap, j3, 100, unbundled, snap)
assert len(unbundled_actions) == 4
assert unbundled_actions[0] == Action("accept")
assert [a.jobs for a in unbundled_actions if a.kind == "verify"] == [
("cand1:c1",),
("cand2:c1",),
("cand1:c2",),
]
assert menu(s_cap, j3, 100, replace(unbundled, max_plans=1), snap) == (Action("accept"),)


def test_forced_accept_run_records_forced_accept_stop_reason(runtime):
from inferrsi.harness.manager.search.vats import Action

_, _, _, _, root = runtime
search = start_search_for_final(runtime, name="forced-accept", forced=True)
record = search.run(forced_action=Action("accept").key)
assert record["status"] == "complete"
assert record["stop_reason"] == "forced_accept"
assert record["selected"] == root.root_id
assert len(record["trace"]) == 1
assert record["trace"][0]["forced"] is True
Loading