diff --git a/bin/routing_figures/measure.py b/bin/routing_figures/measure.py index 65094f7e..21b03a80 100644 --- a/bin/routing_figures/measure.py +++ b/bin/routing_figures/measure.py @@ -54,7 +54,7 @@ class Reports: @dataclasses.dataclass(frozen=True) class ChunkFigures: - """dollars maps each of DIMENSIONS to its labels' dollars; start is the rung a routed chunk started on, None where no item routed it; escalated counts the worker's escalations by trigger; unattributed is the recorded cost that no message of the chunk takes.""" + """dollars maps each of DIMENSIONS to its labels' dollars; start is the rung a routed chunk started on, None where no item routed it; escalated counts the worker's escalations by trigger; unattributed is the recorded cost that no message of the chunk takes; lacking counts the subagents the worker launched that the archive holds no transcript of.""" dollars: dict[str, collections.Counter[str]] start: Rung | None rounds_past_first: int @@ -63,6 +63,7 @@ class ChunkFigures: reports: dict[str, Reports] escalated: collections.Counter[int] unattributed: float + lacking: int = 0 @dataclasses.dataclass(frozen=True) @@ -75,6 +76,7 @@ class Figures: escalated: collections.Counter[int] skipped: tuple[str, ...] = () unattributed: float = 0.0 + lacking: int = 0 @dataclasses.dataclass(frozen=True) @@ -118,6 +120,7 @@ def measured(chunk: Chunk, home: str) -> ChunkFigures: reports=reports, escalated=escalations(launches), unattributed=unattributed, + lacking=len(launches.keys() - {subagent.launched_by for subagent in chunk.subagents}), ) @@ -239,7 +242,7 @@ def totals(chunks: list[ChunkFigures], skipped: tuple[str, ...] = ()) -> Figures routed.setdefault(chunk.start, []).append(chunk) for kind, found in chunk.reports.items(): reports[kind] = reports.get(kind, Reports(0, 0, 0)) + found - return Figures(len(chunks), dollars, routed, reports, summed(chunks, lambda chunk: chunk.escalated), skipped, sum(chunk.unattributed for chunk in chunks)) + return Figures(len(chunks), dollars, routed, reports, summed(chunks, lambda chunk: chunk.escalated), skipped, sum(chunk.unattributed for chunk in chunks), sum(chunk.lacking for chunk in chunks)) def calls(figures: Figures) -> list[str]: @@ -263,7 +266,7 @@ def render(figures: Figures, found: list[str], at: str, cycle: int, since: str) """The figures as markdown; MEASURED_AT reads the cycle back. since is the latest reset's stamp, empty for none.""" sections = [ "# Routing figures", - f"Measured {at}, at cycle {cycle} across loop-claude's archive, from {figures.chunks} finished chunk{'' if figures.chunks == 1 else 's'}{f' that finished after the reset of {since}' if since else ''}. Dollars are what each worker transcript's last `cost-state` entry records for each model, cache reads included, split across the messages in the archive in proportion to their cost at list prices, so a subagent transcript the archive lacks puts its cost on the messages it holds; a chunk without the entry keeps the list prices. A message's dollars count towards the tools whose results it took in, split evenly; a message that took in no tool result counts towards `prompt`. The judge's runs are not archived, so their cost is not counted.{f' {money(figures.unattributed)} of the recorded cost is left out, since it belongs to a model with no list price or with no message in the archive.' if figures.unattributed else ''}", + f"Measured {at}, at cycle {cycle} across loop-claude's archive, from {figures.chunks} finished chunk{'' if figures.chunks == 1 else 's'}{f' that finished after the reset of {since}' if since else ''}. Dollars are what each worker transcript's last `cost-state` entry records for each model, cache reads included, split across the messages in the archive in proportion to their cost at list prices, so a subagent transcript the archive lacks puts its cost on the messages it holds; a chunk without the entry keeps the list prices. A message's dollars count towards the tools whose results it took in, split evenly; a message that took in no tool result counts towards `prompt`. The judge's runs are not archived, so their cost is not counted.{f' {money(figures.unattributed)} of the recorded cost is left out, since it belongs to a model with no list price or with no message in the archive.' if figures.unattributed else ''}{f' {figures.lacking} launched subagent{"" if figures.lacking == 1 else "s"} {"has" if figures.lacking == 1 else "have"} no transcript in the archive.' if figures.lacking else ''}", "## Calls for a routing change", "".join(f"- {call}\n" for call in found).rstrip("\n") or "None.", *[part for dimension in DIMENSIONS for part in (f"## Dollars by {dimension}", table((dimension.capitalize(), "Dollars"), [(label, money(dollars)) for label, dollars in figures.dollars[dimension].most_common()]))], diff --git a/bin/routing_figures/test_routing_figures.py b/bin/routing_figures/test_routing_figures.py index 11d560ad..dc342032 100644 --- a/bin/routing_figures/test_routing_figures.py +++ b/bin/routing_figures/test_routing_figures.py @@ -1,5 +1,6 @@ import collections import contextlib +import dataclasses import io import json import pathlib @@ -157,6 +158,11 @@ class Measured(unittest.TestCase): self.assertEqual(found.dollars["project"], {"log": 9.0}) self.assertEqual(found.unattributed, 0.5) + def test_counts_the_subagents_the_worker_launched_that_have_no_transcript(self): + worker = [message("m1", "2026-10-14T10:00:00Z", call("Agent", "a1", subagent_type="Explore"), call("Agent", "a2", subagent_type="Explore"), call("Read", "r1", file_path="/c/a"))] + found = measured(Chunk("log", [], worker, [Subagent("Explore", "a1", [message("s1", "2026-10-14T10:00:01Z")])]), "/h") + self.assertEqual(found.lacking, 1) + def test_keeps_list_prices_for_a_model_the_cost_state_does_not_name(self): worker = [message("m1", "2026-10-14T10:00:00Z"), message("m2", "2026-10-14T10:01:00Z", model="claude-sonnet-5-5"), cost_state(claude_opus_5_5=3.0)] found = measured(Chunk("log", [], worker, []), "/h") @@ -199,6 +205,8 @@ class Calls(unittest.TestCase): self.assertIn("cache reads included", text) self.assertIn("The judge's runs are not archived, so their cost is not counted.", text) self.assertNotIn("left out", text) + self.assertNotIn("no transcript", text) + self.assertIn("2 launched subagents have no transcript in the archive", render(totals([dataclasses.replace(chunk, lacking=1)] * 2), [], "2026-10-15T00:00:00Z", 40, "")) self.assertIn("$0.50 of the recorded cost is left out", render(totals([ChunkFigures({}, LOW, 0, 0, collections.Counter(), {}, collections.Counter(), 0.5), chunk]), [], "2026-10-15T00:00:00Z", 40, "")) self.assertIn(f"| {LOW} | 1 | 1.0 | 0.0 | {HIGH} 2 | |", text) two = ChunkFigures({}, HIGH, 0, 1, collections.Counter({str(HIGH): 2, str(LOW): 1}), {}, collections.Counter(), 0.0)