Skip to content

cache decorator confuses positional tuples with keyword arguments #3045

Description

@UditDewan

Describe the bug

@cl.cache can return the result of a different call when a positional tuple matches a keyword argument's key/value pair.

To reproduce

Run against current main (190ea74239d9e84b26e7c91bc2882dd038942564):

import chainlit as cl

@cl.cache
def identity(value):
    return value

print(identity(("value", 1)))
print(identity(value=1))

Actual output:

('value', 1)
('value', 1)

Expected output:

('value', 1)
1

Reversing the call order also reproduces the problem: both calls return 1.

Cause

backend/chainlit/cache.py concatenates positional arguments and sorted keyword pairs into a single tuple. Both calls therefore produce the same cache key, even though their argument values differ.

Keeping the function, positional arguments, and keyword pairs as separate parts of the key fixes the collision without changing the public API or locking behavior.

Environment

Windows, Python 3.13.7, Chainlit source version 2.12.0.

This is distinct from #2985 and its merged fix #2987, which addressed collisions between different functions with the same name. I have a fix and a regression test covering both call orders and repeated cache hits.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssue has not had recent activity or appears to be solved. Stale issues will be automatically closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions