Skip to content

GLM-5.1 prompt cache randomly drops to 0 on opencode-go, while DeepSeek V4 Flash works reliably #31348

Closed as not planned

Description

@Sombrer0-1

Description

I use opencode-go in a long-running coding agent workflow. With the same workflow, DeepSeek V4 Flash keeps stable and high cache reads across many turns. But after switching to GLM-5.1, cache reads randomly drop to 0, causing large unexpected cost spikes.

Observed behavior

In one session, DeepSeek V4 Flash ran from turn 1 to turn 116 without abnormal cacheRead=0 events after the initial request.

After switching to GLM-5.1, I saw two complete cache read failures within only 15 turns:

turn 123:
model: GLM-5.1
cacheRead: 0
input: 45918

turn 127:
model: GLM-5.1
cacheRead: 0
input: 63535

The surrounding turns had normal cache reads:

turn 122: cacheRead: 22272
turn 123: cacheRead: 0
turn 124: cacheRead: 35456

turn 126: cacheRead: 45888
turn 127: cacheRead: 0
turn 128: cacheRead: 57408

So GLM-5.1 does support cache sometimes, but cache reads randomly collapse to 0.

Prefix stability evidence

I added debug logging before the model call. Around both abnormal GLM-5.1 turns, the request prefix did not change:

sys_hash:       5d3ec78c
tools_hash:     6244fe09
prefix_4k_hash: 26ac1f5d
prefix_16k_hash: 30e260ca
prefix_64k_hash: d65f320d

The diff against the previous request also showed that only new items were appended:

turn 123:
previous input_items_count: 42
first_changed_input_index: 42

turn 127:
previous input_items_count: 57
first_changed_input_index: 57

This means the existing request prefix was unchanged. There was no mutation to the system prompt, tools, or earlier input items. From the client side, the prompt should have been cache-readable.

Request

Please investigate whether GLM-5.1 on opencode-go has unstable prompt cache routing or cache key/session handling.

Specifically:

  1. Are GLM-5.1 requests using sticky routing / session affinity for prompt cache?
  2. Is a stable cache key or session key passed to the upstream GLM API?
  3. Is GLM-5.1 routed differently from DeepSeek V4 Flash?
  4. Is cacheRead: 0 expected even when the request prefix is unchanged?
  5. If opencode-go only forwards to the official GLM API, could this be escalated upstream with the evidence above?

This behavior makes GLM-5.1 unreliable for long-running coding agent workloads, because cache reads can randomly drop from tens of thousands of tokens to zero even when the request prefix is stable.

Plugins

None

OpenCode version

latest

Steps to reproduce

Use opencode-go with a long-running coding agent workflow through the OpenAI-compatible /v1/chat/completions API.

Screenshot and/or share link

Image

Operating System

Windows 11

Terminal

Windows terminal

