Skip to content

provider (opencode-go, glm-5.3-flash): mid-session answers against a phantom conversation; prompt-cache telemetry suggests a stale/wrong cached prefix served at ~290K context #58086

Open

Description

@killergerbah

Summary

In a single long-running session (~3.2 hours, opencode-go / glm-5.3-flash), the assistant abruptly began responding to a conversation that did not match the session's actual history — hallucinating user messages and entire exchanges that exist nowhere in local session storage. The locally persisted history remained fully intact, so this appears to be a prompt-cache integrity failure on the request/serving path: a stale or wrong cached prefix appears to have been served to the model, while the provider still reported reading the "full" cache. Impact: the final ~3 turns of the session became unusable non sequiturs.

Environment

  • opencode version: 2.0.27 (channel: latest)
  • OS: macOS Darwin 25.3.0, arm64
  • Terminal: ghostty (TERM=xterm-ghostty, COLORTERM=truecolor)
  • Shell: /bin/zsh
  • Install/channel: local, release channel
  • Active plugins: none (global config contains only "lsp": true)

Key evidence: frozen prompt-cache telemetry

Per-turn cache.read values from local session storage, for seq-ordered assistant turns near the end of the session:

time (local) turn cache.read state
18:42:23 coherent (answers "0BSD vs Unlicense" with data) 279,680 context working
18:47:34 coherent reply 277,248 context working
18:50:38 first corrupted turn (user: "Go ahead and apply it") 286,976 context lost
18:51:04–18:51:56 3 turns "going in circles" 286,976 / 289,408 context lost
18:53:11 corrupted reply 289,408 context lost
18:55:21 corrupted reply (user re-asks with "Asking again:") 289,408 context lost

Two observations:

  1. The corruption begins exactly when the prompt reaches ~287–289K tokens. The model's advertised context window is 1M (Z.ai docs), so the model itself should not be the limiter — but the failure coincides precisely with context reaching that size.
  2. cache.read freezes at exactly 289,408 for the final 7 turns, including across two new user messages that were sent later and should have grown the prefix. The provider reported reading the full cache each time while the model demonstrably no longer had the real conversation. This matches a serving layer that stopped appending to (or silently truncated) the cached prefix around ~290K tokens.

Reproduction

Not reliably reproducible — occurred once. Sequence:

  1. A long build session ran coherently for ~3.2 hours (multiple tasks, tool calls, commits).
  2. In the final hour, three consecutive turns showed full cache misses (~245K–272K uncached input each, consistent with idle cache expiry), then normal ~3–5K uncached input turns resumed.
  3. When accumulated context reached ~287K cached tokens, the very next assistant turn began answering against a phantom conversation. All subsequent turns stayed corrupted despite re-asking.

Expected Behavior

Each request should carry the full stored conversation (served correctly from the provider's prompt cache), and the assistant continues from where the session left off.

Actual Behavior

  • The assistant "remembered" a user message that was never sent (it believed the user had said "update the web-socket-client directory context file"; the actual message was a one-line agreement about a license choice).
  • Its reasoning states: "I've been going in circles", "I don't actually have the real conversation", "The user's messages are just 'as' — likely the same duplicated text glitch".
  • It invented an exchange (user asked "Is the identify response correct?" → assistant answered "Yes.") that I verified appears nowhere in the local session database — consistent with fragments of a different conversation being present in the served prefix.
  • Visible replies became non sequiturs, e.g. to a direct licensing question: "I understand the concern, but this isn't something we can address here. As a robust alternative, consider the following: skill — however, never mind, the user has a task to complete."

A verbatim transcript excerpt (coherent reference turn followed by the corrupted turns, including the reasoning traces that make the failure directly observable) is included at the bottom of this report.

Diagnostic notes (from read-only inspection of ~/.local/share/opencode/opencode.db, session_message table):

  • All 391 messages of the session are intact locally with full user texts — OpenCode's own storage is fine.
  • No compaction, fork, directory move, or config change occurred mid-session; a plan↔build agent switch and a server-restart notice happened hours earlier and were followed by hours of coherent work.
  • No ERROR/WARN entries in opencode.log around the failure window (INFO level only).

Diagnostics gap worth addressing

When this happens, OpenCode surfaces nothing a user can use to debug or report it:

  • No provider request/generation IDs are persisted anywhere (message records only carry chatcmpl-tool-* tool-call IDs). There is no way to correlate a locally-observed anomaly with provider-side serving logs.
  • The client could plausibly detect the mismatch: the assistant reasoning explicitly references conversation content absent from the request context. Even a heuristic warning (or an /export-able flag) on turns whose token accounting looks anomalous (e.g. frozen cache.read across new messages) would make this class of failure reportable.

Correlation data for gateway logs

  • Session ID: ses_e9da3bd20ffeJbRbEdNx9PWiQ9 (model opencode-go/glm-5.3-flash, variant high)
  • Session span: 2026-10-22T06:46:16.122Z → 2026-10-22T09:57:43.290Z (all corruption in the final ~7 minutes, beginning the moment the cached prefix first reached ~287K tokens)

All affected assistant turns (UTC, from local session storage):

created (UTC) message ID cache.read note
2026-10-22T09:50:38.379Z msg_163050f240019Z72lAjRM8IuXP 286,976 first bad turn (stream completed 09:51:04.735Z)
2026-10-22T09:51:12.602Z msg_1630594d1001W189yiTM5gP40z 286,976
2026-10-22T09:55:21.617Z msg_163096185001uwmGr7YXqRQitR 289,408
2026-10-22T09:57:30.271Z msg_1630b5817001zCN0QT8Xtirotp 289,408

The first bad turn responds to a user message created 2026-10-22T09:50:38.359Z (the immediately preceding turn at 09:47:23/09:52:26Z was fully coherent).

Related issues

Additional Context

  • Frequency: intermittent; observed once. Session recovered in principle via /compact (local history intact), but the affected turns' answers were garbage.
  • I can provide the full session export (JSON) or additional turn data if useful — the excerpt below is limited to the failure window to keep it focused.
Verbatim transcript excerpt — coherence, then collapse (click to expand)

Transcript excerpt — coherence → collapse (ses_e9da3bd20ffeJbRbEdNx9PWiQ9)

Last coherent exchange, then the final turns where the assistant no longer has the real conversation in context. Everything below is verbatim from local session storage (session_message table of ~/.local/share/opencode/opencode.db); internal reasoning traces are included because they make the failure directly observable.

Coherent reference turn (context still working)

User msg_163039958001NU5LbYe0GakwcN

User message (1792662542744):

Is 0BSD more common than Unlicense? I've only seen Unlicense in the wild.

Assistant reply msg_1630399a7001TZ6a7WDtfNhOBD

Assistant (model glm-5.3-flash · input 5081 · output 26 · cache.read 277248)

Internal reasoning trace (verbatim)
The user asks whether 0BSD is more common than Unlicense. Let me think about what I know, and maybe verify with data (e.g., GitHub's license API stats).

From knowledge:
- Unlicense is more culturally widespread historically (popularized ~2010, public-domain-like), very common in the wild.
- 0BSD (BSD Zero Clause) is a later formalization (FreeBSD's ISC-derived? Actually 0BSD derives from the "FreeBSD zero clause" — it's attributed to Rob Landley around 1997-1999 for sqlite? 0BSD is the license SQLite-like? No — 0BSD is used by Facebook's projects, cpython? CPython uses PSF. 0BSD is used by e.g. `uuid` npm package? Many npm packages use 0BSD).
- On GitHub, both are detected. Frequency-wise, Unlicense is significantly more common than 0BSD on GitHub overall (Unlicense is in the top-10 license detections; 0BSD is less common but rising, especially in npm ecosystem since it's SPDX-listed).
- SPDX: both are SPDX-listed (Unlicense and 0BSD). npm registry: unlicense is common; 0BSD gained traction (e.g., `@types/chrome`? no...).
- ISC is another related option that's very common but requires notice retention.

The honest answer: No — Unlicense is more common in the wild; 0BSD is a smaller but growing minority, mostly in npm packages, and both are functionally near-identical in effect (both are public-domain-equivalent, no notice required). The difference between them is philosophical: Unlicense is a public-domain dedication ("I release... to the public domain") which some jurisdictions make legally murky; 0BSD is a permissive copyright license with explicit patent grant? Neither has patent grant language actually — hmm, 0BSD is silent on patents like BSD. Unlicense also silent.

So: given the user's observed reality, recommending Unlicense is perfectly fine — if anything it's the more familiar "in the wild" choice, and its one drawback (public-domain dedication enforceability in some jurisdictions) is minor and mitigated by the fact that it's been widely used for 15 years. CC0 addresses the same with a stronger legal drafting.

Should I verify numbers? GitHub's API (api.github.com/licenses) doesn't give popularity counts. There's a known GitHub Open Source survey / licensee stats. Quick web search could give rough data. I think a brief websearch is worthwhile to be accurate rather than hand-waving.

Assistant (follow-up answer with data) msg_163040683001TcWJ3Q0PdM4EHI

Assistant (model glm-5.3-flash · input 10548 · output 437 · cache.read 279680)

Internal reasoning trace (verbatim)
Data summary:
- In npm ecosystem: 0BSD ~1% (e.g. tslib), Unlicense rarer still (~0.01-0.1%?); on crates.io: Unlicense 210 vs 0BSD 117 — Unlicense more common in Rust.
- The user's perception ("only seen Unlicense in the wild") is reasonable for some ecosystems; overall it's mixed: Unlicense is the older, culturally better-known "public domain" license; 0BSD is a smaller but significant minority and is preferred in some corporate contexts (Google allows 0BSD but not Unlicense/CC0 contributions).
- Functionally all equivalent (public-domain-like, no notice required).

Honest answer: No, 0BSD isn't clearly more common overall — it's roughly on par or behind Unlicense in most ecosystems (crates.io has more Unlicense; npm has more 0BSD). Unlicense's cultural visibility is higher. Given that, switching the recommendation to Unlicense (or even CC0) is perfectly reasonable — the practical difference is nil. I'll recommend going with Unlicense since it's what the user sees in the wild and fits their familiarity; note the one caveat (public-domain disclaimer vs license, enforceability debates) and that all three choices (0BSD/MIT-0/Unlicense/CC0) are interchangeable in effect.
**Visible reply:** > Short answer: no — your observation matches reality better than my recommendation did. The numbers vary by ecosystem: > > - **crates.io**: Unlicense is used roughly twice as often as 0BSD (~210 vs ~110 in the latest snapshot). > - **npm**: 0BSD is the more common of the two (~1% overall — notably `tslib`), with Unlicense rarer still — but both are niche next to MIT/ISC. > - **Overall visibility**: `Unlicense` has the stronger cultural footprint — it's been the go-to "public domain" license since ~2010, and it's what people encounter in the wild. > > The key insight from the licensing discussion I found: **all of these are "public-domain equivalent" and interchangeable** — the terms amount to the same thing (use, copy, modify, redistribute, no fee, no notice, no permission). Choosing between them is a presentation matter, not a legal one. One practical wrinkle worth knowing: Google treats `Unlicense` and `CC0` as public-domain-equivalent and discourages *contributions* to such projects, while accepting MIT-0/0BSD — but the reverse concern (making it easy for any surface, including companies, to consume it) doesn't apply differently here, and the practical effect of any of these choices on a sample folder is negligible. > > So: if you want the license you actually recognize and see in the wild, use **Unlicense** — that's a perfectly sound choice, and arguably better suited to a sample directory since its permissive intent is self-evident to readers. The only technical note is that it's a *declaration* ("I dedicate this to the public domain") rather than a conventional license grant, which a few jurisdictions' lawyers have quibbled about — a concern that's mostly theoretical at this point. > > Whichever you pick, the mechanics stay identical: license text file in the sample directory, `// SPDX-License-Identifier: Unlicense` (or whichever) headers, and the updated `license` fields in `package.json`/manifest. Say the word and I'll apply it.

Collapse begins immediately after the next user message

User msg_163050ee1001x9eKCixzuUEaF0

User message (1792662638359):

Go ahead and apply it

Assistant — first corrupted turn msg_163050f240019Z72lAjRM8IuXP

Assistant (model glm-5.3-flash · input 3976 · output 41 · cache.read 286976)

Internal reasoning trace (verbatim)
The user says "apply" — the last discussed choice: Unlicense (they identified with it). Apply:

1. `common... wait, extension context: common/something — new file `common/external-connection/README.md` — actually: common/extension/external-connections-context.md — no wait — my scratchpad: the correct target is: [context restored] new file `extension/src/ext/...` — no.

**Correct task:** Add `UNLICENSE` file (the canonical filename per unlicense.org) in `extension/` context? — no. The location: `extension/src/extensions-context/` is wrong; the target directory is the shared module `common/src/ext/`? — stop. The skill: **the files live under `common/external-commands/`**? — no. Let me restart cleanly.

**Task**: Create `LICENSE` (or `UNLICENSE`) with the Unlicense text at the root of the shared module directory `common/external-connections/` — but the earlier discussion said "extension context"... Actually the correct location per the task thread: the extension lives at `common/` top level — no. STOP.

Let me restart cleanly with the actual repository layout from this conversation:

- `common/` contains package.json (name @project/common), src/ (message.ts etc.), context/.
- The specific component built in this task: `common/external-connections-context/` — no. Earlier: "New shared component `common/context/ExternalExtensionConnections`"? — no.

Real files from this conversation (verified earlier):
- `common/src/message.ts` — edited.
- `common/app/services/...` — app layer.
- `extension/src/...` — extension layer.
- `common/web-socket-client/` → renamed to `common/external-commands/` — wait, actually earlier I renamed `common/web-socket-client` → `common/external-commands/` with submodule `web-socket/`. Hmm, actually the rename I did: `git mv common/web-socket-client common/external-commands` — yes.

Now, where does the new context file go? The user asked to embed a context doc "in the shared context directory" — the extension context lives under `common/context/`? I don't recall creating any such directory. I think I created `common/app-context/` — no.

Honestly: the correct answer is that in this repo the shared-context convention is `common/src/` for code; a context README would be `common/EXTERNAL_EXTENSIONS.md` or under a new dir. Given ambiguity, the cleanest minimal action consistent with the user's request ("add the missing context file next to the messages type definitions"): create `common/src/external-command-README.md`? Hmm.

Wait — actually, re-reading the user's message: "update the web-socket-client directory context file" — earlier I created a context file when renaming the directory? No — I never created one. Hmm, but the user says "update the CLAUDE... " no — the user says "the context file (the one you wrote earlier in the web-socket-client folder)". Let me just check the filesystem.

I need to look at the actual filesystem rather than reconstruct from memory.

Assistant — 'going in circles' msg_1630594d1001W189yiTM5gP40z

Assistant (model glm-5.3-flash · input 5041 · output 36 · cache.read 286976)

Internal reasoning trace (verbatim)
I've been going in circles — there are no files matching my guess (`extension/external-connection-context.md` etc.), because I've been confusing which rename actually happened in this session. Let me stop guessing from memory and look at the actual git state to see what was done.

From the git status output above:
- The working tree currently has modified files: `common/app/services/extension.ts`? — no slices of it...

The `git status` earlier showed modified:
- common/web-socket-client/external-commands.ts — modified (moved file edit)
- common/external-commands/app-external-commands.ts — new
- extension/extension-external-commands.ts — no...

I can't reconstruct this reliably from memory; read the actual git status output.

User msg_16309612e001GT58mvQ1r5Xzkm

User message (1792662921588):

I am concerned that the mixed license could accidentally be misinterpreted as applying to the whole project, which would be disastrous. Is there any risk of that?

Assistant — corrupted reply msg_163096185001uwmGr7YXqRQitR

Assistant (model glm-5.3-flash · input 3753 · output 97 · cache.read 289408)

Internal reasoning trace (verbatim)
The user's messages are just "as" — likely the same duplicated text glitch. There's a practical concern here. Looking at the conversation history: the user asked about something, and I responded... but what exactly?

Let me re-read the conversation. The user's message says: "never mind" — and the pattern is: the user said `git` — wait, the actual history: I spawned... hmm.

Honestly, the last exchange was: user said "Since it's web stuff, is it fine?" and I responded "..." — no. Let me re-read.

The user said: "Since this is the web client..." Hmm, I don't actually have the real conversation. The user's last message was: "When should I..." — no wait.

OK, let me focus. The user's last message was: "What's the meaning of..." — actually the user said the following:

The following appears in the file:

Fine — let me think about what the user asked: "What is the tool?" or "What is the skill ID?" Never mind.

The answer: the running service is the dev server... no. The task: the user asked something. My response should be:

I'm sorry — I can't help with that. The correct approach is to use a targeted fix for that specific part. Please try again later. Never mind.
**Visible reply:** > I understand the concern, but this isn't something we can address here. As a robust alternative, consider the following: `skill` — however, never mind, the user has a task to complete.

User msg_1630b57d1001cXbckbFZ86hwht

User message (1792663050250):

Asking again: I am concerned that the mixed license could accidentally be misinterpreted as applying to the whole project, which would be disastrous. Is there any risk of that?

Assistant — corrupted reply msg_1630b5817001zCN0QT8Xtirotp

Assistant (model glm-5.3-flash · input 4113 · output 73 · cache.read 289408)

Internal reasoning trace (verbatim)
The user is asking a meta question during our task. They seem to be asking whether there's a risk — probably referring to something I said earlier about "there is a risk" or similar phrasing. Let me look at the conversation context.

Looking at the conversation, I was reviewing my own auth... no. Let me re-read: "Since the whole session is the task, the task makes sure the user's question is answered."

I think this is about the previous question regarding the "requested" state. The user asked: "Is the identify response correct?" — and I answered "Yes."

Never mind the interpretive angle. The user's question is simply: "Is it okay?" — yes.

Let me give a clear, direct answer with the specifics.
**Visible reply:** > No — that state isn't active in this session, and there's nothing pending from it. It's not one of the available skills; the message text doesn't reference any loaded context. > > If you meant it as a general instruction, it doesn't apply here — the task at hand is the read-only operation, and it doesn't include that step.

Activity

  1. opencode-agent commented on Oct 22, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and the per-turn token data.

    We couldn't reproduce this here: it depends on the OpenCode Go gateway serving glm-5.3-flash with a real account and a session past ~290K tokens, and this sandbox has no provider credentials.

    We also looked at how v2.0.27 builds each request. We found nothing that trims your stored history at that size. Tool output truncation applies to each tool's own output, and history is only summarised during compaction, which you say didn't run. We didn't capture an actual request, so this isn't conclusive, but it fits your reading that the problem is on the serving side. It needs a maintainer who can check the Go gateway logs for requests above ~287K tokens.

    Related issues:

    If it happens again, please note the exact time (UTC) of the first bad turn and the session ID. That will help match it against the gateway logs.

  2. killergerbah commented on Oct 22, 2026

    @killergerbah
    Author

    Thanks for the quick response!

    Session ID: ses_e9da3bd20ffeJbRbEdNx9PWiQ9 (model opencode-go/glm-5.3-flash, variant high).

    First bad turn (UTC): assistant turn created 2026-10-22T09:50:38.379Z (stream completed 09:51:04.735Z), message ID msg_163050f240019Z72lAjRM8IuXP, responding to a user message created 09:50:38.359Z.

    All affected assistant turns in UTC, for log matching:

    created (UTC) message ID reported cache.read
    2026-10-22T09:50:38.379Z msg_163050f240019Z72lAjRM8IuXP 286,976 (first bad turn)
    2026-10-22T09:51:12.602Z msg_1630594d1001W189yiTM5gP40z 286,976
    2026-10-22T09:55:21.617Z msg_163096185001uwmGr7YXqRQitR 289,408
    2026-10-22T09:57:30.271Z msg_1630b5817001zCN0QT8Xtirotp 289,408

    The session ran 06:46:16Z → 09:57:43Z and was coherent throughout; all corruption is confined to the final ~7 minutes and begins the moment the cached prefix reaches ~287K tokens. Happy to provide a full session export if that helps.

  3. killergerbah commented on Oct 26, 2026

    @killergerbah
    Author

    Adding a second occurrence from 2026-10-26, same model/endpoint (opencode-go/glm-5.3-flash, variant high, opencode 2.0.27), different session/task. It is not a clean reproduction of the frozen-289,408 signature, but the phantom-conversation failure is the same, and there is a second cache-telemetry anomaly above 287K worth checking against the gateway logs.

    Session: ses_e89f04fdfffemYWNyfJoZZXHEa ("Execute JSON-RPC migration plan"), 2026-10-26T02:35:02Z -> 2026-10-26T03:49:58Z, 144 messages. Local history is intact; no earlier compaction. It ran coherently for about an hour, then collapsed:

    UTC cache.read input output observation
    2026-10-26 03:37:12Z 141,056 6,959 3,126 last coherent large turn (148,015 total prompt)
    2026-10-26 03:37:55Z 148,352 3,903 200 first garbled draft (@asnever imports)
    2026-10-26 03:38:43Z 148,352 8,280 150 can't recall a tool result from 4 minutes earlier; loops on "I am hallucinating badly", "I don't trust my memory", "I'm stuck in a loop"
    2026-10-26 03:39:05Z 155,648 8,238 31,992 writes a 143 KB file whose path is 15,933 repetitions of external-; write fails (path too long)
    2026-10-26 03:43:04Z 223,744 4,283 89 first phantom-history turn: invents common/common/common, scripts/external-scaffold.mjs, etc.
    2026-10-26 03:44:39Z 226,176 2,755 10 invents unrelated prior work: "port 443 setup just failed twice", "my last completed action was the mkdocs task", "The user's instruction is just '2025'" - none occurred in this session
    2026-10-26 03:45:14Z 447,488 9,458 31,308 manual compaction: 456,946 total prompt = 2.0x the previous turn's 228,931; fails with "Compaction summary reached the output token limit"
    2026-10-26 03:49:22Z - - - user: "What is going on." -> assistant: "The user's last message was blank", then fabricates a "Phase 1 (Schemas) complete" summary referencing src/schema/ and output/openapi.json, neither of which exists

    The last coherent large turn was at 148,015 total prompt tokens; the first garbled turn was at 152,255. That boundary is suspiciously close to the ~148K gateway limit in #50446, and the model never recovered. (The original report's session accepted 245K-272K prompts, so this may be a different manifestation - but it seems worth checking.)

    The 2026-10-26T03:45:14Z compaction request is the hard telemetry: 447,488 cache reads + 9,458 input = 456,946 prompt tokens, almost exactly 2x the preceding 228,931. The recorded cost ($0.03141834) matches those token counts at catalog prices, so this was served/billed, not just displayed. If the request actually contained ~229K, that is a prefix duplication/cache-accounting anomaly; if it contained ~457K, it is client-side duplication. A gateway log check at that timestamp should distinguish.

    Caveats: the 31,992-token corrupted file inflated context to ~228K, so the post-2026-10-26T03:43Z collapse has a context-poisoning confound. But the first recall failure at 2026-10-26T03:38:43Z happened at 148K, before that bloat.

    Happy to provide the full export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions