Skip to content

bug(analytics): branches view shows $0 cost — investigate SUM(DISTINCT) on cost #189

@hashedone

Description

@hashedone

Problem

The branches view (/traces/branches) shows $0.00 cost for all branches even when sessions with actual cost exist.

Likely root cause

get_branches.sql uses:

COALESCE(SUM(DISTINCT s.estimated_cost_usd), 0) AS total_cost

SUM(DISTINCT ...) on a float column deduplicates by value — two sessions with the same cost (e.g. both $0.00) only count once. This is almost certainly unintentional. For sessions with $0.00 cost (which is common — many sessions have zeroed costs), they all deduplicate to a single $0.00 row, so the sum is still 0.

Fix

Change to:

COALESCE(SUM(s.estimated_cost_usd), 0) AS total_cost

Or use a subquery to get distinct session costs by session ID first.

Investigate

Also verify that estimated_cost_usd is actually populated for sessions on this org — the DISTINCT issue aside, costs may be zero because pricing isn't configured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions