-
-
Notifications
You must be signed in to change notification settings - Fork 912
feat(hooks): add cache hit/miss observability hooks #1960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anderson-ufrj
wants to merge
6
commits into
567-labs:main
Choose a base branch
from
anderson-ufrj:contrib/issue-1882
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+628
−4
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Analysis of instructor library architecture for contribution to issue 567-labs#1882: - Core components analysis (hooks, cache, retry, mode system) - Proposed implementation approach for cache observability hooks - Development environment setup and contribution checklist
Add cache observability hooks to enable tracking cache performance: - Add CACHE_HIT and CACHE_MISS to HookName enum - Add CacheHandler protocol for type safety - Add emit_cache_hit() and emit_cache_miss() methods - Update HookNameType and HandlerType unions Part of issue 567-labs#1882
Add optional hooks parameter to load_cached_response(): - Emit CACHE_MISS when key not found in cache - Emit CACHE_HIT with response when cache hit occurs - Backward compatible: hooks parameter is optional Part of issue 567-labs#1882
Pass hooks parameter to load_cached_response() in both sync and async paths to enable cache observability events. Part of issue 567-labs#1882
Add comprehensive test suite for cache hooks: - Test CACHE_HIT and CACHE_MISS enum values - Test emit_cache_hit and emit_cache_miss methods - Test hooks emission in load_cached_response - Test backward compatibility when hooks is None - Test multiple handlers and hit ratio tracking Part of issue 567-labs#1882
Document new cache observability hooks: - Add cache:hit and cache:miss to supported events - Add CacheHandler protocol to hook types section - Add practical example for cache monitoring Part of issue 567-labs#1882
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to 72f43a1 in 1 minute and 32 seconds. Click for details.
- Reviewed
746lines of code in6files - Skipped
0files when reviewing. - Skipped posting
6draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. docs/concepts/hooks.md:56
- Draft comment:
The new cache hook sections (cache:hitandcache:miss) are clear and provide useful usage examples. Great job on updating the documentation! - Reason this comment was not posted:
Confidence changes required:0%<= threshold85%None
2. docs/research/CODEBASE_STUDY.md:1
- Draft comment:
The study notes are very detailed and provide a comprehensive analysis of the cache observability hooks. No issues found. - Reason this comment was not posted:
Confidence changes required:0%<= threshold85%None
3. instructor/cache/__init__.py:195
- Draft comment:
Consider refining the type hint for the 'hooks' parameter in 'load_cached_response' from 'Any | None' to 'Hooks | None' for better type safety and clarity. - Reason this comment was not posted:
Confidence changes required:80%<= threshold85%None
4. instructor/core/hooks.py:204
- Draft comment:
The new CACHE_HIT and CACHE_MISS events and the CacheHandler protocol are implemented correctly. The emit methods for these events are consistent with existing patterns. - Reason this comment was not posted:
Confidence changes required:0%<= threshold85%None
5. instructor/core/patch.py:184
- Draft comment:
Hooks are properly propagated to cache lookup functions in both async and sync paths. The integration of 'hooks' into the patching logic appears consistent and correct. - Reason this comment was not posted:
Confidence changes required:0%<= threshold85%None
6. tests/test_cache_hooks.py:1
- Draft comment:
The test suite comprehensively verifies cache hook emissions for both hit and miss events, including multi-handler integration and hit ratio tracking. Excellent coverage! - Reason this comment was not posted:
Confidence changes required:0%<= threshold85%None
Workflow ID: wflow_1JY3v8D3pTm7bH42
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds cache observability hooks to enable tracking cache performance metrics as requested in #1882.
CACHE_HITandCACHE_MISSevents to theHookNameenumCacheHandlerprotocol for type safetyload_cached_response()functionChanges
instructor/core/hooks.py: Add new hook types and emit methodsinstructor/cache/__init__.py: Emit hooks on cache hit/missinstructor/core/patch.py: Pass hooks to cache functionstests/test_cache_hooks.py: Comprehensive test suite (10 tests)docs/concepts/hooks.md: Document new hooks with usage exampleUsage
Test plan
Closes #1882
Important
Adds cache hit/miss observability hooks to track cache performance metrics, with tests and documentation updates.
CACHE_HITandCACHE_MISSevents toHookNameenum inhooks.py.load_cached_response()incache/__init__.pyfor cache hit/miss.test_cache_hooks.pywith 10 tests for cache hooks.hooks.mdto document new cache hooks with examples.This description was created by
for 72f43a1. You can customize this summary. It will automatically update as commits are pushed.