[PR #3231] [Engine] macOS: conversation cache parks and restores (Metal checkpoints, K/V description, memory guard) #4512

Open
opened 2026-11-07 15:36:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3231
Author: @mnott
Created: 10/19/2026
Status: 🔄 Open

Base: main ← Head: macos-conversation-cache


📝 Commits (6)

  • d3860a2 fix(metal): conversation checkpoints validate and park on Metal
  • 4efa6b8 fix(macos): memory guard reads available RAM on macOS
  • 92ff83e fix(metal): validate checkpoints against the Metal window sizes
  • b67c168 fix(metal): describe the window's K/V in the session's QsaStates for conversation snapshots
  • e993570 fix(metal): session fingerprint reads the MTP file the Metal engine loads
  • 1448109 fix(metal): session restore accepts the files this engine saves

📊 Changes

10 files changed (+244 additions, -35 deletions)

View changed files

📝 include/strata/core/conversation_file.hpp (+15 -0)
📝 metal/CMakeLists.txt (+7 -1)
📝 metal/src/engine/window.cpp (+63 -16)
➕ metal/tests/session_limits_test.cpp (+58 -0)
📝 src/core/conversation_file.cpp (+15 -0)
📝 src/core/conversation_file_test.cpp (+21 -0)
📝 src/core/conversation_memory.cpp (+18 -0)
📝 src/core/conversation_state.cpp (+37 -13)
📝 src/core/mtp.cpp (+3 -0)
📝 src/program/generate.cpp (+7 -5)

📄 Description

Rebased onto v0.2.6 (same six commits).

Problem and result

On macOS (Metal) the conversation cache never parks a conversation: v0.2.6 logs conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload) after every request, so two alternating agent conversations re-read their whole prompt on every turn. With this change Metal parks and restores conversations.

Measured on v0.2.6 vs this branch, Apple Silicon, 128 GB unified memory, Gyro-M TQ2_0, same server config (--conversation-cache-mib 12288 --conversation-cache-slots 4), three Anthropic-API requests: conversation A (18,012 prompt tokens), a different conversation B (3,995), then A again:

A B A again
v0.2.6 16.8 s 1.05 s 11.3 s (14,577 tokens read again; parking skipped)
this branch 17.8 s 1.12 s 0.95 s (restored 18005 tokens (checkpoint) in 24.2 ms, 7 tokens read)

Overview of our related macOS / Metal contributions: #4128.

Approach

  • Conversation checkpoints validate against the Metal window sizes and park/restore on Metal.
  • The window's K/V is described in the session's QsaStates for conversation snapshots.
  • The session fingerprint reads the MTP file the Metal engine loads; restore accepts the files this engine saves.
  • The memory guard reads available RAM on macOS.

Validation

Branch head 1448109465c3e06bbf2189eb37582ec23d13696d, six commits on v0.2.6.

Passed:

  • Build of strata on macOS.
  • Greedy, 80 tokens, Gyro-M: output token ids identical to v0.2.6.
  • Greedy decode, 256 tokens, 3 alternating runs: v0.2.6 63.36 / 62.47 / 63.43 tok/s, this branch 63.46 / 63.75 / 63.18 tok/s (+0.6 %).
  • Server-level park/restore as in the table above.
  • Agent workload, concurrent conversations on one server (Gyro-L TQ3_0, 40-task coding set per conversation, same flags): v0.2.6 skipped every park attempt (218 logged), each switch re-read 14-20k prompt tokens (12-17 s), wall 692-1081 s per run at 10.8-12.4 tok/s per stream; this branch parked every time (221 parked, 0 skipped), restores took ~11 ms, wall 238-380 s per run at 41-53 tok/s per stream with two conversations, and 280-408 s per run (~100-110 tok/s aggregate) with three. Pass rates unchanged (37-40 of 40 on both builds).

Failed:

  • none observed

Not run:

  • CUDA, HIP and SYCL (the fixes are in the Metal window and the macOS memory guard).

Limits

Measured with four conversation slots and a 12 GiB budget. Slot eviction was exercised (three concurrent conversations plus the shared prefix: 5 evictions, no errors); eviction under memory pressure was not.


