Improve cache hit/miss reporting for cache.get() - #2418
Conversation
13bc758 to
7af7a62
Compare
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@mgstabrani I noticed that CI was still flagging the No |
tim-schilling
left a comment
There was a problem hiding this comment.
I appreciate the time and effort @Harsh3006, but I think this implementation isn't something we can adopt. I'm open to alternative solutions or ideas, but this as is, I'm not onboard with right now.
This changes what the user is doing and could have downstream effects in people's applications. For example, if someone has another observability tool implemented underneath the toolbar that counts the unique default values passed in, we would break that functionality. And it would break silently while being extremely difficult to debug. They would see some random memory address being passed as the default which would be hard to search on. They'd have to audit all the packages that do something related to caching to track it down to us, and when they do, I suspect they'll be a little upset 😅
Shorter version: The toolbar shouldn't be making changes to function calls without permission from the user.
|
Thanks @tim-schilling for the explanation. That makes sense. I hadn't considered the effect on downstream instrumentation that may observe the original call arguments. I spent some more time looking for an alternative that could solve this without modifying the actual One alternative I considered was comparing the returned value with the supplied default instead of checking for I also cross-checked this approach against the current test suite, and as expected, these two tests fail:
At this point, the sentinel approach seems to be the only approach I've found that can distinguish these cases reliably, but I understand the concern about modifying the arguments passed to the wrapped function. |
e2d3c9c to
91443f5
Compare
cache.get()
|
@tim-schilling Here are the screenshots showing the template and documentation changes, including a note on the remaining ambiguity and a link to the open discussion. Updated Cache Panel:
|



Description
This change fixes incorrect cache hit/miss reporting in the Cache panel for
cache.get().Previously, the Cache panel determined whether a
cache.get()call was a hit or a miss solely based on whether the returned value wasNone. This resulted in two incorrect scenarios:A missing key with a supplied default (for example,
cache.get("missing", "default")) was reported as a cache hit, even though the value was not retrieved from the cache.A cached value of
Nonewas reported as a cache miss, even though the key existed in the cache.The Cache panel now correctly distinguishes between a missing cache key and a cached value equal to the caller's supplied default while preserving the existing
cache.get()behavior.Fixes #2417
Checklist:
docs/changes.rst.AI/LLM Usage