fix(memory): skip non-text parts and use millis timestamps in memory search - #1468
fix(memory): skip non-text parts and use millis timestamps in memory search#1468rootkiller6788 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.
|
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.
|
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? |
|
Two mechanical things @rootkiller6788: |
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).