diff --git a/bin/routing_figures/measure.py b/bin/routing_figures/measure.py index 21b03a80..e65f6f86 100644 --- a/bin/routing_figures/measure.py +++ b/bin/routing_figures/measure.py @@ -120,7 +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}), + lacking=max(0, len(launches) - len(chunk.subagents)), ) @@ -151,7 +151,7 @@ def recorded_costs(worker: list[dict]) -> dict[str, float]: def costed(spent: list[Spent], project: str, recorded: dict[str, float]) -> tuple[dict[str, collections.Counter[str]], float]: - """Each message's dollars by DIMENSIONS, and the recorded cost that no message takes. A model's recorded cost is split across its messages in proportion to their list prices, so the calls no message records, such as compactions, are counted. A subagent transcript the archive lacks puts its cost on the messages it holds in the same proportion, since nothing says whose it was. A model the record omits keeps its list prices; a recorded model with no priced message is the cost no message takes.""" + """Each message's dollars by DIMENSIONS, and the recorded cost that no message takes. A model's recorded cost is split across its messages in proportion to their list prices, so the calls no message records, such as compactions, are counted. A subagent transcript the archive lacks puts its cost on the messages it holds in the same proportion, which counts it mostly as the worker's; `lacking` counts those subagents. A model the record omits keeps its list prices; a recorded model with no priced message is the cost no message takes.""" listed_by_model: collections.Counter[str] = collections.Counter() for _, _, message in spent: listed_by_model[message.model] += message.list_price @@ -266,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' {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 ''}", + 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 mostly on the worker's messages; 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 dc342032..957aff84 100644 --- a/bin/routing_figures/test_routing_figures.py +++ b/bin/routing_figures/test_routing_figures.py @@ -162,6 +162,8 @@ class Measured(unittest.TestCase): 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) + unnamed = measured(Chunk("log", [], worker, [Subagent("", "", [message("s1", "2026-10-14T10:00:01Z")]), Subagent("", "", [message("s2", "2026-10-14T10:00:02Z")])]), "/h") + self.assertEqual(unnamed.lacking, 0) 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)]