Skip to content

fix(ai): the backend report skips the requests of build_agent #4716

Description

@dan-petty

Problem Description

The backend breakdown of the lifetime spend report (_QUERY_BACKEND_BREAKDOWN in src/devops_cli/ai/spend/ledger.py) keeps only rows with served_by IS NOT NULL. The spend hook of build_agent (src/devops_cli/ai/client/factory.py) passes server and served_model to track_request_spend, but not served_by. So the stage, refine and alternatives requests are not in the backend breakdown, and its mean_duration_seconds ignores them, even after #4504 records the duration of each request.

Reproduction Steps

  1. Run an agent of build_agent on a model with a served_by URL.
  2. Run get_lifetime_report() on the ledger.
  3. report.backends has no entry for the request.

Expected vs Actual Behavior

Expected: the backend breakdown counts every request that a backend served, as the implement step does through record_run_spend.
Actual: the rows of the hook have served_by NULL.

Environment Diagnostics

origin/main after #4504. Found during #4504. Passing the value changes how the pricing registry reads local and hosted calls (calculate_request_cost(served_by=...)), so the fix needs a test of the price of a gateway request.

Pre-Submission Checklist

  • I searched open issues.

Alternatives check of 2026-11-14: none.
Tool: none found.

Activity

  1. added
    source/agent
    type/bug
    scope/ai
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. Report data is incomplete but the tool does not crash.
    • Value: Medium. Backend breakdown accuracy improves for agent requests.
    • Effort: Low. Pass one field to an existing call and add one test.
    • Related: fix(ai): agent requests record no duration in the ledger #4504, which asks for a different change. Both fix missing fields in the same build_agent spend hook; #4504 fixes duration_seconds, this fixes served_by.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The need is internal: the project's own spend hook in src/devops_cli/ai/client/factory.py must pass served_by to track_request_spend so _QUERY_BACKEND_BREAKDOWN in src/devops_cli/ai/spend/ledger.py counts build_agent requests, plus a price test. Searches returned no external tool or library that provides this — the missing field is in the repository's own ledger code, which no third-party project can supply.

    Tool: none found

    Searches run:

    • LLM gateway spend tracking per backend served_by cost ledger library, results: 5
    • LiteLLM spend tracking request cost per deployment model backend, results: 5
    • litellm spend logs track cost per model deployment, results: 5
    • "served_by" request spend backend breakdown python package, results: 5

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 14, 2026
  6. removed
    status/in-review
    on Nov 14, 2026
  7. added a commit that references this issue on Nov 14, 2026
  8. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor
  9. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 15:02 UTC

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

    effort/lowpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions