Skip to content

Bug: OpenRouter Anthropic cacheWrite drops to zero after v2026.6.10 upgrade (conversation cache regression) #96947

Closed as not planned

Description

@FriendofTob

Bug: OpenRouter Anthropic cache markers (cacheWrite) stopped advancing after v2026.6.10 upgrade

Summary

After upgrading from v2026.5.3-1 to v2026.6.10, cacheWrite dropped to zero on every turn for openrouter/anthropic/claude-sonnet-4.6 sessions. Prior to the upgrade, the cache checkpoint was actively advancing through conversation history (cacheWrite growing from ~13K → 94K per turn), enabling cacheRead hits of 60–90K per call. After v2026.6.10, cacheWrite is consistently 0 and cacheRead is capped at the system prompt prefix (~32–35K).

Environment

  • OpenClaw version: 2026.6.10 (regression), 2026.5.3-1 (working)
  • Provider: openrouter
  • Model: anthropic/claude-sonnet-4.6
  • modelApi: openai-completions
  • Config: cacheRetention: "long", contextPruning: { mode: "cache-ttl", ttl: "1h" }

Observed behavior (v2026.6.10)

Every model.completed trajectory entry shows:

lastCallUsage.cacheWrite = 0
lastCallUsage.cacheRead = 32–35k (system prompt prefix only)

This means the cache checkpoint never advances past the initial system prompt. The conversation history is never cached.

Expected behavior (v2026.5.3-1)

cacheWrite actively grew turn-by-turn as conversation history accumulated:

turn 1:  cacheWrite=13k  cacheRead=0
turn 2:  cacheWrite=0    cacheRead=19k
turn 3:  cacheWrite=22k  cacheRead=0
...
turn N:  cacheWrite=47k  cacheRead=0
turn N+1: cacheWrite=0   cacheRead=73k

Peak per-call cacheRead reached 60–94K in active sessions. System prompt alone is ~32–35K, so the delta (25–60K) represents conversation history being cached.

Timeline

Time (UTC) Event
2026-06-25 00:30 v2026.6.10 installed
2026-06-24 13:59 – 2026-06-25 01:56 First session on v2026.6.10 — cacheWrite working (peak 35K write, 75K read)
2026-06-25 02:04 First session where cacheWrite = 0 — all subsequent sessions broken

The regression did not trigger immediately on upgrade. The first 12-hour session on v2026.6.10 had cacheWrite working normally. Starting with the next session at 02:04 UTC, cacheWrite has been zero on every session since.

Data comparison

Last working session (v2026.6.10, session e8f80c5f, ended 2026-06-25T01:56 UTC)

model.completed [selected turns]:
  cacheWrite=27k  cacheRead=0
  cacheWrite=0    cacheRead=27k
  cacheWrite=35k  cacheRead=0
  cacheWrite=0    cacheRead=40k
  cacheWrite=9k   cacheRead=71k
  cacheWrite=0    cacheRead=75k    ← peak

First broken session (v2026.6.10, session 408cd396, started 2026-06-25T02:04 UTC)

model.completed [all turns]:
  cacheWrite=0  cacheRead=32k
  cacheWrite=0  cacheRead=32k
  cacheWrite=0  cacheRead=32k
  [repeats for all turns]

Both sessions: same version, same model, same config, same provider. Only difference is session start time.

Code investigation

createOpenRouterSystemCacheWrapper in src/llm/providers/stream-wrappers/proxy.ts calls applyAnthropicEphemeralCacheControlMarkers which iterates over messages and applies cache_control to system/developer-role messages. This mechanism was what enabled cacheWrite growth in v2026.5.3-1.

In v2026.6.10, cacheWrite = 0 on every call despite the wrapper being invoked, suggesting either:

  1. The message structure passed to the wrapper no longer contains system/developer-role messages (possible change in how messages are serialized for the OpenRouter openai-completions transport), or
  2. A session state migration that ran after the first 6.10 session altered something that affects the wrapper's behavior

PR #85104 (fast-talks auto mode) touched extra-params.ts and the persistent cache schema — may be relevant.

Workaround

None found. Downgrading to v2026.5.3-1 is expected to restore behavior.

Impact

Significant cost regression. Without conversation-level caching, long sessions pay full input price on every turn for all accumulated context above the ~32K system prompt checkpoint.

Activity

  1. clawsweeper commented on Jun 26, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 26, 2026, 1:45 AM ET / 05:45 UTC.

    Summary
    Keep open. The report has detailed production cache telemetry for a fresh v2026.6.10 regression, current main still has the same OpenRouter Anthropic cache-control decision surfaces, and the related open session-affinity/TTL work does not prove this specific cacheWrite regression is fixed.

    Reproducibility: no. The reporter provides strong production telemetry, but this review did not run a live OpenRouter Anthropic session or capture the outgoing request payload, so the current-main failing path is not yet reproduced with high confidence.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.
    • Include redacted logs or terminal output.

    Next step
    Needs maintainer/API investigation and live OpenRouter cache proof before choosing a safe repair path.

    Review details

    Best possible solution:

    Confirm the outgoing v2026.6.10 versus current-main OpenRouter Anthropic payload and usage behavior, then fix the provider-owned OpenRouter/Anthropic cache shaping path with focused regression coverage and live cache proof.

    Do we have a high-confidence way to reproduce the issue?

    No. The reporter provides strong production telemetry, but this review did not run a live OpenRouter Anthropic session or capture the outgoing request payload, so the current-main failing path is not yet reproduced with high confidence.

    Is this the best way to solve the issue?

    Unclear. The fix should likely stay in the OpenRouter/provider stream shaping boundary, but maintainers need to determine whether the best repair is cache_control placement, session affinity, TTL handling, or an extra-param/cache interaction.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The exact failing condition is not yet isolated: it could be cache_control placement, long-TTL handling, session affinity, OpenRouter provider-side behavior, or extra-param caching after the v2026.6.10 change set.
    • Live OpenRouter Anthropic proof or a redacted trajectory/request-payload fixture is needed before a safe fix can be selected.
    • Related open session_id and long-TTL PRs overlap with prompt-cache behavior but should not be treated as this regression's fix without cacheWrite/cacheRead evidence.

    Codex review notes: model internal, reasoning high; reviewed against 4fc504d321b6.

    Label changes

    Label changes:

    • add P1: This is a newly reported regression in a paid provider path that can materially increase cost for long real sessions after upgrade.
    • add impact:auth-provider: The issue centers on OpenRouter provider request shaping, Anthropic model behavior, and cache usage accounting.
    • add impact:other: The concrete user impact is a provider-side cost and performance regression, which is meaningful but outside the more specific owned labels.
    • add issue-rating: 🦐 gold shrimp: Current issue advisory state selects this label.
    • add clawsweeper:needs-info: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.
    • add clawsweeper:needs-product-decision: Current issue advisory state selects this label.

    Label justifications:

    • P1: This is a newly reported regression in a paid provider path that can materially increase cost for long real sessions after upgrade.
    • impact:auth-provider: The issue centers on OpenRouter provider request shaping, Anthropic model behavior, and cache usage accounting.
    • impact:other: The concrete user impact is a provider-side cost and performance regression, which is meaningful but outside the more specific owned labels.
    Evidence reviewed

    What I checked:

    • Issue telemetry and correction read: The reporter says v2026.6.10 immediately changed OpenRouter Anthropic sessions from advancing cacheWrite/cacheRead through conversation history to cacheWrite=0 with cacheRead limited around the system prompt, and corrected the timeline to tie the break to the upgraded gateway restart.
    • Current OpenRouter cache wrapper still central: Current main wraps verified OpenRouter Anthropic requests with createOpenRouterSystemCacheWrapper and applies Anthropic cache-control markers through the payload hook, so this remains the active source surface rather than obsolete code. (src/llm/providers/stream-wrappers/proxy.ts:134, 4fc504d321b6)
    • Current OpenAI-compatible transport maps Anthropic cache markers: For cacheControlFormat='anthropic', current main adds cache_control to the system prompt, last tool, and last user/assistant text, then maps OpenRouter-style cache_write_tokens into cacheWrite; this is exactly the request/usage path implicated by the issue. (src/llm/providers/openai-completions.ts:810, 4fc504d321b6)
    • Docs confirm OpenRouter prompt-cache support but not this regression: The prompt-caching docs describe OpenRouter Anthropic cache-control injection and cacheRetention/contextPruning behavior, but do not explain a current-main fix for cacheWrite staying at zero after v2026.6.10. Public docs: docs/reference/prompt-caching.md. (docs/reference/prompt-caching.md:126, 4fc504d321b6)
    • Related work is overlapping, not resolving: GitHub search found this issue as the only exact OpenRouter Anthropic cacheWrite zero report; open related work on OpenRouter session_id forwarding and long-TTL eligibility may matter, but neither is merged nor proven to fix this regression.
    • History provenance sampled: Current shallow blame routes the active cache/provider files through bead84f, while merged OpenRouter cache PRs 60761 and 77001 show earlier OpenRouter prompt-cache ownership by vincentkoc. (src/llm/providers/stream-wrappers/proxy.ts:134, bead84f0ee6e)

    Likely related people:

    • zhang-guiping: Current shallow blame attributes the active OpenRouter wrapper, OpenAI-compatible cache-control path, and OpenRouter stream wrapper snapshot to this author in bead84f. (role: recent area contributor; confidence: medium; commits: bead84f0ee6e; files: src/llm/providers/stream-wrappers/proxy.ts, src/llm/providers/openai-completions.ts, extensions/openrouter/stream.ts)
    • Ayaan Zaidi: The same current-main cache/provider snapshot was committed by Ayaan Zaidi, making them a likely routing candidate for recent main-line context. (role: recent committer; confidence: medium; commits: bead84f0ee6e; files: src/llm/providers/stream-wrappers/proxy.ts, src/llm/providers/openai-completions.ts, extensions/openrouter/stream.ts)
    • vincentkoc: Merged PR history shows prior OpenRouter prompt-cache marker gating and opt-in response cache work on the same provider/runtime seam. (role: adjacent OpenRouter cache contributor; confidence: high; commits: 0a3211df2d17, 34b3471f8553; files: extensions/openrouter/index.ts, src/agents/pi-embedded-runner/extra-params.ts, src/agents/pi-embedded-runner/proxy-stream-wrappers.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. FriendofTob commented on Jun 26, 2026

    @FriendofTob
    Author

    Correction to timeline

    After closer inspection of the trajectory data, the regression is immediate upon upgrade, not delayed.

    The session spans both before and after the upgrade:

    Time (UTC) Event
    2026-06-24T16:19:44 Last cacheRead=75k in pre-upgrade session
    2026-06-24T16:24:11 Last cacheWrite=0k, cacheRead=75k
    2026-06-25T00:30 v2026.6.10 installed, gateway restarted
    2026-06-25T00:31:54 First turn in same session post-restart: cW=0, cR=0
    2026-06-25T00:32:07 cW=0, cR=35k (system prompt only)
    2026-06-25T00:33:29 cW=0, cR=0

    Every turn from onward: . The regression is immediate and correlated directly with the gateway restart after the install.

    The original issue's claim that the first 6.10 session worked is incorrect — the earlier turns (13:59–16:24) were still running on the pre-upgrade gateway. The break happens the moment the upgraded gateway serves its first request.

  3. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    on Jun 26, 2026
  4. FriendofTob commented on Jun 26, 2026

    @FriendofTob
    Author

    Correction: metric clarification + accurate timeline + cost impact

    Apologies for the earlier inaccurate comment. Here is the verified picture.

    What the 140K actually was

    The pre-upgrade cache state was captured from the OpenClaw /status card at Jun 25 00:20 UTC:

    Tokens:  140,537 of 140,537
    Prompt:  362    (0.3%)
    Cached:  140,175 (99.7%)
    Cost:    $0.0443
    Model:   anthropic/claude-4.6-sonnet-20260217
    

    This is the session-level accumulated cached token count shown in /status — not a per-call lastCallUsage.cacheRead value. At 99.7% cache hit rate, the full conversation history was being cached and served on every call.

    Accurate timeline

    Time (UTC) Event
    Jun 25 00:20 /status shows Cached=140,175 (99.7%) — working correctly
    Jun 25 02:20 v2026.6.10 installed via gateway restart (SSH root)
    Jun 25 02:20+ All subsequent sessions: Cached ~32–35K regardless of session length

    What changed

    Before upgrade: Conversation history was being added to the prompt cache incrementally. Session cached tokens grew as the conversation grew, reaching 140K+ at 99.7% hit rate.

    After upgrade (immediate): cacheWrite = 0 on every call. Only the static system prompt (~32–35K) is cached. Conversation history is never written to cache.

    Cost impact

    Using the same 140,537-token session as a baseline (Sonnet input: ~$3/MTok, cached: ~$0.30/MTok):

    Cached tokens Uncached tokens Estimated cost
    Before (v2026.5.3-1) 140,175 362 $0.044
    After (v2026.6.10) ~35,000 ~105,537 ~$0.327

    ~7.4x cost increase (~640% more expensive) for an identical session. This compounds badly on long sessions — the longer the conversation, the more history is paying full uncached price on every turn.

    Config (unchanged across upgrade)

    "cacheRetention": "long",
    "contextPruning": { "mode": "cache-ttl", "ttl": "1h" }

    Config was not changed. Regression is entirely in v2026.6.10.

  5. openclaw-barnacle commented on Jul 11, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  6. openclaw-barnacle commented on Jul 19, 2026

    @openclaw-barnacle

    Closing due to inactivity.
    If this is still an issue, please retry on the latest OpenClaw release and share updated details.
    If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.

  7. locked as resolved and limited conversation to collaborators on Sep 11, 2026
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

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions