Repository navigation
Conversation
Signed-off-by: CLFutureX <chenyongqyl@163.com>
all-hands-bot
left a comment
There was a problem hiding this comment.
Code Review Summary
Found several issues with the caching implementation that need to be addressed:
🔴 Critical Issues
1. Cache behavior doesn't respect cache=False in LocalFileStore.read() (line 76-80)
The cache is still consulted even when cache=False. Current flow:
- Check cache → return if found (ignores
cacheparam) - Read from disk
- Only cache if
cache=True
This means if a file was previously cached, it will return stale data even when caching is disabled.
Fix: Move the cache check inside the conditional:
if cache and full_path in self.cache:
return self.cache[full_path]🟠 Important Issues
2. Breaking API change (LocalFileStore line 62)
The previous behavior was to always cache (implicit cache=True). Now the default is cache=False, which could cause performance regressions for existing code that hasn't been updated.
Options:
- Change default to
cache=Trueto maintain backward compatibility - Document this as a breaking change and audit all call sites
- Verify there are no other callers besides EventStore
3. Missing documentation (base.py lines 17, 26)
The cache parameter needs docstring explaining:
- When to use
TruevsFalse - That
Truecaches in memory for faster subsequent reads - Use cases:
Truefor frequently-read data (events),Falsefor one-time reads (state snapshots)
🟡 Suggestions
4. Inconsistent default values
LocalFileStore: defaults tocache=FalseMemoryFileStore: defaults tocache=True
This inconsistency could cause confusion. Consider standardizing.
5. MemoryFileStore ignores the cache parameter (lines 26, 31)
The parameter is added but not used since MemoryFileStore stores everything in memory by nature. Consider adding a comment explaining why it's ignored.
6. Verify the change achieves the stated goal
The PR description mentions reducing memory usage in _save_base_state() and _save_processing_history(). However, EventStore now passes cache=True for all writes. If those methods write events, this change won't help. Verify:
- Do those methods use EventStore or FileStore directly?
- Should event writes default to
cache=Falseand only cache on read?
Recommendations
| history_file = f"{get_usermodeling_dir(self.user_id)}/processed_sessions_timestamps.json" # noqa: E501 | ||
|
|
||
| self.file_store.write(history_file, json.dumps(history, indent=2)) | ||
| self.file_store.directWrite(history_file, json.dumps(history, indent=2)) |
There was a problem hiding this comment.
Sorry I'm dense, if read/write get cache argument, do we need directRead/directWrite, isn't it with cache false?
There was a problem hiding this comment.
Sorry I'm dense, if
read/writegetcacheargument, do we needdirectRead/directWrite, isn't it with cache false?
Yes, i initially planned to add the cache parameter. However, i found it would result in redundant parameters in InMemoryFileStore and cause validation failures. Also, to make the interface clearer and easier to use, i decided to add new methods instead.
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
1 similar comment
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
[automated message] @neubig assigned for review according to git blame |
|
[Automatic Post]: This PR seems to be currently waiting for review. @neubig, could you please take a look when you have a chance? |
neubig
left a comment
There was a problem hiding this comment.
Hi @CLFutureX , thank you for opening the PR. Before I fully assess the PR, could you please open an issue with a minimal reproducible example of the problem that you're trying to solve? For instance, a command line argument or script that runs the agent where you monitor the agent's memory and find that it is very large. You could then run the same command with this fix implemented and demonstrate that it significantly reduces memory.
That would help me (1) understand the scope of the problem, and (2) be able to confirm the error on my end as well.
Thank you! And once you are done with that, please click the "re-request review" button next to my name on the reviewers panel.
Thanks for the review. The reason I opened this PR is exactly as described. Also, @enyst please take a look at the latest changes: I think adding a parameter is indeed better than adding a new method. |
neubig
left a comment
There was a problem hiding this comment.
Hi @CLFutureX , we still need a minimal reproducible example for this bug so we can confirm the problem and that it is fixed after the PR. Thank you! If you are able to provide this we can review it, otherwise we will have to close it, because we won't be able to confirm the issue.
Relatedly, please add a test that fails before the PR and passes after the PR demonstrating the problem.
Thanks for your review. I'll find some time to add the relevant examples. |
DescriptionThis change is an enhancement to the existing functionality, so i have added functional correctness tests:
I also added tests for the usage scenario of this feature:
Key Test Detail (test_conversation_state_fs_cache)Before this change, the cache count was 1 for this test case. After adding the "cache on demand" feature (allowing cache to be enabled/disabled as needed), the conversation state is no longer cached in memory. This is verified by the assertion: assert len(loaded_state._fs.cache) == 0 |
neubig
left a comment
There was a problem hiding this comment.
Thanks for adding the tests. However, this still is not the MRE I requested.
The new tests check the internal caching behavior after your change, but they do not minimally reproduce the original problem on main (i.e., excessive memory usage), nor do they show that the memory issue is significant in a real runnable scenario.
Please provide a true minimal reproducible example that includes:
- an exact script or command I can run,
- the minimal setup/input needed,
- the expected vs actual behavior,
- a concrete way to measure memory usage, and
- ideally, numbers showing the behavior on
mainand on this branch.
For example, this could be a small script that runs the agent or conversation state persistence in a loop, measures RSS / memory usage, and demonstrates that memory grows much larger than expected on main.
The assertion assert len(loaded_state._fs.cache) == 0 is not sufficient for this, because it only checks an internal implementation detail of your fix, not the original bug itself.
Once there is a runnable MRE, I’ll be happy to review again.
thanks for the review, I think we might have a slight misunderstanding about this PR This is actually a feature enhancement. Its main goal is to implement on-demand caching to reduce unnecessary memory usage, rather than fixing the current high memory consumption issue. For example, this check: What it really shows is: |
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
I see your argument, but the thing is we don't add features unless they are solving a problem. At the moment, you have not yet demonstrated that there is a problem. What I am asking for is that you demonstrate that there is a problem, for instance demonstrating that OpenHands is using more memory than it should. Once you demonstrate that there is a problem by providing the commands that you used to run the program and monitor memory, you could demonstrate that you ran the same commands after the fix and the memory usage went down. |
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
5 similar comments
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
[Automatic Post]: It has been a while since there was any activity on this PR. @CLFutureX, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
Closing due to lack of activity! |
Background:
Some FileStore usage scenarios actually don’t need caching.For example, _save_base_state() and _save_processing_history() cause extra memory usage.
Change:
Add direct write and direct read methods to enable on-demand caching.