mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(proxy): keep negative compression savings across restart (#4406)
## Description
`SavingsTracker.record_request` keeps a negative compression saving on
purpose (a rewrite that costs more than it removes), but the reload path
and the lifetime-metrics aggregate used the zero-floored
`_coerce_float`. After a restart the stored loss read back as `0.0`, and
`/stats` and `/stats-lifetime` disagreed with `by_model`. The signed
coercion is now used for `compression_savings_usd` in those places only.
Fixes #4401
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)
## Changes Made
- `headroom/proxy/savings_tracker.py`: `_coerce_signed_float` instead of
`_coerce_float` for `compression_savings_usd` when normalising history
points (dict and list shapes), reading the `lifetime` block,
back-filling from the last history point, and building the
`display_session` snapshot. Five call sites; token counts, input cost
and cache savings keep their floor.
- `headroom/proxy/persistent_metrics.py`: new `_coerce_signed_float`,
used for `cost.compression_savings_usd` and
`cost.compression_savings_list_usd` when recording and when loading;
`has_priced_history` is now `!= 0` so a net-negative state is still
migrated as list-priced.
- `headroom/proxy/savings_tracker.py` (review follow-up, second commit):
the v6 `compression_savings_list_usd` is loaded with the signed coercion
too; the lifetime `compression_savings_usd` is back-filled from the last
history point only when the saved counters (tokens, cache reads, output,
tool tokens) are behind that checkpoint, or the field is absent. A
request that saves no tokens and reads no cache appends no history
checkpoint, so the saved total can sit below the last checkpoint and the
old `max()` overwrote the loss.
- `headroom/proxy/savings_tracker.py` (review round 2, third commit):
when the saved lifetime block is behind the last history checkpoint
(`history_ahead`), the checkpoint is the newer source, so its signed
`compression_savings_usd` is taken as is instead of `max(saved,
checkpoint)`. A negative checkpoint was lower than an older zero or
positive lifetime value and was discarded. The case where the saved
lifetime block is not behind the checkpoint (a legitimate loss after the
last checkpoint) is unchanged.
- `tests/test_negative_savings_reload.py`: save/load round trip for the
tracker (lifetime, display_session, history) and for
`PersistentMetricsState`; a negative list total across restart plus
another request; a loss recorded after the last checkpoint; a stale
lifetime block (tokens 0, dollars 0.0 or 1.0) with a newer -0.5
checkpoint (round 2).
## Testing
- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed
### Test Output
```text
# new tests, source change reverted (first commit only, round 1)
FAILED tests/test_negative_savings_reload.py::test_negative_savings_survive_reload
FAILED tests/test_negative_savings_reload.py::test_lifetime_metrics_keep_negative_compression_savings
E Obtained: 0.0
E Expected: -0.5 ± 5.0e-07
2 failed
# review follow-up tests, follow-up source change reverted
FAILED tests/test_negative_savings_reload.py::test_negative_list_total_survives_reload_and_next_request (Obtained: 0.0)
FAILED tests/test_negative_savings_reload.py::test_loss_after_last_checkpoint_is_not_overwritten_by_history (Obtained: 0.5)
2 failed, 2 passed
# new tests + neighbours, with both commits
tests/test_negative_savings_warning.py tests/test_persistent_metrics.py tests/test_persistent_metrics_persistence.py
tests/test_persistent_metrics_integration.py tests/test_proxy_savings_history.py tests/test_savings_record.py
tests/test_savings_ledger.py tests/test_savings_tracker_zero_price.py tests/test_negative_savings_reload.py
141 passed, 2 skipped, 1 warning
# review round 2 (third commit): new test, source change reverted
FAILED tests/test_negative_savings_reload.py::test_newer_negative_checkpoint_wins_over_stale_lifetime_dollars[0.0] (Obtained: 0.0, expected -0.5)
FAILED tests/test_negative_savings_reload.py::test_newer_negative_checkpoint_wins_over_stale_lifetime_dollars[1.0] (Obtained: 1.0, expected -0.5)
2 failed, 4 passed
# review round 2: with the change
tests/test_negative_savings_reload.py: 6 passed
the same 9 neighbouring files plus tests/test_proxy_savings_history.py's legacy-state test: 152 passed, 2 skipped, 1 warning
ruff check headroom/proxy tests/test_negative_savings_reload.py: All checks passed!
ruff format --check <3 changed files>: 3 files already formatted
round 2: ruff check and ruff format --check on headroom/proxy/savings_tracker.py and tests/test_negative_savings_reload.py: passed
```
## Real Behavior Proof
- Environment: Ubuntu 22.04 (WSL2), Python 3.12.15, worktree at upstream
main e995eb9f plus this commit. `headroom/_core.abi3.so` copied
(untracked, not committed) from the official `headroom_ai-0.41.0` wheel
because the checkout has no built Rust core.
- Exact command / steps: seed `proxy_savings.json` by running
`SavingsTracker.record_request` and `record_lifetime_request` with a
compression saving of -0.5 (file holds -0.5 in `lifetime`,
`display_session`, `history`, `lifetime_metrics.cost`); copy that same
file for each run; start the real proxy `HEADROOM_SAVINGS_PATH=<file>
ANTHROPIC_TARGET_API_URL=http://127.0.0.1:18849 python -P -m
headroom.proxy.server --host 127.0.0.1 --port <18840|18841> --no-cache
--no-rate-limit`; `GET /stats` and `GET /stats-lifetime`. "Before" = the
two source files with this commit's change reverted (`git apply -R`).
- Observed result: before, the totals are `0.0` after restart; after,
they are `-0.5` (output below).
- Not tested: a live Anthropic upstream (no upstream request is made;
the state comes from a seeded file); requests that produce a negative
saving through the real pricing path; the dashboard rendering; mypy; the
real proxy for review round 2 (unit-level only).
Before (change reverted), port 18841:
```
GET /stats
/display_session/compression_savings_usd = 0.0
/persistent_savings/lifetime/compression_savings_usd = 0.0
/persistent_savings/display_session/compression_savings_usd = 0.0
/persistent_savings/by_model/claude-sonnet-4/compression_savings_usd = -0.5
GET /stats-lifetime
/cost/compression_savings_usd = 0.0
```
After (this commit), port 18840:
```
GET /stats
/display_session/compression_savings_usd = -0.5
/persistent_savings/lifetime/compression_savings_usd = -0.5
/persistent_savings/display_session/compression_savings_usd = -0.5
/persistent_savings/by_model/claude-sonnet-4/compression_savings_usd = -0.5
GET /stats-lifetime
/cost/compression_savings_usd = -0.5
```
`/stats` `summary.cost.breakdown` and `cost` read 0.0 in both runs: they
are this process's counters and no request was made.
Review follow-up (second commit), same method, seeded file with a
history checkpoint of +0.5 then a no-token request of -1.0 (file:
`lifetime` -0.5 / list -0.5, last history checkpoint +0.5), ports 18861
(follow-up source change reverted) and 18860 (this commit):
```
Before, port 18861 After, port 18860
GET /stats GET /stats
/lifetime/compression_savings_usd = 0.5 /lifetime/compression_savings_usd = -0.5
/lifetime/compression_savings_list_usd = 0.0 /lifetime/compression_savings_list_usd = -0.5
/by_model/claude-sonnet-4/... = -0.5 /by_model/claude-sonnet-4/... = -0.5
```
The proxy made no upstream request in either run (the state comes from
the seeded file; the proxy log names no upstream call).
Review round 2 (third commit) is covered by unit tests only: the real
proxy was not re-run for it. Scenario from the review, reproduced
through `SavingsTracker` on a file written by the PR's own
losing-request helper (history checkpoint 100 tokens / -0.5 USD, then
`lifetime.tokens_saved=0` and `lifetime.compression_savings_usd` set to
0.0 or 1.0):
```
Before: tokens_saved 100, compression_savings_usd 0.0 (and 1.0 for the second case)
After: tokens_saved 100, compression_savings_usd -0.5
```
## Runtime Rollout Safety
- Rollout-managed feature(s): none
- Minimum rollout channel: n/a
- Stable/default behavior changed: totals that were negative on disk are
now shown as negative after a restart instead of 0.0
- Kill switch / disable path: n/a
- Unsafe override required: no
- Qualification impact: none known
- Rollback path: revert the commit
## Review Readiness
- [x] I have performed a self-review
- [x] This PR is ready for human review
## Checklist
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)
## Additional Notes
Only the listed test files were run, not the whole suite. Round 2 does
not change the `compression_savings_list_usd` recovery: a stale lifetime
block's list column is not back-filled from history (history points
carry no list column), as before. A first version of the second fix
(never use history when the field is present) broke
`test_savings_tracker_sanitizes_legacy_state_and_applies_retention`,
which pins history back-fill for a stale lifetime block; the counters
check above keeps that case. The bucket delta in the history rollup
(`savings_tracker.py` around `max(total_usd - prev_total_usd, 0.0)`)
still floors per-bucket deltas and was left alone. Produced with AI
assistance (Claude Code) operated by me (HetCreep); the reproduction was
run on my machine on a clone of the repository.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
JerrettDavis
parent
45dacc1f94
commit
bebe24c5ff
@@ -83,6 +83,15 @@ def _coerce_float(value: Any) -> float:
|
||||
return result if math.isfinite(result) and result >= 0 else 0.0
|
||||
|
||||
|
||||
def _coerce_signed_float(value: Any) -> float:
|
||||
"""_coerce_float without the zero floor, for compression savings that can lose."""
|
||||
try:
|
||||
result = float(value)
|
||||
except (TypeError, ValueError, OverflowError):
|
||||
return 0.0
|
||||
return result if math.isfinite(result) else 0.0
|
||||
|
||||
|
||||
def _label(value: Any) -> str:
|
||||
if not isinstance(value, str):
|
||||
return "other"
|
||||
@@ -257,7 +266,10 @@ class PersistentMetricsState:
|
||||
"compression_savings_list_usd",
|
||||
"cache_savings_usd",
|
||||
):
|
||||
result["cost"][key] = round(_coerce_float(raw_cost.get(key)), 6)
|
||||
coerce = (
|
||||
_coerce_signed_float if key.startswith("compression_savings") else _coerce_float
|
||||
)
|
||||
result["cost"][key] = round(coerce(raw_cost.get(key)), 6)
|
||||
# A state written before cache-aware pricing has no list column and its
|
||||
# dollars WERE list-priced, so that one figure seeds both and the
|
||||
# aggregate stays honestly labelled.
|
||||
@@ -266,7 +278,7 @@ class PersistentMetricsState:
|
||||
# column, and labelling that "list" would tell every new install its
|
||||
# untouched $0.00 total was list-priced. Only a state that actually
|
||||
# accumulated dollars has history to migrate.
|
||||
has_priced_history = result["cost"]["compression_savings_usd"] > 0
|
||||
has_priced_history = result["cost"]["compression_savings_usd"] != 0
|
||||
if "compression_savings_list_usd" in raw_cost:
|
||||
result["cost"]["savings_basis"] = str(raw_cost.get("savings_basis") or "unknown")
|
||||
elif has_priced_history:
|
||||
@@ -466,7 +478,7 @@ class PersistentMetricsState:
|
||||
cost = self._state["cost"]
|
||||
cost["input_usd"] = round(cost["input_usd"] + _coerce_float(input_usd), 6)
|
||||
cost["compression_savings_usd"] = round(
|
||||
cost["compression_savings_usd"] + _coerce_float(compression_savings_usd), 6
|
||||
cost["compression_savings_usd"] + _coerce_signed_float(compression_savings_usd), 6
|
||||
)
|
||||
# Defaults to the cache-aware figure when a caller supplies no ceiling,
|
||||
# which is the truthful reading of "these are the same number" for a
|
||||
@@ -477,7 +489,9 @@ class PersistentMetricsState:
|
||||
else compression_savings_list_usd
|
||||
)
|
||||
cost["compression_savings_list_usd"] = round(
|
||||
_coerce_float(cost.get("compression_savings_list_usd")) + _coerce_float(list_delta), 6
|
||||
_coerce_signed_float(cost.get("compression_savings_list_usd"))
|
||||
+ _coerce_signed_float(list_delta),
|
||||
6,
|
||||
)
|
||||
if savings_basis:
|
||||
cost["savings_basis"] = _blend_savings_basis(cost.get("savings_basis"), savings_basis)
|
||||
|
||||
@@ -727,7 +727,7 @@ def _normalize_history_entry(entry: Any) -> dict[str, Any] | None:
|
||||
if isinstance(entry, dict):
|
||||
timestamp = _parse_timestamp(entry.get("timestamp"))
|
||||
total_tokens_saved = _coerce_int(entry.get("total_tokens_saved"))
|
||||
compression_savings_usd = _coerce_float(entry.get("compression_savings_usd"))
|
||||
compression_savings_usd = _coerce_signed_float(entry.get("compression_savings_usd"))
|
||||
# Older history points predate cache-savings tracking and omit these
|
||||
# keys entirely; default to 0/0.0 rather than raising or dropping the
|
||||
# entry, matching how every other field here handles legacy shapes.
|
||||
@@ -747,7 +747,7 @@ def _normalize_history_entry(entry: Any) -> dict[str, Any] | None:
|
||||
timestamp = _parse_timestamp(entry[0])
|
||||
total_tokens_saved = _coerce_int(entry[1])
|
||||
if len(entry) >= 3:
|
||||
compression_savings_usd = _coerce_float(entry[2])
|
||||
compression_savings_usd = _coerce_signed_float(entry[2])
|
||||
if len(entry) >= 4:
|
||||
total_input_tokens = _coerce_int(entry[3])
|
||||
if len(entry) >= 5:
|
||||
@@ -1881,7 +1881,7 @@ class SavingsTracker:
|
||||
if isinstance(lifetime_raw, dict):
|
||||
lifetime_requests = _coerce_int(lifetime_raw.get("requests"))
|
||||
lifetime_tokens_saved = _coerce_int(lifetime_raw.get("tokens_saved"))
|
||||
lifetime_savings_usd = _coerce_float(lifetime_raw.get("compression_savings_usd"))
|
||||
lifetime_savings_usd = _coerce_signed_float(lifetime_raw.get("compression_savings_usd"))
|
||||
lifetime_tool_tokens_saved = _coerce_int(lifetime_raw.get("tool_tokens_saved"))
|
||||
lifetime_tool_savings_usd = _coerce_float(lifetime_raw.get("tool_schema_savings_usd"))
|
||||
lifetime_cache_read_tokens = _coerce_int(lifetime_raw.get("cache_read_tokens"))
|
||||
@@ -1891,7 +1891,7 @@ class SavingsTracker:
|
||||
migrated_at = lifetime_raw.get("savings_basis_migrated_at")
|
||||
is_v6_lifetime = "compression_savings_list_usd" in lifetime_raw
|
||||
if is_v6_lifetime:
|
||||
lifetime_savings_list_usd = _coerce_float(
|
||||
lifetime_savings_list_usd = _coerce_signed_float(
|
||||
lifetime_raw.get("compression_savings_list_usd")
|
||||
)
|
||||
lifetime_basis = str(lifetime_raw.get("savings_basis") or BASIS_UNKNOWN)
|
||||
@@ -1901,14 +1901,27 @@ class SavingsTracker:
|
||||
|
||||
if normalized_history:
|
||||
last = normalized_history[-1]
|
||||
# A losing request that saves no tokens and reads no cache appends
|
||||
# no checkpoint, so the saved total can legitimately sit BELOW the
|
||||
# last checkpoint. Only trust the checkpoint for dollars when the
|
||||
# saved counters show the lifetime block is behind it.
|
||||
history_ahead = (
|
||||
lifetime_tokens_saved < last["total_tokens_saved"]
|
||||
or lifetime_cache_read_tokens < _coerce_int(last.get("cache_read_tokens"))
|
||||
or lifetime_output_tokens_saved < _coerce_int(last.get("output_tokens_saved"))
|
||||
or lifetime_tool_tokens_saved < _coerce_int(last.get("tool_tokens_saved"))
|
||||
or not (
|
||||
isinstance(lifetime_raw, dict) and "compression_savings_usd" in lifetime_raw
|
||||
)
|
||||
)
|
||||
lifetime_tokens_saved = max(
|
||||
lifetime_tokens_saved,
|
||||
last["total_tokens_saved"],
|
||||
)
|
||||
lifetime_savings_usd = max(
|
||||
lifetime_savings_usd,
|
||||
_coerce_float(last["compression_savings_usd"]),
|
||||
)
|
||||
if history_ahead:
|
||||
# The checkpoint is the newer source here; a numeric max() would
|
||||
# discard a newer negative total in favour of an older higher one.
|
||||
lifetime_savings_usd = _coerce_signed_float(last["compression_savings_usd"])
|
||||
lifetime_tool_tokens_saved = max(
|
||||
lifetime_tool_tokens_saved,
|
||||
_coerce_int(last.get("tool_tokens_saved")),
|
||||
@@ -2225,7 +2238,7 @@ class SavingsTracker:
|
||||
2,
|
||||
)
|
||||
session["compression_savings_usd"] = round(
|
||||
_coerce_float(session.get("compression_savings_usd")),
|
||||
_coerce_signed_float(session.get("compression_savings_usd")),
|
||||
6,
|
||||
)
|
||||
session["total_input_cost_usd"] = round(
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
"""A negative compression-savings total must survive a restart, not reload as 0."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from headroom.proxy.persistent_metrics import PersistentMetricsState
|
||||
from headroom.proxy.savings_tracker import SavingsTracker
|
||||
|
||||
|
||||
def _losing_request(tracker: SavingsTracker) -> None:
|
||||
tracker.record_request(
|
||||
model="claude-sonnet-4",
|
||||
tokens_saved=100,
|
||||
input_tokens=1000,
|
||||
estimated_savings_usd={
|
||||
"compression": -0.5,
|
||||
"tool_schema": 0.0,
|
||||
"compression_list": -0.5,
|
||||
"tool_schema_list": 0.0,
|
||||
"basis": "cache_aware",
|
||||
},
|
||||
)
|
||||
tracker.flush()
|
||||
|
||||
|
||||
def test_negative_savings_survive_reload(tmp_path) -> None:
|
||||
path = str(tmp_path / "savings.json")
|
||||
live = SavingsTracker(path=path)
|
||||
_losing_request(live)
|
||||
snap = live.snapshot()
|
||||
assert snap["lifetime"]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
assert snap["display_session"]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
|
||||
reloaded = SavingsTracker(path=path).snapshot()
|
||||
assert reloaded["lifetime"]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
assert reloaded["display_session"]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
assert reloaded["history"][-1]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
|
||||
|
||||
def test_lifetime_metrics_keep_negative_compression_savings() -> None:
|
||||
state = PersistentMetricsState()
|
||||
state.record_request(
|
||||
provider="anthropic",
|
||||
model="claude-sonnet-4",
|
||||
stack=None,
|
||||
compression_savings_usd=-0.5,
|
||||
)
|
||||
cost = state.to_dict()["cost"]
|
||||
assert cost["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
assert cost["compression_savings_list_usd"] == pytest.approx(-0.5)
|
||||
|
||||
reloaded = PersistentMetricsState(state.to_dict()).to_dict()["cost"]
|
||||
assert reloaded["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
assert reloaded["compression_savings_list_usd"] == pytest.approx(-0.5)
|
||||
|
||||
|
||||
def test_negative_list_total_survives_reload_and_next_request(tmp_path) -> None:
|
||||
path = str(tmp_path / "savings.json")
|
||||
live = SavingsTracker(path=path)
|
||||
_losing_request(live)
|
||||
|
||||
reloaded = SavingsTracker(path=path)
|
||||
assert reloaded.snapshot()["lifetime"]["compression_savings_list_usd"] == pytest.approx(-0.5)
|
||||
reloaded.record_request(
|
||||
model="claude-sonnet-4",
|
||||
tokens_saved=100,
|
||||
input_tokens=1000,
|
||||
estimated_savings_usd={
|
||||
"compression": 0.1,
|
||||
"tool_schema": 0.0,
|
||||
"compression_list": 0.1,
|
||||
"tool_schema_list": 0.0,
|
||||
"basis": "cache_aware",
|
||||
},
|
||||
)
|
||||
lifetime = reloaded.snapshot()["lifetime"]
|
||||
assert lifetime["compression_savings_usd"] == pytest.approx(-0.4)
|
||||
assert lifetime["compression_savings_list_usd"] == pytest.approx(-0.4)
|
||||
|
||||
|
||||
def test_loss_after_last_checkpoint_is_not_overwritten_by_history(tmp_path) -> None:
|
||||
path = tmp_path / "savings.json"
|
||||
live = SavingsTracker(path=str(path))
|
||||
live.record_request(
|
||||
model="claude-sonnet-4",
|
||||
tokens_saved=100,
|
||||
input_tokens=1000,
|
||||
estimated_savings_usd={
|
||||
"compression": 0.5,
|
||||
"tool_schema": 0.0,
|
||||
"compression_list": 0.5,
|
||||
"tool_schema_list": 0.0,
|
||||
"basis": "cache_aware",
|
||||
},
|
||||
)
|
||||
# No tokens saved and no cache reads: no history checkpoint is appended.
|
||||
live.record_request(
|
||||
model="claude-sonnet-4",
|
||||
tokens_saved=0,
|
||||
input_tokens=1000,
|
||||
estimated_savings_usd={
|
||||
"compression": -1.0,
|
||||
"tool_schema": 0.0,
|
||||
"compression_list": -1.0,
|
||||
"tool_schema_list": 0.0,
|
||||
"basis": "cache_aware",
|
||||
},
|
||||
)
|
||||
live.flush()
|
||||
saved = json.loads(path.read_text())
|
||||
assert saved["lifetime"]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
assert saved["history"][-1]["compression_savings_usd"] == pytest.approx(0.5)
|
||||
|
||||
reloaded = SavingsTracker(path=str(path)).snapshot()
|
||||
assert reloaded["lifetime"]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stale_usd", [0.0, 1.0])
|
||||
def test_newer_negative_checkpoint_wins_over_stale_lifetime_dollars(tmp_path, stale_usd) -> None:
|
||||
path = tmp_path / "savings.json"
|
||||
_losing_request(SavingsTracker(path=str(path)))
|
||||
saved = json.loads(path.read_text())
|
||||
assert saved["history"][-1]["total_tokens_saved"] == 100
|
||||
assert saved["history"][-1]["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
# Stale lifetime block: behind the checkpoint on tokens, dollars older/higher.
|
||||
saved["lifetime"]["tokens_saved"] = 0
|
||||
saved["lifetime"]["compression_savings_usd"] = stale_usd
|
||||
path.write_text(json.dumps(saved))
|
||||
|
||||
lifetime = SavingsTracker(path=str(path)).snapshot()["lifetime"]
|
||||
assert lifetime["tokens_saved"] == 100
|
||||
assert lifetime["compression_savings_usd"] == pytest.approx(-0.5)
|
||||
Reference in New Issue
Block a user