Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create over 25 chats #240

Closed
Tengal-Teemo opened this issue Dec 8, 2023 · 12 comments · Fixed by #259
Closed

Cannot create over 25 chats #240

Tengal-Teemo opened this issue Dec 8, 2023 · 12 comments · Fixed by #259
Labels

Comments

@Tengal-Teemo
Copy link
Contributor

Bug description

Ragna UI fails to create over 25 chats, + New Chat button becomes non-responsive with error message:

ERROR:bokeh.server.protocol_handler:error handling message
 message: Message 'PATCH-DOC' content: {'events': [{'kind': 'MessageSent', 'msg_type': 'bokeh_event', 'msg_data': {'type': 'event', 'name': 'button_click', 'values': {'type': 'map', 'entries': [['model', {'id': 'p16815'}]]}}}]} 
 error: UnknownReferenceError("can't resolve reference 'p16815'")
Traceback (most recent call last):
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/server/protocol_handler.py", line 97, in handle
    work = await handler(message, connection)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/server/session.py", line 94, in _needs_document_lock_wrapper
    result = func(self, *args, **kwargs)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/server/session.py", line 286, in _handle_patch
    message.apply_to_document(self.document, self)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/protocol/messages/patch_doc.py", line 104, in apply_to_document
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.payload, setter=setter))
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/document/callbacks.py", line 443, in invoke_with_curdoc
    return f()
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/protocol/messages/patch_doc.py", line 104, in <lambda>
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.payload, setter=setter))
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/document/document.py", line 374, in apply_json_patch
    patch: PatchJson = deserializer.deserialize(patch_json)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 510, in deserialize
    return self.decode(obj.content, obj.buffers)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 525, in decode
    return self._decode(obj)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 566, in _decode
    return {key: self._decode(val) for key, val in obj.items()}
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 566, in <dictcomp>
    return {key: self._decode(val) for key, val in obj.items()}
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 568, in _decode
    return [self._decode(entry) for entry in obj]
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 568, in <listcomp>
    return [self._decode(entry) for entry in obj]
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 566, in _decode
    return {key: self._decode(val) for key, val in obj.items()}
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 566, in <dictcomp>
    return {key: self._decode(val) for key, val in obj.items()}
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 535, in _decode
    return self._decoders[type](obj, self)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/events.py", line 186, in from_serializable
    decoded_values = decoder.decode(values)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 520, in decode
    return self._decode(obj)
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 547, in _decode
    return self._decode_map(cast(MapRep, obj))
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 598, in _decode_map
    return { self._decode(key): self._decode(val) for key, val in entries }
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 598, in <dictcomp>
    return { self._decode(key): self._decode(val) for key, val in entries }
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 564, in _decode
    return self._decode_ref(cast(Ref, obj))
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 578, in _decode_ref
    self.error(UnknownReferenceError(id))
  File "/home/tazukiswift/miniconda3/envs/ragna-dev/lib/python3.9/site-packages/bokeh/core/serialization.py", line 729, in error
    raise error
bokeh.core.serialization.UnknownReferenceError: can't resolve reference 'p16815'

Or similar (pXXXXX)

How to reproduce the bug?

  1. Install ragna and required dependencies
  2. Run ragna init and configure a basic model using demo source storage and assistant
  3. Run ragna ui to launch the server
  4. Create 24 chats with no issues
  5. Create a 25th chat, it will error
  6. Press "Start a Conversation" again, it will proceed into the chat
  7. Press + New Chat, it will be broken and the above error message will appear in console logs

Versions and dependencies used

  • OS: Linux Mint Victoria (21.2)
  • Python Version: 3.10.12
  • Ragna Version: v0.1.1
  • Panel Version: 1.3.4

Anything else?

No response

@Tengal-Teemo Tengal-Teemo added the type: bug 🐛 Something isn't working label Dec 8, 2023
@pmeier
Copy link
Member

pmeier commented Dec 8, 2023

Thanks for the report can reproduce on main. Here is a script to automatically create 24 chats and thus replace step 4. of the reproduction in #240 (comment):

import httpx

client = httpx.Client(base_url="http://127.0.0.1:31476")
client.get("/").raise_for_status()

## authentication

username = password = "ragna-240"
token = (
    client.post(
        "/token",
        data={
            "username": username,
            "password": password,
        },
    )
    .raise_for_status()
    .json()
)
client.headers["Authorization"] = f"Bearer {token}"

## documents

documents = []
for i in range(5):
    name = f"document{i}.txt"
    document_upload = (
        client.post("/document", json={"name": name}).raise_for_status().json()
    )
    parameters = document_upload["parameters"]
    client.request(
        parameters["method"],
        parameters["url"],
        data=parameters["data"],
        files={"file": f"Content of {name}".encode()},
    ).raise_for_status()
    documents.append(document_upload["document"])

## chats

num_chats = 24

for idx in range(num_chats):
    chat = (
        client.post(
            "/chats",
            json={
                "name": f"Chat #{idx + 1}",
                "documents": documents,
                "source_storage": "Ragna/DemoSourceStorage",
                "assistant": "Ragna/DemoAssistant",
                "params": {},
            },
        )
        .raise_for_status()
        .json()
    )

    client.post(f"/chats/{chat['id']}/prepare").raise_for_status()

chats = client.get("/chats").raise_for_status().json()
assert len(chats) == num_chats

This is definitely an UI bug. With the script I can flawlessly create 100+ chats. But I get the same behavior when I try to add one more in the UI.

As additional hint, after the 25th+ chat is started we get two new ones in the side bar:

image

@nenb
Copy link
Contributor

nenb commented Dec 18, 2023

I'm struggling to reproduce this consistently on my local machine. It seems that I require at least 25 chats (often more) and that I also need to interact with the left sidebar scroll before I can reproduce the error.

Based on the traceback (and how difficult it is to reproduce for me), it appears to be something of a race condition related to the scroll_position class attribute. I've opened an issue in the panel (see link above).

If anyone has time, could they check whether patching the scroll_position attribute like here resolves the problem please? It appears to resolve the issue on my machine, but I don't fully understand why.

@pmeier
Copy link
Member

pmeier commented Dec 18, 2023

I'll give it a shot since I could reproduce easily.

@pmeier
Copy link
Member

pmeier commented Dec 18, 2023

@nenb Indeed that seems to be the solution. Would you like to send a PR?

@nenb
Copy link
Contributor

nenb commented Dec 19, 2023

@pmeier What do you mean exactly by a PR here? This was an issue with panel it seems, rather than ragna. I've opened a PR on panel, but it seems like I was just too late for the latest release of panel. So, we will have to wait for the next release for a fix. At that point, we can pin the lower bound on panel in pyproject.toml if you think that this is warranted.

@philippjfr
Copy link

Thanks for tracking this down. I'll try to prioritize another release (1.3.6) this week before everyone disappears for the holidays. It might be worth already bumping the minimum version to 1.3.5 to avoid some performance regressions related to the ChatMessage component in earlier versions.

@pmeier
Copy link
Member

pmeier commented Dec 19, 2023

@nenb

So, we will have to wait for the next release for a fix

Since only the default is broken, we could simply set the right value in our code and not rely on the default. Basically including a scroll_position=0, here

result = pn.Column(
*objects,
stylesheets=[

That being said, if we actually get panel==1.3.6 this week, we can probably wait for a few more days rather than fixing this on our side. After that, feel free to send a PR pinning panel to the new release

"panel>=1.3,<1.4",

With that, I'll also prepare a 0.1.3 bug fix release.

@philippjfr
Copy link

Panel 1.3.6 RC1 is currently building and should be available in the next 10-15 minutes. If anyone could test that would be appreciated. I'll release 1.3.6 in the next two hours.

@pmeier
Copy link
Member

pmeier commented Dec 20, 2023

Will test. Give me a ping here when the RC is available.

@pmeier
Copy link
Member

pmeier commented Dec 20, 2023

Can confirm that panel==1.3.6rc1 resolves the issue. @nenb you can send the PR now and we merge it as soon as the final release is out.

@nenb
Copy link
Contributor

nenb commented Dec 20, 2023

@pmeier It's in #259. I've also removed the upper bound onpanel as I don't see a reason for it and I'm not generally in favour of this (eg long-form reference here). Let me know if there's a reason for the upper bound and I will revert.

@pmeier pmeier linked a pull request Dec 20, 2023 that will close this issue
@philippjfr
Copy link

Panel 1.3.6 now fully release, thanks again for the fix @nenb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants