Repository navigation
fix(tokens): handle keep_count=0 in clean_old_caches to remove all matching caches - #6239
user-Param wants to merge 2 commits into
Conversation
|
def-Param seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="browser_use/tokens/service.py">
<violation number="1" location="browser_use/tokens/service.py:638">
P2: `<= 0` also treats accidental negative `keep_count` values as “delete every cache,” expanding the destructive behavior beyond the requested `0` case. Use `== 0` here, or reject negative counts before cleanup, so a negative retention value cannot wipe all matching caches.</violation>
</file>
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
View guided diff | Re-trigger cubic
|
|
||
| # Remove all but the most recent files | ||
| for cache_file in own_files[:-keep_count]: | ||
| if keep_count <= 0: |
There was a problem hiding this comment.
P2: <= 0 also treats accidental negative keep_count values as “delete every cache,” expanding the destructive behavior beyond the requested 0 case. Use == 0 here, or reject negative counts before cleanup, so a negative retention value cannot wipe all matching caches.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At browser_use/tokens/service.py, line 638:
<comment>`<= 0` also treats accidental negative `keep_count` values as “delete every cache,” expanding the destructive behavior beyond the requested `0` case. Use `== 0` here, or reject negative counts before cleanup, so a negative retention value cannot wipe all matching caches.</comment>
<file context>
@@ -635,7 +635,11 @@ async def clean_old_caches(self, keep_count: int = 3) -> None:
# Remove all but the most recent files
- for cache_file in own_files[:-keep_count]:
+ if keep_count <= 0:
+ files_to_remove = own_files
+ else:
</file context>
| if keep_count <= 0: | |
| if keep_count == 0: |
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
@gregpr07 Could you please review this PR? All tests pass and the fix addresses a real issue. Thank you! |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="browser_use/tokens/tests/test_clean_old_caches.py">
<violation number="1" location="browser_use/tokens/tests/test_clean_old_caches.py:41">
P2: These tests never verify the “matching” part of the contract, so they would pass if `keep_count=0` deleted caches belonging to another pricing URL. Add a differently sourced cache and assert that it remains after cleanup.</violation>
</file>
Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.
View guided diff | Re-trigger cubic
| tc = token_cost_with_cache | ||
| cache_dir = tc._cache_dir | ||
|
|
||
| files = [_make_cache_file(cache_dir, i) for i in range(5)] |
There was a problem hiding this comment.
P2: These tests never verify the “matching” part of the contract, so they would pass if keep_count=0 deleted caches belonging to another pricing URL. Add a differently sourced cache and assert that it remains after cleanup.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At browser_use/tokens/tests/test_clean_old_caches.py, line 41:
<comment>These tests never verify the “matching” part of the contract, so they would pass if `keep_count=0` deleted caches belonging to another pricing URL. Add a differently sourced cache and assert that it remains after cleanup.</comment>
<file context>
@@ -0,0 +1,87 @@
+ tc = token_cost_with_cache
+ cache_dir = tc._cache_dir
+
+ files = [_make_cache_file(cache_dir, i) for i in range(5)]
+ assert all(f.exists() for f in files)
+
</file context>
…ntics (browser-use#6235) Adds 4 tests covering: - keep_count=0 removes all matching cache files - keep_count=N keeps only the N most recent files - keep_count > file count removes nothing - keep_count=1 keeps only the single most recent file Addresses review feedback from r266-tech.
45d3bcb to
83e08e9
Compare
Fixes #6235 - when is passed to , it should remove all matching cache files. Previously resulted in an empty slice, keeping all files. The fix treats as 'remove all'.
Summary by cubic
Fixes #6235 so passing
keep_count=0toclean_old_cachesremoves all matching cache files. Previously,keep_count=0produced an empty slice, which kept every cache file instead of deleting them.keep_countvalues of 0, 1, N, and values larger than the file count.Written for commit 83e08e9. Summary will update on new commits.