Skip to content

Commit 5ff6283

Browse files
author
lpb-docs
committed
chore(env): retire LPB_MAX_TOKENS_CONTEXT_RATIO chain
Response ceilings are per-model now (maxTokens in the lemonade-pi-plugin model catalog — companion plugin commit b396890). The ratio env was dead in the plugin (read as DEFAULT_MAX_TOKENS_CONTEXT_RATIO, never set) and is removed end-to-end: - lpb.conf.env / .env.example: variable + example block removed (.env local file updated separately) - start.sh: bridge name, bare fallback, debug line removed - lpb.py: container env export removed - build.py: REQUIRED_CONF_VARS emptied, build-arg removed - tests: sample conf content updated - doc/fork-improvements.md: Configuration section rewritten Containers built before this change keep the baked env var until rebuild — harmless, nothing reads it anymore.
1 parent da70bba commit 5ff6283

7 files changed

Lines changed: 24 additions & 40 deletions

File tree

.env.example

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,11 @@ LPB_AGENT_BROWSER_IDLE_TIMEOUT_MS=300000
6767
# OpenRouter API key (overflow provider — not needed with Lemonade)
6868
# LPB_OPENROUTER_API_KEY=
6969

70-
# Max tokens as a fraction of context window (lemonade-pi-plugin).
71-
# Computed as: max_tokens = context_window * LPB_MAX_TOKENS_CONTEXT_RATIO
72-
# Default: 0.06 (6 %) — reduced from 0.125 for Qwen thinking models.
73-
# At 0.125, Qwen thinking models generate 10-20k-token thinking blocks that
74-
# push prompt+max_tokens past the 262k window limit, causing overflow errors.
75-
# 0.06 × 262k = ~15.7k maxTokens — leaves room for thinking blocks within window.
76-
# Examples:
77-
# 0.06 → 262K context → 15.7K max tokens
78-
# 0.125 → 262K context → 32.8K max tokens (may overflow with thinking)
79-
# 0.20 → 262K context → 52.4K max tokens
80-
# LPB_MAX_TOKENS_CONTEXT_RATIO=0.06
70+
# Response ceilings are per-model now — the `maxTokens` field in the
71+
# lemonade-pi-plugin model catalog (~/.pi/agent/model-params.json). The old
72+
# global LPB_MAX_TOKENS_CONTEXT_RATIO was retired 2026-09-02 (exact values
73+
# per model, no formula — see lemonade-pi-plugin/docs/qwen-thinking-
74+
# mainstream-pi.md §5.0).
8175

8276
# Capture outgoing provider payloads (lemonade-pi-plugin) — ALL models.
8377
# 1 = the plugin logs one JSON line per request (tuned view for catalogued

doc/fork-improvements.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,20 @@ network calls. Triggered on login, refresh, and `/lemonade change-ctx`.
120120

121121
### Configuration
122122

123-
| Constant | Value | Purpose |
123+
The response ceiling (`max_completion_tokens`) is the **per-model
124+
`maxTokens` catalog field** in the lemonade-pi-plugin model-params catalog
125+
(`~/.pi/agent/model-params.json` + the plugin-shipped tier) — an exact token
126+
value per wire model id, applied at model sync. The former ctx-ratio design
127+
(`DEFAULT_MAX_TOKENS_CONTEXT_RATIO` 0.125, `QWEN_REASONING_MAX_TOKENS_CONTEXT_RATIO`
128+
0.06, the 16384 clamp, and the `LPB_MAX_TOKENS_CONTEXT_RATIO` env chain)
129+
was retired 2026-09-02: the plugin's env read was dead (set by nothing), the
130+
protective work was done by the clamp anyway, and six explicit numbers are
131+
more auditable than a formula.
132+
133+
| Model | maxTokens | Why |
124134
|---|---|---|
125-
| `DEFAULT_MAX_TOKENS_CONTEXT_RATIO` | `0.125` | Non-reasoning Qwen models |
126-
| `QWEN_REASONING_MAX_TOKENS_CONTEXT_RATIO` | `0.06` | Reasoning models (thinking headroom) |
127-
| `QWEN_REASONING_BUDGET_TOKENS` | `0` | Soft-capped thinking (prevents runaway) |
128-
129-
### Why the Ratios Matter
130-
131-
| Model Type | Ratio | 262k Context → maxTokens | Why |
132-
|---|---|---|---|
133-
| Reasoning (Qwen MTP) | `0.06` | ~15.7k | Thinking blocks consume 10-20k tokens |
134-
| Non-reasoning (Qwen) | `0.125` | ~32k | Standard ratio, no thinking overhead |
135+
| Qwen thinking models (27B/35B) | `16384` | Thinking headroom at the 262k window (old formula + clamp landed here) |
136+
| Small / non-Qwen models | `4096` | Default response cap (matches the former fallback) |
135137

