Skip to content

fix(cache): separate positional and keyword cache keys - #3046

Open
UditDewan wants to merge 1 commit into
Chainlit:mainfrom
UditDewan:fix/cache-argument-collision
Open

UditDewan wants to merge 1 commit into
Chainlit:mainfrom
UditDewan:fix/cache-argument-collision

Conversation

@UditDewan

@UditDewan UditDewan commented Sep 16, 2026

Copy link
Copy Markdown

Fixes #3045.

Calling a cached function with ("value", 1) as a positional argument and then with value=1 currently returns the first result for both calls. The cache key concatenates positional arguments and keyword pairs, so these distinct calls become indistinguishable.

Keep the function, positional arguments, and sorted keyword pairs in separate tuple fields. This preserves function isolation, keyword-order independence, and the existing locking behavior.

Validation on Python 3.13.7:

  • The new regression test fails on the original implementation in both call orders: 2 failed, 24 passed.
  • With the fix, PYTHONPATH=backend python -m pytest backend/tests/test_cache.py -q: 26 passed.
  • Ruff lint and formatting checks on both changed files passed.
  • git diff --check passed.

The test also repeats both calls and checks that the function executes only once per distinct input.


Summary by cubic

Fixes #3045. Calling a cached function with ("value", 1) as a positional argument and then with value=1 previously returned the same result for both calls because both produced the same cache key. The key now stores the positional arguments and sorted keyword pairs in separate tuple fields, so these calls get distinct cache entries. The regression test covers both call orders and verifies the function runs only once per distinct input.

Written for commit 58f7696. Summary will update on new commits.

Review in cubic

Keep argument groups distinct to prevent positional tuples from colliding with keyword pairs. Cover both call orders and repeated cache hits.

@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

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.

cache decorator confuses positional tuples with keyword arguments

1 participant