feat(outbox): every evaluated approach becomes something an expert can judge
A run commissioned to evaluate three approaches wrote ONE proposal artefact, so
only the approach it selected could ever receive a verdict. The other two were
evaluated, reported in the settlement, and then taught the learning loop nothing.
The defect class is a key collapse, and it had two halves — fixing either alone
leaves it intact:
* the WRITER wrote one pair per run, so the non-selected approaches never existed
on disk;
* the READER (hitl._read_outbox_proposals) joins proposal to outcome on the
run_id FIELD read from file CONTENT, never the filename. Three files sharing
one run_id collapse onto one dict key, last write wins — so widening only the
filename would have produced three artefacts and still one pending row. This is
the S3.2 collision class: two rows under one key silently become one.
Artefacts are now keyed {run_id}-{approach_id}-*.json AND carry approach_id in the
payload; the join key is (run_id, approach_id). Two properties make them genuinely
judgeable rather than merely present:
* verdict_id is minted per approach (verdicts.verdict_key, the S3.2 content hash)
— reusing the run's single id would let one delivered verdict clear all three
from the queue;
* provenance.validator_decision follows ITS OWN approach — the run's stamp would
report a rejected candidate as validated, and nothing downstream could correct it.
verdicts.verdict_key is public so a run can stamp the key a verdict WILL arrive
under without capturing a decision nobody has made; it delegates to _mint_id
rather than restating the hash (the (p) rule: one keying rule, one copy).
The per-approach set REPLACES the run-level pair rather than joining it — the
selected approach is already among them, and writing both would count it twice in
hitl pending. The selected one carries the run's final outcome, so the outbox can
never disagree with the RunResult; the others carry the validator's verdict, the
only falsifier that ran on them.
mandate.py is deliberately untouched: hanging a ValidatedProposal off a coverage
row would drag validator — and pulp — into a module kept to pydantic+stdlib for
D7 portability, so _evaluate_mandate returns the evaluated outcomes alongside.
Ran it, not just tested it: a real CLI run wrote six artefacts and hitl pending
listed three rows. It also showed the honest edge — three approaches that produce
an identical candidate share one content-hash key, so one verdict settles all
three. That is correct (they were one candidate), and it is now documented.
Load-bearing MEASURED (tests/test_a5_per_approach_artifacts_loadbearing.py) against
the whole 750-test suite, five mutations all red: detach the per-approach writer ·
drop approach_id from the join key · reuse the run's verdict id · reuse the run's
provenance stamp · widen the filename but not the payload. Control: on a full
detach exactly the 5 new tests fail and 745 pre-existing ones stay green — the
no-mandate path is inert, and writes neither the filename segment nor the field.
Docs: bestille-en-kjoring.md (what the commissioner gets) + ekspert-svar.md (what
the expert's queue looks like, and that "rejected" is the validator's verdict on
the numbers, never a professional judgement of the idea).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VtRd8y1PDPGwkrRXFhubqr
This commit is contained in:
parent
9668e17f2f
commit
455d93d33e
7 changed files with 443 additions and 33 deletions
|
|
@ -92,6 +92,7 @@ from portfolio_optimiser.verdicts import (
|
|||
capture_verdict,
|
||||
load_verdicts_from_dir,
|
||||
similarity,
|
||||
verdict_key,
|
||||
)
|
||||
from portfolio_optimiser.value_report import (
|
||||
build_value_report,
|
||||
|
|
@ -263,10 +264,23 @@ def _select_outcome(
|
|||
async def _evaluate_mandate(
|
||||
mandate: Mandate,
|
||||
evaluate: Callable[[Approach | None], Awaitable[ValidatedProposal | Rejection]],
|
||||
) -> tuple[ValidatedProposal | Rejection, tuple[ApproachOutcome, ...]]:
|
||||
) -> tuple[
|
||||
ValidatedProposal | Rejection,
|
||||
tuple[ApproachOutcome, ...],
|
||||
tuple[tuple[str, ValidatedProposal | Rejection], ...],
|
||||
]:
|
||||
"""Evaluate every commissioned approach, then the run's own proposal when allowed, and report
|
||||
what became of each (Trekk A3/A4).
|
||||
|
||||
Returns the selected outcome, the coverage report, and — third — every EVALUATED approach's own
|
||||
outcome paired with its id (A5), which is what lets each of them be written as a judgeable
|
||||
outbox artefact. It is returned alongside rather than folded into ``ApproachOutcome`` on
|
||||
purpose: ``mandate.py`` imports only ``pydantic`` + stdlib to stay D7-portable (guarded by
|
||||
``test_okf_is_maf_free``), and hanging a ``ValidatedProposal`` off a coverage row would drag
|
||||
``validator`` — and with it ``pulp`` — into that deliberately thin module. Rows the run never
|
||||
reached are absent here by construction: a ``not_evaluated`` approach has no proposal, so there
|
||||
is nothing to write and nothing to judge.
|
||||
|
||||
Budget exhaustion mid-list is REPORTED, not swallowed: the approaches that were never reached
|
||||
become ``not_evaluated`` rows. But if the very first approach exhausts the budget there is
|
||||
nothing honest to return, so ``BudgetExceeded`` propagates exactly as it did before — a run
|
||||
|
|
@ -278,6 +292,7 @@ async def _evaluate_mandate(
|
|||
|
||||
rows: list[ApproachOutcome] = []
|
||||
produced: list[tuple[int, ValidatedProposal | Rejection]] = []
|
||||
evaluated: list[tuple[str, ValidatedProposal | Rejection]] = []
|
||||
for index, (row_id, label, approach) in enumerate(plan):
|
||||
try:
|
||||
outcome = await evaluate(approach)
|
||||
|
|
@ -295,9 +310,10 @@ async def _evaluate_mandate(
|
|||
)
|
||||
break
|
||||
produced.append((index, outcome))
|
||||
evaluated.append((row_id, outcome))
|
||||
rows.append(_coverage_row(row_id, label, outcome))
|
||||
|
||||
return _select_outcome(produced), tuple(rows)
|
||||
return _select_outcome(produced), tuple(rows), tuple(evaluated)
|
||||
|
||||
|
||||
def _authored_texts(result: Any, name: str) -> list[str]:
|
||||
|
|
@ -619,10 +635,11 @@ async def run_project(
|
|||
)
|
||||
|
||||
coverage: tuple[ApproachOutcome, ...] = ()
|
||||
evaluated: tuple[tuple[str, ValidatedProposal | Rejection], ...] = ()
|
||||
if mandate is None:
|
||||
validator_outcome = await _evaluate(None)
|
||||
else:
|
||||
validator_outcome, coverage = await _evaluate_mandate(mandate, _evaluate)
|
||||
validator_outcome, coverage, evaluated = await _evaluate_mandate(mandate, _evaluate)
|
||||
proposal = validator_outcome.proposal
|
||||
|
||||
# 6. First-class provenance stamp (authoritative; independent of MAF Annotation).
|
||||
|
|
@ -693,14 +710,50 @@ async def run_project(
|
|||
# is guaranteed non-None by the fail-fast guard at the top.
|
||||
if outbox_dir is not None:
|
||||
assert run_id is not None # narrowed by the step-0 guard; keeps the type checker honest
|
||||
outbox.write_outbox(
|
||||
outbox_dir,
|
||||
run_id,
|
||||
outcome=outcome,
|
||||
provenance=stamp,
|
||||
checker_verdict=checker_decision,
|
||||
verdict_id=verdict.id,
|
||||
)
|
||||
if not evaluated:
|
||||
outbox.write_outbox(
|
||||
outbox_dir,
|
||||
run_id,
|
||||
outcome=outcome,
|
||||
provenance=stamp,
|
||||
checker_verdict=checker_decision,
|
||||
verdict_id=verdict.id,
|
||||
)
|
||||
else:
|
||||
# A5: one judgeable artefact PER evaluated approach. Without this the expert can only
|
||||
# judge the approach the run happened to select, so every other approach they
|
||||
# commissioned teaches the learning loop nothing. The per-approach set REPLACES the
|
||||
# single run-level pair rather than joining it — the selected approach is already among
|
||||
# these, and writing both would make ``hitl pending`` count it twice.
|
||||
for approach_id, approach_outcome in evaluated:
|
||||
# The SELECTED approach carries the run's final outcome, so the outbox can never
|
||||
# disagree with the ``RunResult``: the checker/dimension overrides above apply to
|
||||
# that one. The others carry the validator's verdict, which is the only falsifier
|
||||
# that ran on them.
|
||||
final = outcome if approach_outcome is validator_outcome else approach_outcome
|
||||
outbox.write_outbox(
|
||||
outbox_dir,
|
||||
run_id,
|
||||
outcome=final,
|
||||
# ``validator_decision`` must follow ITS OWN approach — stamping every artefact
|
||||
# with the selected approach's decision would report a rejected candidate as
|
||||
# validated. Everything else (model, citations, token usage) is the run's.
|
||||
provenance=stamp.model_copy(
|
||||
update={
|
||||
"validator_decision": (
|
||||
"validated"
|
||||
if isinstance(approach_outcome, ValidatedProposal)
|
||||
else "rejected"
|
||||
)
|
||||
}
|
||||
),
|
||||
checker_verdict=checker_decision,
|
||||
# The key an expert verdict on THIS candidate will arrive under (S3.2 content
|
||||
# hash). Reusing the run's single verdict id would let one delivered verdict
|
||||
# clear every approach from the pending queue.
|
||||
verdict_id=verdict_key(_features_of(approach_outcome.proposal)),
|
||||
approach_id=approach_id,
|
||||
)
|
||||
|
||||
return RunResult(
|
||||
outcome=outcome,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue