Repository navigation
The host deficit reaches the engine's prompt cache first, judged by the OS's own pressure verdict (card 0f631c46) - #5981
Merged
joelteply merged 3 commits intoNov 14, 2026
Conversation
…he OS's own pressure verdict (card 0f631c46) Two defects left the M5 starving at 0.4 GB free with a 16.5 GB prompt cache untouched (2026-11-13 23:40Z, canary 0ed0d23): 1. host_deficit.rs took a "clean" baseline whenever the counters stood still and the free target was met. Under standing starvation macOS holds its free target by compressing, so the whole 42 GB compressed + 14.5 GB swap became the baseline and the deficit read 0. Now only the OS's own verdict (macOS kern.memorystatus_vm_pressure_level, Linux PSI, read in the continuum-host adapter) decides: OS normal takes the baseline; while it reports pressure the deficit is the displacement since the last OS-normal poll plus the shortfall, never less than the kernel's free target, and no baseline is taken. 2. The cache lever hung off ResourceConsumer::reclaim, which the authority calls only when a resource kind is over its ceiling: it never fired. The lever moves to modules/serving_prompt_cache as a MemoryReporter at Batch (yields first), lowered by its share of the OS deficit, and taken back to its launch grant through a new MemoryReporter::take_again hook after two OS-normal polls. The route through the ServingConsumer is deleted: one reclaim path for host RAM. Dyno 11 (standing starvation) and unit tests at host_deficit, the adapters and the lever wiring. Not compiled locally (the M5 is serving); CI is the compiler. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…fg(test)]) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
How this serves the minds: a resident on a 64 GB Mac thinks at half speed, or not at all, while the host starves. This PR makes the one memory control work end to end: the engine's prompt cache is the first holder to give memory back, and it gets that memory back once the OS recovers. Order of work: line 3b ("one memory budget"), goal 9.
Evidence (the M5, 2026-11-13 23:40Z, canary 0ed0d23, which already includes #5969 and #5971)
--cache-ram 16525MiB.memory.pressure.shed level=critical deficit_mb=0on almost every poll (one read 2169).serving.reclaim.prompt_cachefired zero times in every~/.continuum/logs/continuum-core-server.log*since Serving gives its host prompt cache back first when the authority reclaims memory (card 494c99f1) #5969 went live.Defect 1: standing starvation read as clean
core/continuum-kernel/src/system_resources/memory_pressure/host_deficit.rs(canary,HostDeficit::observe):if shortfall == 0 && !compressing && !swapping_out { self.baseline = Some(displaced); return 0; }. Under standing starvation macOS holds free pages at its small target (vm.vm_page_free_target= 4,000 pages = 64 MB) by compressing, so the compressor and swap stop growing and the shortfall reads 0. The whole 56 GB displaced became the baseline, and the deficit read 0.Fix: only the OS's own verdict decides when the host is clean. The verdict is read in the host adapter (
continuum-host/src/host_memory), and the logic has nocfg:kern.memorystatus_vm_pressure_levelsysctl (1 normal, 2 warn, 4 critical). The mapping is pure (OsMemoryPressure::from_memorystatus_level) and tested on every host./proc/pressure/memory(full avg10 > 0is Critical,some avg10 > 0is Warn, otherwise Normal). The parser is pure (pressure_from_psi).None, which means no deficit claim and never calm.HostDeficit::observenow works like this:max((displaced - baseline) + shortfall, free_target), so it is never 0 while the OS reports pressure. Without an OS-normal poll since boot, the baseline is 0.No fixed fractions. The first-poll "nothing to compare" special case is gone.
Defect 2: the cache lever was on a path that never runs
core/continuum-serving/src/modules/serving_consumer.rs(canary):reclaim_prompt_cache(line 415) was called only fromResourceConsumer::reclaim(line 726).continuum-kernel/src/resources/daemon.rs) callsreclaimonly when a resource kind is over its own ceiling. It never was.MemoryReporter::shed_load(mind results,ShedLru, Bevy).Fix (one control):
modules/serving_prompt_cache/(lever.rsis the oldserving_consumer/prompt_cache.rs, moved and extended). It is registered as aMemoryReporteratMemoryPriority::Batch, the priority that yields first.deficit_atcharges the cache before every higher priority.share_of_deficit, planned from what the cache holds (unchanged from Serving gives its host prompt cache back first when the authority reclaims memory (card 494c99f1) #5969). It acts only on the OS's deficit, never on the fixed RAM gates alone, which would fight the take-again half.MemoryReporter::take_againhook. The monitor calls it after two OS-normal polls in a row (HostDeficit::take_again_due). The cache goes back to its launch grant, and the engine's/prompt-cache/limitreply is the receipt (probeserving.prompt_cache.take_again).ServingConsumer(with_prompt_cache,reclaim_prompt_cache, theprompt_cacheanddevicefields,EngineDeviceCredit::host_memory_is_the_pool) and its tests. Host RAM now has one reclaim path. The physical-measure confirmation of the engine's receipt went with it; the receipt is now the engine's ownheld_bytes/freed_bytes.ServingDaemonModule::give_host_memory_back_first(&pressure_monitor, rt_handle)inipc/start_server.rs.Simulator and tests
serving_daemon/tests/dyno.rs). Built from the recorded readings (0.4 GB free, compressor flat at 42 GB, swap 14.5 GB, kernel critical, cache 16,525 MiB).take_againtakes it back to 16,525 MiB.host_deficit:standing_starvation_is_owed_while_the_os_says_pressuretake_again_is_due_only_after_two_os_normal_pollsserving_prompt_cache/tests.rs):Lines
Diff: 954 added, 409 removed across 20 files. Production code: the consumer loses 124 lines (the cache route), and the shedder adds 271 (about 120 of them docs and probes). Most added lines are tests and the dyno (+312).
Not compiled locally
The M5 is serving live minds, so I ran no cargo build, check or test. CI is the compiler.
Live receipt to take (owner: whoever deploys this; deadline: the first hour after deploy)
Under OS pressure (
sysctl kern.memorystatus_vm_pressure_level2 or 4), check:memory.pressureprobe rows showos_pressure=Some(Warn|Critical)anddeficit_mb > 0;serving.reclaim.prompt_cachefires withheld_bytesfalling;serving.prompt_cache.take_againfires after the OS reads normal.Record free memory, compressor pages (
vm_stat) and swap (sysctl vm.swapusage) before deploy and after one hour, plus prefill and decode tok/s.🤖 Generated with Claude Code
https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo