Skip to content

fix(tokens): preserve concurrent pricing cache snapshots - #6260

Open
Elon-Jiang wants to merge 1 commit into
browser-use:mainfrom
Elon-Jiang:fix/pricing-cache-source-collisions
Open

Elon-Jiang wants to merge 1 commit into
browser-use:mainfrom
Elon-Jiang:fix/pricing-cache-source-collisions

Conversation

@Elon-Jiang

@Elon-Jiang Elon-Jiang commented Oct 31, 2026 •

Copy link
Copy Markdown

Problem

Concurrent TokenCost refreshes share a cache directory, but cache filenames only contain a seconds-resolution timestamp. Different pricing_url sources fetched within the same second overwrite each other's JSON files. Both instances initially have valid in-memory data, while a subsequent instance cannot find the missing source's disk cache and must fetch again. This defeats the existing source-aware cache isolation and loses offline pricing availability.

Change

Add a UUID suffix to each timestamped pricing snapshot. Existing JSON contents, source matching, expiry, glob-based discovery and retention logic stay compatible. Add a regression using eight real local HTTP endpoints: concurrent refreshes must retain every source, and fresh instances must reload their own data without further HTTP responses.

Reproduction and validation

  • On unmodified main, two simultaneous local pricing responses left only one cache file; one source had no matching cache. The new eight-source regression failed before the fix, including a repeat bypassing local proxies.
  • Final focused run: uv run --no-sync pytest tests/ci/test_token_cost_cache_files.py tests/ci/test_openrouter_token_cost.py -q -o addopts='' --tb=short — 6 passed.
  • All configured pre-commit hooks on both changed files passed, including pinned Ruff, pyright, codespell and syntax checks. Separate project-environment whole-repository pyright: 0 errors.
  • Complete tests/ci run on macOS/Python 3.12: 1263 passed, 35 skipped, 5 failed. The failures were the custom-Python Bash test (missing libpython3.12.dylib in its created venv) and four cloud-hint logging assertions. All five also failed during the unmodified-base full-suite comparison. That comparison was interrupted to stop desktop browser interference: 1173 passed, 32 skipped, 7 failed before interruption, including two additional beta-agent failures. This is not a claim of a fully green suite. The cloud-hint module separately passed all 10 tests on the base.

AI assistance: Codex helped investigate, implement and validate this fix.


Summary by cubic

Fixes concurrent TokenCost refreshes overwriting each other's cache files when fetched within the same second, causing later instances to refetch and lose offline pricing availability.

Bug Fixes

  • Adds a UUID suffix to pricing snapshot filenames so simultaneous refreshes from different sources no longer collide.
  • Adds a regression test with eight concurrent sources to verify each keeps its cache and fresh instances load from disk.

Written for commit 56c10c8. Summary will update on new commits.

View guided diff

@mintlify

mintlify Bot commented Oct 31, 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 56c10c8.

Approve preview

@CLAassistant

CLAassistant commented Oct 31, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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.

2 participants