[PR #2082] [CLOSED] fix: make conversation parking admission fail safely #3850

Closed
opened 2026-11-07 15:31:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2082
Author: @ivanov84
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: pr/parking-admission-fail-safe


📝 Commits (10+)

  • ae3e21c park: bound eviction by what is freeable, keep the K/V a refusal did not use, name the failure
  • 76d9a10 park: act on review - drop put_reuse's dead guard, free the probe's reservation on failure, strip the BOM
  • 4addb40 docs: record the measured e2e blocker (server on 8080, 0.1.40 engine, GPUs full)
  • ce4d820 docs: the header fixes do reach the SYCL build (shared include path, strata_resolve fallback)
  • ac96332 docs: record the reviewer's confirmed points and stated uncertainties, and show the new tests do not build without the patch
  • 08f2115 AGENTS.md: drop the BOM and two mojibake em-dashes, and space the new heading before it
  • 7c500a8 parking: move the eviction round into evict_for_admission() so the loop can be tested
  • 1805bce park: act on the second review of the eviction-round move - the reviewer found no behaviour change and five wording/test defects; each was checked against the code first. - doc: the 'hopeless' bullet claimed an immediate refusal; the helper samples first (conversation_memory.hpp:117-122), so it only decides what a refusal says. The claim that a refusal can print a shortfall measured before an eviction is refuted and removed: the helper re-samples after every eviction (:131) and refreshes short_by (:136); what is true is that freeable is a snapshot of the round that decided it could not win, and that arm evicts nothing. 'Measured output of the test' -> what the checks assert. 'both park copies share the named-cause failure lines' -> the four causes and ram_note() are CUDA-only; SYCL still prints its two generic lines (sycl/src/program/generate.cpp:7502, 7525). - test: the old-loop copy dropped its retained-K/V state (that loop reads neither evictable_bytes() nor reuse_, and evict_oldest() never touches it); the equivalence table now compares short_by and freeable as well, and is equal on all twelve cases that entered the loop; added a round against one unpinned plus one pinned entry. - header: the dead-for-ConversationCache !evict_oldest() bound is marked as the template's bound; dropped top-level const on the parameters. conversation_cache_test 4281 checks, memory test 32, ctest 43/43 (2 skipped, CPU-only), fresh build_tests_clean [131/131] with 0 errors, cl /Zs CL_EXIT=0, CUDA engine rebuilt and reports strata 0.1.42 with the same string table. Co-authored-by: openhands openhands@all-hands.dev
  • bf73014 build notes + pinned blob references - AGENTS.md: a bare cl/cmake --build without vcvars64 reports C1083 'cannot open include file: algorithm', which is a missing toolchain env, not a code error - the test and the doc now cite git show 3ae6a9ec:src/program/generate.cpp for the loop the equivalence table retypes; HEAD~1 stops naming the right blob as soon as this branch moves conversation_cache_test 4281 checks after the edit. Co-authored-by: openhands openhands@all-hands.dev
  • a7c28d6 park: record the end-to-end run the user made on this tree

📊 Changes

9 files changed (+1174 additions, -35 deletions)

View changed files

📝 AGENTS.md (+40 -0)
➕ LOCAL-PARKING-PATCH-0.1.43.md (+605 -0)
📝 include/strata/core/conversation_cache.hpp (+17 -0)
📝 include/strata/core/conversation_memory.hpp (+67 -0)
📝 src/core/conversation_cache_test.cpp (+277 -0)
📝 src/core/conversation_memory.cpp (+35 -0)
📝 src/core/conversation_memory_test.cpp (+32 -0)
📝 src/program/generate.cpp (+75 -28)
📝 sycl/src/program/generate.cpp (+26 -7)

📄 Description

Summary

This hardens conversation-cache admission and retained K/V reuse under memory pressure. On Windows the engine
runs out of the system commit limit rather than physical RAM, and the park path had no way to tell that it had
already given up, no way to see why an allocation failed, and it silently dropped the retained K/V whenever
admission said no.

The eviction round now lives in ConversationCache::evict_for_admission(), which makes the loop's decisions
testable for the first time; the tests assert the old and new loops against one cache state.

Changes

  • Stop eviction when it cannot make admission progress. The inline loop was bounded by slots() and called
    evict_oldest() unconditionally, so a request larger than the total freeable capacity evicted every parked
    conversation and still refused. evict_for_admission() checks the request against evictable_bytes() first
    and stops at the first round that stops making progress, reporting why (stalled, hopeless, freeable).
  • Avoid unnecessary eviction when no additional capacity is required. The retained K/V is already held, so it
    is subtracted before the admission need is computed; a park that needs no new capacity evicts nothing.
  • Preserve retained K/V reuse state when admission is declined. take_reuse() used to leave the buffers with
    the caller, so a declined park lost them and the next turn rebuilt them. They go back through put_reuse() on
    every early-return path.
  • Improve diagnostics. Allocation failures now name where they happened (at the capture, after the checkpoint split, after the full-model load) and the probe reports whether the machine is out of commit or
    out of address space. Refusal lines print both resources and the process' own commit rather than one number.
  • Regression coverage for admission and eviction edge cases, including a twelve-case table asserting the old
    and new loops agree everywhere they should and differ only in the hopeless case.

Validation

Built and run on Windows, MSVC + CUDA 12.8, sm_120:

cmake -G Ninja + fresh build dir         exit 0, 1 warning (upstream dequant.cpp C4456)
conversation_cache_test                  4286 checks passed
conversation_memory_test                 32 checks passed
conversation_split_failure_test          stages 1/2/3 allocation-failure cases preserved: 8/12/16
ctest                                    43/43 passed, 2 skipped (CPU-only build: expert_multi, isa_guard)
cl /Zs over the CUDA park path           exit 0
CUDA engine build                        exit 0, strata 0.1.43
git diff --check                         clean

String audit of the built engine: the textless allocation failed; skip parking is gone, and the named-cause and
admission lines are present.

End-to-end, against a real model on this machine — the user's production server running a build of this tree,
2026-10-11 23:42 to 2026-10-12 02:46, two RTX 5060 Ti with --layer-split auto, --max-context 262144,
--conversation-cache-mib 16384 --conversation-cache-slots 4 --conversation-cache-min-free-mib 4096. Counted
over that session's log:

park attempts: 216 (176 at >= 50k tokens, largest 232826 tokens)
refusals:      1 of 216
"allocation failed; skip parking": 0
restores: 130; 129 of the 216 parks reused retained K/V (up to 3.29 GiB in one park)
evict-to-admit rounds: 12 (11 evicted one conversation, one evicted two; largest admitted request 4006 MiB)
budget (make_room) refusals: 0; refusal arms seen: hopeless 1, stalled 0, short_by 0

The single refusal is the hopeless arm: the request was 3966 MiB against 2152 MiB freeable in total, and it
names both numbers instead of evicting a conversation that could not have paid for it. Parking continued normally
afterwards. The same workload on the unpatched 0.1.40.1 engine logged 293 skip parking lines — 203 of them the
bare textless allocation failed; skip parking and 90 the budget refusal ending in a static
or telemetry unavailable — out of 2772 attempts (291 refused, 10.5%). That build never ran an evict-to-admit
round at all: the loop that would have run does not exist in 0.1.40.

That run was built from the 0.1.42 base of this series; the rebase onto 0.1.43 changed no source of the patch, so
the runtime evidence is the same code. The binary was string-audited first: the textless failure line absent, the
named-cause and admission lines present.

Limitations

  • The stalled arm of evict_for_admission(), the bad_alloc probe, and the budget-refusal K/V hand-back are
    asserted only by the native tests. The run above produced no stalled round (evicting did return memory on this
    machine), no failed allocation, and no budget refusal, so those three paths are runtime-untested.
  • Windows-only validation. The SYCL copy of the park path was edited by hand and reviewed, but no oneAPI toolchain
    is installed here, so it is not compiled. The header changes do reach the SYCL build through the shared include
    path.
  • Multi-GPU runtime behavior beyond this one two-GPU WDDM data point is not covered.
  • The change does not reduce the system-commit cost of the resident expert arena, which is the underlying pressure
    on this machine; it makes admission stop early, keep what it already holds, and say why it declined.
  • Not every previously observed parking failure has a known cause. What is measured here is that these refusals
    now explain themselves.

Review focus

  • Retained K/V ownership on every early-return and exception path in the park body: it is taken with
    take_reuse() and must be handed back with put_reuse() on all of them.
  • The resource accounting used by admission: evictable_bytes() deliberately excludes the retained K/V and pinned
    entries, because evict_oldest() cannot free either. bytes() still charges both, which is correct for the
    cache budget and wrong for "what can I free right now".
  • The safety of the allocation diagnostic probe: it reserves, tries to commit, and must release the reservation on
    every path, including failure.
  • ConversationCache::clear() from #879 is upstream's, and it is consistent with this: it zeroes reuse_, and
    evictable_bytes() never counted it.

This PR was prepared by an AI agent (OpenHands) on behalf of the author. The agent's work was reviewed by two
independent review passes before the branch was pushed; the review notes and the answers to them are recorded in
LOCAL-PARKING-PATCH-0.1.43.md, which is included in the branch along with the repo-local AGENTS.md notes.
Happy to drop either file from the change if you would rather keep them out of the repository.


🔄 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/2082 **Author:** [@ivanov84](https://github.com/ivanov84) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/parking-admission-fail-safe` --- ### 📝 Commits (10+) - [`ae3e21c`](https://github.com/Niko1221/Strata/commit/ae3e21cd46d806dd36a0d11694ef9b377e110a65) park: bound eviction by what is freeable, keep the K/V a refusal did not use, name the failure - [`76d9a10`](https://github.com/Niko1221/Strata/commit/76d9a1082f11292facd94eee6e69ad1c26d836a0) park: act on review - drop put_reuse's dead guard, free the probe's reservation on failure, strip the BOM - [`4addb40`](https://github.com/Niko1221/Strata/commit/4addb4099449385c97e049a050f9d58c22573533) docs: record the measured e2e blocker (server on 8080, 0.1.40 engine, GPUs full) - [`ce4d820`](https://github.com/Niko1221/Strata/commit/ce4d82017e5467e642ccd3bb4fe36273295977e0) docs: the header fixes do reach the SYCL build (shared include path, strata_resolve fallback) - [`ac96332`](https://github.com/Niko1221/Strata/commit/ac96332a72385a40be79198ad619dd7f605e208a) docs: record the reviewer's confirmed points and stated uncertainties, and show the new tests do not build without the patch - [`08f2115`](https://github.com/Niko1221/Strata/commit/08f2115c9780018a22e1308f900520f70fd2461f) AGENTS.md: drop the BOM and two mojibake em-dashes, and space the new heading before it - [`7c500a8`](https://github.com/Niko1221/Strata/commit/7c500a8a1348609ba1952c560d7774d4c967dc54) parking: move the eviction round into evict_for_admission() so the loop can be tested - [`1805bce`](https://github.com/Niko1221/Strata/commit/1805bcedef9bddf9d300f9833ff7b583748080d2) park: act on the second review of the eviction-round move - the reviewer found no behaviour change and five wording/test defects; each was checked against the code first. - doc: the 'hopeless' bullet claimed an immediate refusal; the helper samples first (conversation_memory.hpp:117-122), so it only decides what a refusal says. The claim that a refusal can print a shortfall measured before an eviction is refuted and removed: the helper re-samples after every eviction (:131) and refreshes short_by (:136); what is true is that freeable is a snapshot of the round that decided it could not win, and that arm evicts nothing. 'Measured output of the test' -> what the checks assert. 'both park copies share the named-cause failure lines' -> the four causes and ram_note() are CUDA-only; SYCL still prints its two generic lines (sycl/src/program/generate.cpp:7502, 7525). - test: the old-loop copy dropped its retained-K/V state (that loop reads neither evictable_bytes() nor reuse_, and evict_oldest() never touches it); the equivalence table now compares short_by and freeable as well, and is equal on all twelve cases that entered the loop; added a round against one unpinned plus one pinned entry. - header: the dead-for-ConversationCache !evict_oldest() bound is marked as the template's bound; dropped top-level const on the parameters. conversation_cache_test 4281 checks, memory test 32, ctest 43/43 (2 skipped, CPU-only), fresh build_tests_clean [131/131] with 0 errors, cl /Zs CL_EXIT=0, CUDA engine rebuilt and reports strata 0.1.42 with the same string table. Co-authored-by: openhands <openhands@all-hands.dev> - [`bf73014`](https://github.com/Niko1221/Strata/commit/bf730147db05fa13fe1e625b6faf3cd94171b016) build notes + pinned blob references - AGENTS.md: a bare cl/cmake --build without vcvars64 reports C1083 'cannot open include file: algorithm', which is a missing toolchain env, not a code error - the test and the doc now cite git show 3ae6a9ec:src/program/generate.cpp for the loop the equivalence table retypes; HEAD~1 stops naming the right blob as soon as this branch moves conversation_cache_test 4281 checks after the edit. Co-authored-by: openhands <openhands@all-hands.dev> - [`a7c28d6`](https://github.com/Niko1221/Strata/commit/a7c28d6b539eea7c14b73467ce783ca903e1e85d) park: record the end-to-end run the user made on this tree ### 📊 Changes **9 files changed** (+1174 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `AGENTS.md` (+40 -0) ➕ `LOCAL-PARKING-PATCH-0.1.43.md` (+605 -0) 📝 `include/strata/core/conversation_cache.hpp` (+17 -0) 📝 `include/strata/core/conversation_memory.hpp` (+67 -0) 📝 `src/core/conversation_cache_test.cpp` (+277 -0) 📝 `src/core/conversation_memory.cpp` (+35 -0) 📝 `src/core/conversation_memory_test.cpp` (+32 -0) 📝 `src/program/generate.cpp` (+75 -28) 📝 `sycl/src/program/generate.cpp` (+26 -7) </details> ### 📄 Description ## Summary This hardens conversation-cache admission and retained K/V reuse under memory pressure. On Windows the engine runs out of the *system commit* limit rather than physical RAM, and the park path had no way to tell that it had already given up, no way to see why an allocation failed, and it silently dropped the retained K/V whenever admission said no. The eviction round now lives in `ConversationCache::evict_for_admission()`, which makes the loop's decisions testable for the first time; the tests assert the old and new loops against one cache state. ## Changes - **Stop eviction when it cannot make admission progress.** The inline loop was bounded by `slots()` and called `evict_oldest()` unconditionally, so a request larger than the total freeable capacity evicted every parked conversation and still refused. `evict_for_admission()` checks the request against `evictable_bytes()` first and stops at the first round that stops making progress, reporting why (`stalled`, `hopeless`, `freeable`). - **Avoid unnecessary eviction when no additional capacity is required.** The retained K/V is already held, so it is subtracted before the admission need is computed; a park that needs no new capacity evicts nothing. - **Preserve retained K/V reuse state when admission is declined.** `take_reuse()` used to leave the buffers with the caller, so a declined park lost them and the next turn rebuilt them. They go back through `put_reuse()` on every early-return path. - **Improve diagnostics.** Allocation failures now name where they happened (`at the capture`, `after the checkpoint split`, `after the full-model load`) and the probe reports whether the machine is out of commit or out of address space. Refusal lines print both resources and the process' own commit rather than one number. - **Regression coverage** for admission and eviction edge cases, including a twelve-case table asserting the old and new loops agree everywhere they should and differ only in the hopeless case. ## Validation Built and run on Windows, MSVC + CUDA 12.8, sm_120: ``` cmake -G Ninja + fresh build dir exit 0, 1 warning (upstream dequant.cpp C4456) conversation_cache_test 4286 checks passed conversation_memory_test 32 checks passed conversation_split_failure_test stages 1/2/3 allocation-failure cases preserved: 8/12/16 ctest 43/43 passed, 2 skipped (CPU-only build: expert_multi, isa_guard) cl /Zs over the CUDA park path exit 0 CUDA engine build exit 0, strata 0.1.43 git diff --check clean ``` String audit of the built engine: the textless `allocation failed; skip parking` is gone, and the named-cause and admission lines are present. End-to-end, against a real model on this machine — the user's production server running a build of this tree, 2026-10-11 23:42 to 2026-10-12 02:46, two RTX 5060 Ti with `--layer-split auto`, `--max-context 262144`, `--conversation-cache-mib 16384 --conversation-cache-slots 4 --conversation-cache-min-free-mib 4096`. Counted over that session's log: ``` park attempts: 216 (176 at >= 50k tokens, largest 232826 tokens) refusals: 1 of 216 "allocation failed; skip parking": 0 restores: 130; 129 of the 216 parks reused retained K/V (up to 3.29 GiB in one park) evict-to-admit rounds: 12 (11 evicted one conversation, one evicted two; largest admitted request 4006 MiB) budget (make_room) refusals: 0; refusal arms seen: hopeless 1, stalled 0, short_by 0 ``` The single refusal is the `hopeless` arm: the request was 3966 MiB against 2152 MiB freeable in total, and it names both numbers instead of evicting a conversation that could not have paid for it. Parking continued normally afterwards. The same workload on the unpatched 0.1.40.1 engine logged 293 `skip parking` lines — 203 of them the bare textless `allocation failed; skip parking` and 90 the budget refusal ending in a static `or telemetry unavailable` — out of 2772 attempts (291 refused, 10.5%). That build never ran an evict-to-admit round at all: the loop that would have run does not exist in 0.1.40. That run was built from the 0.1.42 base of this series; the rebase onto 0.1.43 changed no source of the patch, so the runtime evidence is the same code. The binary was string-audited first: the textless failure line absent, the named-cause and admission lines present. ## Limitations - The stalled arm of `evict_for_admission()`, the `bad_alloc` probe, and the budget-refusal K/V hand-back are asserted only by the native tests. The run above produced no stalled round (evicting did return memory on this machine), no failed allocation, and no budget refusal, so those three paths are runtime-untested. - Windows-only validation. The SYCL copy of the park path was edited by hand and reviewed, but no oneAPI toolchain is installed here, so it is not compiled. The header changes do reach the SYCL build through the shared include path. - Multi-GPU runtime behavior beyond this one two-GPU WDDM data point is not covered. - The change does not reduce the system-commit cost of the resident expert arena, which is the underlying pressure on this machine; it makes admission stop early, keep what it already holds, and say why it declined. - Not every previously observed parking failure has a known cause. What is measured here is that these refusals now explain themselves. ## Review focus - Retained K/V ownership on every early-return and exception path in the park body: it is taken with `take_reuse()` and must be handed back with `put_reuse()` on all of them. - The resource accounting used by admission: `evictable_bytes()` deliberately excludes the retained K/V and pinned entries, because `evict_oldest()` cannot free either. `bytes()` still charges both, which is correct for the cache budget and wrong for "what can I free right now". - The safety of the allocation diagnostic probe: it reserves, tries to commit, and must release the reservation on every path, including failure. - `ConversationCache::clear()` from #879 is upstream's, and it is consistent with this: it zeroes `reuse_`, and `evictable_bytes()` never counted it. <sub>This PR was prepared by an AI agent (OpenHands) on behalf of the author. The agent's work was reviewed by two independent review passes before the branch was pushed; the review notes and the answers to them are recorded in `LOCAL-PARKING-PATCH-0.1.43.md`, which is included in the branch along with the repo-local `AGENTS.md` notes. Happy to drop either file from the change if you would rather keep them out of the repository.</sub> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:31:12 +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
Niko1221/Strata#3850
No description provided.