fix(memory): skip non-text parts and use millis timestamps in memory search - #1468
Open
rootkiller6788 wants to merge 2 commits into
Open
fix(memory): skip non-text parts and use millis timestamps in memory search#1468rootkiller6788 wants to merge 2 commits into
rootkiller6788 wants to merge 2 commits into
Conversation
…search searchMemory called Part.text().get() on every part, which throws NoSuchElementException when a stored event contains a non-text part (e.g. a function call or function response). Only text parts are searchable, so non-text parts are now skipped instead of crashing the loadMemory tool. formatTimestamp treated the event timestamp as epoch seconds, but Event.timestamp() is epoch milliseconds, so returned memory timestamps were off by ~1000x. Use Instant.ofEpochMilli to match the event timestamp unit.
Contributor
|
Hi @rootkiller6788, thank you for your contribution and for taking the time to submit this PR. You're right that One ask for the scope then: once #1465 lands, could you rebase this down to just the |
Dropping the non-text part guard from this branch — it duplicates the other open PR (google#1465) which already fixes the same crash and adds its own test. Keeping it here would collide on the same test file once that PR lands. What's left is the formatTimestamp fix: Event.timestamp() is epoch milliseconds, so reading it as epoch seconds was producing memory timestamps ~1000x in the future. Switch to Instant.ofEpochMilli and add a focused test for it under a separate file so there's no name clash.
Author
|
Thanks for the review, @sherryfox. I've narrowed the PR down to just the formatTimestamp fix as you suggested.
The timestamp test passes against the core module (1 test, no failures). Could you please take another look? |
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
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
InMemoryMemoryService.searchMemoryhad two bugs:Crash on non-text parts. It called
Part.text().get()unconditionally for every part in a stored event. When a session contains tool activity, the stored events includefunctionCall/functionResponseparts whosetext()Optional is empty, so the nextloadMemorysearch threwNoSuchElementExceptionand the memory tool failed.Wrong timestamp unit.
formatTimestampusedInstant.ofEpochSecond, butEvent.timestamp()is epoch milliseconds (Event.build()defaults toInstant.now().toEpochMilli()), so returned memory timestamps were ~1000× in the future.Changes
Instant.ofEpochMilli.InMemoryMemoryServiceTestcovering both regressions.Verification
InMemoryMemoryServiceTest(2 tests).AgentWithMemoryTeststill passes.coremodule suite: 1776 tests, only pre-existing Windows path-separator failure inLocalSkillSourceTest.testListResources(fails on untouched HEAD too).