[GH-ISSUE #4144] [Engine] Mac: conversation cache never parks (no macOS RAM reading; Metal checkpoints fail validation) #1815

Open
opened 2026-11-04 01:54:18 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @swhite1122 on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4144

Area

Engine

Desktop app, Terminal or source?

Source (git clone, ./setup.sh, engine built by setup)

What happened

On the Mac, the conversation cache never parks anything, so an agent that alternates conversations re-reads its whole prompt on every switch.

Client: Codex CLI 0.164 over /v1/responses. With Codex's memories feature on, Codex runs its memory-consolidation thread alongside the main task, and the two take turns on the server. One short lookup took 14 minutes: 16 requests, 862 s, of which 661 s were full prompt reads of 16K-36K tokens. The last two requests, after the second thread finished, reused the cache and read in 2-3 s.

The same Codex setup on Windows (RTX 5080, engine 0.1.50) parks fine: conversation cache: parked 445 tokens in 68.8 ms; parked=2 ....

There are two gaps on Metal.

1. sample_host_memory() has no macOS branch. In src/core/conversation_memory.cpp it only handles _WIN32 and __linux__ and returns {} otherwise, so every Mac start prints:

strata generate: memory guard: the available RAM cannot be read; parking and session save/restore are refused
strata serve: conversation cache off: not enough free RAM to park conversations (--conversation-cache-mib N asks for one anyway)

I tried a local branch using the same rule as arena_avail() in metal/src/engine/arena_budget.h:

#elif defined(__APPLE__)
    vm_statistics64_data_t vs{};
    mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
    if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) &vs, &count) != KERN_SUCCESS) return {};
    uint64_t total = 0;
    size_t len = sizeof total;
    if (sysctlbyname("hw.memsize", &total, &len, nullptr, 0) != 0) return {};
    const uint64_t pg = (uint64_t) vm_page_size;
    const uint64_t available = ((uint64_t) vs.free_count + vs.purgeable_count) * pg +
                               std::min<uint64_t>(((uint64_t) vs.inactive_count + vs.speculative_count) * pg,
                                                  (uint64_t) vs.external_page_count * pg);
    return combine(available, total, CgroupScan{}, memory_limit_bytes());

With that, the guard reads the RAM and the cache is sized:

strata generate: memory guard: limit 48.0 GiB (source: meminfo), current 14.1 GiB, reclaimable cache credited 0.0 GiB; available 33.9 GiB (MemAvailable 33.9 GiB), floor 2560 MiB
strata serve: conversation cache sized from the free RAM: 4864 MiB for up to 4 parked conversations, so an agent's next turn reuses its prompt (--conversation-cache-mib N sets it, 0 turns it off)

2. Then every park fails validation. Two alternating conversations (12K and 7K tokens, three turns each) gave, five times:

strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload)

conversation_checkpoint_validate() (src/core/conversation_state.cpp) checks gdn, ple, tails, dead and block_pos against the SessionState layout, but under STRATA_GPU_METAL conversation_checkpoint_save() goes to window_checkpoint_save(), whose running state comes from the Metal decode window and does not match those sizes. I did not force it past the check, because a mismatched restore would silently corrupt answers, and I reverted the local change. Both gaps are still in main as of 4b9e05a.

Expected: on a Mac, conversations park and restore as they do on Windows and Linux, so an agent's alternating threads keep their prompt cache.

Smallest steps or command that reproduce it

  1. Start the server on a Mac (any model; mine streams experts from the SSD).
  2. Send two different conversations in turn, A, B, A, B, each a few thousand tokens. Every request reads its full prompt again, and the log shows conversation cache off.
  3. With the macOS branch above added, the same run logs skip parking (conversation snapshot: invalid checkpoint running-state payload) on every switch.

Reproduction status

Reproduces every time

Strata version

Source v0.2.3.1 (commit 7ddc17a), Metal engine 0.1.48. Both code paths above are unchanged in main (4b9e05a).

Graphics card, memory and system

MacBook Pro, Apple M5 Pro, 48 GB unified memory, macOS 26.7.1.

Model, size and settings

Qwen3.8-Flash-Next ISTA IQ3_XXS, experts streamed from the SSD (STRATA_METAL_ARENA_GB=20, the experts' copy), --spec 2 --suffix-draft 0 --prefill auto, context 262,144, vision on (GPU reader).

Logs

The log lines are quoted above.

Originally created by @swhite1122 on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4144 ### Area Engine ### Desktop app, Terminal or source? Source (git clone, `./setup.sh`, engine built by setup) ### What happened On the Mac, the conversation cache never parks anything, so an agent that alternates conversations re-reads its whole prompt on every switch. Client: Codex CLI 0.164 over `/v1/responses`. With Codex's memories feature on, Codex runs its memory-consolidation thread alongside the main task, and the two take turns on the server. One short lookup took 14 minutes: 16 requests, 862 s, of which 661 s were full prompt reads of 16K-36K tokens. The last two requests, after the second thread finished, reused the cache and read in 2-3 s. The same Codex setup on Windows (RTX 5080, engine 0.1.50) parks fine: `conversation cache: parked 445 tokens in 68.8 ms; parked=2 ...`. There are two gaps on Metal. **1. `sample_host_memory()` has no macOS branch.** In `src/core/conversation_memory.cpp` it only handles `_WIN32` and `__linux__` and returns `{}` otherwise, so every Mac start prints: ``` strata generate: memory guard: the available RAM cannot be read; parking and session save/restore are refused strata serve: conversation cache off: not enough free RAM to park conversations (--conversation-cache-mib N asks for one anyway) ``` I tried a local branch using the same rule as `arena_avail()` in `metal/src/engine/arena_budget.h`: ```cpp #elif defined(__APPLE__) vm_statistics64_data_t vs{}; mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) &vs, &count) != KERN_SUCCESS) return {}; uint64_t total = 0; size_t len = sizeof total; if (sysctlbyname("hw.memsize", &total, &len, nullptr, 0) != 0) return {}; const uint64_t pg = (uint64_t) vm_page_size; const uint64_t available = ((uint64_t) vs.free_count + vs.purgeable_count) * pg + std::min<uint64_t>(((uint64_t) vs.inactive_count + vs.speculative_count) * pg, (uint64_t) vs.external_page_count * pg); return combine(available, total, CgroupScan{}, memory_limit_bytes()); ``` With that, the guard reads the RAM and the cache is sized: ``` strata generate: memory guard: limit 48.0 GiB (source: meminfo), current 14.1 GiB, reclaimable cache credited 0.0 GiB; available 33.9 GiB (MemAvailable 33.9 GiB), floor 2560 MiB strata serve: conversation cache sized from the free RAM: 4864 MiB for up to 4 parked conversations, so an agent's next turn reuses its prompt (--conversation-cache-mib N sets it, 0 turns it off) ``` **2. Then every park fails validation.** Two alternating conversations (12K and 7K tokens, three turns each) gave, five times: ``` strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload) ``` `conversation_checkpoint_validate()` (`src/core/conversation_state.cpp`) checks `gdn`, `ple`, `tails`, `dead` and `block_pos` against the `SessionState` layout, but under `STRATA_GPU_METAL` `conversation_checkpoint_save()` goes to `window_checkpoint_save()`, whose running state comes from the Metal decode window and does not match those sizes. I did not force it past the check, because a mismatched restore would silently corrupt answers, and I reverted the local change. Both gaps are still in `main` as of 4b9e05a. Expected: on a Mac, conversations park and restore as they do on Windows and Linux, so an agent's alternating threads keep their prompt cache. ### Smallest steps or command that reproduce it 1. Start the server on a Mac (any model; mine streams experts from the SSD). 2. Send two different conversations in turn, A, B, A, B, each a few thousand tokens. Every request reads its full prompt again, and the log shows `conversation cache off`. 3. With the macOS branch above added, the same run logs `skip parking (conversation snapshot: invalid checkpoint running-state payload)` on every switch. ### Reproduction status Reproduces every time ### Strata version Source v0.2.3.1 (commit 7ddc17a), Metal engine 0.1.48. Both code paths above are unchanged in `main` (4b9e05a). ### Graphics card, memory and system MacBook Pro, Apple M5 Pro, 48 GB unified memory, macOS 26.7.1. ### Model, size and settings Qwen3.8-Flash-Next ISTA IQ3_XXS, experts streamed from the SSD (`STRATA_METAL_ARENA_GB=20`, the experts' copy), `--spec 2 --suffix-draft 0 --prefill auto`, context 262,144, vision on (GPU reader). ### Logs The log lines are quoted above.
Author
Owner

@stalker1211 commented on GitHub (Oct 30, 2026):

Same here on Terminal 0.1.54 / engine 0.1.54-macos-arm64-metal (M5 Pro 48 GB, Q2_0, 128K, STRATA_METAL_STREAM=1). Claude Code does side requests for title / recap ~4-5K which invalidate the main conversation cache and re-reads 45–56K tokens.

--set memory-limit-mib=49152 gets past the RAM guard, and conversation-cache-min-tokens works as described:

strata serve: conversation cache: skip parking (5361 tokens, below the 10000 minimum; parked=0)
strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload)

The second line shows up for every large conversation (>10000 in my settings).

Workaround (for claude) is
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "1"
"awaySummaryEnabled": false

