Skip to content

Aggregate cost renders $0.00 for positive sub-micro spend #1046

Closed

Description

@evaline-ju

What happens

costevent.Event.Micros() = math.Round(CostUSD * 1e6) in costevent.go rounds sub-half-micro costs to 0. The event is still marked priced. After aggregation, CostMicros can be 0 while PricedRequests > 0. renderCostSummary then printsCOST $0.00 — the same output as a genuinely-free priced call.

This can occur for models like Anthropic Haiku's ~$0.25/M input rate, where a 1-token priced call is $2.5e-7 and rounds to 0 micros.

Behavior impact

Small-but-real spend reads as free in the usage-graph total. The per-event cell is unaffected (it renders through formatUSDCell's <$0.0001 floor against the raw CostUSD, not against the rounded micros).

Proposed fix

Add a PositiveCostRequests counter that sources from the pre-rounding CostUSD > 0 predicate:

  • costevent.eventCost — new predicate exposed
  • usage.Counts + Counts.Add — new field, folded at every accumulation site
  • renderCostSummary — render <$0.01 when CostMicros == 0 && PositiveCostRequests > 0

Do not clamp Micros() to 1 — it changes the documented rounding semantics and lies about the underlying figure.

Ref #1000 (addressed by #1042)

Assisted-By: Claude (Anthropic AI) [email protected]

Activity

  1. changed the title [-]Aggregate cost renders $0.00 for genuinely positive sub-micro spend[/-] [+]Aggregate cost renders $0.00 for positive sub-micro spend[/+] on Sep 17, 2026
  2. mrsabath commented on Oct 2, 2026

    @mrsabath
    Member

    Closing as substantially addressed — but by a different route than proposed here, and with one narrow case left open. Recording both so this is not lost.

    What fixed itself

    The user-visible symptom — a positive cost rendering as $0.00, indistinguishable from genuinely free — no longer reproduces for any figure that survives rounding. formatUSDTotalMicros (cmd/agentop/tui/prune_saving.go:164) now carries exactly the floor this issue asked for:

    if micros > 0 && micros < 5_000 {
        // Positive but under half a cent.
        return "<$0.01"
    }

    And the contract above it states the rule as settled policy rather than a local fix: "NEITHER FORM EVER RENDERS A POSITIVE FIGURE AS ZERO. Cents falls back to <$0.01 and four decimals to <$0.0001." That arrived with the cent-arithmetic extraction out of renderCostSummary, not as a fix for this issue.

    The PositiveCostRequests counter proposed here was never implemented — it appears nowhere in the tree. The symptom was closed more cheaply, at the formatter rather than threaded through usage.Counts and every accumulation site.

    What is still true

    The floor is gated on micros > 0, so the case in this issue's body survives in the aggregate total:

    A single 1-token Haiku call at ~$2.5e-7 therefore still reaches the renderer as exactly 0 micros and prints COST $0.00. What changed is that any window whose aggregate clears half a micro now reads <$0.01 instead of $0.00 — which is every realistic window, and why this stopped being observable.

    Why close rather than finish it

    Distinguishing "rounded to zero" from "actually free" still requires the original fix: a counter sourced from the pre-rounding CostUSD > 0 predicate, threaded through usage.Counts and folded at every accumulation site. That is real work across the cost core for a case that needs a window containing exactly one sub-half-micro priced call and nothing else. The cheap alternative is still correctly ruled out by this issue — clamping Micros() to 1 lies about the figure, and event.go:364 now independently states the same rule for the bound case: "a clamped figure is a wrong number wearing a right label."

    Reopen if a real window ever reads $0.00 with priced traffic in it — that would mean the aggregate is rounding to zero in practice, which is the version worth paying for.

    Note for anyone following the links above: this issue's file reference is stale. authbridge/authlib/costevent/costevent.go moved to core/cost/event/event.go.

    Tracked on the cost surface under #1113.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions