Skip to content

fix(ai): Guard urlsplit in cost report for unparseable backend #2462

Closed

Description

@dan-petty

Problem Description

devops ai cost report stops with a ValueError when the spend ledger holds a served_by value that urllib.parse.urlsplit cannot read.

  • _is_single_server_local in src/devops_cli/ai/spend/pricing.py calls urlsplit(clean) on the stored served_by value, with no guard.
  • For http://[::1, urlsplit raises ValueError: Invalid IPv6 URL, and the report command fails before it shows a table.
  • extract_served_by now refuses such a header value, so a new row cannot hold one. Ledger rows from before that change can hold one.

Reproduction Steps

  1. Record a gateway call in a spend ledger with served_by="http://[::1" (SpendLedger.record_request).
  2. Run devops ai cost report --by backend against that ledger.

Expected vs Actual Behavior

  • Expected: the report shows the row, and the serving backend shows as unknown.
  • Actual: the command exits 1. The traceback ends in pricing.py, _is_single_server_local, urlsplit(clean), with ValueError: Invalid IPv6 URL.

Environment Diagnostics

Found with an offline probe at 4226904e, while the change for #1110 was tested. The probe used a temporary ledger and typer.testing.CliRunner.

Logs, Traces, or Terminal Output

File "src/devops_cli/ai/spend/pricing.py", in _is_single_server_local
    if clean in CONST_LOCAL_TRANSPORT_LABELS or urlsplit(clean).scheme == "http+unix":
ValueError: Invalid IPv6 URL

Proposed design

Problem statement

The devops ai cost report command crashes with an unhandled ValueError when a spend ledger row holds a served_by value that urllib.parse.urlsplit cannot parse, such as http://[::1. The function _is_single_server_local calls urlsplit without a guard. New rows cannot hold such a value because extract_served_by now refuses it, but legacy rows from before that change can. The report must show the row and treat the backend as unknown instead of exiting with a traceback.

Acceptance criteria

Requirement: Report does not crash on unparseable served_by

The report command SHALL NOT raise an unhandled ValueError when a ledger row holds a served_by value that urlsplit cannot parse.

Scenario: Ledger row with served_by http://[::1

  • WHEN A spend ledger row has served_by set to http://[::1 and the user runs devops ai cost report --by backend
  • THEN The command exits 0 and prints the report table without a traceback

Requirement: Unparseable backend shows as unknown

The report SHALL display the serving backend as unknown for a row whose served_by value urlsplit cannot parse.

Scenario: Backend column for unparseable value

  • WHEN The report renders a row whose served_by is http://[::1
  • THEN The backend column for that row shows unknown

Requirement: Valid served_by values still resolve

The report SHALL resolve a valid served_by value to its local or hosted classification as before.

Scenario: Valid local backend still detected

  • WHEN A ledger row has served_by set to http://localhost:11434 and the user runs devops ai cost report --by backend
  • THEN The row is classified as local and the backend column shows the resolved value

Existing Tool Considered

No external tool covers this need. The fix is a try-except ValueError guard around one urlsplit call in src/devops_cli/ai/spend/pricing.py, plus one test. The written cost is roughly 10 lines of code and 15 lines of test, kept in the same file. No new dependency is added.

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

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

  3. added
    priority/p2-medium
    on Oct 28, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  5. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 0f7bc26 (see proposed design in issue body).

  6. added
    scope/ai
    on Oct 30, 2026
  7. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/2462-devops-ai-cost-report-shows-a, draft pull request #2990. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Guard urlsplit in _is_single_server_local and add tests: 2803 tokens

    These paths of the plan are no file on the default branch, and no group creates them: tests/test_pricing.py. A person checks that the plan names them right.

  8. added
    owner/service
    and removed
    status/ready
    on Nov 1, 2026
  9. 292 remaining items

  10. added
    status/blocked
    and removed
    status/in-progress
    on Nov 4, 2026
  11. devops-cli-service commented on Nov 4, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261104-223515-3ed5 ended: succeeded.
    Image digest: sha256:bf609edd0c01ca1c27bdc7e5d0f9e7385ff29934887b4e531bc648ef36301351

    The last lines of its log:

    Tool call: shell, started: uv run devops ci test tests/ai/spend/test_ai_spend_pricing.py ...
    Tool call: shell, program uv, ok.
    Tool call: shell, started: uv run devops openspec check
    Tool call: shell, program uv, ok.
    Tool call: shell, started: other
    Tool call: shell, program other, refused.
    Tool call: shell, started: ls -la
    Tool call: shell, program ls, ok.
    Tool call: shell, started: other
    Tool call: shell, program other, refused.
    Tool call: shell, started: grep -n 1.1\\|1.2\\|1.3 openspec/changes/2462-devops-ai-cost-report-shows-a/tasks.md
    Tool call: shell, program grep, refused.
    Tool call: shell, started: grep -n 1.1 openspec/changes/2462-devops-ai-cost-report-shows-a/tasks.md
    Tool call: shell, program grep, ok.
    Tool call: shell, started: grep -n 1.2 openspec/changes/2462-devops-ai-cost-report-shows-a/tasks.md
    Tool call: shell, program grep, ok.
    Tool call: shell, started: grep -n 1.3 openspec/changes/2462-devops-ai-cost-report-shows-a/tasks.md
    Tool call: shell, program grep, ok.
    Tool call: shell, started: grep -A 5 -B 5 try: ...
    Tool call: shell, program grep, ok.
    Tool call: shell, started: uv run devops ci test tests/ai/spend/test_ai_spend_pricing.py::test_a_stored_served_by_that_urlsplit_cannot_read_is_hosted ...
    Tool call: shell, program uv, ok.
    Tool call: shell, started: uv run pytest tests/ai/spend/test_ai_spend_pricing.py::test_a_stored_served_by_that_urlsplit_cannot_read_is_hosted tests/ai/client/test_ai_served_by.py -k ...
    Tool call: shell, program uv, ok.
    Tool call: shell, started: uv run pytest tests/ai/spend/test_ai_spend_pricing.py::test_a_stored_served_by_that_urlsplit_cannot_read_is_hosted -v
    Tool call: shell, program uv, ok.
    Tool call: write_file, retry (Parent directory '.data/agent/scratch' does not exist. Create the parent directory first.).
    Tool call: shell, started: other
    Tool call: shell, program other, refused.
    Tool call: shell, started: ls -la openspec/changes/2462-devops-ai-cost-report-shows-a/tasks.md
    Tool call: shell, program ls, ok.
    Removed stray files that the group does not name: tmp_test.py.
    Formatted: src/devops_cli/ai/spend/pricing.py, tests/ai/spend/test_ai_spend_pricing.py
    Tool call: shell, started: other
    Tool call: shell, program other, refused.
    Tool call: shell, started: ls -la .data/agent/scratch/
    Tool call: shell, program ls, ok.
    Failure class not_ticked. Action left: amend.
    ✓ Took 0 item(s) to a ready pull request, stopped 1.
    Elapsed: 14m 24s
    
  12. removed
    owner/service
    on Nov 4, 2026
  13. changed the title [-]fix(ai): devops ai cost report shows a stored serving backend that urlsplit cannot read, and stops with no ValueError[/-] [+]fix(ai): Guard urlsplit in cost report for unparseable backend[/+] on Nov 6, 2026
  14. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 108 characters, and the limit is 60. The type and the scope stay.

    • Before: fix(ai): devops ai cost report shows a stored serving backend that urlsplit cannot read, and stops with no ValueError
    • After: fix(ai): Guard urlsplit in cost report for unparseable backend
    • Source of the summary: the background model
  15. added
    status/in-progress
    and removed
    status/blocked
    on Nov 9, 2026
  16. added
    status/in-review
    and removed
    status/in-progress
    on Nov 9, 2026
  17. removed
    status/in-review
    on Nov 9, 2026
  18. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-09 14:13 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