Files
alzeo/oc-limits.sh
T
Hasan BasbunarandClaude Opus 5.5 7f458a89bf DaisyRose 27B as a sixth target of the 27B lane (daisyrose)
RadixArk/DaisyRose-27B-NVFP4 @ c4d85c5, RadixArk's reinforcement-learning-only fine-tune of Qwen3.8-27B (Apache-2.0, no SFT and no distillation), in RadixArk's own NVFP4 of the 27B (MIXED_PRECISION, 401 layers: 208 FP8 and 193 NVFP4, identical layer to layer to RadixArk/Qwen3.8-27B-NVFP4; same architecture, tokenizer and chat template, byte for byte, 21.95 GB; its config loads with the lane image's transformers 5.19.0). Nothing measured on the reference box yet; RadixArk publishes Terminal-Bench 2.1 at 75.5 against 73.0 for Qwen3.8-27B (xhigh reasoning). Pinned where arete is: install.sh, switch-model.sh, run.sh, prepare-lane.sh, check-pins.sh, mirror-pins.sh (MIRROR.md, not yet checked), uninstall.sh, lane_registry.py, boxmem.py (a 64 GB box takes it: 21.95 GB, RadixArk's size), the CI's pin contracts and limits. Served by stock's unit with no --kv-cache-dtype: like arete, its checkpoint declares no KV cache either, so its switch and install.sh's apply_context_configs run patch-kv.py after the window's configs, and run.sh refuses it undeclared. Its limits are the 27B's (oc-limits.sh), opencode names it "DaisyRose-27B NVFP4 + DFlash2", the cockpit offers it as a sixth version (DaisyRose 27B NVFP4, RadixArk) with its recipe, pin and switch. stock stays the default. Tests that fail on the code before: test_daisyrose_target (new, 11), the target lists of test_boxmem, test_spark_64, test_target_names, test_recipes, test_page_behaviour, test_cockpit_box, test_install_oc_artifact (DaisyRose's name under a flash install), test_check_pins and test_mirror_pins (one checkpoint more), each run alone with python3 -m unittest.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 23:20:17 +01:00

358 lines
20 KiB
Bash
Executable File

#!/usr/bin/env bash
# The opencode limits a target deserves: one table, three callers.
#
# install.sh writes these limits at install time, switch-model.sh rewrites them
# at switch time, and CI asserts them. They are not decoration: opencode compacts
# a conversation when it reaches `limit.context`, and if that number is larger
# than what the lane can serve, the keepalive proxy refuses the request with a
# 400 BEFORE opencode ever decides to compact. The user then sees a hard failure
# in the middle of a session instead of a compaction. A switch from a 27B box in
# 1M mode (700,000 context) to the flash lane (200,000 one-prompt ceiling) is
# exactly that shape, and until 2026-09-08 the switch left the old numbers in
# place because only the installer knew this table.
#
# Duplicating it in each caller would have been the easy fix, and is how two
# numbers drift apart. So there is one table and it lives here.
#
# ./oc-limits.sh <choice> <tier-or-mode> # explicit: what install.sh knows
# ./oc-limits.sh <choice> --from <invocation> # derived: what a switch can read
# ./oc-limits.sh --max-out # the ceiling every caller shares
# ./oc-limits.sh --preserve <ctx> # tokens a compaction keeps verbatim
#
# `choice` is a target name. The second argument is the flash serving tier
# (context | concurrency | throughput) for a flash target, or the 27B context
# mode (native | 1m) for the others. With `--from`, the answer is derived from
# what the box actually serves instead: the tier from the launcher's
# --max-running-requests, the context mode from the unit's --context-length.
#
# Prints "CTX OUT LABEL". Every number is measured; the measurements are in
# BENCHMARKS.md and the reasoning is in the comments below.
set -uo pipefail
usage() {
printf 'usage: %s <choice> <tier-or-mode>\n %s <choice> --from <invocation-file>\n %s --max-out\n' \
"$0" "$0" "$0" >&2
exit 2
}
CHOICE="${1:-}"
[ -n "$CHOICE" ] || usage
# --max-out: the largest output any target can ask for.
#
# OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX is a CEILING, not a per-target number:
# opencode sends max_tokens = min(limit.output, that ceiling). limit.output is
# the number that follows a switch (rewritten from this table), so the ceiling
# only has to sit above every value the table can produce. Deriving it from the
# INSTALLED target instead is the bug this exists to prevent: a box installed on
# the flash lane wrote a 64,000 ceiling, the switch to a 27B box in 1M mode
# raised limit.output to 200,000, the ceiling stayed, and a long turn was cut at
# 64,000 with no error and no text, which is the exact failure the 32,000
# default produces. Computed by asking this table for every pair, so it cannot
# drift from it.
if [ "$CHOICE" = "--max-out" ]; then
MAXOUT=0
for _c in flash flash-nvda flash-uncensored; do
for _t in context concurrency throughput; do
_o="$("$0" "$_c" "$_t" | awk '{print $2}')"
[ -n "$_o" ] || { printf 'oc-limits: --max-out could not read %s %s\n' "$_c" "$_t" >&2; exit 2; }
[ "$_o" -gt "$MAXOUT" ] && MAXOUT="$_o"
done
done
for _c in stock uncensored fp8 uncensored-fp8 arete daisyrose; do
for _t in native 1m; do
_o="$("$0" "$_c" "$_t" | awk '{print $2}')"
[ -n "$_o" ] || { printf 'oc-limits: --max-out could not read %s %s\n' "$_c" "$_t" >&2; exit 2; }
[ "$_o" -gt "$MAXOUT" ] && MAXOUT="$_o"
done
done
[ "$MAXOUT" -gt 0 ] || { printf 'oc-limits: --max-out found no limits\n' >&2; exit 2; }
printf '%s\n' "$MAXOUT"
exit 0
fi
# --preserve: how much of the recent conversation survives a compaction verbatim.
#
# opencode's default is min(15,000, max(2,000, threshold/4)), and that 15,000 cap
# is the problem on a big window: it was chosen for models with a 128K context,
# and on this lane it means a compaction at 205,000 tokens keeps 15,000 and
# summarises the other 190,000. The window is then not being used, it is being
# refilled from scratch every time.
#
# So the installed value is opencode's own intent without the cap: a quarter of
# the compaction threshold, which is limit.context minus the 20,000 opencode
# reserves. Rounded to 1,000. Sized from the INSTALLED target because the key is
# global in opencode.json while the threshold is per-target: install.sh and
# switch-model.sh rewrite it with the limits, so it always tracks the lane that
# serves (and oc-fit-limits.py with them, when it fits the context to the pool). A
# value at or above the threshold would make select() keep everything and summarise
# the lot, which a quarter never is: the cap at a third this carried could not apply,
# and is gone (found in review, 2026-09-24).
if [ "$CHOICE" = "--preserve" ]; then
CTX_IN="${2:-}"
case "$CTX_IN" in ''|*[!0-9]*) printf 'oc-limits: --preserve needs a context size\n' >&2; exit 2 ;; esac
THRESH=$(( CTX_IN - 20000 ))
[ "$THRESH" -gt 0 ] || { printf '0\n'; exit 0; }
printf '%s\n' "$(( THRESH / 4 / 1000 * 1000 ))"
exit 0
fi
SECOND="${2:-}"
INVOCATION=""
SELECTOR=""
case "$SECOND" in
--from)
INVOCATION="${3:-}"
[ -n "$INVOCATION" ] || usage
# A missing file keeps the old contract (defaults, rc 0: switch-model.sh
# treats "no limits" as leave-everything, mid-switch is no place to die),
# but it says so loudly instead of silently serving another lane's numbers.
[ -f "$INVOCATION" ] || echo "oc-limits.sh: --from $INVOCATION is not a file; using defaults" >&2
;;
"") ;; # nothing given: fall back to the defaults below
*) SELECTOR="$SECOND" ;;
esac
flag() { # $1 flag name -> its value in the invocation, or empty
[ -n "$INVOCATION" ] && [ -f "$INVOCATION" ] || return 0
grep -oE -- "$1 [0-9]+" "$INVOCATION" 2>/dev/null | awk '{print $2}' | head -1
}
case "$CHOICE" in
flash|flash-nvda|flash-uncensored)
TIER="$SELECTOR"
if [ -z "$TIER" ]; then
# Derived, or defaulted: the tier is what the launcher pins as concurrency.
case "$(flag '--max-running-requests')" in
24) TIER=throughput ;;
8) TIER=concurrency ;;
*) TIER=context ;;
esac
fi
# The budget is min(the proxy's one-prompt ceiling, what the tier's KV pool
# holds alongside the answer).
#
# Where the context-tier number comes from, since it is not the ceiling:
# opencode does NOT estimate its context. It compacts when the LAST response's
# reported usage reaches limit.input minus min(20,000, its output cap), so the
# threshold is simply CTX - 20,000 (opencode 1.18.27, SessionCompaction). The
# numbers it compares are the engine's own prompt_tokens, exact.
#
# What can still overrun the ceiling is the step AFTER that check: opencode
# decides between turns, then a single turn appends its tool results and sends.
# So the rule is threshold + one worst step <= the proxy's ceiling. Measured
# here over 2,156 flash-lane steps (opencode's own session store, 2026-09): the
# largest single-step prompt growth is 43,863 tokens, p99 18,512.
#
# 225,000 - 20,000 + 43,863 = 248,863 <= 250,000 ceiling
#
# The ceiling is 250,000 because the box was measured there rather than assumed
# (2026-09-13, this engine, MemAvailable sampled through each prefill):
#
# 195,784 tokens -> 1.16 GiB of host headroom, 94.7 s
# 225,051 tokens -> 1.57 GiB, 111.3 s
# 249,500 tokens -> 1.52 GiB, 126.1 s, floor 7.0 GiB
#
# The old 128,000 and 200,000 ceilings came from a v1.5 engine whose PLE mapping
# faulted in whole page-cache folios (~0.27 GiB per 1k tokens past 90k, and 3.5
# GiB at 200k). v1.8 serves an engine that does not: a full-depth prefill now
# costs about 1.5 GiB and leaves 7 GiB, so the memory argument for stopping at
# 200,000 no longer holds and the window the model actually has is usable.
# What does still hold is the engine's own wall, max_req_input_len = 262,138:
# 250,000 leaves 12,138 tokens of slack under it, which is the band that keeps
# a mis-count on the proxy's side from reaching a truncation on the engine's.
#
# The 175,000 this replaces, and the 190,000 before it, were both set by reading
# proxy refusals as opencode "drifting" from the engine's count. It does not
# drift: the proxy was charging every image a flat 4,096 tokens where the engine
# charges 880 to 1,562 for an agent screenshot, so a session holding 24 of them
# was refused ~61,000 tokens early. Fixed in the proxy (v6.15).
#
# And the answer has to fit beside that prompt: the engine refuses any request whose
# input + max_tokens passes its 262,144 window (validate_total_tokens, on in the
# flash image; checked 2026-09-24), and opencode asks for max_tokens = OUT. So the
# same threshold + worst step, with the answer on top, must fit the window:
#
# 205,000 - 20,000 + 43,863 + 32,000 = 260,863 <= 262,144
#
# 225,000 met the ceiling and not this: a prompt past 230,144 was refused by the
# engine, in the band one large step reaches after the threshold (found in review,
# 2026-09-24). oc-fit-limits.py applies the same rule after each boot.
case "$TIER" in
context) CTX=205000; OUT=32000 ;; # threshold + one worst step + the answer fits the 262,144 window, and stays under the 250,000 ceiling (see above)
concurrency) CTX=205000; OUT=32000 ;; # the context tier's pair since v1.20.3: one
# request fits as it does there (the same threshold, worst step and answer under the
# same ceiling and window), and eight at once share the pool. When they outgrow it,
# the engine queues the newcomers and retracts as it must, which costs time and fails
# nothing. 100,000/16,000 until then kept eight at once inside the pool, and cut every
# agent's session at 84,000 tokens: measured live on 2026-10-01, eight opencode
# subagents held 60 to 68 % of the 474,816-token pool at that window, and a
# documentation agent compacted at 88,520. The operator's call: a queue rather than a
# 100K window.
throughput) CTX=110000; OUT=32000 ;; # a big pool, but 24 requests share it
*) printf 'oc-limits: unknown flash tier "%s"\n' "$TIER" >&2; exit 2 ;;
esac
LABEL="local"
;;
stock|uncensored|fp8|uncensored-fp8|arete|daisyrose|custom)
# custom: a --model-path this table does not know, kept from the installed 27B unit
# (install.sh). It had no row, so every update of such a box died at step 7 (found in
# review, 2026-09-24). Its weights are of no known format, so in 1m it gets the pair of
# the smaller pool; the fit at the end of the install then sets the pair its engine's
# real pool allows.
MODE="$SELECTOR"
if [ -z "$MODE" ]; then
CTX_LEN="$(flag '--context-length')"
if [ "${CTX_LEN:-0}" -gt 262144 ] 2>/dev/null; then MODE=1m; else MODE=native; fi
fi
case "$MODE" in
1m)
case "$CHOICE" in
fp8|uncensored-fp8|custom)
# FP8 weights cost KV pool (measured on the retired image at
# fraction 0.70, same 1M unit: 863,398 on NVFP4, 771,139 on FP8),
# and the NVFP4 numbers do not transfer: 680,000 of compaction plus
# 200,000 of output is an 880,000 worst case.
# Re-measured 2026-09-18 on the official v0.5.19 image at 0.76:
# 881,895 on FP8 against 887,797 on NVFP4, so the gap all but closed
# and this pair is now conservative rather than tight. Kept as is:
# these are the static numbers, oc-fit-limits.py rewrites them from
# the pool the boot actually got, and the CI gate that asserts them
# against 771,139 stays the stricter of the two bounds on purpose.
CTX=480000; OUT=160000 ;;
*)
CTX=700000; OUT=200000 ;;
esac
LABEL="local, 1M"
;;
# 262,144 window: threshold + one worst step + the answer must fit it, the rule the
# flash context tier explains above (173,000 - 20,000 + 43,863 + 64,000 = 260,863).
# 194,048 fitted 64,000 beside a prompt of exactly 194,048, not beside the one a
# large step brings past compaction (found in review, 2026-09-24).
native) CTX=173000; OUT=64000; LABEL="local" ;;
*) printf 'oc-limits: unknown context mode "%s"\n' "$MODE" >&2; exit 2 ;;
esac
;;
kolibri|kolibri-nvfp4)
# The Kolibri lane serves Aleph Alpha's 262,144-token window, and vLLM refuses any
# request whose prompt + max_tokens passes it. Its KV cache holds about 2.1 million
# tokens (8 requests at the full window, either checkpoint), so the pool binds nothing
# and the window decides, by the rule the flash context tier explains above:
# 205,000 - 20,000 + 43,863 + 32,000 = 260,863 <= 262,144
# It was the native 27B pair, 173,000 + 64,000, for reasoning room at the high effort its
# template defaults to: opencode compacted at 153,000 tokens, and the 64,000 kept for each
# answer went unused. Measured in an opencode session on the reference box (2026-10-14,
# 26 replies at that effort, reasoning included): median 386 tokens, longest 1,742.
# 32,000 is that longest eighteen times over, the flash lane's answer, and compaction
# comes at 185,000.
CTX=205000; OUT=32000; LABEL="local, 262K"
;;
nemotron)
# The Nemotron lane serves Bolt's 262,144-token window, and vLLM refuses any request whose
# prompt + max_tokens passes it. Its KV cache holds 6.5 million tokens (24 requests at the full
# window, measured 2026-10-16), so the pool binds nothing and the window decides, by the same
# rule and the same numbers as the Kolibri lane's:
# 205,000 - 20,000 + 43,863 + 32,000 = 260,863 <= 262,144
CTX=205000; OUT=32000; LABEL="local, 262K"
;;
nemotron-super)
# The Nemotron Super lane serves Super VL's window of 1,048,576 tokens, and vLLM refuses any
# request whose prompt + max_tokens passes it. Its KV cache holds the window 1.2 times over
# (measured 2026-10-16), so the window decides here too, by the same rule:
# 990,000 - 20,000 + 43,863 + 32,000 = 1,045,863 <= 1,048,576
CTX=990000; OUT=32000; LABEL="local, 1M"
;;
flash-local)
# Its context mode (native | 1m, FLASH_LOCAL_CONTEXT of install-flash-local.sh), or, with --from, its unit's
# --max-model-len: the switch reads the unit it has just staged.
MODE="$SELECTOR"
if [ -z "$MODE" ]; then
MAX_LEN="$(flag '--max-model-len')"
if [ "${MAX_LEN:-0}" -gt 262144 ] 2>/dev/null; then MODE=1m; else MODE=native; fi
fi
case "$MODE" in
# The Qwen3.8 Flash-Next FP4-Local lane serves the flash lane's 262,144-token window, and vLLM refuses any
# request whose prompt + max_tokens passes it. Its KV cache holds 921,090 tokens at the card's
# memory share (measured 2026-10-19), the window 3.5 times over, so the window decides, by the
# flash lane's rule and numbers (the same model, the same window, the proxy's same ceiling):
# 205,000 - 20,000 + 43,863 + 32,000 = 260,863 <= 262,144
native) CTX=205000; OUT=32000; LABEL="local, 262K" ;;
# At its 1M window (1,048,576 tokens by YaRN, v1.45.2) the pool decides: 1,061,819 tokens at the lane's share
# (measured 2026-11-09), the window 1.01 times over, and the proxy relays a prompt up to 92 % of it, no flash
# ceiling there. The pair keeps the lane's answer budget and fits the cockpit's check (fit_verdict) with a pool
# 10 % smaller than the one measured, the margin oc-fit-limits.py keeps for a boot that gets less:
# 840,000 + 32,000 = 872,000 <= 1,061,819 x 0.92 x 0.90 = 879,186
# 840,000 - 20,000 + 43,863 + 32,000 = 895,863 <= 1,048,576
1m) CTX=840000; OUT=32000; LABEL="local, 1M" ;;
*) printf 'oc-limits: unknown context mode "%s"\n' "$MODE" >&2; exit 2 ;;
esac
;;
ornith-122b)
# The Ornith 1.5 122B lane serves a window of 1,048,576 tokens (the model's own 262,144 four
# times over, with YaRN), and vLLM refuses any request whose prompt + max_tokens passes it. Its KV
# cache is fixed at 17 GiB, 1,301,680 tokens (measured 2026-10-21), the window 1.24 times over, so
# the window decides, by the Nemotron Super lane's rule and numbers (Ornith's tokenizer counts text
# as Qwen's does: the same vocabulary, merges and pre-tokenizer, seven audio tokens fewer; checked
# 2026-10-21):
# 990,000 - 20,000 + 43,863 + 32,000 = 1,045,863 <= 1,048,576
CTX=990000; OUT=32000; LABEL="local, 1M"
;;
flash-unsloth|flash-unsloth-iq3)
# Its window, one request's (native | 1m, FLASH_UNSLOTH_CONTEXT of install-flash-unsloth.sh), or, with --from, its
# unit's: lanes.sh's llamacpp_window, the -c of its engine, which holds a window for each of its requests (or the one
# they share with -kvu, which its installer refuses: a unit edited by hand), past 262,144 by YaRN alone. llama.cpp
# refuses a prompt past a request's window, so the window decides the pair, and each mode's pair fits every window
# from its own up: a window under 1,048,576 gets the native pair. Its two targets, UD-Q4_K_XL and UD-IQ3_XXS, give
# each request the same windows (v1.49): they differ in how many requests they serve at once, not in a request's.
MODE="$SELECTOR"
if [ -z "$MODE" ]; then
WINDOW=""
if [ -n "$INVOCATION" ] && [ -f "$INVOCATION" ]; then
# shellcheck source=lanes.sh
. "$(dirname "${BASH_SOURCE[0]}")/lanes.sh"
WINDOW="$(llamacpp_window "$INVOCATION")"
fi
if [ "${WINDOW:-0}" -ge 1048576 ] 2>/dev/null; then MODE=1m; else MODE=native; fi
fi
case "$MODE" in
# The model's own window, 262,144 tokens (the context the GGUF says it was trained for), for each of its requests,
# two on UD-Q4_K_XL (decision 1318, 2026-11-12), four on UD-IQ3_XXS (decision 1366): the flash lane's rule and
# numbers (the same model, the same tokenizer, the proxy's same ceiling):
# 205,000 - 20,000 + 43,863 + 32,000 = 260,863 <= 262,144
native) CTX=205000; OUT=32000; LABEL="local, 262K" ;;
# FLASH_UNSLOTH_CONTEXT=1m: one request at a time with a window of 1,048,576 tokens (YaRN at four times), the pool
# (llama.cpp's memory fit lowers a -c left unset alone, common/fit.cpp), whose prompt the proxy relays up to 92 %,
# no flash ceiling there (wide_flash), on either target. The pair keeps the lane's answer budget and is sized by the
# FP4-Local lane's rule at its 1M: the cockpit's check (fit_verdict) with a pool 10 % smaller, and the window
# holding the prompt at opencode's compaction point, one worst step and the answer:
# 830,000 + 32,000 = 862,000 <= 1,048,576 x 0.92 x 0.90 = 868,220
# 830,000 - 20,000 + 43,863 + 32,000 = 885,863 <= 1,048,576
1m) CTX=830000; OUT=32000; LABEL="local, 1M" ;;
*) printf 'oc-limits: unknown context mode "%s"\n' "$MODE" >&2; exit 2 ;;
esac
;;
lfm25)
# The Liquid AI LFM2.5 24B-A2B lane serves the model's window, 131,072 tokens (its config's
# max_position_embeddings, the unit's --context-length), and SGLang refuses any request whose prompt +
# max_tokens passes it. Its KV cache holds 1,667,049 tokens (measured 2026-11-14), the window 12.7 times over,
# so the window decides, by the flash lane's rule with the answer the flash lane keeps (32,000), and by
# oc-fit-limits.py's, whose margin is the worst agent step less opencode's compaction reserve (43,863 - 20,000),
# rounded up to 25,000, so that the two land on one pair:
# 74,000 - 20,000 + 43,863 + 32,000 = 129,863 <= 131,072
# 74,000 + 25,000 + 32,000 = 131,000 <= 131,072
CTX=74000; OUT=32000; LABEL="local, 131K"
;;
lfm3)
# The Liquid AI LFM3 lane serves the model's window, 262,144 tokens (its config's max_position_embeddings, the
# unit's --max-model-len), and vLLM refuses any request whose prompt + max_tokens passes it. Its KV cache held
# 5,239,455 tokens with no memory share (measured 2026-11-16), the window twenty times over; its share of 0.75 keeps
# several windows' worth, so the window decides, by the flash lane's rule and numbers (the same window), which
# oc-fit-limits.py's margin keeps too (the worst agent step less opencode's compaction reserve, rounded up):
# 205,000 - 20,000 + 43,863 + 32,000 = 260,863 <= 262,144
# 205,000 + 25,000 + 32,000 = 262,000 <= 262,144
CTX=205000; OUT=32000; LABEL="local, 262K"
;;
*) printf 'oc-limits: unknown target "%s"\n' "$CHOICE" >&2; exit 2 ;;
esac
printf '%s %s %s\n' "$CTX" "$OUT" "$LABEL"