<!-- gh-comment-id:6531638452 --> @stalker1211 commented on GitHub (Oct 30, 2026): Same here on Terminal 0.1.54 / engine 0.1.54-macos-arm64-metal (M5 Pro 48 GB, Q2_0, 128K, STRATA_METAL_STREAM=1). Claude Code does side requests for title / recap ~4-5K which invalidate the main conversation cache and re-reads 45–56K tokens. --set memory-limit-mib=49152 gets past the RAM guard, and conversation-cache-min-tokens works as described: _strata serve: conversation cache: skip parking (5361 tokens, below the 10000 minimum; parked=0) strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload)_ The second line shows up for every large conversation (>10000 in my settings). Workaround (for claude) is "CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "1" "awaySummaryEnabled": false
Author
Owner

@hyspace commented on GitHub (Nov 2, 2026):

Confirming on a second Mac setup, with a source-level explanation that matches the issue text.

Environment: Strata Terminal 0.1.55, engine 0.1.55-macos-arm64-metal, Apple M5 Ultra 96 GB (Darwin 27.2), Qwen3.8-Flash-Next IQ3_S, --mtp --spec 2 --kv k8v4 --mmap-experts --max-context 262144 --conversation-cache-mib 8192, run as strata serve.

Workload: Hermes agent as the main chat, plus the Hindsight memory server (retain / consolidation) as a second client on the same engine. Same pattern as the Codex memory-consolidation thread in the description: two clients with different prompts take turns, and every switch re-reads the whole prompt (37-41K tokens for the main chat, about 15 s).

What the log says (every start, and after every request):

strata generate: memory guard: the available RAM cannot be read; parking and session save/restore are refused
strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload)

Controlled test (/v1/chat/completions, ~12K-token prompts, conversation A grows by one assistant reply plus one user turn, B is unrelated):

sequence A2 prompt tokens reused
A1, A2 (no B in between) 11,944 of 11,965
A1, B1, A2 0 of 11,970 (all re-read, 4.9 s)

Adding --memory-limit-mib 90000 --conversation-cache-min-free-mib 0 changes nothing: the "cannot be read" line still prints and the park still fails with the payload error. So the two gaps in the description are independent, and fixing only the first one is not enough.

(Note for anyone reproducing: a test where A2 only changes the last user sentence is not valid. The hybrid recurrent state can only resume at a checkpoint boundary, so it shows 0 reuse even when nothing is wrong.)

Source reading (not instrumented on our build, so no new measurements beyond #4730):

  • sample_host_memory() in src/core/conversation_memory.cpp has _WIN32 and __linux__ branches and #else return {}.
  • conversation_checkpoint_validate() compares gdn / ple / tails / dead / block_pos sizes with the CUDA layout. Window::checkpoint_save() writes the Metal ring (ts = 4 * 4 * 128 per layer) and ends with c.block_pos.clear(). Under STRATA_GPU_METAL the normal checkpoint restore returns before the validator, but the park path (view_validate) does not.

Things we tried that do not work around it:

  • --parallel 2 ("parallel": 2, 3.85 GB per slot on Metal): a request that arrives alone takes the solo path in generate_batched (alone and left > 1) and never looks at slot prefixes, so sequential alternation still reuses 0. Overlapping requests do use slot prefixes (one reused 12,137 tokens), but we also saw strata batch: restoring slot 0 failed (metal window: a slot copy with a fold pending); reading the prompt twice.
  • Disk sessions (--slot-save-path): not tested, but from the source they go through the same checkpoint save/restore code, so they probably hit the same validation.

PR #3231 looks like the right fix for both gaps. It is currently marked as conflicting with main, so the 0.1.55 engine does not include it.

<!-- gh-comment-id:6571652002 --> @hyspace commented on GitHub (Nov 2, 2026): Confirming on a second Mac setup, with a source-level explanation that matches the issue text. **Environment:** Strata Terminal 0.1.55, engine `0.1.55-macos-arm64-metal`, Apple M5 Ultra 96 GB (Darwin 27.2), Qwen3.8-Flash-Next IQ3_S, `--mtp --spec 2 --kv k8v4 --mmap-experts --max-context 262144 --conversation-cache-mib 8192`, run as `strata serve`. **Workload:** Hermes agent as the main chat, plus the Hindsight memory server (retain / consolidation) as a second client on the same engine. Same pattern as the Codex memory-consolidation thread in the description: two clients with different prompts take turns, and every switch re-reads the whole prompt (37-41K tokens for the main chat, about 15 s). **What the log says** (every start, and after every request): ``` strata generate: memory guard: the available RAM cannot be read; parking and session save/restore are refused strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload) ``` **Controlled test** (`/v1/chat/completions`, ~12K-token prompts, conversation A grows by one assistant reply plus one user turn, B is unrelated): | sequence | A2 prompt tokens reused | |---|---| | A1, A2 (no B in between) | 11,944 of 11,965 | | A1, B1, A2 | 0 of 11,970 (all re-read, 4.9 s) | Adding `--memory-limit-mib 90000 --conversation-cache-min-free-mib 0` changes nothing: the "cannot be read" line still prints and the park still fails with the payload error. So the two gaps in the description are independent, and fixing only the first one is not enough. (Note for anyone reproducing: a test where A2 only changes the last user sentence is not valid. The hybrid recurrent state can only resume at a checkpoint boundary, so it shows 0 reuse even when nothing is wrong.) **Source reading (not instrumented on our build, so no new measurements beyond #4730):** - `sample_host_memory()` in `src/core/conversation_memory.cpp` has `_WIN32` and `__linux__` branches and `#else return {}`. - `conversation_checkpoint_validate()` compares `gdn / ple / tails / dead / block_pos` sizes with the CUDA layout. `Window::checkpoint_save()` writes the Metal ring (`ts = 4 * 4 * 128` per layer) and ends with `c.block_pos.clear()`. Under `STRATA_GPU_METAL` the normal checkpoint restore returns before the validator, but the park path (`view_validate`) does not. **Things we tried that do not work around it:** - `--parallel 2` (`"parallel": 2`, 3.85 GB per slot on Metal): a request that arrives alone takes the solo path in `generate_batched` (`alone and left > 1`) and never looks at slot prefixes, so sequential alternation still reuses 0. Overlapping requests do use slot prefixes (one reused 12,137 tokens), but we also saw `strata batch: restoring slot 0 failed (metal window: a slot copy with a fold pending); reading the prompt` twice. - Disk sessions (`--slot-save-path`): not tested, but from the source they go through the same checkpoint save/restore code, so they probably hit the same validation. PR #3231 looks like the right fix for both gaps. It is currently marked as conflicting with `main`, so the 0.1.55 engine does not include it.
Author
Owner

@hyspace commented on GitHub (Nov 3, 2026):

Follow-up and a correction to my comment above: I said PR #3231 looked like the fix and that the engine did not include it yet. I had not checked main, which already had the maintainer's fix in d01b1817 ("Metal: conversations park and restore (#4730, #4144)"). That fix shipped in 0.2.10 / engine 0.1.56.

Verified on engine 0.1.56-macos-arm64-metal (same machine and flags as above: M5 Ultra 96 GB, Qwen3.8-Flash-Next IQ3_S, --mtp --spec 2 --kv k8v4 --mmap-experts --conversation-cache-mib 8192):

  • The memory guard reads the RAM now: memory guard: limit 96.0 GiB (source: meminfo), current 27.2 GiB, ... available 68.8 GiB
  • The same A1, B1, A2 test (each ~12K tokens, A grows by one turn):
engine A2 reused after B A2 prompt read
0.1.55 0 of 11,970 4.9 s
0.1.56 11,949 of 11,970 0.16 s
strata serve: conversation cache: parked 11949 tokens in 24.4 ms; parked=2 bytes=955679740 evictions=0 snapshot_bytes=418662108 reused_kv_bytes=0
strata serve: conversation cache: restored 11949 tokens (live) in 20.3 ms; parked=2 bytes=1138717312

No invalid checkpoint running-state payload lines any more. Each ~12K-token snapshot took 420-540 MB of RAM. From our side this issue looks resolved by 0.1.56.

<!-- gh-comment-id:6594740926 --> @hyspace commented on GitHub (Nov 3, 2026): Follow-up and a correction to my comment above: I said PR #3231 looked like the fix and that the engine did not include it yet. I had not checked `main`, which already had the maintainer's fix in d01b1817 ("Metal: conversations park and restore (#4730, #4144)"). That fix shipped in 0.2.10 / engine 0.1.56. **Verified on engine `0.1.56-macos-arm64-metal`** (same machine and flags as above: M5 Ultra 96 GB, Qwen3.8-Flash-Next IQ3_S, `--mtp --spec 2 --kv k8v4 --mmap-experts --conversation-cache-mib 8192`): - The memory guard reads the RAM now: `memory guard: limit 96.0 GiB (source: meminfo), current 27.2 GiB, ... available 68.8 GiB` - The same A1, B1, A2 test (each ~12K tokens, A grows by one turn): | engine | A2 reused after B | A2 prompt read | |---|---|---| | 0.1.55 | 0 of 11,970 | 4.9 s | | 0.1.56 | 11,949 of 11,970 | 0.16 s | ``` strata serve: conversation cache: parked 11949 tokens in 24.4 ms; parked=2 bytes=955679740 evictions=0 snapshot_bytes=418662108 reused_kv_bytes=0 strata serve: conversation cache: restored 11949 tokens (live) in 20.3 ms; parked=2 bytes=1138717312 ``` No `invalid checkpoint running-state payload` lines any more. Each ~12K-token snapshot took 420-540 MB of RAM. From our side this issue looks resolved by 0.1.56.
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#1815
No description provided.