# 005: Context overflow causes blank or hallucinated responses

**Reporter:** cthegray
**Date:** 2026-03-03
**Priority:** high
**Status:** open
**Affects:** All platforms, chat quality

## Description

When the context window fills up (long pages injected as context), the model either:
1. Returns completely blank responses (silent failure, nothing displayed)
2. Starts hallucinating about unrelated content, specifically talking about the uncloseai.com page itself or the Nous Research page

## Reproduction

1. Navigate to a very long page (e.g., Wikipedia's Napoleon article)
2. Use the page-read feature to inject the page content as context
3. Ask a question about the page
4. Response is either blank or talks about uncloseai/Nous Research instead of the page content

## Analysis

The page content is likely exceeding the model's `max_model_len` (context window). When this happens:
- The API may return an error that the client silently swallows (blank response)
- The context may be truncated in a way that drops the user's page content but keeps the system prompt and uncloseai UI text, causing the model to talk about those instead
- The Nous Research hallucination suggests the model's training data is bleeding through when it has no useful context to work with

Possible fixes:
- Check page content length before injection, truncate intelligently if it exceeds the model's `max_model_len` (available from `/v1/models` discovery)
- Show a user-facing warning when context is too long: "This page is too long, content has been trimmed"
- Implement chunked summarization for long pages (summarize in sections, then inject summaries)
- Never silently swallow API errors: if the completion fails, show the error to the user
- Prioritize user message and page content over system prompt when truncating

## Fix Implemented

Smart content collapsing in `content.js` via `fitPageContent()`. Progressive stages run in order of aggressiveness, stopping when content fits:

1. **Deduplicate paragraphs**: remove exact duplicate blocks (common in scraped DOM)
2. **Collapse nav links**: 5+ consecutive links become `[Navigation: N links including ...]`
3. **Collapse references**: dense URL/citation clusters become `[... N references collapsed]`
4. **Collapse lists**: 7+ item lists keep first 5, note `[... N more items]`
5. **Collapse code blocks**: 12+ line blocks keep first 10, note `[... N more lines]`
6. **Collapse sidebar debris**: runs of 6+ short fragments get compressed
7. **Hard truncate**: last resort, cuts at paragraph/sentence boundary

No summarization. All content stays real, just structurally compressed. Uses `max_model_len` from model discovery with 15k token overhead reserved for system prompt, computed intel, chat history, and output.

## Notes

Hermes bumped to 82k context. Wikipedia Napoleon (~67k tokens) should fit after collapsing without hard truncation.
