[PR #7926] [MERGED] fix(claude-subscription): drop the extra history cache marker; keep Claude Code's marked turn stable #8007

Closed
opened 2026-10-24 04:09:36 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7926
Author: @stonebystone
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/claude-sub-cache-marker-limit


📝 Commits (2)

  • 9aa8a22 fix(claude-subscription): drop the extra history cache marker; keep Claude Code's marked turn stable
  • fa90692 Merge branch 'staging' into fix/claude-sub-cache-marker-limit

📊 Changes

4 files changed (+55 additions, -104 deletions)

View changed files

📝 docs/connections/subscription-clis.md (+0 -2)
📝 packages/server/src/services/llm/providers/claude-subscription.provider.ts (+4 -13)
📝 packages/server/src/services/llm/providers/claude-subscription/jsonl-entries.ts (+21 -23)
📝 scripts/regressions/claude-subscription-cache.regression.ts (+30 -66)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7925

Note

Whoops: I introduced this bug in #7866, and this PR fixes it. My live tests for #7866 ran from a shell inside the Claude desktop app. That environment changes how Claude Code builds its requests, and there the broken request is accepted. This time the fix was tested with those variables removed, the way Marinara's server runs, and clicked through in a test server.

Why this change

#7866 broke Claude (Subscription) for anyone with the 1-hour cache on. Every request fails with "A maximum of 4 blocks with cache_control may be provided. Found 5." Claude Code already places four cache markers itself (two on the system prompt, two on the last two messages), so the extra one #7866 added is one too many.

It also turns out the extra marker was never needed. Claude Code already marks the last history entry (the previous reply). That entry didn't match the next request only because the xml wrap appends </chat_history> to it, and the tag moves to the next reply every turn.

What changed

  • Reverted #7866's history marker: assembleEntries no longer adds cache_control, and the provider no longer passes one. The debug line returns to its earlier form.
  • splitHistoryForResume (claude-subscription jsonl-entries.ts): when the last history entry ends with the xml </chat_history> close, the tag moves to the start of the current turn. The model sees the same text in the same order. The entry Claude Code marks is now identical in the next request, so the history is read from cache.
  • docs/connections/subscription-clis.md: removed the paragraph #7866 added, since history reuse no longer depends on the 1-hour setting. #7867 (its translation follow-up) is no longer needed.
  • claude-subscription-cache regression: checks the tag move, that unwrapped history is left alone, and that the resumed history carries no cache_control.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Agent-run checks (for the reviewer, not ticked above):

  • pnpm check: passes (one existing client lint warning, unrelated).

  • claude-subscription-cache regression passes, and fails with the tag move removed. The other five Claude regressions pass.

  • The failing prompt from a real chat (97 messages, Opus 5.5, 1-hour cache on) fails with "Found 5" on staging and succeeds with this branch, both run with the desktop app's environment variables removed.

  • Live run against a real subscription, server-like environment (Opus 5.5, 26k-token prompt, xml-style </chat_history> on the last history entry):

    Turn Cache read Cache write
    1 0 52,085
    2 0 26,043
    3 25,976 103
    4 26,012 96
    5 52,252 103

    The same run with the 1-hour cache on gave the same pattern. History reads start on the third turn. The first turn writes roughly twice the prompt and the second reads nothing; I haven't traced why.

Manual verification notes

  • Manually verify in the app: on a Claude (Subscription) connection with the 1-hour cache on, send a message in a chat with several earlier replies. It should no longer fail with "A maximum of 4 blocks with cache_control".
  • Manually verify that from the third message on, the reply's usage shows most of the prompt read from cache (tokensCachedPrompt close to the prompt size), with the 1-hour cache on and off.
  • Manually verify Peek Prompt still shows </chat_history> where it did before (this change only affects the request sent to Claude Code).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

cc @SpicyMarinara

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved resumed Claude conversations by preserving chat-history boundaries correctly when continuing a conversation.
    • Removed extended cache markers from resumed conversation history, providing more consistent prompt handling.
    • Resume behavior now remains unchanged for conversations without a recognized history marker.
  • Documentation

    • Updated subscription CLI documentation to retain current cache duration, override, and logging details while removing outdated explanations of extended caching and plan usage.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7926 **Author:** [@stonebystone](https://github.com/stonebystone) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/claude-sub-cache-marker-limit` --- ### 📝 Commits (2) - [`9aa8a22`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9aa8a227e55b3c51be9b98dbc3e24b82f6772fd8) fix(claude-subscription): drop the extra history cache marker; keep Claude Code's marked turn stable - [`fa90692`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fa906924bafe3675b5f7793bee2680ee9b62ac65) Merge branch 'staging' into fix/claude-sub-cache-marker-limit ### 📊 Changes **4 files changed** (+55 additions, -104 deletions) <details> <summary>View changed files</summary> 📝 `docs/connections/subscription-clis.md` (+0 -2) 📝 `packages/server/src/services/llm/providers/claude-subscription.provider.ts` (+4 -13) 📝 `packages/server/src/services/llm/providers/claude-subscription/jsonl-entries.ts` (+21 -23) 📝 `scripts/regressions/claude-subscription-cache.regression.ts` (+30 -66) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #7925 > [!NOTE] > Whoops: I introduced this bug in #7866, and this PR fixes it. My live tests for #7866 ran from a shell inside the Claude desktop app. That environment changes how Claude Code builds its requests, and there the broken request is accepted. This time the fix was tested with those variables removed, the way Marinara's server runs, and clicked through in a test server. ## Why this change #7866 broke Claude (Subscription) for anyone with the 1-hour cache on. Every request fails with "A maximum of 4 blocks with cache_control may be provided. Found 5." Claude Code already places four cache markers itself (two on the system prompt, two on the last two messages), so the extra one #7866 added is one too many. It also turns out the extra marker was never needed. Claude Code already marks the last history entry (the previous reply). That entry didn't match the next request only because the xml wrap appends `</chat_history>` to it, and the tag moves to the next reply every turn. ## What changed - Reverted #7866's history marker: `assembleEntries` no longer adds `cache_control`, and the provider no longer passes one. The debug line returns to its earlier form. - `splitHistoryForResume` (claude-subscription `jsonl-entries.ts`): when the last history entry ends with the xml `</chat_history>` close, the tag moves to the start of the current turn. The model sees the same text in the same order. The entry Claude Code marks is now identical in the next request, so the history is read from cache. - `docs/connections/subscription-clis.md`: removed the paragraph #7866 added, since history reuse no longer depends on the 1-hour setting. #7867 (its translation follow-up) is no longer needed. - `claude-subscription-cache` regression: checks the tag move, that unwrapped history is left alone, and that the resumed history carries no `cache_control`. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` Agent-run checks (for the reviewer, not ticked above): - `pnpm check`: passes (one existing client lint warning, unrelated). - `claude-subscription-cache` regression passes, and fails with the tag move removed. The other five Claude regressions pass. - The failing prompt from a real chat (97 messages, Opus 5.5, 1-hour cache on) fails with "Found 5" on staging and succeeds with this branch, both run with the desktop app's environment variables removed. - Live run against a real subscription, server-like environment (Opus 5.5, 26k-token prompt, xml-style `</chat_history>` on the last history entry): | Turn | Cache read | Cache write | | --- | --- | --- | | 1 | 0 | 52,085 | | 2 | 0 | 26,043 | | 3 | 25,976 | 103 | | 4 | 26,012 | 96 | | 5 | 52,252 | 103 | The same run with the 1-hour cache on gave the same pattern. History reads start on the third turn. The first turn writes roughly twice the prompt and the second reads nothing; I haven't traced why. ### Manual verification notes - Manually verify in the app: on a Claude (Subscription) connection with the 1-hour cache on, send a message in a chat with several earlier replies. It should no longer fail with "A maximum of 4 blocks with cache_control". - Manually verify that from the third message on, the reply's usage shows most of the prompt read from cache (`tokensCachedPrompt` close to the prompt size), with the 1-hour cache on and off. - Manually verify Peek Prompt still shows `</chat_history>` where it did before (this change only affects the request sent to Claude Code). ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) cc @SpicyMarinara 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **Bug Fixes** - Improved resumed Claude conversations by preserving chat-history boundaries correctly when continuing a conversation. - Removed extended cache markers from resumed conversation history, providing more consistent prompt handling. - Resume behavior now remains unchanged for conversations without a recognized history marker. - **Documentation** - Updated subscription CLI documentation to retain current cache duration, override, and logging details while removing outdated explanations of extended caching and plan usage. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:36 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8007
No description provided.