Repository navigation
Description
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_localinsrc/devops_cli/ai/spend/pricing.pycallsurlsplit(clean)on the stored served_by value, with no guard.- For
http://[::1,urlsplitraisesValueError: Invalid IPv6 URL, and the report command fails before it shows a table. extract_served_bynow refuses such a header value, so a new row cannot hold one. Ledger rows from before that change can hold one.
Reproduction Steps
- Record a gateway call in a spend ledger with
served_by="http://[::1"(SpendLedger.record_request). - Run
devops ai cost report --by backendagainst 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), withValueError: 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:11434and 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
- What should _is_single_server_local return when urlsplit raises ValueError on the input string?: Return False, treating the server as not local. This lets the pricing path proceed and the report show the row with the backend as unknown. (best practice) [sources: src/devops_cli/ai/spend/pricing.py:243, openspec/changes/archive/2026-10-28-1110-reply-server-origin/design.md:33]
- Chosen: Return False on ValueError. The value is not a valid URL, so it cannot be a local server. Returning False lets the caller proceed with normal pricing. This matches the expected behavior in the issue body.
- Rejected: Raise a custom domain error. The project prohibits raising bare built-in exceptions in domain logic (docs/SDLC.md:124), but a custom error would still crash the report. The issue expects the row to show, not to error.
- Rejected: Pre-validate the string with a regex before urlsplit. A regex check adds a second code path to maintain and does not cover every malformed input that urlsplit rejects. A try-except is simpler and covers all cases.
- Does the project already guard urlsplit calls elsewhere?: Yes. _is_local_host in the same file catches ValueError from ipaddress.ip_address, and the pattern of catching ValueError around a parse call is established in this module. [sources: src/devops_cli/ai/spend/pricing.py:230]
- Is this fix independent of issue fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache #1110?: Yes. fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache #1110 changes extract_served_by to refuse bad values at write time. This issue adds a guard at read time for legacy rows. The guard works whether or not fix(ai): replies carry their server as an httpx2 origin, so a password in an AI URL stays out of output, the spend ledger, metrics, spans and cache #1110 is merged. [sources: openspec/changes/archive/2026-10-28-1110-reply-server-origin/design.md:33, src/devops_cli/ai/client/network.py:99]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The command crashes with an unhandled ValueError on legacy ledger data.It is a crash, but only triggered by old ledger rows that new code no longer writes.Users with legacy ledgers containing invalid IPv6 URLs lose the cost report entirely.A single try-except or guard around one urlsplit call in pricing.py.Both deal with how the serving backend value is stored and read, but #1110 changes the data model while the candidate adds error handling for legacy rows.fix(ai): a reply names its server by the origin of the URL called, so…
devops-cli-service commentedon Oct 29, 2026
Status set to Ready at 0f7bc26 (see proposed design in issue body).
devops-cli-service commentedon Nov 1, 2026
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:
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.292 remaining items
devops-cli-service commentedon Nov 4, 2026
The runner Job devops-cli-runner-20261104-223515-3ed5 ended: succeeded.
Image digest: sha256:bf609edd0c01ca1c27bdc7e5d0f9e7385ff29934887b4e531bc648ef36301351
The last lines of its log:
[-]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[/+]dan-petty commentedon Nov 6, 2026
The job shortened the title of this item. The summary had 108 characters, and the limit is 60. The type and the scope stay.
fix(ai): devops ai cost report shows a stored serving backend that urlsplit cannot read, and stops with no ValueErrorfix(ai): Guard urlsplit in cost report for unparseable backendfix(ai): guard urlsplit in cost report for unparseable backend
devops-cli-service commentedon Nov 9, 2026
Released in v0.100.2: https://github.com/dan-petty/devops-cli/releases/tag/v0.100.2
devops-cli-service commentedon Nov 9, 2026
Live since 2026-11-09 14:13 UTC