Skip to content

Commit ed6281b

Browse files
feat(eval): planner-variant arms as an orthogonal axis, and the §5 verdict door
Council D-12 wants the five planner variants measured as ARMS -- shipped, or_first_filtered, and_first_unfiltered, or_only_unfiltered and the candidate and_then_prose_or -- without overloading the mcp|cli|hybrid|frozen transport arms. So the planner is a second axis: `mcp:and_then_prose_or` is the real session_search tool through FastMCP with one function substituted for retrieval.plan_natural_language for the duration of the call, exactly as the arm already substitutes the database path. plan_query is never substituted, so the explicit door is identical across variants by construction (tested through the tool for every variant). The subprocess CLI arm and the frozen control refuse a variant: one cannot be reached in-process and the other must not move. The candidate builds on the shipped planner captured at import -- not on the module attribute it temporarily stands in for -- so it keeps the shipped AND arm, STOP set, length filter, no-content-terms return and de-duplication, and swaps only the widen string for prose_or_query(raw). Tests pin each of those properties and the end-to-end widen string in retrieval_status. eval/lexical.py evaluates the four pre-registered clauses FROM a receipt, by code: recall CI95 lower bound strictly above zero; precision@5 drop at most 0.05 absolute; the three explicit-door assertions re-run on the live planner; the pre-planner golden byte-identical to d060d3f. It also derives the committed receipt with digests in sha256:/git: notation, because the detect-secrets hook flags any bare quoted hex string (a 16-hex prefix included -- tested). `python -m agent_session_tools.eval lexical-verdict` is the door; the gold subcommand now also pairs precision@K and MRR@K with the same bootstrap and prints P@K per arm, and its comparison printer speaks the third receipt shape instead of assuming two.
1 parent 1ce1414 commit ed6281b

5 files changed

Lines changed: 906 additions & 20 deletions

File tree

‎packages/agent-session-tools/src/agent_session_tools/eval/__main__.py‎

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
python -m agent_session_tools.eval stage5-latency \
1616
--db ~/.local/share/studyloop/eval-clones/bakeoff-bge-20260915/sessions.db \
1717
--out receipt.json
18+
19+
``lexical-verdict`` (§5 stream, council D-12) judges a gold receipt that carries
20+
the planner-variant arms (``--arms mcp,mcp:and_then_prose_or,...``) by the
21+
pre-registered clauses in :mod:`.lexical` and writes the committed form:
22+
23+
python -m agent_session_tools.eval lexical-verdict \
24+
--receipt raw.json --candidate mcp:and_then_prose_or --control mcp \
25+
--out docs/architecture/session-memory/receipts/lexical/or-fallback-dev-2026-09-15.json
1826
"""
1927

2028
from __future__ import annotations
@@ -26,10 +34,15 @@
2634
from typing import Any
2735

2836
from . import K, SEED
29-
from .arms import ARMS, DEFAULT_ROWS, build_arm
37+
from .arms import ARMS, DEFAULT_ROWS, PLANNERS, build_arm
3038
from .census import census_receipt, collect_questions, run_census
3139
from .gold import load_gold, score_arm
32-
from .metrics import cluster_bootstrap, non_inferiority
40+
from .metrics import (
41+
cluster_bootstrap,
42+
non_inferiority,
43+
paired_cluster_bootstrap,
44+
precision_values,
45+
)
3346
from .receipt import build_receipt, write_receipt
3447

3548

@@ -49,7 +62,11 @@ def _parser() -> argparse.ArgumentParser:
4962
gold.add_argument(
5063
"--arms",
5164
default="mcp,frozen",
52-
help=f"comma-separated arm names ({', '.join(sorted(ARMS))})",
65+
help=(
66+
f"comma-separated arm names ({', '.join(sorted(ARMS))}); "
67+
f"<arm>:<planner> selects a planner variant ({', '.join(PLANNERS)}) "
68+
"on an in-process arm"
69+
),
5370
)
5471
gold.add_argument(
5572
"--rows",
@@ -99,26 +116,50 @@ def _parser() -> argparse.ArgumentParser:
99116
help="Gate L: resident-state latency for the mcp/web default flip",
100117
)
101118
)
119+
120+
# §5 stream: the adopt/reject verdict, computed from a gold receipt by the
121+
# frozen clauses in ``eval/lexical.py`` and written as the committed form.
122+
from .lexical import DEFAULT_CANDIDATE, DEFAULT_CONTROL
123+
124+
verdict = sub.add_parser(
125+
"lexical-verdict",
126+
help="§5: judge the prose-OR widen candidate from a gold receipt (D-12 clauses)",
127+
)
128+
verdict.add_argument("--receipt", required=True, help="raw gold receipt to judge")
129+
verdict.add_argument(
130+
"--candidate", default=DEFAULT_CANDIDATE, help="candidate arm name"
131+
)
132+
verdict.add_argument("--control", default=DEFAULT_CONTROL, help="control arm name")
133+
verdict.add_argument("--k", type=int, default=K, help=f"rank cut-off (default {K})")
134+
verdict.add_argument(
135+
"--out", required=True, help="committed receipt to write (digests prefixed)"
136+
)
102137
return parser
103138

104139

105140
def _format_comparison(pair: str, stats: dict) -> str:
106-
"""One console line per comparison, speaking BOTH receipt shapes.
141+
"""One console line per comparison, speaking EVERY receipt shape.
107142
108-
Delta comparisons carry a ``ci95`` pair; the K non-inferiority entry
109-
carries ``ci95_upper``/``upper_at_least_zero`` instead (Stage 4 addendum,
110-
astra 5 / kimi 1). The 2026-09-15 SEALED run proved the printer must
111-
never assume one shape: it crashed AFTER the receipt was written, on the
112-
first two-arm run that reached the K entry.
143+
Delta comparisons carry a ``ci95`` pair and either ``established`` (the
144+
recall lift rule) or ``lower_above_zero`` (the §5 value bootstraps); the K
145+
non-inferiority entry carries ``ci95_upper``/``upper_at_least_zero``
146+
instead (Stage 4 addendum, astra 5 / kimi 1). The 2026-09-15 SEALED run
147+
proved the printer must never assume one shape: it crashed AFTER the
148+
receipt was written, on the first two-arm run that reached the K entry.
113149
"""
114150
if "ci95" in stats:
115151
low, high = stats["ci95"]
152+
verdict = (
153+
f"established={stats['established']}"
154+
if "established" in stats
155+
else f"lower_above_zero={stats['lower_above_zero']}"
156+
)
116157
return (
117-
f"{pair:>16} delta macro {stats['point']:+.4f}"
118-
f" CI95 [{low:+.4f}, {high:+.4f}] established={stats['established']}"
158+
f"{pair:>48} delta macro {stats['point']:+.4f}"
159+
f" CI95 [{low:+.4f}, {high:+.4f}] {verdict}"
119160
)
120161
return (
121-
f"{pair:>16} delta {stats.get('stratum', '?')} {stats['point']:+.4f}"
162+
f"{pair:>48} delta {stats.get('stratum', '?')} {stats['point']:+.4f}"
122163
f" CI95 upper {stats['ci95_upper']:+.4f}"
123164
f" upper_at_least_zero={stats['upper_at_least_zero']}"
124165
)
@@ -149,6 +190,19 @@ def _run_gold(args: argparse.Namespace) -> int:
149190
comparisons[f"{a}_vs_{b}_K"] = non_inferiority(
150191
results[a].per_item, results[b].per_item, items, margin=0.0, stratum="K"
151192
)
193+
# §5 guardrails (pre-registration 2026-09-15): precision@K and MRR@K
194+
# paired the same way, so a widen step that buys recall with junk
195+
# rows is visible as a precision interval, not a footnote.
196+
comparisons[f"{a}_vs_{b}_precision"] = paired_cluster_bootstrap(
197+
precision_values(results[a].per_item, items, args.k),
198+
precision_values(results[b].per_item, items, args.k),
199+
items,
200+
)
201+
comparisons[f"{a}_vs_{b}_mrr"] = paired_cluster_bootstrap(
202+
{i: s.rr for i, s in results[a].per_item.items()},
203+
{i: s.rr for i, s in results[b].per_item.items()},
204+
items,
205+
)
152206

