Skip to content

[Bug]: gpt-5-nano chat breaks with "context window exceeded" on a simple weather query (input grows to 372K tokens) #28

Description

@FireTable

What happened?

A simple chat query (今天天气如何, "what's the weather today") using the gpt-5-nano model fails with:

"Your input exceeds the context window of this model. Please adjust your input and try again."

Observability metrics for the run:

  • LLM CALLS: 5
  • TOOL CALLS: 4
  • HITL: 1
  • FAILED: 5 / 5 — every LLM call in the run failed
  • INPUT: 372K tokens
  • OUTPUT: 155 tokens
  • TOTAL: 372K tokens
  • DURATION: 28.08s

gpt-5-nano's context window is on the order of ~128K tokens (and likely smaller on some versions). 372K is several times over, so every call in the run collapses. The user then waits 28 seconds before seeing the error.

Notably, the user input itself is one short Chinese sentence (今天天气如何). The 372K tokens almost certainly come from accumulated memory system blocks and/or prior tool / turn results that the chat graph is re-injecting on every LLM call without any token-aware truncation.

Observability panel — gpt-5-nano run shows 5/5 FAILED, INPUT 372K tokens, context-window-exceeded error

What did you expect to happen?

  • A simple, fresh-feeling query like "what's the weather today" should not blow the context window, even on a small model.
  • The chat agent should either:
    • Cap / summarize memory and prior-turn content before each LLM call so the assembled prompt fits the chosen model's window, or
    • Fail fast (before the first LLM call) with a clear error if the assembled prompt exceeds the window, instead of burning 28s + 5 retries before showing the error.

Steps to reproduce

  1. Sign in, open https://ai.firetable.tech/chat.
  2. Use a session / thread where memory has accumulated over time (so the memory system block has grown).
  3. With OPENAI_MODEL=gpt-5-nano (or whatever selector picks the nano model), send 今天天气如何 (or any short, fresh query).
  4. Observe: 5 LLM calls, 5 failed, 28s wasted, final response is the context-window-exceeded error.

Severity

S1 — feature broken, no workaround from the user side. The user can't fix this by retrying; the only escape is to switch to a larger-context model or wipe memory manually.

Environment

  • Site: https://ai.firetable.tech/chat
  • Model: gpt-5-nano
  • Deployed commit: 6730007 (refactor(env): replace NEXT_PUBLIC_* with window.__CONFIG__ injection)
  • Input size at failure: 372K tokens (vs ~128K context window for the nano model)

Investigation hints

Likely root cause (for whoever picks this up):

  • The chat graph likely prepends the memory system block and/or prior thread messages on every LLM call without checking the assembled token count against the chosen model's limit.
  • Suggested mitigations:
    • Token-aware prompt assembly — count input tokens → summarize / truncate memory if it exceeds ~80% of the model's window.
    • Pre-call validation — reject before invoking the model when the assembled prompt is over the window, so the user gets a fast, clear error.
    • Smaller-window models should auto-summarize memory instead of letting raw accumulated memory flow through unchanged.

Relevant logs / screenshots

gpt-5-nano Observability: 5/5 failed, INPUT 372K tokens, context-window-exceeded error

Self-checks

  • I reproduced on main (current deployed commit 6730007).
  • I searched existing issues and didn't find a duplicate.
  • No secrets in this report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNeeds review and prioritization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions