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: 28 additions & 5 deletions agents/faculties/sizing/_sizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,13 @@ def empty_discovery_reason(mind: Path, work_type: str) -> str:
# external contributor's request. Judged from the prompt's own words.
# Kept deliberately specific. A loose keyword here does not fail safe in the way
# it first appears: it grades everything `judge`, the tier starves, and the model
# stops discriminating at all. `raise` alone matched "praise" and every prose
# mention of raising a question; `raises ` earns its place, bare `raise` does not.
# stops discriminating at all. The 233-prompt campaign regrade moved 15 prompts
# from judge to glance after dropping `raises `; all carried declared tiers.
# Crash descriptions are not error-contract changes; `error contract` covers
# the latter without judging every symptom that names a raised exception.
JUDGE_SURFACE_KEYWORDS = [
"public api", "default value", "defaults to", "error contract",
"raises ", "science policy", "external contributor", "external reporter",
"science policy", "external contributor", "external reporter",
"user-filed", "reported by", "backwards-compat", "backwards compat",
"breaking change",
]
Expand Down Expand Up @@ -495,6 +497,7 @@ def declared_header(text: str) -> dict:
"declared_autonomy": None, "status": None,
"priority": None, "blocked_by": [], "closes_when": [],
"declared_consequence": None, "witness": None,
"witness_none_reason": None, "unknown_unattended": None,
"declared_review_minutes": None, "declared_unattended": None,
"lane": None}
in_fence = False
Expand Down Expand Up @@ -538,8 +541,13 @@ def declared_header(text: str) -> dict:
v = value.lower()
if v in CONSEQUENCE_TIERS and out["declared_consequence"] is None:
out["declared_consequence"] = v
elif key == "witness" and out["witness"] is None:
out["witness"] = value
elif key == "witness" and out["witness"] is None \
and out["witness_none_reason"] is None:
none = re.match(r"^none\b\s*[—-]?\s*(.*)", value, re.I)
if none:
out["witness_none_reason"] = none.group(1)
else:
out["witness"] = value
elif key == "review-minutes" and out["declared_review_minutes"] is None:
m2 = re.search(r"\d+", value)
if m2:
Expand All @@ -552,6 +560,8 @@ def declared_header(text: str) -> dict:
v = _norm_level(value)
if v in UNATTENDED_LEVELS and out["declared_unattended"] is None:
out["declared_unattended"] = v
elif v not in UNATTENDED_LEVELS and out["unknown_unattended"] is None:
out["unknown_unattended"] = value
return out


Expand Down Expand Up @@ -818,6 +828,8 @@ def estimate_consequence(p: dict, factors: dict | None = None):
reasons = []

# 1. Work types whose deliverable is never a quietly-mergeable diff.
if p["work_type"] == "triage":
return "judge", ["work-type triage: classification still open"]
if p["work_type"] in ("release", HUMAN_REVIEW):
return "judge", [f"work-type {p['work_type']} is a human act by contract"]

Expand All @@ -828,6 +840,11 @@ def estimate_consequence(p: dict, factors: dict | None = None):

# 3. The default that makes the model bite.
if not witness:
if p.get("witness_none_reason") is not None:
reason = "Witness: none declared"
if p["witness_none_reason"]:
reason += f" — {p['witness_none_reason']}"
return "judge", [reason]
return "judge", ["no Witness: declared — nothing to check but the diff"]
reasons.append(f"witness declared: {witness[:60]}")

Expand Down Expand Up @@ -861,6 +878,8 @@ def estimate_unattended(p: dict, level: str, factors: dict | None = None):
"""
if factors is None:
_, _, factors = estimate_difficulty(p)
if p["work_type"] == "triage":
return "never", ["work-type triage: classification still open"]
if p["work_type"] in ("release", HUMAN_REVIEW):
return "never", [f"work-type {p['work_type']} is human-driven by contract"]
if p.get("declared_autonomy") == "human-required":
Expand Down Expand Up @@ -912,6 +931,10 @@ def effective_unattended(p: dict, level: str, factors: dict | None = None,
"""
derived, reasons = estimate_unattended(p, level, factors)
grade = p.get("declared_unattended") or derived
if p.get("unknown_unattended") is not None:
reasons = reasons + [
f"unknown Unattended: {p['unknown_unattended']} — expected "
+ ", ".join(UNATTENDED_LEVELS)]
if grade == "ready" and derived_level == "too-large":
reasons = reasons + [
"CAUTION: the heuristic derives too-large; the declared level won."
Expand Down
2 changes: 1 addition & 1 deletion tests/test_intake_review_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
HEADER_FIELDS, analyse, infer_autonomy, parse_header,
)

RAW = "Tidy the @PyAutoBrain board copy so a 403 reads as an egress block.\n"
RAW = "Type: maintenance\nTidy the @PyAutoBrain board copy so a 403 reads as an egress block.\n"
WITNESSED = RAW + "Witness: the degraded row renders and a test pins its text.\n"


Expand Down
110 changes: 110 additions & 0 deletions tests/test_sizing_none_triage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""None witnesses and unclassified work must retain visible review reasons."""

from pathlib import Path
import sys

import pytest

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "agents" / "faculties" / "sizing"))
from _sizing import ( # noqa: E402
declared_header,
effective_consequence,
effective_difficulty,
effective_unattended,
estimate_consequence,
estimate_unattended,
parse_prompt,
)


def _prompt(tmp_path, header, work_type="bug", body="Repair the short-chain crash."):
path = tmp_path / "draft" / work_type / "samplelib" / "task.md"
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(f"# Short-chain repair\n\n{header}\n\n{body}\n")
return parse_prompt(path, tmp_path)


@pytest.mark.parametrize("value, reason", [
("none", ""),
("NONE", ""),
("None — human judgement needed", "human judgement needed"),
("none - human judgement needed", "human judgement needed"),
("none human judgement needed", "human judgement needed"),
])
def test_none_witness_is_absent_with_an_explanatory_reason(tmp_path, value, reason):
p = _prompt(tmp_path, f"Witness: {value}")
assert p["witness"] is None
assert p["witness_none_reason"] == reason
expected = "Witness: none declared" + (f" — {reason}" if reason else "")
assert estimate_consequence(p) == ("judge", [expected])


def test_none_header_preserves_first_declaration_and_raw_reason():
p = declared_header("Witness: none — inspect PR #123\nWitness: tests pass")
assert p["witness"] is None
assert p["witness_none_reason"] == "inspect PR #123"
p = declared_header("Witness: tests pass\nWitness: none")
assert p["witness"] == "tests pass"
assert p["witness_none_reason"] is None


def test_none_is_a_word_and_fenced_headers_are_not_declarations(tmp_path):
p = _prompt(tmp_path, "```\nWitness: none\n```\nWitness: nonetheless tests pass")
assert p["witness"] == "nonetheless tests pass"
assert estimate_consequence(p)[0] == "glance"


def test_absent_witness_keeps_the_existing_reason(tmp_path):
assert estimate_consequence(_prompt(tmp_path, "")) == (
"judge", ["no Witness: declared — nothing to check but the diff"])


@pytest.mark.parametrize("header", ["", "Witness: tests pass", "Witness: none"])
def test_triage_requires_classification_before_unattended_work(tmp_path, header):
p = _prompt(tmp_path, header, work_type="triage")
assert p["work_type"] == "triage"
assert estimate_consequence(p) == (
"judge", ["work-type triage: classification still open"])
assert estimate_unattended(p, "small") == (
"never", ["work-type triage: classification still open"])


def test_declared_tiers_still_win_and_derived_triage_is_visible(tmp_path):
p = _prompt(tmp_path, "Witness: tests pass\nConsequence: glance\nUnattended: ready",
work_type="triage")
assert effective_consequence(p)[::2] == ("glance", "judge")
assert effective_unattended(p, "small")[::2] == ("ready", "never")


def test_unknown_unattended_value_is_reported_without_inventing_a_grade(tmp_path):
p = _prompt(tmp_path, "Unattended: needs-decision # awaiting classification")
assert p["declared_unattended"] is None
assert p["unknown_unattended"] == "needs-decision"
level, _, factors, derived_level = effective_difficulty(p)
grade, reasons, derived = effective_unattended(p, level, factors, derived_level)
assert grade == derived == "ready"
assert reasons == ["fits one unattended run",
"unknown Unattended: needs-decision — expected ready, needs-slicing, never"]


def test_unknown_unattended_reason_survives_a_never_rule(tmp_path):
p = _prompt(tmp_path, "Unattended: needs-decision", work_type="triage")
grade, reasons, derived = effective_unattended(p, "small")
assert grade == derived == "never"
assert "triage" in reasons[0]
assert "needs-decision" in reasons[1]


@pytest.mark.parametrize("exception", ["`IndexError`", "IndexError"])
def test_exception_symptoms_no_longer_imply_a_judged_surface(tmp_path, exception):
p = _prompt(tmp_path, "Witness: short-chain regression passes",
body=f"A short chain raises {exception}. Repair the slice.")
assert estimate_consequence(p)[0] == "glance"


def test_error_contract_still_requires_judgement(tmp_path):
p = _prompt(tmp_path, "Witness: regression passes",
body="Change the error contract for an invalid chain.")
tier, reasons = estimate_consequence(p)
assert tier == "judge"
assert "error contract" in reasons[0]
Loading