Skip to content

[BUG]: AI Chat Fails Due to Context Window Overflow (Improper Token Handling) #407

Closed

Description

@Tushar15769

Description

The current AI chat system limits conversation context by storing only the last 8 messages, assuming this prevents exceeding the model’s context window. However, this approach does not account for token size variability, where longer messages can significantly increase token count.

As a result, even with fewer messages, the total token size can exceed the model’s limit, causing API failures such as “Context Window Exceeded” errors. This leads to unstable chat behavior and failed responses during extended or detailed conversations.

Steps to Reproduce

Open the AI chat feature
Enter multiple long or detailed messages (e.g., large paragraphs or code blocks)
Continue the conversation beyond a few exchanges
Observe API failure or missing response

Expected Behavior

The chat system should dynamically manage context to stay within token limits
AI responses should consistently generate without errors
Long conversations should be handled gracefully

Actual Behavior

API requests fail with context window exceeded errors
Chat responses stop working after several long messages
No fallback or recovery mechanism is triggered

Screenshots / Logs

N/A

OS

Windows

Browser

Chrome

Version

No response

Activity

  1. Tushar15769 commented on May 3, 2026

    @Tushar15769
    ContributorAuthor

    Please assign this issue to me under NSoC'26
    Thanks!

  2. added
    bugSomething isn't working
    NSoC'26For issues and PRs which are a part of the Nexus Spring of Code open source event
    on May 8, 2026
  3. madsysharma commented on May 10, 2026

    @madsysharma

    Hi @devanshi14malhotra , I would like to work on this issue as part of GSSoC 2026.

  4. Tushar15769 commented on May 10, 2026

    @Tushar15769
    ContributorAuthor

    I have resolved the issue and raised the PR so whenever you get time please review it and tell your views on the changes @devanshi14malhotra .
    Thanks!

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

Metadata

Metadata

Assignees

Labels

NSoC'26For issues and PRs which are a part of the Nexus Spring of Code open source eventaibugSomething isn't workingimportantlevel25 points

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions