Fix the risk check for a new response cache
Your task
An endpoint was slow under load. An AI agent added a 60 second in-memory cache, and p99 latency (the time 99 percent of requests beat) dropped in the load test. Before you merge, you score the load test's numbers to see whether the cache fixed the slow path or only hid it.
An assistant wrote assess_cache_fix(uncached_ms, cached_ms, hit_rate_percent, latency_budget_ms). It is in the editor. It has a bug. Find it and fix it.
Input and output:
uncached_ms: the latency of a request that misses the cache, in whole milliseconds, 0 or more.cached_ms: the latency of a cache hit, in whole milliseconds, 0 or more.hit_rate_percent: the share of requests the cache serves, a whole percent from 0 to 100.latency_budget_ms: the endpoint's latency budget, in whole milliseconds, 0 or more.- Return the list of findings, possibly empty.
Rules the tests check:
- Run every check below, in this order, and add each one that applies:
root_path_still_slowwhenuncached_msis abovelatency_budget_ms.masked_by_cachewhenuncached_msis above the budget andcached_msis at or below it.blended_over_budgetwhen the blended latency is above the budget. The blend ishit_rate_percenttimescached_ms, plus100 - hit_rate_percenttimesuncached_ms, all divided by 100. Do not round it.stampede_exposurewhenhit_rate_percentis 95 or more anduncached_msis more than 10 timescached_ms. Whencached_msis 0, anyuncached_msabove 0 counts. A stampede is what happens when cached entries expire together and the whole crowd hits the slow path at once.
Examples
assess_cache_fix(uncached_ms: int, cached_ms: int, hit_rate_percent: int, latency_budget_ms: int) -> list[str]Example 1
Input
assess_cache_fix(2400, 8, 98, 300)Output
["root_path_still_slow", "masked_by_cache", "stampede_exposure"]Example 2
Input
assess_cache_fix(120, 8, 90, 300)Output
[]Example 3
Input
assess_cache_fix(2400, 400, 50, 300)Output
["root_path_still_slow", "blended_over_budget"]