fix(cost_map): label the card's loaded_at as per-worker and cover the integrity-failure fallback

This commit is contained in:
mateo-berri 2026-09-07 18:20:41 -07:00
parent 9041768fb4
commit bb52fd44fa
3 changed files with 31 additions and 0 deletions

View file

@ -684,3 +684,23 @@ def test_boot_load_fallback_to_the_backup_reports_its_blob_id_and_drops_the_remo
assert source["source"] == "local"
assert source["etag"] is None
assert source["source_revision"] == _bundled_blob_id()
def test_boot_load_that_fails_the_integrity_check_reports_the_backup_not_the_rejected_fetch():
"""A fetch that succeeds but fails integrity validation is thrown away, so the provenance must
describe the backup that got loaded, never the ETag or bytes of the map that was rejected."""
remote, _ = _mock_client(
[httpx.Response(200, headers={"ETag": 'W/"boot"'}, content=_real_map_bytes())], client_cls=httpx.Client
)
get_model_cost_map(url=_URL, sleep=_SyncSleepRecorder(), rng=random.Random(0), client=remote)
shrunk_body = b'{"gpt-5.4-mini": {"mode": "chat", "input_cost_per_token": 1e-06, "output_cost_per_token": 2e-06}}'
shrunk, _ = _mock_client([httpx.Response(200, headers={"ETag": 'W/"shrunk"'}, content=shrunk_body)], client_cls=httpx.Client)
get_model_cost_map(url=_URL, sleep=_SyncSleepRecorder(), rng=random.Random(0), client=shrunk)
source = get_model_cost_map_source_info()
assert source["source"] == "local"
assert source["fallback_reason"] == "Remote data failed integrity validation"
assert source["etag"] is None
assert source["source_revision"] == _bundled_blob_id()
assert source["source_revision"] != git_blob_id(shrunk_body)

View file

@ -68,6 +68,7 @@ describe("PriceDataReload", () => {
expect(screen.getByText("ETag:")).toBeInTheDocument();
expect(screen.getByText('W/"eb8e9a53f4cc284b"')).toBeInTheDocument();
expect(screen.getByText("Loaded at:")).toBeInTheDocument();
expect(screen.getByText(/worker that answered this request/)).toBeInTheDocument();
expect(screen.getByText(new Date(provenance.loaded_at).toLocaleString())).toBeInTheDocument();
});
@ -91,6 +92,7 @@ describe("PriceDataReload", () => {
expect(screen.queryByText("Source revision:")).not.toBeInTheDocument();
expect(screen.queryByText("ETag:")).not.toBeInTheDocument();
expect(screen.queryByText("Loaded at:")).not.toBeInTheDocument();
expect(screen.queryByText(/worker that answered this request/)).not.toBeInTheDocument();
});
it("confirms an immediate reload and refreshes dependent data", async () => {

View file

@ -132,6 +132,15 @@ const CostMapProvenanceRows: React.FC<{ sourceInfo: CostMapSourceInfo }> = ({ so
<span className="font-medium">{formatDateTime(sourceInfo.loaded_at)}</span>
</div>
)}
{sourceInfo.loaded_at && (
<div className="flex items-center gap-1.5 text-xs text-muted-foreground">
<Info className="size-3.5 shrink-0" />
<span>
Reported by the worker that answered this request. Other workers pick up a reload on their next poll
</span>
</div>
)}
</>
);