Activity

  1. mrrusty-87 commented on Jun 8, 2026

    @mrrusty-87

    same issue here today. no prompt caching. output from opencode usage history:

    Date | Model | Input | Output | Cost | Session
    Jun 8, 9:12 PM | glm-5.1 | 109900 | 180 | Go ($0.1537) | U4P6qlck
    Jun 8, 9:10 PM | glm-5.1 | 109769 | 112 | Go ($0.0290) | U4P6qlck
    Jun 8, 9:10 PM | glm-5.1 | 108190 | 1570 | Go ($0.0365) | U4P6qlck
    Jun 8, 9:10 PM | glm-5.1 | 107155 | 34 | Go ($0.0350) | U4P6qlck
    Jun 8, 9:10 PM | glm-5.1 | 106845 | 60 | Go ($0.0281) | U4P6qlck
    Jun 8, 9:09 PM | glm-5.1 | 106582 | 254 | Go ($0.0290) | U4P6qlck
    Jun 8, 9:09 PM | glm-5.1 | 106372 | 83 | Go ($0.0281) | U4P6qlck
    Jun 8, 9:09 PM | glm-5.1 | 106156 | 207 | Go ($0.0286) | U4P6qlck
    Jun 8, 9:09 PM | glm-5.1 | 105474 | 602 | Go ($0.0309) | U4P6qlck
    Jun 8, 9:09 PM | glm-5.1 | 104688 | 31 | Go ($0.0282) | U4P6qlck
    Jun 8, 9:09 PM | glm-5.1 | 103848 | 68 | Go ($0.0314) | U4P6qlck
    Jun 8, 9:09 PM | glm-5.1 | 100988 | 64 | Go ($0.0269) | U4P6qlck
    Jun 8, 9:08 PM | glm-5.1 | 100769 | 194 | Go ($0.0276) | U4P6qlck
    Jun 8, 9:04 PM | glm-5.1 | 100646 | 1628 | Go ($0.0344) | U4P6qlck
    Jun 8, 8:59 PM | glm-5.1 | 100535 | 72 | Go ($0.0271) | U4P6qlck
    Jun 8, 8:58 PM | glm-5.1 | 100318 | 968 | Go ($0.0314) | U4P6qlck
    Jun 8, 8:55 PM | glm-5.1 | 100068 | 123 | Go ($0.1406) | U4P6qlck
    Jun 8, 8:54 PM | glm-5.1 | 99678 | 30 | Go ($0.0261) | U4P6qlck
    Jun 8, 8:54 PM | glm-5.1 | 99421 | 249 | Go ($0.0275) | U4P6qlck
    Jun 8, 8:54 PM | glm-5.1 | 99486 | 18 | Go ($0.0260) | U4P6qlck
    Jun 8, 8:54 PM | glm-5.1 | 99409 | 68 | Go ($0.0263) | U4P6qlck
    Jun 8, 8:54 PM | glm-5.1 | 99220 | 97 | Go ($0.0264) | U4P6qlck
    Jun 8, 8:54 PM | glm-5.1 | 98987 | 143 | Go ($0.0407) | U4P6qlck

  2. michaelBelsanti commented on Jun 25, 2026

    @michaelBelsanti

    Seeing the same issue with GLM-5.2. It makes the models pretty much unusable with how fast it goes through your usage.

  3. mgadda commented on Jun 27, 2026

    @mgadda

    Same experience for me with GLM-5.2 (Opencode Go). Definitely seems broken (hopefully not by design!). The net effect is that it's wildly more expensive than closed frontier models like GPT-5.5. I spent 67% of the 5-hour quota on a single prompt (and, egregiously also 26% of weekly, and 13% of monthly!). Usage showed cache misses on almost every other request. This behavior was reproducible in Conductor, opencode desktop and opencode CLI.

  4. mgadda commented on Jun 27, 2026

    @mgadda

    This appears to be duplicate of #33998.

  5. MiunaQwQ commented on Jun 29, 2026

    @MiunaQwQ

    Looks like the same issue is also happening on glm-5.2

    Observed logs:

    Request UTC time Model Input tokens Cached read tokens Output tokens Reasoning tokens Cost
    1 2026-06-29 19:21 UTC glm-5.2 111300 0 1931 0 $0.1643
    2 2026-06-29 19:21 UTC glm-5.2 2515 111232 1478 0 $0.0389
    3 2026-06-29 19:21 UTC glm-5.2 115741 0 177 0 $0.1628
    4 2026-06-29 19:22 UTC glm-5.2 115926 0 806 0 $0.1658
    5 2026-06-29 19:22 UTC glm-5.2 116738 0 513 0 $0.1657
    6 2026-06-29 19:22 UTC glm-5.2 117751 64 146 0 $0.1655
    7 2026-06-29 19:22 UTC glm-5.2 2946 115200 203 0 $0.0350

    Cost impact:

    • Actual cost of the 4 abnormal turns: about $0.6599
    • Estimated cost if cache had stayed stable: about $0.1408
    • Extra cost: about $0.5191
    • Cost increase on affected turns: about 4.69x

    Excluding the initial cold request:

    • Actual cost: about $0.7338
    • Expected cost with stable cache: about $0.2147
    • Overall increase after warmup: about 3.42x
  6. Marvinthebored commented on Jul 5, 2026

    @Marvinthebored

    This looks like the same mechanism root-caused in #35402: GLM models on Zen are multi-sourced with no stickyProvider configured, so requests intermittently re-resolve to a different upstream with a cold prompt cache (byte-identical-request repro in that issue). DeepSeek working reliably for you is consistent — models with a single upstream (or sticky enabled) don't flap. Consolidating discussion in #35402 may help.

  7. github-actions commented on Sep 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

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