Skip to content

Fix unbounded AI conversation history causing token explosion and DoW abuse#231

Merged
knoxiboy merged 1 commit into
knoxiboy:mainfrom
dheeraj12347:fix/ai-context-windowing
May 25, 2026
Merged

Fix unbounded AI conversation history causing token explosion and DoW abuse#231
knoxiboy merged 1 commit into
knoxiboy:mainfrom
dheeraj12347:fix/ai-context-windowing

Conversation

@dheeraj12347
Copy link
Copy Markdown
Contributor

Summary

This PR fixes unbounded AI conversation history growth in /api/ask-ai, which could previously allow excessive token consumption and denial-of-wallet style abuse.

Changes Made

  • Added maximum history length limits
  • Implemented sliding conversation windowing
  • Added request payload size validation
  • Added lightweight token estimation before inference
  • Added context size validation
  • Added history sanitization and truncation
  • Prevented oversized follow-up payloads from reaching Groq inference

Security Improvements

This mitigates:

  • excessive token consumption
  • backend memory amplification
  • latency degradation
  • large payload abuse
  • multi-model fallback amplification risks

Fixes #222

@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

@dheeraj12347 is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@knoxiboy knoxiboy added type:bug Bug fix level:advanced Advanced level task gssoc'26 GSSoC program issue labels May 23, 2026
knoxiboy

This comment was marked as spam.

knoxiboy

This comment was marked as outdated.

Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical Review

Hi @dheeraj12347! Thank you for your contribution to DoubtDesk.

The code changes look good. Before we can complete the technical review, approve, and merge this pull request, we have one final requirement for all contributors: Please star the DoubtDesk repository.

Once you have starred the repository, please drop a comment here saying "done" (or we will automatically detect it) and we will proceed with approving and merging your PR. Thank you.

@knoxiboy knoxiboy self-requested a review May 24, 2026 12:26
@knoxiboy knoxiboy added gssoc and removed gssoc labels May 24, 2026
@dheeraj12347
Copy link
Copy Markdown
Contributor Author

Technical Review

Hi @dheeraj12347! Thank you for your contribution to DoubtDesk.

The code changes look good. Before we can complete the technical review, approve, and merge this pull request, we have one final requirement for all contributors: Please star the DoubtDesk repository.

Once you have starred the repository, please drop a comment here saying "done" (or we will automatically detect it) and we will proceed with approving and merging your PR. Thank you.

hi @knoxiboy , "done" :)

Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: Thank you for starring the repository! The PR is approved.

@knoxiboy knoxiboy merged commit 803fbeb into knoxiboy:main May 25, 2026
1 of 2 checks passed
@knoxiboy knoxiboy added gssoc:approved Approved for GSSoC mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality labels May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC gssoc'26 GSSoC program issue level:advanced Advanced level task mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unbounded AI conversation history can cause token explosion and denial-of-wallet abuse

2 participants