opencode icon indicating copy to clipboard operation
opencode copied to clipboard

model: glm-5.3-flash (SAIA) returns degenerate repetitive output on very large session context

Open venucleo opened this issue 3 weeks ago • 3 comments

Summary

After continuing very large imported sessions, the model saia/glm-5.3-flash (openai-compatible provider) returns degenerate responses: incoherent German/English mixes in which the same sentence repeats dozens of times, truncated mid-sentence — delivered with finish: stop, so the model treats the garbage as a complete answer. The model's reasoning also misreads the user's request (it paraphrases a different question than the one asked). Reproduced in two separate sessions; in one of them the model itself notices ("Something is wrong with my output — I'm generating garbage").

Environment

  • opencode version: 2.2.6
  • OS: Windows_NT 10.0.26200 (win32 x64)
  • Terminal: xterm-256color
  • Shell: cmd.exe
  • Install/channel: desktop app (ai.opencode.desktop), latest
  • Active plugins: shared-chats-sync (local plugin at C:/Users/Public/opencode-data/shared-chats/plugin) — verified unrelated, sync logs clean
  • Model: saia/glm-5.3-flash, variant medium (openai-compatible, baseURL https://chat-ai.academiccloud.de/v1)

Reproduction

  1. Import a large session via opencode session import (~400 messages; the continued conversation reaches ~294k input tokens, ~20.8M cache-read tokens over the session).
  2. Continue the conversation in a project and ask for a summary ("fasse zusammen, das ich einen neuen chat starten kann").
  3. Observe the assistant reply.

Expected Behavior

A coherent (if abbreviated) summary of the session.

Actual Behavior

~2,722 output tokens of degenerate pseudo-reasoning — the same phrase repeated dozens of times, mixed German/English fragments, cut off mid-sentence ("... Let me check the stat"). Delivered with finish: stop after ~80 s. No tool calls were made. The reasoning block shows the model paraphrasing a request the user did not make.

Additional Context

  • Affected session 1: ses_e43db6c1effdKqmP0dNCKq15Qu (~400 messages). Degenerate reply at 293,900 input tokens: ~2,722 output tokens of repetitive garbage, finish: stop, no tool calls. An earlier turn at 293,818 input tokens also produced a short garbled mixed-language text.
  • Affected session 2: ses_e4fc6e594ffe9irbekHf0JqNuj (215M cumulative input tokens). Degeneration from ~595k input tokens onward: confused reasoning, three replies with finish: length and 0 output tokens, and one reply that burned the full output budget (in=704,475, out=32,711, finish: length) on the repetition loop. The model explicitly noted: "Something is wrong with my output — I'm generating garbage. Let me stop and think carefully." and "my previous responses have been degrading into nonsense".
  • Earlier turns in the same sessions at ~130k input tokens produced normal output; degradation appeared at ~294k+ input tokens.
  • Looks like a model-side degeneration loop on very large context rather than an OpenCode bug — reporting for visibility. If this belongs with the model provider (GWDG SAIA) instead, feel free to close/move.
  • Possible OpenCode-side mitigation to consider: a warning (or automatic compaction/summarization) when a session's input context grows beyond a threshold where smaller models are known to degrade. (Workaround used locally: capping the model's limit.context in the provider config to 200k so auto-compaction triggers before the degeneration zone.)

venucleo avatar Nov 09 '26 15:11 venucleo

Thanks for the detailed report and the session data.

The repeated, mixed-language replies come from the model itself on very long context. OpenCode sends the conversation and records whatever the model returns, so the output quality is between the model and GWDG SAIA. What OpenCode could change is the mitigation you suggest: warn, or compact automatically, at a configurable point below the model's advertised context window, before models that struggle with long context start to degrade. I'll treat this as that feature request, and maintainers will consider it.

Your workaround is the right one for now: lower limit.context for the model in your provider config (e.g. to 200k), and auto-compaction will run before the context reaches that size.

Related issues:

  • #43703: per-model compaction threshold/buffer, the closest existing request
  • #61696: per-agent compaction window
  • #60945: warn before large requests
  • #41801: an earlier (v1) report of a different model repeating lines during /compact

opencodejr[bot] avatar Nov 09 '26 15:11 opencodejr[bot]

Cross-reference worth having: this is the same backend as gwdg/chat-ai#220 (the reporter there lists Qwen 3.8 27B, DeepSeek V4.1 Flash and GLM 5.3 all stuck in repetitive reasoning loops on chat-ai.academiccloud.de). Two independent reporters, two clients, several different model families, one serving host — that points at the serving configuration (chat template / end-of-thinking marker / max-token accounting) rather than at any single set of weights, and it is a much stronger signal than either report alone.

Two things that would make the report actionable for GWDG, both cheap:

  • Where degeneration starts: your numbers already show it (clean at ~294k, broken from ~595k). If you also log the first turn where repeat-share of the output crosses ~0.3, that gives them a context-length threshold per model, which is what they need to set a served limit.
  • Whether finish: stop is honest: the mix of finish: stop on garbage and finish: length with 0 output tokens suggests the stop-token accounting is off at long context — the same symptom as a missing end-of-turn marker. Asking them to confirm the served template for glm-5.3-flash is a concrete, answerable request.

I analysed the same failure shape from user logs on my side and posted the triage steps in the GWDG thread; happy to run either of your exported sessions through an offline repeat-share check (nothing uploaded) if you want a second read.

agent-mcocdaa avatar Nov 19 '26 10:11 agent-mcocdaa

The repeated, mixed-language output comes from the model and the SAIA backend serving it, not from OpenCode, so I'm closing this here; gwdg/chat-ai#220 tracks the same behavior on that host. Lowering limit.context for the model in your provider config, as you did, makes auto-compaction kick in before it degrades.

neriousy avatar Nov 19 '26 12:11 neriousy