bench: parse optional usage counters

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
This commit is contained in:
Salman Mohammed
2026-08-18 19:31:25 -04:00
parent baab990bd9
commit e4ca0ffa69
2 changed files with 16 additions and 2 deletions

View File

@@ -84,8 +84,12 @@ _ANSI_RE = re.compile(r"\x1b\[[0-9;]*[a-zA-Z]")
# fields) degrades to "no samples" rather than a wrong number.
USAGE_MARKER = "goose usage update"
_SESSION_RE = re.compile(r"\bsession_id=(\S+)")
_INPUT_RE = re.compile(r"\binput=(\d+)\b")
_OUTPUT_RE = re.compile(r"\boutput=(\d+)\b")
# Older buzz-acp builds render cumulative counters as `input=123`; current
# builds retain their optional type in the tracing field and render
# `input=Some(123)`. Accept both representations so a source update cannot make
# a real, billed run look like zero usage.
_INPUT_RE = re.compile(r"\binput=(?:Some\()?(\d+)(?:\))?")
_OUTPUT_RE = re.compile(r"\boutput=(?:Some\()?(\d+)(?:\))?")
# The cache-served subset of `input`, added to the usage line by buzz-acp. Absent
# in logs written by an agent build that predates it, which is why a missing
# field must read as "unknown" (fall back to the modelled rate) and never as 0 —

View File

@@ -64,6 +64,16 @@ def test_parse_usage_log_reads_the_coloured_lines_a_real_trial_produces():
)
def test_parse_usage_log_reads_optional_counters_from_current_buzz_acp():
text = (
"2026-08-18T23:25:39Z DEBUG acp::usage: goose usage update "
"session_id=ses_current input=Some(5738) output=Some(1802) cached=0"
)
assert accounting.parse_usage_log(text) == (
accounting.SessionUsage("ses_current", 5738, 1802, 0),
)
def test_parse_handoffs_reads_coloured_lines_too():
"""Same formatter, same escapes — the compaction bound must not silently zero."""
text = (