-
Notifications
You must be signed in to change notification settings - Fork 325
fix: historyLength=0 returns full history (#573) #612
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @lbobinski, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request correctly fixes the bug where historyLength=0 would return the full history instead of an empty list. The logic change in apply_history_length is sound, and the new test cases in test_apply_history_length_cases effectively verify the fix. I have one suggestion to refactor the new test to make it more robust and maintainable by using subTest and parameterization.
| # Setup task with 3 messages | ||
| history = [ | ||
| Message(role=Role.user, parts=[Part(root=TextPart(text='1'))], message_id='1'), | ||
| Message(role=Role.agent, parts=[Part(root=TextPart(text='2'))], message_id='2'), | ||
| Message(role=Role.user, parts=[Part(root=TextPart(text='3'))], message_id='3'), | ||
| ] | ||
| task_id = str(uuid.uuid4()) | ||
| context_id = str(uuid.uuid4()) | ||
| task = completed_task( | ||
| task_id=task_id, | ||
| context_id=context_id, | ||
| artifacts=[Artifact(artifact_id='a', parts=[Part(root=TextPart(text='a'))])], | ||
| history=history | ||
| ) | ||
|
|
||
| # historyLength = 0 -> empty | ||
| t0 = apply_history_length(task, 0) | ||
| self.assertEqual(len(t0.history), 0) | ||
|
|
||
| # historyLength = 1 -> last one | ||
| t1 = apply_history_length(task, 1) | ||
| self.assertEqual(len(t1.history), 1) | ||
| self.assertEqual(t1.history[0].message_id, '3') | ||
|
|
||
| # historyLength = 2 -> last two | ||
| t2 = apply_history_length(task, 2) | ||
| self.assertEqual(len(t2.history), 2) | ||
| self.assertEqual(t2.history[0].message_id, '2') | ||
| self.assertEqual(t2.history[1].message_id, '3') | ||
|
|
||
| # historyLength = None -> all | ||
| tn = apply_history_length(task, None) | ||
| self.assertEqual(len(tn.history), 3) | ||
|
|
||
| # historyLength = 10 -> all | ||
| t10 = apply_history_length(task, 10) | ||
| self.assertEqual(len(t10.history), 3) |
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.
This test is great for covering the main scenarios. It could be made more robust and maintainable by parameterizing the test cases and using unittest.subTest. This approach has a few benefits:
- Clarity: It separates the test data from the test logic, making it easier to see what's being tested.
- Maintainability: Adding new test cases is as simple as adding a new entry to the
test_casesdictionary. - Better Failure Reporting:
subTestensures that all cases are run, and it reports failures for each subtest individually, rather than stopping at the first failure. - Improved Assertions: The assertions can be made more consistent and thorough by checking the exact sequence of message IDs for every case.
# Setup task with 3 messages
history = [
Message(role=Role.user, parts=[Part(root=TextPart(text='1'))], message_id='1'),
Message(role=Role.agent, parts=[Part(root=TextPart(text='2'))], message_id='2'),
Message(role=Role.user, parts=[Part(root=TextPart(text='3'))], message_id='3'),
]
task = completed_task(
task_id=str(uuid.uuid4()),
context_id=str(uuid.uuid4()),
artifacts=[Artifact(artifact_id='a', parts=[Part(root=TextPart(text='a'))])],
history=history,
)
test_cases = {
'zero_length': (0, []),
'one_item': (1, ['3']),
'two_items': (2, ['2', '3']),
'none_length_is_full_history': (None, ['1', '2', '3']),
'length_greater_than_history_is_full_history': (10, ['1', '2', '3']),
}
for name, (length, expected_ids) in test_cases.items():
with self.subTest(msg=name):
new_task = apply_history_length(task, length)
actual_ids = [m.message_id for m in new_task.history]
self.assertEqual(actual_ids, expected_ids)|
this PR will break current agents, because if history_length is unset it defaults to zero. we should wait for the "optional" tag on the field to propagate, before introducing this. |
|
+1 to what Kuba said. FYI I left a similar comment on the referenced issue a month ago. |
|
1.0 Migration PR #572 |
This PR fixes a bug where setting historyLength=0 would return the full history instead of an empty list.
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a SemVer patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.bash scripts/format.shfrom the repository root to format)Fixes #573 🦕