Skip to content

Bug: the agent's model traffic is invisible, so cost and error-class projections only ever describe the reviewer #128

Description

@thedancingdeveloper

Problem

In session mode the harness has no record of the agent's model traffic, so
/api/audit/cost, /api/errors and the rate-limit projections can only ever
describe the reviewer — a minority of the spend, and the stage least likely to
fail.

Model telemetry is produced by ModelClient's on_event, wired into the
audit store in _fleet_for_serve. SessionExecutor calls ModelClient once,
for review. Planning and implementation run as claude -p {prompt_file} in a
PTY session, whose requests never pass through the harness, so nothing about
them is recorded: no tokens, no cost, no latency, no error class, no rate
limit.

Evidence

Live on aidevenv-feat / Node B, harness cbfdb7ce, after a full redeploy, a
fleet start, a worktree reap and an agent run in progress:

$ sqlite3 /var/lib/aidevenv/audit.sqlite "select kind, count(*) from events group by kind;"
work|16

$ sqlite3 /var/lib/aidevenv/audit.sqlite "select count(*) from events where model is not null;"
0

$ grep -c model_call /var/lib/aidevenv/events.jsonl
0

Sixteen events, all of them work. Not one row carries a model, and the
model_call kind has never been written at all — across this deployment's
whole history, which includes the previous workload's twenty-odd item
attempts.

Consequently:

$ curl -sS -H "$A" .../api/errors      | jq -c '{total, by_class}'
{"total":0,"by_class":null}
$ curl -sS -H "$A" .../api/audit/cost  | jq -c '{total_cost_usd, rows: (.rows|length)}'
{"total_cost_usd":null,"rows":0}

Those two zeroes have been read as a telemetry bug more than once — #113 was
opened about them. #120 fixed the wiring, and the wiring is now demonstrably
live for work events. The remaining emptiness is not a broken sink; it is
that in session mode there is only one role's worth of traffic to record, and
that role runs last.

Why it matters

AGENTS.md rule 1 judges this work by the error-class breakdown. A breakdown
that structurally excludes the implementer cannot support that, and the
failure mode is quiet: the numbers look like a calm fleet rather than an
unmeasured one.

It also means spend is unattributable. An item that burns a large amount of
agent time and then fails its checks records a cost of null, so "what did
this backlog cost?" has no answer for the stage that dominates it.

What would fix it

Three shapes, not mutually exclusive:

  • Ask the agent. claude -p can be told to emit structured output; if the
    session captured a usage summary on exit, the harness could write one
    model_call event per item with tokens and cost. Cheapest, coarsest.
  • Put the agent behind the harness. Route the CLI at an endpoint the
    harness proxies, so its requests become ModelClient traffic like any
    other. Most faithful, most invasive.
  • Record what is knowable and say what is not. If neither of the above
    lands, /api/audit/cost should distinguish "zero spend" from "spend this
    harness cannot see", the way cost_usd already distinguishes null from
    zero for an unpriced model. A null that means "not measured" must not
    render as a zero that means "nothing was spent".

Related: the companion issue on the role map advertising planner/implementer
routes that session mode never calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions