8000 feat(chat): recover when the model's context is full, and show what a summary covers by adeelahmad · Pull Request #558 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

feat(chat): recover when the model's context is full, and show what a summary covers - #558

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-w4pz1s
Oct 18, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/project-thread-w4pz1s

Conversation

@adeelahmad
8000 Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: when a request still didn't fit the model (a big tool result, a window smaller than Lens thought), the model server's "context length exceeded" error ended the answer. In the web app nothing showed which messages the assistant was reading only as a summary.

After: Lens reads that error (llm.ContextFull, from 400/413 bodies, keeping the window the server names), shortens what tools returned (keeping each result's ends, so the untrusted-text markers stay whole), and if it still doesn't fit, folds all but the last two messages into the summary and asks once more (the search path also halves the excerpts). GET /api/v1/chats/{id} gains summary ({text, upto, at, covers}), and the chat shows a line under the last summarised message ("Summarised up to here", or "Cleared here" after /clear) with Show summary.

How: chat.fit, chat.room, chat.shrink (reuses chat.compact, force, keep 2), chat.stream_fitted / reply_fitted, tool_answer(shrink=); the web route and chat-room bridge pass shrink. chat.covered builds the summary view; components/chat/summary-mark.tsx draws it.

Motivation and Context

Adeel: "auto compress and manage the context of larger chats!" Follows #528 (summarise at the model's real window).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md. (n/a: the title says it)

Done questions (AGENTS.md)

  • Goal: a full context no longer ends the answer, and the user sees what the summary covers; merged on green.
  • Agents: recovery applies to API, MCP and chat-room answers alike; summary is in GET /api/v1/chats/{id}.
  • Zero setup: nothing to set.
  • Fewest clicks: automatic; the summary is one click to show.
  • Configurable: honours ai.compact (off: tool results are still trimmed, no fold).
  • Light: no new calls unless the server says the context is full.
  • Private and secure: n/a, no new surface; trimmed tool results keep their untrusted markers.
  • Cost: one extra summary call (by ai.compact_model, in the ledger under the chat) only when a request overflows.
  • User decides: defaults unchanged.
  • Upgrades: n/a, no change to stored data.
  • Honest: the UI line says the messages above are read as a summary.
  • Tests, docs: test_the_server_saying_the_context_is_full_is_understood, test_what_tools_returned_is_cut_to_fit_the_model, test_a_conversation_that_doesnt_fit_is_folded_in_and_asked_again, chat-summary-mark.test.tsx; docs/assistant.md, docs/requirements.md; OpenAPI and client regenerated with tooling.
  • Open standards: OpenAI-compatible errors; no new dependencies.
  • Reported in the project thread; refine later: the answer record (meta) doesn't yet say an answer was fitted or shrunk.
  • Reuse: reuses chat.compact for the fold; no second summariser.

Generated by Claude Code

… summary covers

When the model server says a request is too long for the model, the answer
is tried again instead of failing: what tools returned is shortened, then
all but the last two messages are folded into the summary now. The window
the server names is kept as the model's. A 400 for a full context no longer
reads as a model that can't use tools.

GET /chats/{id} gives the summary with the messages it covers, and the chat
shows a line under the last of them, with Show summary.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XZAK1YALs8mQRwgGnyju4F
Copy link
Copy Markdown
Owner Author

Clicks and keystrokes per feature failed on the phone survey only: first-question timed out waiting for the answer. The backend log shows the question posted (POST /chats/1/messages 200) and then no further request for that chat, with no error logged; the page then shows "No answer was saved", meaning the web app had dropped its live answer rather than the API failing. The same journey passed on the computer survey in this run, and passed 3 of 3 times locally on the phone with this branch (ci/clicks/run.sh --device phone --only install,first-admin,setup-wizard,first-question). Nothing this PR changes runs before the first answer streams except a cached model-list lookup, which the computer run also made.

I've re-run the failed job once and am repeating the phone journey locally after a computer run, as CI does. If it fails again I'll treat it as this PR's and fix it here.


Generated by Claude Code

@adeelahmad
adeelahmad merged commit 3adb06b into main Oct 18, 2026
11 of 12 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-w4pz1s branch October 18, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0