🔄 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/Niko1221/Strata/pull/3231 **Author:** [@mnott](https://github.com/mnott) **Created:** 10/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `macos-conversation-cache` --- ### 📝 Commits (6) - [`d3860a2`](https://github.com/Niko1221/Strata/commit/d3860a2d89fd0ebe212da9be7ac18252ec6ce3d4) fix(metal): conversation checkpoints validate and park on Metal - [`4efa6b8`](https://github.com/Niko1221/Strata/commit/4efa6b8535e83155239aaa877e1eb3f9fce79118) fix(macos): memory guard reads available RAM on macOS - [`92ff83e`](https://github.com/Niko1221/Strata/commit/92ff83ee9fe99ca45406f5ca71d33d2f6ef127b5) fix(metal): validate checkpoints against the Metal window sizes - [`b67c168`](https://github.com/Niko1221/Strata/commit/b67c168482efe05ea467220387e4277370a0e150) fix(metal): describe the window's K/V in the session's QsaStates for conversation snapshots - [`e993570`](https://github.com/Niko1221/Strata/commit/e99357093cd78f505d4febfa42caf3ee4ca5390b) fix(metal): session fingerprint reads the MTP file the Metal engine loads - [`1448109`](https://github.com/Niko1221/Strata/commit/1448109465c3e06bbf2189eb37582ec23d13696d) fix(metal): session restore accepts the files this engine saves ### 📊 Changes **10 files changed** (+244 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/conversation_file.hpp` (+15 -0) 📝 `metal/CMakeLists.txt` (+7 -1) 📝 `metal/src/engine/window.cpp` (+63 -16) ➕ `metal/tests/session_limits_test.cpp` (+58 -0) 📝 `src/core/conversation_file.cpp` (+15 -0) 📝 `src/core/conversation_file_test.cpp` (+21 -0) 📝 `src/core/conversation_memory.cpp` (+18 -0) 📝 `src/core/conversation_state.cpp` (+37 -13) 📝 `src/core/mtp.cpp` (+3 -0) 📝 `src/program/generate.cpp` (+7 -5) </details> ### 📄 Description Rebased onto v0.2.6 (same six commits). ## Problem and result On macOS (Metal) the conversation cache never parks a conversation: v0.2.6 logs `conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload)` after every request, so two alternating agent conversations re-read their whole prompt on every turn. With this change Metal parks and restores conversations. Measured on v0.2.6 vs this branch, Apple Silicon, 128 GB unified memory, Gyro-M TQ2_0, same server config (`--conversation-cache-mib 12288 --conversation-cache-slots 4`), three Anthropic-API requests: conversation A (18,012 prompt tokens), a different conversation B (3,995), then A again: | | A | B | A again | |---|---|---|---| | v0.2.6 | 16.8 s | 1.05 s | 11.3 s (14,577 tokens read again; parking skipped) | | this branch | 17.8 s | 1.12 s | 0.95 s (`restored 18005 tokens (checkpoint) in 24.2 ms`, 7 tokens read) | ## Related discussion Overview of our related macOS / Metal contributions: #4128. ## Approach - Conversation checkpoints validate against the Metal window sizes and park/restore on Metal. - The window's K/V is described in the session's QsaStates for conversation snapshots. - The session fingerprint reads the MTP file the Metal engine loads; restore accepts the files this engine saves. - The memory guard reads available RAM on macOS. ## Validation Branch head `1448109465c3e06bbf2189eb37582ec23d13696d`, six commits on `v0.2.6`. **Passed:** - Build of `strata` on macOS. - Greedy, 80 tokens, Gyro-M: output token ids identical to `v0.2.6`. - Greedy decode, 256 tokens, 3 alternating runs: v0.2.6 63.36 / 62.47 / 63.43 tok/s, this branch 63.46 / 63.75 / 63.18 tok/s (+0.6 %). - Server-level park/restore as in the table above. - Agent workload, concurrent conversations on one server (Gyro-L TQ3_0, 40-task coding set per conversation, same flags): v0.2.6 skipped every park attempt (218 logged), each switch re-read 14-20k prompt tokens (12-17 s), wall 692-1081 s per run at 10.8-12.4 tok/s per stream; this branch parked every time (221 parked, 0 skipped), restores took ~11 ms, wall 238-380 s per run at 41-53 tok/s per stream with two conversations, and 280-408 s per run (~100-110 tok/s aggregate) with three. Pass rates unchanged (37-40 of 40 on both builds). **Failed:** - none observed **Not run:** - CUDA, HIP and SYCL (the fixes are in the Metal window and the macOS memory guard). ## Limits Measured with four conversation slots and a 12 GiB budget. Slot eviction was exercised (three concurrent conversations plus the shared prefix: 5 evictions, no errors); eviction under memory pressure was not. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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
Niko1221/Strata#4512
No description provided.