From 5e5e00c6b9fbc813e75bee13f7c39b117087deff Mon Sep 17 00:00:00 2001 From: MiloBot Date: Thu, 5 Feb 2026 18:03:36 +0000 Subject: [PATCH] fix: initialize user_can_view before conditional check Fix UnboundLocalError when on_shared_thread_view hook is not defined. The user_can_view variable was only assigned inside the optional on_shared_thread_view hook block, but was used unconditionally in the subsequent check. When the hook is not defined, this caused: UnboundLocalError: cannot access local variable 'user_can_view' where it is not associated with a value This fix initializes user_can_view to False before the conditional block, ensuring the variable is always defined. Fixes #2766 --- backend/chainlit/server.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/chainlit/server.py b/backend/chainlit/server.py index 41215c675c..4fa024e4fc 100644 --- a/backend/chainlit/server.py +++ b/backend/chainlit/server.py @@ -1005,6 +1005,7 @@ async def get_shared_thread( if not isinstance(metadata, dict): metadata = {} + user_can_view = False if getattr(config.code, "on_shared_thread_view", None): try: user_can_view = await config.code.on_shared_thread_view(