The current time leads every GPT prompt, so the prompt cache cannot match

A popular open-source chat app for web and desktop across many providers; its memory summary and history window keep each request small.
≈ 360,000 tokens per 1,000 calls, prompt tokens the cache could have served on gpt models estimate
Audited with leanprompt 0.1.0-dev.15
Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.
- Repository
- ChatGPTNextWeb/NextChat
- Commit audited
1d3dc33- leanprompt version
- 0.1.0-dev.15
- Audit date
- Status
- The maintainers have been told about this audit; no response yet.
- Maintainers
- the issue
- How it ran
- Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.
leanprompt read the code at commit 1d3dc33 and found 2 places where its LLM calls could use fewer tokens, 2 the project already knows about, plus 5 other problems, not scored. Static score: 89 of 100 (an estimate from the findings, leaving out what the project already knows about). The code may have changed since.
Findings
-
LP-PC-03No ids, timestamps, versions or paths at the top of the promptapp/store/chat.ts:179· severity high · saves prefill · size is assumedWhat happens. For gpt-* models the first message of every request is a system prompt that starts with the current time, written with seconds (new Date().toString()). It differs on every call, so OpenAI's automatic prefix cache cannot reuse anything after it: the memory summary, the mask's context messages and the history.
The change. Drop the time line from the system message, or move it into the newest user message, so the system message is the same on every call.
Why it helps. Prompt caching matches from the first byte. A timestamp on line 4 of message 1 makes every later token a cache miss, even when the rest of the prompt is the same as the last turn.
Estimate about 360,000 prompt tokens per 1,000 calls not served from cache
Assumptions. average prompt 2,000 tokens; 30% of calls on gpt-* have a reusable prefix of about 1,200 tokens (the 1,024 minimum applies; short chats lose nothing); the history window and summaries move on some turns, so not every turn can reuse its prefix. The share is of all prompt tokens of gpt-* sessions.
Who reaches this. gpt-* and chatgpt-* models (the default model gpt-4o-mini), default setting on
How big. On a gpt-* chat whose prompt is over 1,024 tokens, send two turns a minute apart and read cached_tokens on the second; it should be about 0 today and rise after the time line moves.
-
LP-PC-08Cache-aware compactionapp/store/chat.ts:636· severity medium · saves prefill · size is assumedWhat happens. The request is built as system prompt, then the rewritten memory summary, then the mask's fixed context messages, then history. The summary changes each time it is refreshed, so the mask context that sits behind it is recomputed on every refresh although it never changes.
The change. Build the list as system prompt, mask context, memory summary, history. The summary then starts after the stable part.
Why it helps. A cache only reuses tokens up to the first change. A part that changes (the summary) in front of a part that never changes (the mask context) throws the stable part away each time.
Overlaps. Finding 1 loses some of the same tokens; the totals count the larger once.
Estimate about 75,000 prompt tokens per 1,000 calls (estimate)
Assumptions. 10% of calls use a mask with about 1,500 tokens of context; half of those follow a summary refresh. Only pays off once the time line is also out of the first message on gpt-* models, which is why the two overlap.
Who reaches this. sessions with a mask that has long context messages and a summary
How big. How many sessions use a mask with context messages over about 500 tokens (masks the app ships, or user masks).
Already known to the project
The project’s own issues, pull requests or docs already cover these, so they are not counted above and are left out of the static score.
-
LP-PC-01Put cache marks where the provider needs themapp/client/platforms/anthropic.ts:182· severity high · saves prefill · size is assumedWhat happens. Requests to Anthropic carry no cache_control mark anywhere, and the system and memory messages are sent as ordinary user messages, so nothing is cached on Claude models.
The change. Send the fixed head (system, mask context) as a system block with one mark, and mark the last stable message. Do this together with the time and order fixes, since a changing head means the marks are written and never read.
Why it helps. Anthropic caches only at marks. Without them every turn pays full input price for the whole prompt.
Already reported. open feature request (Aug 2024) for Claude prompt caching; a maintainer replied that they would look into it. It proposes custom headers, not cache_control marks. https://github.com/ChatGPTNextWeb/NextChat/issues/5279
Estimate about 360,000 prompt tokens per 1,000 calls could be read from cache; about 600,000 newly written (estimate)
Assumptions. average prompt 2,000 tokens; 30% of calls continue a prefix of about 1,200 tokens that is above the model's minimum (1,024 or 4,096 by model); the history window slides on some turns, so reads per write are near the break-even of about 0.3. Net gain is small and uncertain on the default window settings.
Who reaches this. sessions that use Anthropic models
How big. cache_read_input_tokens and cache_creation_input_tokens on two consecutive turns of a chat over the model's minimum cacheable length.
-
LP-GE-08Route trivially small calls to a small modelapp/store/chat.ts:151· severity medium · saves prefill and generation · costs no tokens todayWhat happens. The title and the memory summary use the chat's own model unless it is gpt-*, gemini* or deepseek-*. A user on Claude, Qwen, Grok or any other model pays that model's price for a four-word title and for a 200-word summary that can run after every long turn.
The change. Default the title and summary model to a small model of the same provider, and keep compressModel as the override.
Why it helps. A title and a short recap do not need the largest model; it costs more per token and is slower.
Already reported. open request to change the model used for auto titles; the compressModel setting (PR 5426, merged) lets a user pick one, but the default is still the chat model. https://github.com/ChatGPTNextWeb/NextChat/issues/5368
Estimate no token loss; a price and latency difference (not scored)
Assumptions. summary runs when more than 1,000 estimated tokens arrived since the last one (chat.ts:761), so with long answers on most turns.
Other problems the audit found
Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.
-
A cut-off answer is shown as complete (OpenAI reasoning models)
app/client/platforms/openai.ts:246·LP-GE-12Read the finish reason before using an answer · severity highWhat happens. For gpt-5 and o-series models the limit sent is max_completion_tokens = Max Tokens, 4000 by default (store/config.ts:71). Reasoning tokens count against it. The stream parser reads delta content only (openai.ts:333-366) and never reads finish_reason, so a reply that stopped on the limit, or an empty one after long reasoning, is stored and shown as a finished answer.
The change. Read finish_reason from the last stream chunk; on length, mark the message as cut off in the UI and offer to continue, and raise or drop the default cap for reasoning models.
Why it matters. The user pays for the reasoning and gets half an answer with no sign it stopped early.
To check. Set a low cap on a gpt-5 chat and ask a long question: the message shows a cut-off marker and the finish reason is length.
-
Claude replies cut at max_tokens are not flagged
app/client/platforms/anthropic.ts:244·LP-GE-12Read the finish reason before using an answer · severity mediumWhat happens. max_tokens defaults to 4000 (anthropic.ts:187). The stream handler checks stop_reason only for refusal; stop_reason max_tokens is ignored, so a long answer ends mid-sentence without notice.
The change. On message_delta with stop_reason max_tokens, mark the reply as cut off and offer to continue.
To check. Ask for a long answer with Max Tokens at 100: the reply shows a cut-off marker.
-
The Max Tokens setting is not sent to most chat providers
app/client/platforms/openai.ts:238·LP-GE-17Send the output cap the owner set, on every path · severity mediumDeclined by the project. a code comment says max_tokens is deliberately not sent; PR 4401 (optional max_tokens) was closed unmerged. https://github.com/ChatGPTNextWeb/NextChat/blob/1d3dc331512929a4b1d3e82354e72acce33b5c7a/app/client/platforms/openai.ts#L238-L239
To check. Set Max Tokens to 100 on a gpt-4o-mini chat: replies still run long today; after the change they stop at about 100 tokens.
-
A failed summary leaves a half-written memory
app/store/chat.ts:783·LP-GE-12Read the finish reason before using an answer · severity lowWhat happens. While the summary streams, onUpdate writes the partial text straight into session.memoryPrompt. onError only logs (chat.ts:794), and lastSummarizeIndex is not advanced, so an aborted or failed summary replaces the old memory with a fragment and the same summary is attempted again on the next turn.
The change. Keep the stream text in a local variable and write memoryPrompt and lastSummarizeIndex together in onFinish.
To check. Abort a summary call midway: memoryPrompt keeps its previous value.
-
A chat's summary is built from the open chat's memory
app/store/chat.ts:531·LP-GE-12Read the finish reason before using an answer · severity mediumWhat happens. getMemoryPrompt reads currentSession(), but summarizeSession(targetSession) calls it at chat.ts:745. If the user opens another chat while a reply streams, the summary of the first chat is built from the second chat's memory.
The change. Pass the target session into getMemoryPrompt.
In progress. open PR fixing issue 6935 (Nov 2026): summarize a chat with its own memory prompt, not the open chat's. https://github.com/ChatGPTNextWeb/NextChat/pull/6936
To check. Start a reply, open another chat that has a memory, and check the first chat's summary does not mention it.
The maintainers’ response
No response from the maintainers yet.
How this was made
The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.
Corrections and takedown: email info@podwarden.com or open an issue.