136138
---
137139

lpb.conf.env

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ LPB_LEMONADE_BASE_URL=http://127.0.0.1:13305/v1
2929
# OpenRouter overflow provider (not needed with Lemonade)
3030
LPB_OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
3131

32-
# ─── Context Window ─────────────────────────────────────────────────────
33-
# max_tokens = context_window * LPB_MAX_TOKENS_CONTEXT_RATIO
34-
# Default: 0.06 (6%) — reduced from 0.125 for Qwen thinking models.
35-
# Prevents overflow when thinking blocks push prompt+max_tokens past 262k.
36-
LPB_MAX_TOKENS_CONTEXT_RATIO=0.06
37-
3832
# ─── Persistence ────────────────────────────────────────────────────────
3933
# Launcher-time host state directory → bind-mounted into the container at
4034
# /home/lpb/.pi (the Pi config home). Persists across container rebuilds.

scripts/lpb.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,6 @@ def _build_run_env(mount_path: str) -> list[str]:
17631763
# has no need for it — start.sh uses its own defaults. Passing it here
17641764
# would pollute .devstack-env and break future host runs.
17651765
f"LPB_EXA_API_KEY={os.environ.get('LPB_EXA_API_KEY', os.environ.get('EXA_API_KEY', ''))}",
1766-
f"LPB_MAX_TOKENS_CONTEXT_RATIO={os.environ.get('LPB_MAX_TOKENS_CONTEXT_RATIO', _conf_cfg.get('LPB_MAX_TOKENS_CONTEXT_RATIO', '0.06'))}",
17671766
]
17681767
# Lemonade model server — resolved by the unified setup preflight in
17691768
# cmd_run (all modes): interactive wizard before a fresh start, or

scripts/test_localpibox_build.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ def test_build_load_env_success(tmpdir):
3333
"LPB_NODE_VERSION=24\n"
3434
"LPB_VSCODIUM_VERSION=1.126.04524\n"
3535
)
36-
(tmpdir / "lpb.conf.env").write_text("LPB_MAX_TOKENS_CONTEXT_RATIO=0.06\n")
36+
(tmpdir / "lpb.conf.env").write_text("# no required conf vars (ratio retired)\n")
3737
env = build.load_build_env(tmpdir.path)
3838
assert env["LPB_IMAGE_CLI"] == "ghcr.io/lpb-stack/devstack:cli"
39-
assert env["LPB_MAX_TOKENS_CONTEXT_RATIO"] == "0.06"
4039

4140

4241
def test_build_load_env_missing_file(tmpdir):
@@ -50,7 +49,7 @@ def test_build_load_env_missing_file(tmpdir):
5049

5150
def test_build_load_env_missing_var(tmpdir):
5251
for name in ("lpb.stack.env", "lpb.conf.env"):
53-
(tmpdir / name).write_text("LPB_MAX_TOKENS_CONTEXT_RATIO=0.06\n")
52+
(tmpdir / name).write_text("# no required conf vars (ratio retired)\n")
5453
try:
5554
build.load_build_env(tmpdir.path)
5655
assert False, "should raise RuntimeError"
@@ -64,7 +63,7 @@ def test_build_load_env_expands_home(tmpdir):
6463
"LPB_CONFIG_FORK=c\nLPB_CONFIG_REF=m\nLPB_NODE_VERSION=n\nLPB_VSCODIUM_VERSION=v\n"
6564
)
6665
(tmpdir / "lpb.conf.env").write_text(
67-
"LPB_MAX_TOKENS_CONTEXT_RATIO=0.06\nLPB_STATE_DIR=${HOME}/.lpb-stack/state\n"
66+
"LPB_STATE_DIR=${HOME}/.lpb-stack/state\n"
6867
)
6968
env = build.load_build_env(tmpdir.path)
7069
assert env["LPB_STATE_DIR"] == os.path.expanduser("~") + "/.lpb-stack/state"
@@ -75,7 +74,6 @@ def test_build_build_args_with_fake_git(tmpdir):
7574
"LPB_PI_VERSION": "0.84.4",
7675
"LPB_CONFIG_FORK": "cfg", "LPB_CONFIG_REF": "main",
7776
"LPB_NODE_VERSION": "24", "LPB_VSCODIUM_VERSION": "v",
78-
"LPB_MAX_TOKENS_CONTEXT_RATIO": "0.06",
7977
"LPB_IMAGE_CLI": "cli", "LPB_IMAGE_WEB": "web",
8078
}
8179
(tmpdir / "VERSION").write_text("0.9.9-test\n")
@@ -99,7 +97,6 @@ def test_build_build_args_git_fail(tmpdir):
9997
"LPB_PI_VERSION": "0.84.4",
10098
"LPB_CONFIG_FORK": "cfg", "LPB_CONFIG_REF": "main",
10199
"LPB_NODE_VERSION": "24", "LPB_VSCODIUM_VERSION": "v",
102-
"LPB_MAX_TOKENS_CONTEXT_RATIO": "0.06",
103100
"LPB_IMAGE_CLI": "cli", "LPB_IMAGE_WEB": "web",
104101
}
105102
runner = _fake_runner({"ls-remote": ("", 128), "rev-parse": ("", 128)})

