From 85a29f47cdf41f685307087cef3df267ec21c184 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Thu, 12 Nov 2026 10:03:12 -0800 Subject: [PATCH 1/4] fix(tier3): respect negative-control routing in case advice Signed-off-by: Narendran Raghavan --- CHANGELOG.md | 4 + src/skillevaluator/tier3/case_summary.py | 7 +- tests/test_tier3_case_summary.py | 97 ++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0fed53ad..2ad971d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -308,6 +308,10 @@ All notable changes to SkillEvaluator are documented in this file. ### Fixed +- Tier 3 improvement recommendations respect each case's expected skill routing: + passing negative controls no longer inherit activation-loss advice from positive + cases, while failed negatives retain task, environment, and run-error diagnostics. + - Repository CI can opt in to reviewed, per-skill SkillSpector baselines from the PR or merge request's target revision. Policy files from the proposed changes cannot approve their own exceptions. diff --git a/src/skillevaluator/tier3/case_summary.py b/src/skillevaluator/tier3/case_summary.py index 4337a8eef..bc619bd18 100644 --- a/src/skillevaluator/tier3/case_summary.py +++ b/src/skillevaluator/tier3/case_summary.py @@ -24,6 +24,7 @@ from skillevaluator.reporting.summary_copy import pass_at_k_summary from skillevaluator.reporting.terminal_styles import AMBER from skillevaluator.tier3.attempt_verdict import attempt_verdict, scored_goal_accuracy +from skillevaluator.tier3.eval_core.checks import resolve_should_trigger from skillevaluator.tier3.harbor.progress import redact_progress_detail, secret_values_from_environment from skillevaluator.utils.redaction import redact_sensitive_text from skillevaluator.utils.secret_redaction import Redactor @@ -881,7 +882,9 @@ def _diagnose_agent_case( wp, wn = _attempt_rate(with_marks) bp, bn = _attempt_rate(without_marks) errors = with_marks.count(ERROR) - not_used = _never_activated(agent) + # Negative controls must avoid the skill; an agent-wide positive miss does not apply to them. + should_trigger = resolve_should_trigger(dict(_dataset_entries(run_dir).get(case_id, {}))) + not_used = should_trigger is not False and _never_activated(agent) failed_trials = [] for attempt in with_case.get("attempts", []) if isinstance(with_case, Mapping) else []: if isinstance(attempt, Mapping) and attempt.get("passed") is not True: @@ -932,7 +935,7 @@ def _diagnose_agent_case( elif finals and all(_ASKS_FOR_INPUT.search(f) for f in finals): kind = "missing input" what = f'the agent stopped to ask for input the case does not provide: "{_short(finals[0], 140)}"' - elif activations and all(a is False for a in activations): + elif should_trigger is not False and activations and all(a is False for a in activations): kind, what = "skill not used", "the agent never loaded the skill in the failed attempts" if reasons: what += f"; {reasons.most_common(1)[0][0]}" diff --git a/tests/test_tier3_case_summary.py b/tests/test_tier3_case_summary.py index 3fe8f45ef..99bcdebe5 100644 --- a/tests/test_tier3_case_summary.py +++ b/tests/test_tier3_case_summary.py @@ -6,6 +6,7 @@ import json from pathlib import Path +import pytest from rich.console import Console from skillevaluator.tier3.case_summary import render_case_summary, verdict, what_to_fix @@ -405,6 +406,102 @@ def test_never_activated_scores_do_not_claim_a_skill_effect(tmp_path: Path) -> N assert "inconclusive" in output +@pytest.mark.parametrize( + "negative_routing", + [{"expected_skill": None}, {"should_trigger": False, "expected_skill": "release-review"}], +) +def test_mixed_activation_miss_does_not_blame_passing_negative(tmp_path: Path, negative_routing: dict) -> None: + from skillevaluator.tier3.harbor.activation import summarize_skill_activation + from skillevaluator.tier3.harbor.metrics import DEFAULT_METRICS + + negative = { + **dict.fromkeys(DEFAULT_METRICS, 1.0), + "_trial_name": "n0", + "details": {"skill_execution": {"should_trigger": False, "negative_check": {"passed": True}}}, + } + positive = { + **dict.fromkeys(DEFAULT_METRICS, 0.2), + "_trial_name": "p0", + "details": {"skill_execution": {"should_trigger": True, "activation": {"passed": False, "score": 0.0}}}, + } + agent = _agent( + {"negative": _case(True, prefix="n"), "positive": _case(False, prefix="p")}, + {"negative": _case(True), "positive": _case(False)}, + ) + agent["skill_activation"] = summarize_skill_activation([negative, positive]) + (tmp_path / "dataset_snapshot.json").write_text( + json.dumps( + { + "dataset": [ + {"id": "negative", **negative_routing}, + {"id": "positive", "expected_skill": "release-review"}, + ] + } + ) + ) + _trial(tmp_path, "a", "n0", negative) + _trial(tmp_path, "a", "p0", positive) + + [fix] = what_to_fix({"agents": {"a": agent}}, run_dir=tmp_path, use_llm=False) + + assert (fix["case"], fix["kind"], fix["attempts_lost"]) == ("positive", "skill not used", 1) + assert "frontmatter description" in fix["action"] + console = Console(record=True, width=160) + render_case_summary({"agents": {"a": agent}}, console=console, fixes=[fix]) + advice = console.export_text().split("How to improve", 1)[1] + assert "positive" in advice and "negative" not in advice + + +@pytest.mark.parametrize("activation_status", ["never_activated", "unknown"]) +@pytest.mark.parametrize("failure_kind", ["skill", "environment", "run error"]) +def test_failed_negative_keeps_task_diagnostics(tmp_path: Path, activation_status: str, failure_kind: str) -> None: + case = _case(missing=1) if failure_kind == "run error" else _case(False) + agent = _agent({"negative": case}, {}) + agent["skill_activation"] = {"status": activation_status} + (tmp_path / "dataset_snapshot.json").write_text( + json.dumps({"dataset": [{"id": "negative", "should_trigger": False, "expected_skill": "release-review"}]}) + ) + if failure_kind == "run error": + trial = tmp_path / "a" / "with-skill" / "trials" / "negative__attempt1" + trial.mkdir(parents=True) + (trial / "failure.json").write_text(json.dumps({"error": {"type": "AgentTimeoutError", "message": "900s"}})) + else: + reward = _reward(False, "the answer omitted the requested total") + reward["details"]["skill_execution"]["should_trigger"] = False + observation = "ModuleNotFoundError: No module named 'pypdf'" if failure_kind == "environment" else "" + _trial(tmp_path, "a", "t0", reward, observation) + + [fix] = what_to_fix({"agents": {"a": agent}}, run_dir=tmp_path, use_llm=False) + + assert (fix["case"], fix["kind"], fix["attempts_lost"]) == ("negative", failure_kind, 1) + assert "frontmatter description" not in fix["action"] + if failure_kind == "environment": + assert "No module named 'pypdf'" in fix["what"] + elif failure_kind == "run error": + assert "AgentTimeoutError" in fix["what"] + else: + assert "omitted the requested total" in fix["what"] + + +@pytest.mark.parametrize("snapshot", [None, "{broken", '{"dataset": [{"id": "c"}]}']) +@pytest.mark.parametrize("activation_status", ["never_activated", "unknown"]) +def test_unlabeled_snapshot_preserves_legacy_activation_diagnosis( + tmp_path: Path, snapshot: str | None, activation_status: str +) -> None: + agent = _agent({"c": _case(True)}, {}) + agent["skill_activation"] = {"status": activation_status} + if snapshot is not None: + (tmp_path / "dataset_snapshot.json").write_text(snapshot) + + fixes = what_to_fix({"agents": {"a": agent}}, run_dir=tmp_path, use_llm=False) + + if activation_status == "never_activated": + [fix] = fixes + assert (fix["case"], fix["kind"], fix["attempts_lost"]) == ("c", "skill not used", 1) + else: + assert fixes == [] + + def test_truncated_attempts_cannot_produce_a_complete_effect_or_clean_bill(tmp_path: Path) -> None: case = {**_case(True), "attempt_details_total": 2, "attempt_details_truncated": True} agent = _agent({"c": case}, {"c": _case(False, False)}) From 589e9bdc5d20dbc336d0ae9988103850be8a85c4 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Thu, 12 Nov 2026 10:40:29 -0800 Subject: [PATCH 2/4] fix(tier3): read recommendation dataset snapshot once Signed-off-by: Narendran Raghavan --- CHANGELOG.md | 1 + src/skillevaluator/tier3/case_summary.py | 15 +++++-- tests/test_tier3_case_summary.py | 56 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad971d18..02e7b510a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -311,6 +311,7 @@ All notable changes to SkillEvaluator are documented in this file. - Tier 3 improvement recommendations respect each case's expected skill routing: passing negative controls no longer inherit activation-loss advice from positive cases, while failed negatives retain task, environment, and run-error diagnostics. + The dataset snapshot is read once per recommendation pass across all cases and agents. - Repository CI can opt in to reviewed, per-skill SkillSpector baselines from the PR or merge request's target revision. Policy files from the proposed diff --git a/src/skillevaluator/tier3/case_summary.py b/src/skillevaluator/tier3/case_summary.py index bc619bd18..bb5f14198 100644 --- a/src/skillevaluator/tier3/case_summary.py +++ b/src/skillevaluator/tier3/case_summary.py @@ -875,7 +875,12 @@ def _run_error(trial_dir: Path, run_dir: Path) -> str: def _diagnose_agent_case( - run_dir: Path, agent_name: str, agent: Mapping[str, Any], case_id: str + run_dir: Path, + agent_name: str, + agent: Mapping[str, Any], + case_id: str, + *, + entry: Mapping[str, Any] | None = None, ) -> list[dict[str, Any]]: with_case = _cases(agent, "with_skill").get(case_id) with_marks, without_marks = _marks(with_case), _marks(_cases(agent, "without_skill").get(case_id)) @@ -883,7 +888,9 @@ def _diagnose_agent_case( bp, bn = _attempt_rate(without_marks) errors = with_marks.count(ERROR) # Negative controls must avoid the skill; an agent-wide positive miss does not apply to them. - should_trigger = resolve_should_trigger(dict(_dataset_entries(run_dir).get(case_id, {}))) + if entry is None: + entry = _dataset_entries(run_dir).get(case_id, {}) + should_trigger = resolve_should_trigger(dict(entry)) not_used = should_trigger is not False and _never_activated(agent) failed_trials = [] for attempt in with_case.get("attempts", []) if isinstance(with_case, Mapping) else []: @@ -1163,10 +1170,11 @@ def what_to_fix( ) -> list[dict[str, Any]]: """Rank failed test cases across agents by attempts lost and attach one fix each.""" agents = {str(k): v for k, v in (result.get("agents") or {}).items() if isinstance(v, Mapping)} + dataset = _dataset_entries(run_dir) grouped: dict[tuple[str, str], list[dict[str, Any]]] = {} for case_id in _case_ids(agents): for name, agent in agents.items(): - for issue in _diagnose_agent_case(run_dir, name, agent, case_id): + for issue in _diagnose_agent_case(run_dir, name, agent, case_id, entry=dataset.get(case_id, {})): grouped.setdefault((case_id, issue["kind"]), []).append(issue) issues = [] for items in grouped.values(): @@ -1184,7 +1192,6 @@ def what_to_fix( env_errors=list(dict.fromkeys(e for item in items for e in item["env_errors"])), ) issues.append(merged) - dataset = _dataset_entries(run_dir) description = _skill_description(skill_path) for issue in issues: entry = dataset.get(issue["case"], {}) diff --git a/tests/test_tier3_case_summary.py b/tests/test_tier3_case_summary.py index 99bcdebe5..b25eb79c0 100644 --- a/tests/test_tier3_case_summary.py +++ b/tests/test_tier3_case_summary.py @@ -502,6 +502,62 @@ def test_unlabeled_snapshot_preserves_legacy_activation_diagnosis( assert fixes == [] +@pytest.mark.parametrize("case_count", [20, 100]) +@pytest.mark.parametrize("agent_count", [1, 2]) +@pytest.mark.parametrize("scenario", ["passing", "mixed negative", "empty snapshot"]) +def test_case_advice_reads_snapshot_once( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, case_count: int, agent_count: int, scenario: str +) -> None: + from skillevaluator.utils.secure_fs import SecureRoot + + case_ids = [f"case-{i:03d}" for i in range(case_count)] + entries = [ + {"id": case_id, "should_trigger": bool(i % 2), "expected_skill": "release-review"} + for i, case_id in enumerate(case_ids) + ] + (tmp_path / "dataset_snapshot.json").write_text( + json.dumps({"dataset": [] if scenario == "empty snapshot" else entries}) + ) + cases = {case_id: _case(scenario != "mixed negative" or i % 2 == 0) for i, case_id in enumerate(case_ids)} + agents = {f"agent-{i}": _agent(cases, {}) for i in range(agent_count)} + for agent in agents.values(): + agent["skill_activation"] = {"status": "unknown" if scenario == "passing" else "never_activated"} + snapshot_reads = 0 + read_bytes = SecureRoot.read_bytes + + def count_reads(self, path, *args, **kwargs): + nonlocal snapshot_reads + if str(path) == "dataset_snapshot.json": + snapshot_reads += 1 + return read_bytes(self, path, *args, **kwargs) + + monkeypatch.setattr(SecureRoot, "read_bytes", count_reads) + + fixes = what_to_fix({"agents": agents}, run_dir=tmp_path, use_llm=False) + + if scenario == "passing": + assert fixes == [] + else: + [fix] = fixes + expected_cases = case_ids[1::2] if scenario == "mixed negative" else case_ids + assert fix["cases"] == expected_cases + assert fix["kind"] == "skill not used" + assert fix["attempts_lost"] == len(expected_cases) * agent_count + assert snapshot_reads == 1 + + +def test_direct_case_diagnosis_still_loads_snapshot(tmp_path: Path) -> None: + from skillevaluator.tier3.case_summary import _diagnose_agent_case + + (tmp_path / "dataset_snapshot.json").write_text( + json.dumps({"dataset": [{"id": "negative", "should_trigger": False, "expected_skill": "release-review"}]}) + ) + agent = _agent({"negative": _case(True)}, {}) + agent["skill_activation"] = {"status": "never_activated"} + + assert _diagnose_agent_case(tmp_path, "a", agent, "negative") == [] + + def test_truncated_attempts_cannot_produce_a_complete_effect_or_clean_bill(tmp_path: Path) -> None: case = {**_case(True), "attempt_details_total": 2, "attempt_details_truncated": True} agent = _agent({"c": case}, {"c": _case(False, False)}) From aacd62fad02cf9650219d7fd5dcca1dfd27e4781 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Thu, 12 Nov 2026 11:12:54 -0800 Subject: [PATCH 3/4] docs(changelog): group advice fix with dataset routing corrections Signed-off-by: Narendran Raghavan --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a23956a..e02364457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -318,11 +318,6 @@ All notable changes to SkillEvaluator are documented in this file. ### Fixed -- Tier 3 improvement recommendations respect each case's expected skill routing: - passing negative controls no longer inherit activation-loss advice from positive - cases, while failed negatives retain task, environment, and run-error diagnostics. - The dataset snapshot is read once per recommendation pass across all cases and agents. - - Public MCP URL probes handle modern SDK client and stream APIs while retaining checked-address connections, header grants, response limits, and bounded cleanup. Redirect responses are refused before SDK-level redirect handling. @@ -368,6 +363,11 @@ All notable changes to SkillEvaluator are documented in this file. use schema 1.1; valid schema 1.0 snapshots retain their original datasets and integrity checks, with corrected summaries projected without rewriting files. +- Tier 3 improvement recommendations respect each case's expected skill routing: + passing negative controls no longer inherit activation-loss advice from positive + cases, while failed negatives retain task, environment, and run-error diagnostics. + The dataset snapshot is read once per recommendation pass across all cases and agents. + - Tier 2 includes qualifying shell comment blocks at end of file in context deduplication. Previously those blocks disappeared unless a blank line or code followed them, which could hide repeated guidance across shell files. From f2919d1158dee204d632a43b90a92a568ca9fa83 Mon Sep 17 00:00:00 2001 From: Narendran Raghavan Date: Thu, 12 Nov 2026 11:39:02 -0800 Subject: [PATCH 4/4] test(tier3): wait for authenticated bridge readiness Signed-off-by: Narendran Raghavan (cherry picked from commit cbfea3e2edb82454cada413ff7c61dead46daed4) Signed-off-by: Narendran Raghavan --- tests/test_nvidia_build_bridge.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_nvidia_build_bridge.py b/tests/test_nvidia_build_bridge.py index fcfd98bba..61ec3bc20 100644 --- a/tests/test_nvidia_build_bridge.py +++ b/tests/test_nvidia_build_bridge.py @@ -1133,14 +1133,21 @@ def test_dynamic_bridge_ignores_prebound_old_port_and_checker_authenticates_heal text=True, ) deadline = time.monotonic() + 5 - while not ready_file.exists() and process.poll() is None and time.monotonic() < deadline: - time.sleep(0.025) + ready_origin = None + while process.poll() is None and time.monotonic() < deadline: + try: + ready_origin = bridge.check_ready_file(ready_file) + except (OSError, RuntimeError): + time.sleep(0.025) + else: + break assert process.poll() is None, process.communicate(timeout=1) - assert ready_file.exists() + assert ready_origin is not None, "bridge did not pass its authenticated readiness check" ready = json.loads(ready_file.read_text(encoding="utf-8")) origin = ready["origin"] readiness_token = ready["readiness_token"] + assert origin == ready_origin assert origin != "http://127.0.0.1:18080" assert _request("http://127.0.0.1:18080/healthz")[0] == 200 assert _request(f"{origin}/healthz")[0] == 403