Skip to content

Expired session tokens causing no response to user from LLM Model #4

Description

@RiyazPrynAI

Ussue Description

  • Error only shows up the next day when you reopen the browser, and it clears up after you sign out and back in.
  • Chainlit UI expires every day but not Microsoft authentication. When error happens i have to signout from chainlit UI then it takes me to /auth page where i take token from Microsoft External Entra and then sign back in.

Error Message
Error: peer closed connection without sending complete message body (incomplete chunked read)

Image

Likely Causes:

Expired session tokens :

  • apps store an access token in local storage or cookies. Overnight, that token may expire. When the client tries to resume a streaming request with an invalid token, the server often just closes the connection instead of sending a clean JSON error — which surfaces as the “peer closed connection without sending complete message body” error.

Stale cookies or cached state:

  • If the browser restores the app tab from the previous day, the client may try to reuse an old connection or cached auth state that the server no longer accepts.

Why signing out/in fixes it

  • Signing out clears the stale token/cookies.

  • Signing back in forces a fresh token exchange, so subsequent requests succeed and the server no longer drops the connection.

Files to refer:

https://github.com/PrynAI/PrynAI-chat/tree/main/apps/chainlit-ui/src/auth
https://github.com/PrynAI/PrynAI-chat/tree/main/apps/gateway-fastapi/src/auth
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/public/login-redirect.js
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/main.py
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/server.py
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/threads_client.py

Potential Fixes:

Implement token refresh:

  • Store both access and refresh tokens securely.
  • Before each API call, check expiry and refresh if needed.
  • Or use a library that handles this automatically (MSAL for Python/JS).

Bootstrap check: On app load, validate the token. If expired, refresh immediately instead of waiting for the first API call to fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions