Answer stability round 1: 0 🔴, 7 🟡 (0 misread); hold a rung to a whole count of findings, tell a 🔴 by its opening mark, test the second reference replay failing alone, and share the candidate rungs
This commit is contained in:
+31
-26
@@ -1,25 +1,26 @@
|
||||
"""The bar review-replay holds a rung to, and its report: docs/decisions.md → `routing: a review pass runs below the project's rung only on a rung whose replay of its rounds finds a share of their 🔴 and 🟡 findings no more than a margin below the project's rung's own replay`."""
|
||||
import dataclasses
|
||||
from rung_replay.command import down_from
|
||||
from fractions import Fraction
|
||||
|
||||
from review_replay.rounds import is_red, Round
|
||||
from model_routing.ladder import LADDER, Rung
|
||||
from review_replay.rounds import Round
|
||||
import math
|
||||
|
||||
# A rung qualifies with a share of the archived findings up to this far below the project's rung's. The project's rung found 69 to 73% of its own findings again, so about 3 of the 30 to 40 that 10 rounds hold go either way between two replays.
|
||||
# A rung qualifies with a share of the archived findings up to this far below the project's rung's. The project's rung found 69 to 78% of its own findings again, and its two replays of the same rounds differed by up to 4 points.
|
||||
MARGIN = Fraction(1, 10)
|
||||
# The rounds a rung is tried on: 8 of the 10 the tool samples, so up to two may fail on the project's rung.
|
||||
# The fewest rounds a rung is tried on: 8 of the 10 the tool samples, so up to two may fail on the project's rung.
|
||||
ENOUGH_ROUNDS = 8
|
||||
# Lowest first, as Claude Code's --effort takes them.
|
||||
EFFORTS = ("low", "medium", "high", "xhigh", "max")
|
||||
# The two replays on the project's rung: each round's indexes of its findings that each found.
|
||||
# The two replays on the project's rung. Each lists, round by round, the indexes of the findings it found.
|
||||
Reference = tuple[list[set[int]], list[set[int]]]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class RungRecall:
|
||||
"""A rung's replay: its share of the archived findings, and each 🔴 it missed that the project's rung found both times, as a round and the finding's index."""
|
||||
"""A rung's replay: how many of the archived findings it found, and each 🔴 it missed that both of the project's rung's replays found, as a round and the finding's index."""
|
||||
rung: Rung
|
||||
share: Fraction
|
||||
found: int
|
||||
missed_red: list[tuple[Round, int]]
|
||||
qualifies: bool
|
||||
|
||||
@@ -37,48 +38,52 @@ class Recall:
|
||||
def candidates(project: Rung) -> list[Rung]:
|
||||
"""The rungs tried below the project's, highest first: its model at each lower effort, which the ladder leaves out, then each ladder rung below it, down to the ladder's lowest. That reaches below the lowest a worker routes to, since a pass may run below the worker's rung."""
|
||||
lower_efforts = [Rung(project.model, effort) for effort in reversed(EFFORTS[:EFFORTS.index(project.effort)])]
|
||||
return lower_efforts + list(LADDER[:LADDER.index(project)])[::-1]
|
||||
return lower_efforts + down_from(project, LADDER[0])[1:]
|
||||
|
||||
|
||||
def enough(rounds: list[Round]) -> bool:
|
||||
return len(rounds) >= ENOUGH_ROUNDS
|
||||
|
||||
|
||||
def found_any(reference: Reference) -> bool:
|
||||
return any(map(any, reference))
|
||||
def count(found: list[set[int]]) -> int:
|
||||
return sum(map(len, found))
|
||||
|
||||
|
||||
def share(rounds: list[Round], found: list[set[int]]) -> Fraction:
|
||||
"""The share of rounds' findings that found holds; rounds is never empty, and each holds a finding."""
|
||||
return Fraction(sum(map(len, found)), sum(len(one.findings) for one in rounds))
|
||||
def held(rounds: list[Round]) -> int:
|
||||
"""How many findings rounds hold."""
|
||||
return sum(len(one.findings) for one in rounds)
|
||||
|
||||
|
||||
def bar(rounds: list[Round], reference: Reference) -> Fraction:
|
||||
"""The share a rung needs: the mean of the project's rung's two shares, less MARGIN."""
|
||||
return (share(rounds, reference[0]) + share(rounds, reference[1])) / 2 - MARGIN
|
||||
def mean_share(rounds: list[Round], reference: Reference) -> Fraction:
|
||||
"""The mean share of rounds' findings that the project's rung's two replays found; rounds is never empty, and each holds a finding."""
|
||||
return Fraction(count(reference[0]) + count(reference[1]), 2 * held(rounds))
|
||||
|
||||
|
||||
def needed(rounds: list[Round], reference: Reference) -> int:
|
||||
"""How many of rounds' findings a rung needs to find: the fewest that reach the project's rung's mean share less MARGIN. Zero or below, no rung is tried, since a rung that found nothing would qualify."""
|
||||
return math.ceil((mean_share(rounds, reference) - MARGIN) * held(rounds))
|
||||
|
||||
|
||||
def tried(rung: Rung, rounds: list[Round], reference: Reference, found: list[set[int]]) -> RungRecall:
|
||||
"""rung's recall, from the indexes of each round's findings it found. It qualifies at the bar or above, missing no 🔴 the project's rung found both times; where the project's rung found nothing, no rung qualifies."""
|
||||
missed_red = [(one, index) for one, first, second, got in zip(rounds, *reference, found) for index in sorted((first & second) - got) if "🔴" in one.findings[index].splitlines()[0]]
|
||||
got = share(rounds, found)
|
||||
return RungRecall(rung, got, missed_red, found_any(reference) and got >= bar(rounds, reference) and not missed_red)
|
||||
"""rung's recall, from the indexes of each round's findings it found. It qualifies finding as many as needed, missing no 🔴 that both of the project's rung's replays found."""
|
||||
missed_red = [(one, index) for one, first, second, got in zip(rounds, *reference, found) for index in sorted((first & second) - got) if is_red(one.findings[index])]
|
||||
return RungRecall(rung, count(found), missed_red, 0 < needed(rounds, reference) <= count(found) and not missed_red)
|
||||
|
||||
|
||||
def recall_report(reviewed: str, project: Rung, recall: Recall) -> str:
|
||||
rounds, (first, second) = recall.rounds, recall.reference
|
||||
lines = [
|
||||
f"Replayed {len(rounds)} {reviewed} rounds of {project.model} projects, which hold {sum(len(one.findings) for one in rounds)} 🔴 and 🟡 findings, twice on the project's rung, {project}.",
|
||||
f"Replayed {len(rounds)} {reviewed} rounds of {project.model} projects, which hold {held(rounds)} 🔴 and 🟡 findings, twice on the project's rung, {project}.",
|
||||
*([f"Left out {recall.left_out} more, which a replay on the project's rung failed on; stderr says why."] if recall.left_out else []),
|
||||
]
|
||||
if not enough(rounds):
|
||||
return "\n".join([*lines, f"No rung tried: fewer than {ENOUGH_ROUNDS} rounds were replayed on the project's rung without a failure."])
|
||||
if not found_any(recall.reference):
|
||||
return "\n".join([*lines, "No rung tried: the project's rung found none of them."])
|
||||
lines.append(f"The project's rung found {sum(map(len, first))} and then {sum(map(len, second))} of them, {percent(bar(rounds, recall.reference) + MARGIN)}, so a rung qualifies at {percent(bar(rounds, recall.reference))} or more and missing no 🔴 it found both times.")
|
||||
if needed(rounds, recall.reference) <= 0:
|
||||
return "\n".join([*lines, "No rung tried: the project's rung found too few of them to hold a rung to."])
|
||||
lines.append(f"The project's rung found {count(first)} and then {count(second)} of the {held(rounds)}, {percent(mean_share(rounds, recall.reference))} on average, so a rung qualifies finding {needed(rounds, recall.reference)} or more of them, missing no 🔴 that both of its replays found.")
|
||||
for one in recall.tried:
|
||||
verdict = ": it qualifies." if one.qualifies else ":" if one.missed_red else "."
|
||||
lines += [f"{one.rung} found {percent(one.share)} and missed {len(one.missed_red) or 'no'} such 🔴{verdict}", *(f" {at.root} {at.at}: {at.findings[index].splitlines()[0]}" for at, index in one.missed_red)]
|
||||
verdict = "it qualifies" if one.qualifies else "it doesn't qualify"
|
||||
lines += [f"{one.rung} found {one.found}, {percent(Fraction(one.found, held(rounds)))}, and missed {len(one.missed_red) or 'no'} such 🔴: {verdict}.", *(f" {at.root} {at.at}: {at.findings[index].splitlines()[0]}" for at, index in one.missed_red)]
|
||||
lowest = recall.lowest or "none below the project's rung"
|
||||
lines.append(f"Lowest rung that qualifies: {lowest}")
|
||||
return "\n".join(lines)
|
||||
|
||||
Reference in New Issue
Block a user