Dashboard › opencode-lore › Distillation
154b61ef-9936-4081-b738-2ce3c640cdca["lore_tm_v1_LlO5fU9nYSIHbAhxgkcMGDwv4_WY0EHKn3tp3QgDsbM","lore_tm_v1_cBhLS8xC-Fp7fCCXW7j_juXARThq7VB2tVLUNes-hhs","lore_tm_v1_i6pqzn-qsMYF4UUtezrG3FpH9LAnLyD4HcZAcSuFaro","lore_tm_v1_P6TnRWxlM31nXJrCpMn2_pYQ1ftNaZU9oa32fLlMAUA","lore_tm_v1_Z8imKw4mTiBPQO0ynyvEb1Sf4Z6IFLSySYhN9MYCsnQ","lore_tm_v1_fT1mgQLfUYBMXUOafufOZwQXNvcjPSvpAye6o_7ttMk","lore_tm_v1_3ISJbmSdUAUOGpMGW-xbeTEZK0I4T-kZj8ry4l8w-no","lore_tm_v1_9xetJCtxgw4iAKWxrigp0pKtc3nOz8ekheTNE5tYgmE"]
Date: Sep 16, 2026
/proc/self/cgroup and /proc/self/mountinfo for each admission decision.memory.current, memory.high, and memory.max.packages/core/src/cgroup-memory.ts: resolveLinuxCgroupMemoryFiles(cgroupContent, mountInfoContent) parses cgroup membership and mountinfo, prefers an explicit cgroup v1 memory controller over unified cgroup v2 on hybrid hosts, chooses the direct mount with the longest matching root, and accepts a host-side namespaced-root interpretation only when exactly one candidate is available.decodeProcPath(value) decodes procfs octal escapes (\NNN), requires an absolute path, rejects NUL bytes and .. path components, and normalizes with posix.normalize().readLinuxCgroupMemoryHeadroomBytes() calculates the tightest inherited memory headroom from the selected cgroup directory through its mount point. For cgroup v2 it reads memory.current against both memory.high and memory.max; for cgroup v1 it reads memory.usage_in_bytes against memory.limit_in_bytes. Finite headroom is Math.max(0, limit - usage), with the minimum inherited candidate winning.undefined on malformed numeric values, unsafe integers, unreadable required files, invalid parent traversal, ambiguous namespace mounts, or other exceptions. max and numeric limits above Number.MAX_SAFE_INTEGER are treated as unlimited.packages/core/test/cgroup-memory.test.ts covers cgroup v2 and v1 resolution, octal-escaped mount paths, hybrid v1-memory/v2 hosts, direct versus namespaced mount roots, ambiguous namespace resolution, tight inherited v2 limits, soft memory.high boundaries, unreadable or changing membership/accounting, and v1 usage/limit headroom.packages/core/src/embedding/local.ts now exposes availableMemoryHeadroom(): on Linux it consults readLinuxCgroupMemoryHeadroomBytes(); on Node it combines that with process.availableMemory() and process.constrainedMemory(); on Bun it omits Bun’s host-wide availableMemory() value because it currently aliases host freemem() inside constrained cgroups.containerFreeBytes() now passes host freemem(), constrainedMemoryLimit(), and availableMemoryHeadroom() into clampFreeToContainerLimit(). Test controls include _setConstrainedMemoryForTest(bytes), _setContainerFreeForTest(bytes), and _setAvailableMemoryForTest(bytes).clampFreeToContainerLimit() to “never raise the figure (monotonic — can only reduce memory use).”clampFreeToContainerLimit(hostFree, constrained, available?) uses the minimum of host free memory, a finite positive process limit, and finite nonnegative current headroom. If a finite cgroup limit exists but trustworthy headroom is absent or invalid, it returns 0; discovered headroom remains authoritative even when the hard limit is unlimited.resolveMemoryHeadroom(constrained, linuxHeadroom?, runtimeAvailable?) selects the tightest valid Linux, runtime, and process-limit value. It permits Linux soft-only boundaries, uses runtime headroom on constrained non-Linux Node, returns undefined for constrained Bun without trustworthy usage, and does not invent headroom from host-wide runtime availability on an unconstrained host.7 GiB with a 512 MiB cgroup clamps to 512 MiB; a 12 GiB limit with 23 MiB current headroom clamps to 23 MiB; 384 MiB drives memoryModelEmbedCap() to MIN_EMBED_TOKENS; and host-free values 1 GiB, 3 GiB, 6.72 GiB, and 7 GiB remain unchanged under a roomy 12 GiB cgroup.EMBED_WORKER_RESIDENT_RESERVE_BYTES = 1536 * 1024 * 1024 bytes; PER_WORKER_MEM_BUDGET_BYTES is the maximum of the modeled worker budget and this observed 1536 MiB resident high-water. Consequently desiredEmbedPoolSize(3 * GiB - 1) is 1, while desiredEmbedPoolSize(3 * GiB) is 2.clampEmbedCap() maps all non-finite inputs to MIN_EMBED_TOKENS.backoffEmbedCap() must remain at MIN_EMBED_TOKENS once it reaches that floor.clampEmbedCap(n) rounds finite in-range values, clamps below-floor values to MIN_EMBED_TOKENS, clamps above-ceiling values to MODEL_MAX_TOKENS, and maps NaN, Infinity, and -Infinity to the floor.backoffEmbedCap() reduces the cap by approximately 0.7 per step: 8192 → 5734 and 1000 → 700; 300 * 0.7 = 210 is clamped to MIN_EMBED_TOKENS. Tests require convergence from 8192 to the floor in fewer than 15 steps and idempotence at the floor.EMBED_POOL_BUDGET_REF_TOKENS is 2048, DEFAULT_MAX_EMBED_POOL is 2, and EMBED_POOL_ABS_MAX is 8. desiredEmbedPoolSize() floors invalid free memory at 0, computes affordable workers as Math.max(1, Math.floor(free / PER_WORKER_MEM_BUDGET_BYTES)), and always retains one primary worker.EMBED_WASM_HEAP_MAX_BYTES = 4 * 1024 * 1024 * 1024 from 65536 pages × 64 KiB, with EMBED_WASM_HEAP_USABLE_FRACTION = 0.85; the resulting hard token ceiling is approximately 4962, matching observed safe convergence at ≤4962.EmbeddingPool.liveFreemem() now combines freemem(), constrainedMemoryLimit(), and availableMemoryHeadroom(); when a finite constraint exists but headroom is unknown it returns 0, preventing additional worker admission.best.inflight > 0), room below the configured/absolute ceiling including retired workers, and live headroom of at least (number of unhealthy slots + 1) * PER_WORKER_MEM_BUDGET_BYTES. This reserves memory for an admitted worker whose initialization has not yet appeared in live cgroup usage.2, host free 64 GiB, and cgroup limit 256 MiB, only one worker may exist; with a 12 GiB limit but only 23 MiB current headroom, only one worker may exist; with ceiling 4, host free 64 GiB, a 12 GiB limit, and 1600 MiB headroom, exactly one additional starting worker is admitted and the same headroom cannot be spent again before initialization completes.