feat(retry): add comprehensive tracking of all failed attempts and exceptions#1802
feat(retry): add comprehensive tracking of all failed attempts and exceptions#1802
Conversation
…ceptions - Add FailedAttempt data structure to track individual retry failures - Extend InstructorRetryException to include failed_attempts list - Modify retry_sync and retry_async to collect all failures across retries - Track attempt number, exception, and completion for each failed retry - Enables detailed analysis of retry patterns and failure modes
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
instructor | 69f2017 | Commit Preview URL Branch Preview URL |
Sep 04 2025, 07:53 PM |
|
Claude finished @jxnl's task —— View job Code Review Complete ✅Reviewing the retry tracking enhancement PR. Here's my analysis checklist:
Code Review ResultsThis PR adds comprehensive retry tracking functionality to the Instructor library. Here's my detailed analysis: ✅ Code Quality & Best PracticesPositive aspects:
Areas for improvement:
🐛 Potential IssuesMinor concerns:
⚡ Performance ConsiderationsGood performance practices:
Potential optimization:
🔒 Security ConcernsNo security issues identified:
🧪 Test CoverageConcerns identified:
Recommended test additions: # Test that failed_attempts are populated correctly
def test_instructor_retry_exception_with_failed_attempts():
from instructor.core.exceptions import FailedAttempt
attempt1 = FailedAttempt(1, ValueError("first error"), None)
attempt2 = FailedAttempt(2, ValueError("second error"), {"some": "completion"})
with pytest.raises(InstructorRetryException) as exc_info:
raise InstructorRetryException(
n_attempts=2,
total_usage=100,
failed_attempts=[attempt1, attempt2]
)
exception = exc_info.value
assert len(exception.failed_attempts) == 2
assert exception.failed_attempts[0].attempt_number == 1
assert exception.failed_attempts[1].completion == {"some": "completion"}
# Test backward compatibility
def test_instructor_retry_exception_backward_compatibility():
# Should work without failed_attempts parameter
with pytest.raises(InstructorRetryException) as exc_info:
raise InstructorRetryException(n_attempts=1, total_usage=50)
assert exc_info.value.failed_attempts == []📋 Additional ObservationsPositive implementation details:
Minor suggestions:
Final VerdictThis is a solid implementation that adds valuable debugging capabilities without breaking existing functionality. The main concerns are:
The PR is functionally correct and ready for use, but I recommend adding comprehensive tests before merging to ensure the new functionality works as expected and maintains backward compatibility. |
|
Claude finished @jxnl's task —— View job PR Review Complete ✅Reviewing PR #1802: Enhanced retry mechanism with comprehensive failure tracking Todo List:
Code Review Feedback✅ Strengths
🔍 Code Quality & Best PracticesGood practices observed:
Areas for consideration:
|
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed 69f2017 in 40 seconds. Click for details.
- Reviewed
156lines of code in1files - Skipped
0files when reviewing. - Skipped posting
1draft 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. examples/retry-tracking/example.py:1
- Draft comment:
The entire example file has been removed. This file previously provided a valuable usage demonstration of the enhanced retry tracking feature. Please ensure that updated usage examples (in docs or tests) are provided so developers can understand and utilize the new feature. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
Workflow ID: wflow_5jWLZcAyrGi2UXHW
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to df8be82 in 1 minute and 54 seconds. Click for details.
- Reviewed
312lines of code in3files - Skipped
0files when reviewing. - Skipped posting
5draft 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. examples/retry-tracking/example.py:131
- Draft comment:
Ensure the example code references a defined 'analyze_completion' function. The snippet uses 'analyze_completion(attempt.completion)' but this function isn’t defined/imported. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 85% This is a code example shown as a string inside triple quotes, meant to demonstrate API usage patterns. It's common in documentation to show example function calls that aren't fully implemented. The analyze_completion function is clearly a placeholder to show where custom analysis code would go. The code isn't meant to be run directly - it's demonstrative. The comment does identify a technically accurate issue - the function isn't defined. And someone copy-pasting this example directly would get an error. Documentation examples often use placeholder functions to demonstrate patterns. The comment is being overly pedantic about example code that isn't meant to be executed directly. Delete the comment. The undefined function is an intentional placeholder in example code meant to demonstrate usage patterns, not production code.
2. instructor/core/exceptions.py:53
- Draft comment:
Consider adding a docstring note for the new 'failed_attempts' field in InstructorRetryException to document its purpose. - Reason this comment was not posted:
Confidence changes required:66%<= threshold85%None
3. instructor/core/retry.py:278
- Draft comment:
When raising InstructorRetryException in the sync retry, use e.last_attempt.retry_state.attempt_number instead of the loop variable 'attempt.retry_state.attempt_number' to ensure correct attempt count. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
4. instructor/core/retry.py:336
- Draft comment:
In the async retry loop, replace 'with attempt:' with 'async with attempt:' to properly handle the asynchronous context manager. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
5. instructor/core/retry.py:433
- Draft comment:
Similarly, in the async function's RetryError block, use e.last_attempt.retry_state.attempt_number instead of 'attempt.retry_state.attempt_number' when setting 'n_attempts'. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
Workflow ID: wflow_PwyLKBX6RirvfgcW
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Description
This PR enhances the retry mechanism in Instructor to track all failed completions and exceptions across the entire range of retries, not just the final failure. This provides much better debugging capabilities and insight into retry patterns.
Changes
Core Changes
Key Features
Benefits
Usage Example
Testing
Backward Compatibility
This change is fully backward compatible. The new field is optional and defaults to an empty list if not provided.
This PR was written by Cursor
Important
Enhances retry mechanism to track all failed attempts and exceptions for improved debugging and analysis.
FailedAttemptinexceptions.pyto track retry attempts with attempt number, exception, and completion.InstructorRetryExceptionto includefailed_attemptslist.retry_syncandretry_asyncinretry.pyto populatefailed_attemptswith each failed attempt.failed_attemptsto an empty list if not provided.This description was created by
for 69f2017. You can customize this summary. It will automatically update as commits are pushed.