Skip to content

Multi-tier framework for evaluating AI agent skills and plugins with quality gates, security scanning, harness compatibility checks, semantic overlap detection, synthetic evaluation dataset generation, and live agent evaluation that measures how skills affect agent behavior. Ships reusable CI templates that bring every check to any repository.

fix(tier3): withhold behavior scores built on cut final answers (#503)

Narendran Raghavanc2f5a0204ba5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cd95119a..f3710154 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -60,6 +60,19 @@ All notable changes to SkillEvaluator are documented in this file.
### Fixed
+- Behavior checks no longer score a final answer that the evidence limits
+ shortened. The final-response allowance rises from 800 to 8,000 characters,
+ with the total behavior evidence budget reconciled to 12,000, so an ordinary
+ answer reaches the judge whole instead of losing its middle; the user request
+ is reserved alongside it, ahead of the optional exploration output in the
+ compact tool history. The `behavior_check` evidence record now reports
+ whether the required evidence is complete, not only whether something was
+ dropped. When the final answer still cannot fit, the judge returns an
+ explicit evaluation error and no behavior score, rather than grading the
+ evidence loss as a behavior failure, and that missing score stays missing
+ instead of being averaged in as a zero.
+ `SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT` and
+ `SKILL_EVAL_BEHAVIOR_CHECK_BUDGET` still override both limits.
- The supporting Tier 3 Pass@k table displays an unavailable or skipped
baseline rate as `N/A`, preserving an observed baseline rate of `0%`.
- Tier 3 budget summaries disclose measured usage above configured limits,
diff --git a/src/skillevaluator/tier3/eval_core/atif_helpers.py b/src/skillevaluator/tier3/eval_core/atif_helpers.py
index be089464..f1c4b187 100644
--- a/src/skillevaluator/tier3/eval_core/atif_helpers.py
+++ b/src/skillevaluator/tier3/eval_core/atif_helpers.py
@@ -193,8 +193,12 @@ def build_conversation_summary(traj: dict[str, Any], question: str) -> str:
_BEHAVIOR_EVIDENCE_MAX_CHARS = 4000
-_DEFAULT_BEHAVIOR_FINAL_RESPONSE_LIMIT = 800
-_DEFAULT_BEHAVIOR_CHECK_BUDGET = 8000
+# A realistic final answer runs to a few thousand characters, so the old 800
+# cap cut grading-relevant text out of the middle of ordinary answers (issue
+# #234). Allow a whole answer through, and keep the total budget finite by
+# reconciling it with the tool-history headroom in _behavior_check_budget.
+_DEFAULT_BEHAVIOR_FINAL_RESPONSE_LIMIT = 8000
+_DEFAULT_BEHAVIOR_CHECK_BUDGET = _DEFAULT_BEHAVIOR_FINAL_RESPONSE_LIMIT + 4000
_DEFAULT_TOOL_HISTORY_HEADROOM = 4000
_MIN_BEHAVIOR_HISTORY_HEADROOM = 1600
_SECTION_COMPACT_TOOL_HISTORY = "COMPACT TOOL HISTORY"
@@ -226,6 +230,17 @@ def _behavior_check_budget() -> int:
return max(base_budget, final_limit + _DEFAULT_TOOL_HISTORY_HEADROOM)
+def _behavior_user_request_limit() -> int:
+ """Return the behavior evidence allowance for the user request section.
+
+ The request the agent answered is required evidence, like the answer
+ itself, so it gets the same allowance instead of a fixed 800 characters.
+ It is still appended before the optional exploration output in the compact
+ tool history, so a long request costs history, never the final answer.
+ """
+ return _behavior_final_response_limit()
+
+
_BEHAVIOR_WRITE_TOOLS = {
"write",
"write_file",
@@ -386,8 +401,11 @@ def build_behavior_evidence(
file_changes = "\n\n".join(_collect_file_change_evidence(traj))
final = get_final_response(traj)
history = build_conversation_summary(traj, question)
+ user_request_limit = _behavior_user_request_limit()
user_needed = (
- min(800, len(_SECTION_USER_REQUEST) + len(question.strip()) + 2) if question and question.strip() else 0
+ min(user_request_limit, len(_SECTION_USER_REQUEST) + len(question.strip()) + 2)
+ if question and question.strip()
+ else 0
)
history_needed = len(_SECTION_COMPACT_TOOL_HISTORY) + len(history.strip()) + 2 if history and history.strip() else 0
tail_needed = user_needed + (2 if user_needed and history_needed else 0) + history_needed
@@ -441,7 +459,7 @@ def build_behavior_evidence(
_SECTION_USER_REQUEST,
question,
remaining,
- section_limit=800,
+ section_limit=user_request_limit,
)
remaining = _append_section_with_budget(parts, _SECTION_COMPACT_TOOL_HISTORY, history, remaining)
@@ -971,17 +989,17 @@ def _build_verified_facts_section(facts: list[dict[str, Any]]) -> str:
return "\n".join(lines)
-def _final_answer_reaches_judge(final: str, evidence: str) -> bool:
- """Return True when every character of the final answer appears in *evidence*.
+def _source_reaches_judge(source: str, evidence: str) -> bool:
+ """Return True when every character of *source* appears in *evidence*.
- A long answer can arrive in two pieces: the compact history repeats the
+ A long source can arrive in two pieces: the compact history repeats the
first 1,500 characters of a text-only final step, and the final-response
- section keeps the end. Find the longest prefix of the answer present in
- *evidence*; the answer is complete when the rest is present too.
+ section keeps the end. Find the longest prefix of the source present in
+ *evidence*; the source is complete when the rest is present too.
Whitespace at the split does not count, because the history section
drops trailing whitespace.
"""
- answer = final.strip()
+ answer = source.strip()
lo, hi = 0, len(answer)
while lo < hi:
mid = (lo + hi + 1) // 2
@@ -992,6 +1010,80 @@ def _final_answer_reaches_judge(final: str, evidence: str) -> bool:
return answer[lo:].lstrip() in evidence
+def _final_answer_reaches_judge(final: str, evidence: str) -> bool:
+ """Return True when every character of the final answer appears in *evidence*."""
+ return _source_reaches_judge(final, evidence)
+
+
+_BEHAVIOR_SECTION_LABELS = (
+ (_SECTION_FINAL_RESPONSE, "final response"),
+ (_SECTION_USER_REQUEST, "user request"),
+ (_SECTION_FILE_CHANGES, "file changes"),
+ (_SECTION_COMPACT_TOOL_HISTORY, "compact tool history"),
+)
+# Only the final answer gates the behavior judge. It is the one piece of
+# required evidence with a small, bounded source and a dedicated cap of its
+# own, so a gap in it means a limit cut text the judge needed, never that the
+# run was simply large (issue #234). File changes and the tool history have
+# unbounded sources that any finite budget shortens on a long run, so their
+# completeness is reported for diagnosis but never withholds a score. The user
+# request reaches the judge twice (its own reserved section and the head of
+# the compact history), so it is reported the same way.
+_BEHAVIOR_REQUIRED_EVIDENCE = (_SECTION_FINAL_RESPONSE,)
+_BEHAVIOR_EVIDENCE_GAP_HINT = (
+ "Raise SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT and SKILL_EVAL_BEHAVIOR_CHECK_BUDGET, "
+ "or shorten the case, then re-run"
+)
+
+
+def _behavior_evidence_completeness(
+ traj: dict[str, Any],
+ question: str,
+ evidence: str,
+) -> tuple[bool, list[str], list[str]]:
+ """Report which behavior evidence sections reached the judge whole.
+
+ Every section is compared against its complete source rather than against
+ another budgeted rendering, so a cut the budget and the final-response cap
+ both applied cannot hide behind either one. Returns
+ ``(required_complete, required_missing, incomplete_sections)``.
+ """
+ sources = {
+ _SECTION_FINAL_RESPONSE: get_final_response(traj),
+ _SECTION_USER_REQUEST: question,
+ _SECTION_FILE_CHANGES: "\n\n".join(_collect_file_change_evidence(traj)),
+ _SECTION_COMPACT_TOOL_HISTORY: build_conversation_summary(traj, question),
+ }
+ required_missing: list[str] = []
+ incomplete: list[str] = []
+ for section, label in _BEHAVIOR_SECTION_LABELS:
+ source = str(sources.get(section) or "")
+ if not source.strip() or _source_reaches_judge(source, evidence):
+ continue
+ incomplete.append(label)
+ if section in _BEHAVIOR_REQUIRED_EVIDENCE:
+ required_missing.append(label)
+ return not required_missing, required_missing, incomplete
+
+
+def behavior_evidence_gap(omitted: Any) -> str:
+ """Describe the required behavior evidence missing from a bundle, or ``""``.
+
+ A behavior score read off evidence whose final answer was silently
+ shortened grades the evidence loss, not the agent, so callers use this to
+ withhold the score and raise an explicit evaluation error instead.
+ """
+ if not isinstance(omitted, dict) or omitted.get("required_complete", True):
+ return ""
+ missing = [str(item).strip() for item in omitted.get("required_missing") or [] if str(item).strip()]
+ names = ", ".join(missing) or "required evidence"
+ reason = str(omitted.get("reason") or "").strip()
+ detail = f" ({reason})" if reason else ""
+ return (
+ f"behavior_check evidence is incomplete: {names} did not reach the judge{detail}. {_BEHAVIOR_EVIDENCE_GAP_HINT}"
+ )
+
+
def build_metric_evidence_bundles(
traj: dict[str, Any],
question: str,
@@ -1094,13 +1186,21 @@ def build_metric_evidence_bundles(
bc_causes.append("final response shortened to fit SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT")
bc_trunc = bool(bc_causes)
bc_reason = "; ".join(bc_causes)
+ bc_evidence = _prepend_facts(bc_text)
+ # ``truncated`` says only that something was dropped, which on a long run
+ # is ordinary. Completeness says whether the evidence the judge must read
+ # survived, so the judge can refuse to score an evidence-loss artifact.
+ bc_required_ok, bc_required_missing, bc_incomplete = _behavior_evidence_completeness(traj, question, bc_evidence)
bundles["behavior_check"] = {
- "prompt_evidence": _prepend_facts(bc_text),
+ "prompt_evidence": bc_evidence,
"evidence_refs": refs["behavior_check"],
"omitted": {
"count": 1 if bc_trunc else 0,
"truncated": bc_trunc,
"reason": bc_reason,
+ "required_complete": bc_required_ok,
+ "required_missing": bc_required_missing,
+ "incomplete_sections": bc_incomplete,
},
"verified": facts,
}
diff --git a/src/skillevaluator/tier3/eval_core/llm_judge.py b/src/skillevaluator/tier3/eval_core/llm_judge.py
index 22767dcb..1c840e45 100644
--- a/src/skillevaluator/tier3/eval_core/llm_judge.py
+++ b/src/skillevaluator/tier3/eval_core/llm_judge.py
@@ -29,12 +29,14 @@ from skillevaluator.provider_config import (
effective_reasoning_effort,
)
from skillevaluator.tier3.eval_core.atif_helpers import (
+ _BEHAVIOR_EVIDENCE_GAP_HINT,
_SECTION_COMPACT_TOOL_HISTORY,
_SECTION_FINAL_RESPONSE,
_SECTION_USER_REQUEST,
_behavior_check_budget,
_behavior_final_response_limit,
_truncate_for_behavior,
+ behavior_evidence_gap,
)
from skillevaluator.tier3.eval_core.character_facts import append_character_facts
from skillevaluator.tier3.eval_core.optional_reference import normalize_expected_behaviors
@@ -1015,9 +1017,17 @@ def _behavior_prompt_example(expected_count: int) -> str:
def judge_behavior_check(
conversation_text: str,
expected_behaviors: list[str],
+ *,
+ evidence_omitted: dict[str, Any] | None = None,
**kwargs: Any,
) -> dict[str, Any]:
- """Run the behavior check LLM judge; the score is the share of behaviors observed."""
+ """Run the behavior check LLM judge; the score is the share of behaviors observed.
+
+ *evidence_omitted* is the behavior_check bundle's omission accounting. When
+ it reports that required evidence did not reach the judge, no model is
+ called and an explicit evaluation error is returned with no score: grading
+ a shortened final answer scores the evidence loss, not the agent.
+ """
expected_behaviors = normalize_expected_behaviors(expected_behaviors)
if not _has_judge_reference(expected_behaviors):
return _judge_not_applicable(_NO_EXPECTED_BEHAVIOR_REASON, results=[])
@@ -1025,7 +1035,22 @@ def judge_behavior_check(
expected_count = len(expected_behaviors)
behaviors_text = "\n".join(f"{i + 1}. {b}" for i, b in enumerate(expected_behaviors))
+ gap = behavior_evidence_gap(evidence_omitted)
+ if gap:
+ return _judge_error(gap, results=[], expectations=_behavior_expectations(expected_behaviors, [], gap))
+
conversation = _compact_behavior_conversation(conversation_text)
+ if evidence_omitted is not None and conversation != conversation_text:
+ # The bundle is built to fit this budget, so a second cut here would
+ # drop evidence nothing has accounted for. Refuse rather than score it.
+ second_cut = (
+ "behavior_check evidence was shortened again inside the judge, past the omission accounting. "
+ f"{_BEHAVIOR_EVIDENCE_GAP_HINT}"
+ )
+ return _judge_error(
+ second_cut, results=[], expectations=_behavior_expectations(expected_behaviors, [], second_cut)
+ )
+
prompt = BEHAVIOR_CHECK_PROMPT.format(
conversation=conversation,
behaviors=behaviors_text,
diff --git a/src/skillevaluator/tier3/harbor/templates/eval.py b/src/skillevaluator/tier3/harbor/templates/eval.py
index 71d0b831..28f1200e 100644
--- a/src/skillevaluator/tier3/harbor/templates/eval.py
+++ b/src/skillevaluator/tier3/harbor/templates/eval.py
@@ -752,6 +752,12 @@ _SECTION_USER_REQUEST = _shared_atif._SECTION_USER_REQUEST
_env_positive_int = _shared_atif._env_positive_int
_behavior_final_response_limit = _shared_atif._behavior_final_response_limit
_behavior_check_budget = _shared_atif._behavior_check_budget
+_behavior_user_request_limit = _shared_atif._behavior_user_request_limit
+_BEHAVIOR_SECTION_LABELS = _shared_atif._BEHAVIOR_SECTION_LABELS
+_BEHAVIOR_REQUIRED_EVIDENCE = _shared_atif._BEHAVIOR_REQUIRED_EVIDENCE
+_BEHAVIOR_EVIDENCE_GAP_HINT = _shared_atif._BEHAVIOR_EVIDENCE_GAP_HINT
+_behavior_evidence_completeness = _shared_atif._behavior_evidence_completeness
+behavior_evidence_gap = _shared_atif.behavior_evidence_gap
_BEHAVIOR_WRITE_TOOLS = _shared_atif._BEHAVIOR_WRITE_TOOLS
_BEHAVIOR_EXEC_TOOLS = _shared_atif._BEHAVIOR_EXEC_TOOLS
_BEHAVIOR_WRITE_COMMAND_MARKERS = _shared_atif._BEHAVIOR_WRITE_COMMAND_MARKERS
@@ -3479,14 +3485,36 @@ def _behavior_prompt_example(expected_count):
)
-def judge_behavior_check(conversation_text, expected_behaviors):
+def judge_behavior_check(conversation_text, expected_behaviors, *, evidence_omitted=None):
+ """Judge expected behaviors, or refuse when required evidence did not reach the judge.
+
+ *evidence_omitted* is the behavior_check bundle's omission accounting. When
+ it reports that required evidence is incomplete, no model is called and an
+ explicit evaluation error is returned with no score: grading a shortened
+ final answer scores the evidence loss, not the agent.
+ """
expected_behaviors = normalize_expected_behaviors(expected_behaviors)
if not _has_judge_reference(expected_behaviors):
return _judge_not_applicable(_NO_EXPECTED_BEHAVIOR_REASON, results=[])
expected_count = len(expected_behaviors)
behaviors_text = "\n".join(f"{i + 1}. {b}" for i, b in enumerate(expected_behaviors))
+
+ gap = behavior_evidence_gap(evidence_omitted)
+ if gap:
+ return _judge_error(gap, results=[], expectations=_behavior_expectations(expected_behaviors, [], gap))
+
conversation = _compact_behavior_conversation(conversation_text)
+ if evidence_omitted is not None and conversation != conversation_text:
+ # The bundle is built to fit this budget, so a second cut here would
+ # drop evidence nothing has accounted for. Refuse rather than score it.
+ second_cut = (
+ "behavior_check evidence was shortened again inside the judge, past the omission accounting. "
+ f"{_BEHAVIOR_EVIDENCE_GAP_HINT}"
+ )
+ return _judge_error(
+ second_cut, results=[], expectations=_behavior_expectations(expected_behaviors, [], second_cut)
+ )
prompt = f"""You are evaluating whether an AI agent showed each expected behavior during a task. \
Read the conversation and decide, for each numbered behavior, whether it was observed.
@@ -4167,6 +4195,7 @@ def main():
judge_behavior_check,
bundles["behavior_check"]["prompt_evidence"],
expected_behavior,
+ evidence_omitted=bundles["behavior_check"]["omitted"],
)
else:
bc_result = _judge_not_applicable(_NO_EXPECTED_BEHAVIOR_REASON, results=[])
@@ -4176,6 +4205,7 @@ def main():
judge_behavior_check,
bundles["behavior_check"]["prompt_evidence"],
expected_behavior,
+ evidence_omitted=bundles["behavior_check"]["omitted"],
allow_not_applicable=not _has_judge_reference(expected_behavior),
)
if declarative_checks:
diff --git a/tests/tier3/test_behavior_evidence.py b/tests/tier3/test_behavior_evidence.py
index fddd6f2f..a31391d5 100644
--- a/tests/tier3/test_behavior_evidence.py
+++ b/tests/tier3/test_behavior_evidence.py
@@ -15,6 +15,14 @@ from skillevaluator.tier3.eval_core.atif_helpers import (
build_conversation_summary,
)
+# build_behavior_evidence called without max_chars reconciles its own budget
+# with the final-response allowance, so the standalone default tracks that
+# limit instead of staying at _BEHAVIOR_EVIDENCE_MAX_CHARS.
+_STANDALONE_DEFAULT_BUDGET = max(
+ atif_helpers._BEHAVIOR_EVIDENCE_MAX_CHARS,
+ atif_helpers._DEFAULT_BEHAVIOR_FINAL_RESPONSE_LIMIT + atif_helpers._MIN_BEHAVIOR_HISTORY_HEADROOM,
+)
+
def _trajectory_with_late_write() -> dict:
steps = [
@@ -94,7 +102,7 @@ def test_behavior_evidence_prioritizes_late_write_tool_calls() -> None:
evidence = build_behavior_evidence(traj, "question")
- assert len(evidence) <= 4000
+ assert len(evidence) <= _STANDALONE_DEFAULT_BUDGET
assert "FILE CHANGES" in evidence
assert "Agent called: Write" in evidence
assert evidence.find("Agent called: Read") == -1 or (
@@ -119,7 +127,7 @@ def test_harbor_template_behavior_evidence_matches_shared_helper() -> None:
evidence = module.build_behavior_evidence(_trajectory_with_late_write(), "question")
- assert len(evidence) <= 4000
+ assert len(evidence) <= _STANDALONE_DEFAULT_BUDGET
assert "FILE CHANGES" in evidence
assert "Agent called: Write" in evidence
assert "pl.GPUEngine(raise_on_fail=True)" in evidence
@@ -548,7 +556,7 @@ def test_behavior_evidence_keeps_write_when_prompt_is_long() -> None:
evidence = build_behavior_evidence(traj, long_question)
- assert len(evidence) <= 4000
+ assert len(evidence) <= _STANDALONE_DEFAULT_BUDGET
assert evidence.startswith("FILE CHANGES")
assert "Agent called: Write" in evidence
assert "/workspace/output/test_gpu_engine_selection.py" in evidence
@@ -690,9 +698,13 @@ def test_behavior_evidence_ignores_non_write_shell_gt() -> None:
assert "/workspace/output/from_python.txt" in file_changes
-def _trajectory_with_long_final_response() -> dict:
- """Build a synthetic trajectory with a long agent response."""
- body = "START_MARKER_" + ("A" * 1700) + "_LATE_MARKER_" + ("B" * 500) + "_TAIL"
+def _trajectory_with_long_final_response(middle: int = 1700, tail: int = 500) -> dict:
+ """Build a synthetic trajectory with a long agent response.
+
+ ``middle`` places ``_LATE_MARKER_`` far enough into the answer that a cap
+ below it drops the marker with the rest of the answer's middle.
+ """
+ body = "START_MARKER_" + ("A" * middle) + "_LATE_MARKER_" + ("B" * tail) + "_TAIL"
return {
"steps": [
{
@@ -708,22 +720,36 @@ def _trajectory_with_long_final_response() -> dict:
def test_behavior_evidence_final_response_default_and_env_override(monkeypatch) -> None:
- traj = _trajectory_with_long_final_response()
+ # An answer past the 8,000-character default still loses its middle. The
+ # test below covers the other side: an answer under the default survives.
+ traj = _trajectory_with_long_final_response(middle=7000, tail=3000)
- # By default, final response is capped at 800 chars and truncated
default_evidence = build_behavior_evidence(traj, "question")
assert "START_MARKER_" in default_evidence
assert "_LATE_MARKER_" not in default_evidence
assert "...[truncated]..." in default_evidence
# Overriding via environment variable expands the capture limit
- monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", "3000")
- expanded_evidence = build_behavior_evidence(traj, "question", max_chars=8000)
+ monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", "20000")
+ expanded_evidence = build_behavior_evidence(traj, "question", max_chars=24000)
assert "START_MARKER_" in expanded_evidence
assert "_LATE_MARKER_" in expanded_evidence
assert "...[truncated]..." not in expanded_evidence
+def test_behavior_evidence_default_keeps_a_realistic_final_answer() -> None:
+ # Issue #234: the old 800-character default cut grading-relevant text out
+ # of the middle of an ordinary final answer. The default must now carry
+ # one whole.
+ traj = _trajectory_with_long_final_response(middle=1700, tail=500)
+
+ evidence = build_behavior_evidence(traj, "question")
+
+ assert "START_MARKER_" in evidence
+ assert "_LATE_MARKER_" in evidence
+ assert "...[truncated]..." not in evidence
+
+
def test_behavior_evidence_final_response_explicit_arg() -> None:
traj = _trajectory_with_long_final_response()
@@ -753,18 +779,18 @@ def test_behavior_evidence_standalone_reconciles_max_chars(monkeypatch) -> None:
def test_behavior_check_budget_and_compactor_env_override(monkeypatch) -> None:
from skillevaluator.tier3.eval_core.llm_judge import _compact_behavior_conversation
- sample_conversation = "A" * 9000
+ sample_conversation = "A" * 13000
- # Default compactor threshold is 8000
+ # Default compactor threshold is the reconciled 12000 budget
compacted = _compact_behavior_conversation(sample_conversation)
assert "...[middle truncated for behavior check]..." in compacted
- assert len(compacted) <= 8000
+ assert len(compacted) <= 12000
# Overriding SKILL_EVAL_BEHAVIOR_CHECK_BUDGET raises compactor threshold
- monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_CHECK_BUDGET", "12000")
+ monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_CHECK_BUDGET", "16000")
uncompacted = _compact_behavior_conversation(sample_conversation)
assert "...[middle truncated for behavior check]..." not in uncompacted
- assert len(uncompacted) == 9000
+ assert len(uncompacted) == 13000
def test_behavior_check_budget_auto_reconciles_tool_history_headroom(monkeypatch) -> None:
@@ -967,17 +993,17 @@ def test_seam_bundle_to_judge_behavior_check_retains_failed_command_and_claim(mo
def test_harbor_template_behavior_evidence_respects_custom_limits(monkeypatch) -> None:
module = _load_harbor_template_module()
- traj = _trajectory_with_long_final_response()
+ traj = _trajectory_with_long_final_response(middle=7000, tail=3000)
- # Template default caps at 800
+ # Template default caps at 8000
evidence_default = module.build_behavior_evidence(traj, "question")
assert "START_MARKER_" in evidence_default
assert "_LATE_MARKER_" not in evidence_default
assert "...[truncated]..." in evidence_default
# Template override respects SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT
- monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", "3000")
- evidence_custom = module.build_behavior_evidence(traj, "question", max_chars=8000)
+ monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", "20000")
+ evidence_custom = module.build_behavior_evidence(traj, "question", max_chars=24000)
assert "START_MARKER_" in evidence_custom
assert "_LATE_MARKER_" in evidence_custom
assert "...[truncated]..." not in evidence_custom
diff --git a/tests/tier3/test_evidence_compiler.py b/tests/tier3/test_evidence_compiler.py
index 9592d08d..1e472684 100644
--- a/tests/tier3/test_evidence_compiler.py
+++ b/tests/tier3/test_evidence_compiler.py
@@ -83,7 +83,8 @@ def test_bundle_budgets_defaults_and_env_overrides(monkeypatch) -> None:
budgets = atif_helpers._bundle_budgets()
assert budgets["accuracy"] == 8000
assert budgets["goal_accuracy"] == 12000
- assert budgets["behavior_check"] == 8000
+ # 8000 final-response allowance reconciled with the 4000 tool-history headroom
+ assert budgets["behavior_check"] == 12000
# Non-integer / invalid fallback across all 4 budget/limit env vars
for invalid_val in ("invalid", " ", "3.14", ""):
@@ -93,8 +94,8 @@ def test_bundle_budgets_defaults_and_env_overrides(monkeypatch) -> None:
monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", invalid_val)
assert atif_helpers._accuracy_budget() == 8000
assert atif_helpers._goal_accuracy_budget() == 12000
- assert atif_helpers._behavior_final_response_limit() == 800
- assert atif_helpers._behavior_check_budget() == 8000
+ assert atif_helpers._behavior_final_response_limit() == 8000
+ assert atif_helpers._behavior_check_budget() == 12000
# Non-positive integer clamping and headroom reconciliation
for non_positive in ("0", "-10", "-500"):
@@ -377,7 +378,7 @@ def test_behavior_bundle_reports_final_response_cap_loss() -> None:
# compare two renderings that shared the cap, so the loss was reported
# as truncated=False.
marker = "MIGRATE_UNIQUE_COVERAGE_FIRST"
- answer = "A" * 2000 + marker + "B" * 2000
+ answer = "A" * 8000 + marker + "B" * 8000
traj = {"steps": [{"source": "agent", "message": answer}]}
for module in (atif_helpers, _load_harbor_template_module()):
@@ -388,6 +389,47 @@ def test_behavior_bundle_reports_final_response_cap_loss() -> None:
assert bundle["omitted"]["reason"]
+def test_behavior_bundle_keeps_a_realistic_final_answer_at_the_default_limit() -> None:
+ # Issue #234's own repro: at the raised default the marker in the middle
+ # of a 4,000-character answer reaches the judge, and the accounting says
+ # the required evidence is complete.
+ marker = "MIGRATE_UNIQUE_COVERAGE_FIRST"
+ answer = "A" * 2000 + marker + "B" * 2000
+ traj = {"steps": [{"source": "agent", "message": answer}]}
+
+ for module in (atif_helpers, _load_harbor_template_module()):
+ bundle = module.build_metric_evidence_bundles(traj, "Explain the migration.")["behavior_check"]
+ assert marker in bundle["prompt_evidence"]
+ assert bundle["omitted"]["truncated"] is False
+ assert bundle["omitted"]["required_complete"] is True
+ assert bundle["omitted"]["required_missing"] == []
+ assert bundle["omitted"]["incomplete_sections"] == []
+
+
+def test_behavior_bundle_completeness_follows_the_final_response_limit_env_var(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ # The same answer is complete at the default and incomplete once the limit
+ # is lowered, so the env var still steers both the evidence and the
+ # completeness metadata the judge gates on.
+ marker = "MIGRATE_UNIQUE_COVERAGE_FIRST"
+ answer = "A" * 2000 + marker + "B" * 2000
+ traj = {"steps": [{"source": "agent", "message": answer}]}
+
+ monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", "800")
+ for module in (atif_helpers, _load_harbor_template_module()):
+ bundle = module.build_metric_evidence_bundles(traj, "Explain the migration.")["behavior_check"]
+ assert marker not in bundle["prompt_evidence"]
+ assert bundle["omitted"]["required_complete"] is False
+ assert bundle["omitted"]["required_missing"] == ["final response"]
+
+ monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", "16000")
+ for module in (atif_helpers, _load_harbor_template_module()):
+ bundle = module.build_metric_evidence_bundles(traj, "Explain the migration.")["behavior_check"]
+ assert marker in bundle["prompt_evidence"]
+ assert bundle["omitted"]["required_complete"] is True
+
+
def test_behavior_bundle_complete_evidence_is_not_reported_truncated() -> None:
# Control case: when nothing is dropped, the accounting must still say so.
traj = {"steps": [{"source": "agent", "message": "Short final answer."}]}
@@ -424,7 +466,7 @@ def test_behavior_bundle_final_answer_past_history_repeat_is_truncated() -> None
# missing from the evidence, and the reason names the setting that
# applied so users know which limit to raise.
marker = "DEEP_ANSWER_COVERAGE_TOKEN"
- answer = "A" * 2000 + marker + "B" * 2000
+ answer = "A" * 8000 + marker + "B" * 8000
traj = {"steps": [{"source": "agent", "message": answer}]}
for module in (atif_helpers, _load_harbor_template_module()):
@@ -433,6 +475,8 @@ def test_behavior_bundle_final_answer_past_history_repeat_is_truncated() -> None
assert bundle["omitted"]["truncated"] is True
assert bundle["omitted"]["count"] >= 1
assert "SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT" in bundle["omitted"]["reason"]
+ assert bundle["omitted"]["required_complete"] is False
+ assert bundle["omitted"]["required_missing"] == ["final response"]
_BUDGET_REASON = "behavior evidence shortened to fit SKILL_EVAL_BEHAVIOR_CHECK_BUDGET"
@@ -448,14 +492,18 @@ def _distinct_text(length: int) -> str:
@pytest.mark.parametrize("cut_char", [" ", "-"], ids=["space-at-cut", "text-at-cut"])
@pytest.mark.parametrize(("length", "truncated"), [(1501, False), (1640, False), (1755, False), (1756, True)])
def test_behavior_bundle_final_answer_split_across_history_and_section(
- length: int, truncated: bool, cut_char: str
+ monkeypatch: pytest.MonkeyPatch, length: int, truncated: bool, cut_char: str
) -> None:
# The compact history repeats the first 1,500 characters of a text-only
- # final answer, and at the default limit the final-response section keeps
- # its last 255. Together they carry an answer of up to 1,755 characters
- # in full, although no single piece holds all of it. The history drops
- # trailing whitespace, so cover a cut that falls on a space and one that
- # falls on text.
+ # final answer, and the final-response section keeps its last 255 when the
+ # section limit is 800. Together they carry an answer of up to 1,755
+ # characters in full, although no single piece holds all of it. The
+ # history drops trailing whitespace, so cover a cut that falls on a space
+ # and one that falls on text. The limit is pinned to the pre-#234 800 so
+ # the split is exercised at all: at the 8,000 default the section alone
+ # holds every answer this short, and the env var still overriding it is
+ # part of what this asserts.
+ monkeypatch.setenv("SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT", "800")
answer = _distinct_text(length)
answer = answer[:1499] + cut_char + answer[1500:]
traj = {"steps": [{"source": "agent", "message": answer}]}
@@ -474,9 +522,9 @@ def test_behavior_bundle_final_answer_split_across_history_and_section(
[
({}, f"{_BUDGET_REASON}; {_LIMIT_REASON}"),
({"SKILL_EVAL_BEHAVIOR_CHECK_BUDGET": "100000"}, _LIMIT_REASON),
- ({"SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT": "3000"}, _BUDGET_REASON),
+ ({"SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT": "20000"}, _BUDGET_REASON),
(
- {"SKILL_EVAL_BEHAVIOR_CHECK_BUDGET": "100000", "SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT": "3000"},
+ {"SKILL_EVAL_BEHAVIOR_CHECK_BUDGET": "100000", "SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT": "20000"},
"",
),
],
@@ -486,7 +534,7 @@ def test_behavior_bundle_reason_names_each_setting_that_cut_evidence(
monkeypatch: pytest.MonkeyPatch, env: dict[str, str], reason: str
) -> None:
# A long tool history overflows the default behavior budget, and a final
- # answer past 1,755 characters also loses its middle to the default
+ # answer past the 8,000-character default also loses its middle to the
# final-response limit. The reason must name every setting that applied,
# so raising only the budget is not mistaken for a fix.
for name in ("SKILL_EVAL_BEHAVIOR_CHECK_BUDGET", "SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT"):
@@ -504,7 +552,7 @@ def test_behavior_bundle_reason_names_each_setting_that_cut_evidence(
}],
"observation": {"results": [{"source_call_id": f"list-{idx}", "content": f"step {idx:02d} " + "z" * 292}]},
})
- answer = _distinct_text(2000)
+ answer = _distinct_text(12000)
steps.append({"source": "agent", "message": answer})
for module in (atif_helpers, _load_harbor_template_module()):
@@ -512,4 +560,7 @@ def test_behavior_bundle_reason_names_each_setting_that_cut_evidence(
assert bundle["omitted"]["truncated"] is bool(reason)
assert bundle["omitted"]["count"] == (1 if reason else 0)
assert bundle["omitted"]["reason"] == reason
- assert (answer in bundle["prompt_evidence"]) is (_LIMIT_REASON not in reason)
+ # The answer can reach the judge split between the compact history and
+ # the final-response section, so completeness is the coverage check,
+ # not a contiguous substring. Only the final-response limit loses it.
+ assert bundle["omitted"]["required_complete"] is (_LIMIT_REASON not in reason)
diff --git a/tests/tier3/test_judge_contracts.py b/tests/tier3/test_judge_contracts.py
index 4138e9d2..64f0c819 100644
--- a/tests/tier3/test_judge_contracts.py
+++ b/tests/tier3/test_judge_contracts.py
@@ -13,7 +13,7 @@ from typing import Any
import pytest
from tests.conftest import load_harbor_eval_template
-from skillevaluator.tier3.eval_core import llm_judge
+from skillevaluator.tier3.eval_core import atif_helpers, llm_judge
from skillevaluator.tier3.harbor.metrics import RESERVED_METRIC_NAMES
eval_template = load_harbor_eval_template("harbor_template_eval_judge_contracts")
@@ -246,6 +246,125 @@ def test_behavior_salvage_rejects_repeated_steps(judge_module, monkeypatch) -> N
assert result["status"] == "error"
+# ── Incomplete evidence gate (issue #234) ────────────────────────────────────
+
+
+def _never_called(*args: Any, **kwargs: Any):
+ raise AssertionError("the judge must not call a model on incomplete evidence")
+
+
+def _behavior_bundle(module: ModuleType, traj: dict[str, Any]) -> dict[str, Any]:
+ """Build the behavior_check bundle with the module the judge belongs to."""
+ builder = atif_helpers if module is llm_judge else module
+ return builder.build_metric_evidence_bundles(traj, "Explain the migration.")["behavior_check"]
+
+
+def test_incomplete_required_behavior_evidence_errors_without_a_model_call(judge_module, monkeypatch) -> None:
+ # A behavior score read off a shortened final answer grades the evidence
+ # loss, not the agent, so the judge returns an evaluation error instead.
+ monkeypatch.setattr(judge_module, "call_public_llm", _never_called)
+ omitted = {
+ "count": 1,
+ "truncated": True,
+ "reason": "final response shortened to fit SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT",
+ "required_complete": False,
+ "required_missing": ["final response"],
+ "incomplete_sections": ["final response"],
+ }
+
+ result = judge_module.judge_behavior_check("conversation", ["b1", "b2"], evidence_omitted=omitted)
+
+ assert result["score"] is None
+ assert result["status"] == "error"
+ assert "final response" in result["reason"]
+ assert "SKILL_EVAL_BEHAVIOR_FINAL_RESPONSE_LIMIT" in result["reason"]
+ assert result["results"] == []
+ assert [item["status"] for item in result["expectations"]] == ["not_checked", "not_checked"]
+
+
+def test_complete_required_behavior_evidence_is_judged_normally(judge_module, monkeypatch) -> None:
+ calls: list[dict[str, Any]] = []
+ monkeypatch.setattr(judge_module, "call_public_llm", _script([(_BEHAVIOR_RESPONSE, None)], calls))
+ omitted = {
+ "count": 1,
+ "truncated": True,
+ "reason": "behavior evidence shortened to fit SKILL_EVAL_BEHAVIOR_CHECK_BUDGET",
+ "required_complete": True,
+ "required_missing": [],
+ "incomplete_sections": ["compact tool history"],
+ }
+
+ result = judge_module.judge_behavior_check("conversation", ["b1", "b2"], evidence_omitted=omitted)
+
+ # Optional exploration output dropped to fit the budget is ordinary; only
+ # missing required evidence withholds the score.
+ assert result["score"] == 0.5
+ assert len(calls) == 1
+
+
+def test_behavior_judge_refuses_to_cut_accounted_evidence_a_second_time(judge_module, monkeypatch) -> None:
+ monkeypatch.setattr(judge_module, "call_public_llm", _never_called)
+ oversized = "A" * (judge_module._behavior_check_budget() + 5000)
+ omitted = {"count": 0, "truncated": False, "reason": "", "required_complete": True, "required_missing": []}
+
+ result = judge_module.judge_behavior_check(oversized, ["b1"], evidence_omitted=omitted)
+
+ assert result["score"] is None
+ assert result["status"] == "error"
+ assert "shortened again inside the judge" in result["reason"]
+
+
+def test_oversized_final_answer_reaches_the_judge_gate_as_an_error(judge_module, monkeypatch) -> None:
+ # End to end over the seam the verifier uses: bundle -> judge. No model is
+ # called and no behavior score is produced.
+ monkeypatch.setattr(judge_module, "call_public_llm", _never_called)
+ marker = "MIGRATE_UNIQUE_COVERAGE_FIRST"
+ answer = "A" * 8000 + marker + "B" * 8000
+ bundle = _behavior_bundle(judge_module, {"steps": [{"source": "agent", "message": answer}]})
+
+ assert marker not in bundle["prompt_evidence"]
+ assert bundle["omitted"]["required_complete"] is False
+
+ result = judge_module.judge_behavior_check(
+ bundle["prompt_evidence"], ["explains the migration"], evidence_omitted=bundle["omitted"]
+ )
+
+ assert result["score"] is None
+ assert result["status"] == "error"
+
+
+def test_gated_behavior_result_never_becomes_a_zero_downstream(judge_module, monkeypatch) -> None:
+ from skillevaluator.tier3.eval_core.declarative_checks import combine_behavior_check
+ from skillevaluator.tier3.harbor.metrics import overall_score_from_metrics
+
+ monkeypatch.setattr(judge_module, "call_public_llm", _never_called)
+ omitted = {"required_complete": False, "required_missing": ["final response"], "reason": "cut"}
+ gated = judge_module.judge_behavior_check("conversation", ["b1"], evidence_omitted=omitted)
+
+ # The verifier's own normalization keeps it scoreless, even where an N/A
+ # result would be accepted.
+ normalized = eval_template._normalize_required_judge_result("behavior_check", gated, allow_not_applicable=True)
+ assert normalized["score"] is None
+ assert normalized["status"] == "error"
+
+ # Direct declarative checks beside the judge must not fill the gap either.
+ combined = combine_behavior_check(gated, [{"step": 1, "passed": True}], 1)
+ assert combined["score"] is None
+ assert combined["status"] == "error"
+
+ # And a missing behavior score leaves the overall score undefined rather
+ # than averaging a zero into the dimension mean (see PR #240).
+ scores = {
+ "security": 1.0,
+ "skill_execution": 1.0,
+ "skill_efficiency": 1.0,
+ "accuracy": 1.0,
+ "goal_accuracy": 1.0,
+ "behavior_check": None,
+ }
+ assert overall_score_from_metrics(scores) is None
+
+
# ── Specific retries ─────────────────────────────────────────────────────────