Repository navigation
[Bug][Windows Desktop] OpenAI-compatible requests silently clamp max_completion_tokens to 1 and automatic compaction fails #14342
azalata-ai
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Title: OpenAI-compatible requests silently clamp max_completion_tokens to 1 at ~23K/32K context; desktop compaction configuration targets the wrong instance
Summary
We reproduced a failure in DeepSeek Harness Desktop with a local OpenAI-compatible Strata server. A session recorded maxTokens=8192, but the actual HTTP request sent max_completion_tokens=1. This produced a one-token answer with stopReason="length" despite approximately 10K tokens of real context capacity remaining.
A related desktop configuration issue prevented automatic compaction: the profile override targeted the host compaction-basic entry, which dsh-web-app disables. The active Standard preset has a separate compaction-basic instance and retained defaults unsuitable for a 32K model.
After applying a narrowly scoped local workaround for the client-side clamp and configuring the active preset, automatic compaction succeeded in the actual Desktop UI. The summary request contained 23,245 prompt tokens, generated a 335-token checkpoint, and preserved all five control values in a subsequent independent recall test.
Environment
Issue 1: silent one-token clamp
Expected behavior
A request that fits the provider's actual 32,768-token context should retain a meaningful configured output budget. If the client cannot safely dispatch, it should surface an actionable pressure/overflow signal so Harness can compact, rather than silently changing an 8,192-token budget to one token and presenting this as an ordinary generation limit.
Actual behavior and evidence
For the reproduced Desktop session:
The failure repeated as the session grew to approximately 25K. A temporary local HTTP forwarding proxy captured:
max_completion_tokens: 1
chat_template_kwargs: { enable_thinking: false }
Thus the one-token limit was sent by the client; the server was not independently imposing it. The proxy was removed after diagnosis. No authorization headers are included in the attached evidence.
Code path
Bundled pi-ai dist/api/simple-options.js:
const CONTEXT_SAFETY_TOKENS = 4096;
const MIN_MAX_TOKENS = 1;
const available = model.contextWindow
- estimateContextTokens(context).tokens
- CONTEXT_SAFETY_TOKENS;
return Math.min(maxTokens, Math.max(MIN_MAX_TOKENS, available));
The relevant full path includes:
The bundled estimate.js uses a 3.5-characters-per-token heuristic when usable historical usage is absent. A reproduction using the installed toPiContext AND normalizeContext produced:
estimated tokens: 31082
usageTokens: 0
trailingTokens: 31082
lastUsageIndex: null
requested maxTokens: 8192
clamped maxTokens: 1
The corresponding actual Strata prompt had 22845 tokens. Calling the estimator before normalizeContext does NOT reproduce the same estimate; including normalization and tool schemas is important.
Reproduction outline
"Synthetic reliability record: validate inputs, preserve state, record failures, retry safely, verify outputs.\n"
and request only STORED.
Exact prompt counts depend on the installed system prompt and tool schemas. For a deterministic unit test, construct a normalized context whose heuristic estimate is >= contextWindow-4096, with explicit maxTokens=8192, and verify the current implementation returns 1. An integration test should also cover a real tokenizer count substantially below the heuristic estimate.
Local workaround, not a proposed generic upstream implementation
We modified only clampMaxTokensToContext in the local app.asar so that two explicitly named local Strata routes retain the requested cap. Strata then enforces its actual tokenizer/context constraints. The bypass is restricted to strata-local/strata-summary and loopback endpoints; other providers retain original behavior.
After restarting Desktop, the HTTP capture showed max_completion_tokens=8192 and enable_thinking=false. Six scope/regression assertions passed for the local routes and unrelated provider/endpoint cases.
We are NOT proposing globally disabling context protection. Potential upstream approaches include an explicit adapter capability/configuration for server-authoritative context enforcement, preserving valid usage anchors, using a suitable tokenizer, or raising an actionable overflow/compaction signal instead of silently returning a one-token cap. Please choose an approach consistent with the adapter contracts.
Issue 2: active Desktop compaction instance versus host override
Our profile originally contained a top-level patch:
name: '@deepseek-ai/dsh-compaction-basic'
config:
auto: true
thresholdRatio: 0.60
headroomTokens: 4096
retainTokens: 2048
maxTokens: 8192
compactionRetries: 2
summarizationProvider: strata-summary
summarizationModel: qwen3.8-flash-next-iq2_xs
However, dsh-web-app/cordis.patch.yml disables that host entry. The active instance belongs to:
preset-standard -> config.plugins -> compaction group -> config -> compaction-basic
That active instance had no explicit policy and retained defaults including headroomTokens=65536. For a 32768-context model, this cannot produce a valid automatic compaction budget. The pre-step handler can warn and continue before a compaction/start event is emitted, leaving the session growing while the UI subsequently reports an output-token limit.
Applying the policy to the active Standard preset fixed the Desktop automatic-compaction path. This is a configuration targeting/diagnostics issue distinct from the pi-ai clamp. Please consider documenting the effective Desktop override path, warning about overrides to disabled instances, surfacing invalid small-context policies in the UI, and providing a stable way to override only the preset's compaction policy without copying the full shipped preset.
Issue 3: enable_thinking=false compatibility requirements
Setting only compat.chatTemplateKwargs.enable_thinking=false was insufficient for this custom model. The installed openai-completions implementation emits chat_template_kwargs only when thinkingFormat="chat-template" and model.reasoning is true.
Working model configuration:
reasoningEfforts:
off: null
low: low
compat:
thinkingFormat: chat-template
chatTemplateKwargs:
enable_thinking: false
The HTTP capture confirmed the resulting field. This may be intended behavior rather than a separate bug, but validation/documentation should make the dependency explicit, particularly for users who want to disable thinking on a custom OpenAI-compatible route.
Final end-to-end validation
PROJECT=HARNESS-STRESS-2026
CHECKPOINT=ALPHA-731
MODE=READ_ONLY
CATIA_PART=Part2.CATPart
PARAMETER_COUNT=15
The Standard policy used thresholdRatio=0.60, headroomTokens=4096, retainTokens=2048, maxTokens=8192, compactionRetries=2. The calculated threshold is floor(min(32768*0.60,32768-8192-4096))=19660 estimated tokens. This is an empirically tested configuration, not a universal recommended ratio.
Requested regression coverage
Evidence and limitations
Available local artifacts: clamp-proof.json, wire-cap-evidence.json, archive-patch.json, final-checks.json, desktop-session-evidence.json, and the patched module. Review/redact full session artifacts before public upload because they may contain local paths or prompt metadata. The synthetic workload is repetitive; it does not establish universal summary fidelity or production reliability. Full arbitrary-history preservation is not claimed. No CAD files or CATIA HTTP Bridge code was modified. No report has been submitted automatically.
The current workaround changes app.asar and may be overwritten by upgrades. Is there a supported local-plugin extension point for controlling provider request budgeting after normalization, while preserving transcript integrity, tool conversion, attribution headers, cancellation, and error mapping? A supported route-specific capability would avoid maintaining a binary-package patch.
All reactions