microsoft / microsoft/amplifier

bug(streaming-ui): sub-cent costs show raw Decimal arithmetic precision (e.g. $0.00711955 instead of $0.0071)

Open
#289 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3.1k
Forks
261
Avg merge
3h 28m
Merged PRs (30d)
13

Description

Repo: amplifier-module-hooks-streaming-ui
File: amplifier_module_hooks_streaming_ui/__init__.pyformat_cost_usd()

Evidence

Real haiku session output:

└ Input: 12,530 (64% cached) | Output: 145 | Total: 12,675 | Cost: $0.00711955

Expected: $0.0071 (2 sig figs). Got: $0.00711955 (8 digits, 7 decimal places).

Root cause

format_cost_usd used input_exp = -cost.as_tuple().exponent to determine decimal places. This reads stored Decimal arithmetic precision, not display precision. When compute_cost multiplies token counts by rate constants like Decimal("3.000"), Python stores the full intermediate precision (8–12+ places), making input_exp far larger than needed.

Fix (already applied on feat/m0-cost-management)

# Remove input_exp entirely. Use exp_floor for 2 sig figs + strip trailing zeros.
decimal_places = -exp_floor + 1
result = f"${cost:.{decimal_places}f}"
return result.rstrip("0") or "$0.00"

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open amplifier_module_hooks_streaming_ui/init.py and inspect format_cost_usd(), then reproduce the sub-cent output shown in the issue. Compare the function with the fix already applied on feat/m0-cost-management. Done means sub-cent costs display with two significant figures, such as $0.0071, without raw Decimal precision.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.