[GH-ISSUE #3847] macOS: conversation cache is always refused ("available RAM cannot be read") #1638

Closed
opened 2026-11-04 01:52:49 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @d4bk on GitHub (Oct 23, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3847

On macOS the engine refuses the conversation cache even when --conversation-cache-mib is set. Every start logs:

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)

Setup: engine 0.1.48 (5c8dd3225+metal, from the v0.2.3 feed), Apple M4 Pro with 64 GB, macOS 27.2. Qwen3.8-Flash-Next Q2_0 with the experts streamed (STRATA_METAL_STREAM=1, STRATA_METAL_ARENA_GB=16), --conversation-cache-mib 2048.

Cause, as far as I can see: src/core/conversation_memory.cpp reads the available memory from /proc/meminfo (Linux) or the Windows API. On macOS neither exists, so conversation_mem_available returns nothing and parking is refused. The Metal stream code reads the RAM fine in the same run: RAM 68.7 GB (35.4 GB available, 10.3 GB kept for macOS).

Effect: Mabja, a local agent OS I'm building, sends short background requests between the turns of a long conversation, so it pays the full prompt again on every turn. Here an 11k-token prompt took 50–68 s per call, where the conversation cache would restore it in about a second (your measurement in docs/RESEARCH_RUNS.md).

Suggestion: give conversation_memory.cpp the same macOS source the Metal arena budget already uses for "available".

Originally created by @d4bk on GitHub (Oct 23, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3847 On macOS the engine refuses the conversation cache even when `--conversation-cache-mib` is set. Every start logs: ``` 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) ``` **Setup:** engine 0.1.48 (`5c8dd3225+metal`, from the v0.2.3 feed), Apple M4 Pro with 64 GB, macOS 27.2. Qwen3.8-Flash-Next Q2_0 with the experts streamed (`STRATA_METAL_STREAM=1`, `STRATA_METAL_ARENA_GB=16`), `--conversation-cache-mib 2048`. **Cause, as far as I can see:** `src/core/conversation_memory.cpp` reads the available memory from `/proc/meminfo` (Linux) or the Windows API. On macOS neither exists, so `conversation_mem_available` returns nothing and parking is refused. The Metal stream code reads the RAM fine in the same run: `RAM 68.7 GB (35.4 GB available, 10.3 GB kept for macOS)`. **Effect:** Mabja, a local agent OS I'm building, sends short background requests between the turns of a long conversation, so it pays the full prompt again on every turn. Here an 11k-token prompt took 50–68 s per call, where the conversation cache would restore it in about a second (your measurement in `docs/RESEARCH_RUNS.md`). **Suggestion:** give `conversation_memory.cpp` the same macOS source the Metal arena budget already uses for "available".
bsakaguchi 2026-11-04 01:52:49 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 23, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6367308344 --> @github-actions[bot] commented on GitHub (Oct 23, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@d4bk commented on GitHub (Oct 23, 2026):

Update: on the same setup parking also fails for a second reason. After every request (130 times in one session) the engine logs strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload), with the experts streamed on Metal (STRATA_METAL_STREAM=1). So fixing the RAM reading alone may not be enough on macOS. Within one conversation reuse works (5024 of 5037 tokens, 0.7 s); any request in between resets it to 0. One more observation: a STOP sent while a long prompt is being read only takes effect at its end (17269 of 17276 read … (cancelled)). Is that by design?

<!-- gh-comment-id:6375721796 --> @d4bk commented on GitHub (Oct 23, 2026): Update: on the same setup parking also fails for a second reason. After every request (130 times in one session) the engine logs `strata serve: conversation cache: skip parking (conversation snapshot: invalid checkpoint running-state payload)`, with the experts streamed on Metal (`STRATA_METAL_STREAM=1`). So fixing the RAM reading alone may not be enough on macOS. Within one conversation reuse works (5024 of 5037 tokens, 0.7 s); any request in between resets it to 0. One more observation: a `STOP` sent while a long prompt is being read only takes effect at its end (`17269 of 17276 read … (cancelled)`). Is that by design?
Author
Owner

@fzql commented on GitHub (Oct 24, 2026):

Can confirm both the issue and the fix on macOS (tested on an M1 Ultra 64 GB).

In src/core/conversation_memory.cpp, implementing sample_host_memory() for __APPLE__ using mach_host_self() and sysctl(CTL_HW, HW_MEMSIZE) restores the memory telemetry:

#elif defined(__APPLE__)
    vm_size_t page_size = 0;
    mach_port_t host = mach_host_self();
    if (host_page_size(host, &page_size) != KERN_SUCCESS) return;
    vm_statistics64_data_t vm_stat;
    mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
    if (host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stat, &count) == KERN_SUCCESS) {
        uint64_t free_bytes = (uint64_t)(vm_stat.free_count + vm_stat.inactive_count) * page_size;
        int mib[2] = {CTL_HW, HW_MEMSIZE};
        uint64_t total_bytes = 0;
        size_t len = sizeof(total_bytes);
        if (sysctl(mib, 2, &total_bytes, &len, nullptr, 0) == 0 && total_bytes > 0) {
            std::lock_guard<std::mutex> lk(host_memory_mu);
            cached_host_memory.total_bytes = total_bytes;
            cached_host_memory.available_bytes = free_bytes;
            cached_host_memory.valid = true;
        }
    }

This is actively being addressed in PR #3541 and PR #3564. When combined with Metal KV state binding in Window::bind_session, conversation cache parking works end-to-end on macOS (tested with two concurrent sessions totaling 4.37 GB in RAM, cutting re-prefill stalls from 2.5 min down to 1.29 s).

<!-- gh-comment-id:6381360934 --> @fzql commented on GitHub (Oct 24, 2026): Can confirm both the issue and the fix on macOS (tested on an M1 Ultra 64 GB). In `src/core/conversation_memory.cpp`, implementing `sample_host_memory()` for `__APPLE__` using `mach_host_self()` and `sysctl(CTL_HW, HW_MEMSIZE)` restores the memory telemetry: ```cpp #elif defined(__APPLE__) vm_size_t page_size = 0; mach_port_t host = mach_host_self(); if (host_page_size(host, &page_size) != KERN_SUCCESS) return; vm_statistics64_data_t vm_stat; mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; if (host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stat, &count) == KERN_SUCCESS) { uint64_t free_bytes = (uint64_t)(vm_stat.free_count + vm_stat.inactive_count) * page_size; int mib[2] = {CTL_HW, HW_MEMSIZE}; uint64_t total_bytes = 0; size_t len = sizeof(total_bytes); if (sysctl(mib, 2, &total_bytes, &len, nullptr, 0) == 0 && total_bytes > 0) { std::lock_guard<std::mutex> lk(host_memory_mu); cached_host_memory.total_bytes = total_bytes; cached_host_memory.available_bytes = free_bytes; cached_host_memory.valid = true; } } ``` This is actively being addressed in PR #3541 and PR #3564. When combined with Metal KV state binding in `Window::bind_session`, conversation cache parking works end-to-end on macOS (tested with two concurrent sessions totaling 4.37 GB in RAM, cutting re-prefill stalls from 2.5 min down to 1.29 s).
Author
Owner

@github-actions[bot] commented on GitHub (Oct 29, 2026):

Closing this issue because it still did not follow the format after 5 days. That is housekeeping, not a rejection.

To bring it back: fix the title (area prefix) and the missing parts, then comment /reopen. A check runs and reopens it, or tells you what is still missing. See CONTRIBUTING.md.

<!-- gh-comment-id:6494800555 --> @github-actions[bot] commented on GitHub (Oct 29, 2026): Closing this issue because it still did not follow the format after 5 days. That is housekeeping, not a rejection. To bring it back: fix the title (area prefix) and the missing parts, then comment `/reopen`. A check runs and reopens it, or tells you what is still missing. See [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
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#1638
No description provided.