[GH-ISSUE #7925] [Issue]: Claude (Subscription) fails with "A maximum of 4 blocks with cache_control" when the 1-hour cache is on #4358

Closed
opened 2026-10-22 04:05:59 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @stonebystone on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7925

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Since #7866 merged, every Claude (Subscription) request with Extended token caching (1 hour) on fails with:

Claude (Subscription) request failed: Claude Code returned an error result: API Error: 400 A maximum of 4 blocks with cache_control may be provided. Found 5.

Expected behavior

Replies generate normally, and the previous turns' chat history is read from the prompt cache.

Actual behavior

The request is rejected. #7866 added one cache_control to the resumed chat history. When Marinara runs it, Claude Code already places four markers itself: two on the system prompt and two on the last two messages. The extra one makes five.

It passed testing because the live tests ran from inside the Claude desktop app. In that environment the same five-marker request is accepted (the desktop entrypoint is handled differently). A normal Marinara server environment gets the error.

Steps to reproduce

  1. Use a Claude (Subscription) connection with Prompt Caching → Extended token caching (1 hour) on, on current staging.
  2. Send a message in any chat with at least two earlier replies.
  3. The request fails with the error above.

Turning the 1-hour setting off avoids the error, because #7866 only adds the marker in that mode.

Environment

  • Marinara Engine version: 2.5.0 (staging @ d0e481913)
  • Install type: source
  • OS + version: Windows 11
  • Browser or app shell: browser

Additional context

  • Regression from #7866 (which closed #7865). The real cause of #7865 turned out to be different: Claude Code already marks the last history entry, but with xml wrapping </chat_history> is appended to that entry and moves every turn, so the marked entry never matches the next request.
  • Proposed fix in the linked PR: drop Marinara's extra marker, and move the </chat_history> close to the start of the current turn on the Claude (Subscription) resume path. Live test (Opus 5.5, server-like environment, 26k-token prompt): from the third turn on, each turn reads the whole history from cache and writes about 100 tokens, with the 1-hour cache on or off, and no errors.

cc @SpicyMarinara

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @stonebystone on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7925 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Since #7866 merged, every Claude (Subscription) request with **Extended token caching (1 hour)** on fails with: > Claude (Subscription) request failed: Claude Code returned an error result: API Error: 400 A maximum of 4 blocks with cache_control may be provided. Found 5. ## Expected behavior Replies generate normally, and the previous turns' chat history is read from the prompt cache. ## Actual behavior The request is rejected. #7866 added one `cache_control` to the resumed chat history. When Marinara runs it, Claude Code already places four markers itself: two on the system prompt and two on the last two messages. The extra one makes five. It passed testing because the live tests ran from inside the Claude desktop app. In that environment the same five-marker request is accepted (the desktop entrypoint is handled differently). A normal Marinara server environment gets the error. ## Steps to reproduce 1. Use a Claude (Subscription) connection with **Prompt Caching → Extended token caching (1 hour)** on, on current staging. 2. Send a message in any chat with at least two earlier replies. 3. The request fails with the error above. Turning the 1-hour setting off avoids the error, because #7866 only adds the marker in that mode. ## Environment - Marinara Engine version: 2.5.0 (staging @ d0e481913) - Install type: source - OS + version: Windows 11 - Browser or app shell: browser ## Additional context - Regression from #7866 (which closed #7865). The real cause of #7865 turned out to be different: Claude Code already marks the last history entry, but with xml wrapping `</chat_history>` is appended to that entry and moves every turn, so the marked entry never matches the next request. - Proposed fix in the linked PR: drop Marinara's extra marker, and move the `</chat_history>` close to the start of the current turn on the Claude (Subscription) resume path. Live test (Opus 5.5, server-like environment, 26k-token prompt): from the third turn on, each turn reads the whole history from cache and writes about 100 tokens, with the 1-hour cache on or off, and no errors. cc @SpicyMarinara ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-22 04:05:59 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Oct 21, 2026):

Thank you for the PR; it's merged. ;)

<!-- gh-comment-id:6312319631 --> @SpicyMarinara commented on GitHub (Oct 21, 2026): Thank you for the PR; it's merged. ;)
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#4358
No description provided.