support/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"LPB_NODE_VERSION",
3939
"LPB_VSCODIUM_VERSION",
4040
]
41-
REQUIRED_CONF_VARS = ["LPB_MAX_TOKENS_CONTEXT_RATIO"]
41+
# No required conf vars (LPB_MAX_TOKENS_CONTEXT_RATIO retired 2026-09-02 —
42+
# response ceilings are per-model in the lemonade-pi-plugin catalog now).
43+
REQUIRED_CONF_VARS = []
4244
ENV_FILES = ["lpb.stack.env", "lpb.conf.env"]
4345

4446
# Mainstream pi repo — used only to resolve the source sha of the pinned
@@ -119,7 +121,6 @@ def build_args(
119121
"--build-arg", f"CONFIG_REF={env['LPB_CONFIG_REF']}",
120122
"--build-arg", f"NODE_VERSION={env['LPB_NODE_VERSION']}",
121123
"--build-arg", f"VSCODIUM_VERSION={env['LPB_VSCODIUM_VERSION']}",
122-
"--build-arg", f"LPB_MAX_TOKENS_CONTEXT_RATIO={env['LPB_MAX_TOKENS_CONTEXT_RATIO']}",
123124
"--build-arg", f"LPB_VERSION={lpb_version}",
124125
"--build-arg", f"IMAGE_REVISION={git_head_short(root, runner=runner)}",
125126
"--build-arg", f"IMAGE_BUILT={now.strftime('%Y-%m-%dT%H:%M:%SZ')}",

support/start.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ BARE_NAMES=(
138138
HOST
139139
CONNECTION_TOKEN
140140
DEVCONTAINER_WORKSPACE_DIR
141-
MAX_TOKENS_CONTEXT_RATIO
142141
GITHUB_TOOLSETS
143142
AGENT_BROWSER_ARGS
144143
AGENT_BROWSER_MAX_OUTPUT
@@ -155,7 +154,6 @@ declare -A BARE_FALLBACKS=(
155154
[HOST]="0.0.0.0"
156155
[CONNECTION_TOKEN]="$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen 2>/dev/null || python3 -c 'import uuid;print(uuid.uuid4())')"
157156
[DEVCONTAINER_WORKSPACE_DIR]="/home/lpb/workspace"
158-
[MAX_TOKENS_CONTEXT_RATIO]="0.06"
159157
[GITHUB_TOOLSETS]="all"
160158
[AGENT_BROWSER_ARGS]="--no-sandbox,--no-first-run,--disable-gpu,--disable-crashpad"
161159
[AGENT_BROWSER_MAX_OUTPUT]="4000"
@@ -213,7 +211,6 @@ debug "LEMONADE_BASE_URL=$LEMONADE_BASE_URL"
213211
debug "WORKSPACE_DIR=$WORKSPACE_DIR"
214212
debug "ED_PORT=$ED_PORT"
215213
debug "EDITOR_HOST=$HOST"
216-
debug "MAX_TOKENS_CONTEXT_RATIO=$MAX_TOKENS_CONTEXT_RATIO"
217214

218215
# ─── 2. RESOLVE PROJECT DIRECTORY & LOAD .ENV ──────────────────────────────
219216
# The project is a subdirectory of the workspace (e.g. "/home/lpb/workspace/<project>")

0 commit comments

Comments
 (0)