153207
from .arms import _git_head
154208

@@ -168,7 +222,8 @@ def _run_gold(args: argparse.Namespace) -> int:
168222
", ".join(f"{k}={n}" for k, n in result.errors_by_kind.items()) or "none"
169223
)
170224
print(
171-
f"{name:>8} macro recall@{args.k} {recall['macro']:.4f} {strata}"
225+
f"{name:>24} macro recall@{args.k} {recall['macro']:.4f} {strata}"
226+
f" P@{args.k} {result.precision['macro']:.4f}"
172227
f" MRR {result.mrr['macro']:.4f}"
173228
f" crashes {result.crashes}/{gold.n} ({kinds})"
174229
f" p50 {result.latency_ms['p50']:.1f} ms p95 {result.latency_ms['p95']:.1f} ms"
@@ -211,6 +266,22 @@ def _run_census(args: argparse.Namespace) -> int:
211266
return 0
212267

213268

269+
def _run_lexical_verdict(args: argparse.Namespace) -> int:
270+
import json
271+
272+
from .lexical import derive_receipt, format_verdict, judge
273+
274+
raw_path = Path(args.receipt).expanduser()
275+
raw_bytes = raw_path.read_bytes()
276+
raw = json.loads(raw_bytes)
277+
verdict = judge(raw, candidate=args.candidate, control=args.control, k=args.k)
278+
derived = derive_receipt(raw, raw_bytes, verdict, raw_path=str(raw_path))
279+
out = write_receipt(args.out, derived)
280+
print(format_verdict(verdict))
281+
print(f"receipt -> {out}")
282+
return 0
283+
284+
214285
def main(argv: list[str] | None = None) -> int:
215286
args = _parser().parse_args(argv)
216287
if args.ruler == "gold":
@@ -221,6 +292,8 @@ def main(argv: list[str] | None = None) -> int:
221292
from .stage5_latency import run_parent
222293

223294
return run_parent(args)
295+
if args.ruler == "lexical-verdict":
296+
return _run_lexical_verdict(args)
224297
return 2
225298

226299

0 commit comments

Comments
 (0)