Skip to content

fix(tokens): honor zero cache retention - #6236

Open
elysiopires wants to merge 1 commit into
browser-use:mainfrom
elysiopires:codex/fix-zero-cache-retention
Open

elysiopires wants to merge 1 commit into
browser-use:mainfrom
elysiopires:codex/fix-zero-cache-retention

Conversation

@elysiopires

@elysiopires elysiopires commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #6235.

TokenCost.clean_old_caches(keep_count=0) currently keeps all files because [:-0] selects an empty slice. Select all matching-source files for zero retention; retain the existing positive-count behavior and source filtering.

Added temporary-directory tests for 0, 1, and 3 retained caches, including checks that foreign-source and malformed files survive. The zero case fails before the change; the positive controls pass.

Validation:

  • ANONYMIZED_TELEMETRY=false BROWSER_USE_SETUP_LOGGING=false .venv/bin/python -m pytest tests/ci/test_token_cost_cache_cleanup.py tests/ci/test_openrouter_token_cost.py -q -o addopts='' --tb=short: 8 passed.
  • .venv/bin/pre-commit run --files browser_use/tokens/service.py tests/ci/test_token_cost_cache_cleanup.py: all applicable hooks passed, including Ruff and Pyright.
  • No browser, model, or network requests used by the regression tests.

Searched issues and open PRs for this method and pricing-cache retention; no overlapping fix found. Codex assisted with investigation, implementation, and testing; the reported checks ran locally.


Summary by cubic

Fixes TokenCost.clean_old_caches(keep_count=0) so it removes all cached pricing files instead of keeping everything, because Python's [:-0] slice selects an empty range.

  • Adds regression tests covering 0, 1, and 3 retained caches, including checks that foreign-source and malformed files are left untouched.
  • Preserves the existing positive-count behavior and per-source filtering.

Written for commit 83dcaf0. Summary will update on new commits.

View guided diff

@mintlify

mintlify Bot commented Oct 29, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 83dcaf0.

Approve preview

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: clean_old_caches(keep_count=0) retains every pricing cache

2 participants