Skip to content

fix: allow configuring Pi output token limit - #12393

Merged
danielhanchen merged 2 commits into
unslothai:mainfrom
Imagineer99:fix/pi-output-token-limit
Oct 1, 2026
Merged

danielhanchen merged 2 commits into
unslothai:mainfrom
Imagineer99:fix/pi-output-token-limit

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Pi launches regenerate models.json with a fixed output cap (a quarter of the context window, up to 32,000 tokens), so users cannot request longer responses without editing each session's config.

Add --max-tokens to unsloth start pi and pass it into both the normal provider config and the local subagent config. For example:

unsloth start pi --model 'path' --max-tokens 10000

The option is the same shared --max-tokens that unsloth start opencode already takes, with the same rules: the default is unchanged when omitted, nonpositive values are rejected, and a value above half the loaded context window is capped at half with a warning so the conversation keeps room. When Studio reports no context length, the requested value is written as given. The option must be supplied each launch; it does not create a saved preference.

Validation: unsloth_cli/tests/test_start.py and unsloth_cli/tests/test_pi_subagent.py pass. Tests cover both launch modes, repeated config generation, the half-window cap, invalid values, and missing or alternate context metadata.

@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #12393, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#270.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 3131fcff9 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on unsloth_cli/commands/start.py (on the mirror)

@@ -5714,6 +5729,7 @@ def pi(
     launch: bool = _LAUNCH_OPTION,
     gguf_variant: Optional[str] = _GGUF_VARIANT_OPTION,
     max_seq_length: int = _CONTEXT_OPTION,
+    max_tokens: Optional[int] = _MAX_TOKENS_OPTION,

P2 Badge Accept the advertised underscore alias

When a caller uses the advertised --max_tokens spelling, this added parameter never receives the value because the shared _MAX_TOKENS_OPTION declares only --max-tokens. Since Pi uses _PASSTHROUGH with unknown options ignored, the unrecognized flag is silently forwarded in ctx.args to Pi while the generated config keeps its default token limit, so this supported invocation does not configure the requested output length and may instead fail in the downstream CLI.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Not adopting the alias: Pi now reuses the shared --max-tokens option that opencode already uses, which has no underscore spelling and is the only one --help lists. The underscore mention was a stale line in the PR description, now corrected.

chatgpt-codex-connector[bot] on unsloth_cli/commands/start.py (on the mirror)

@@ -5084,7 +5099,7 @@ def write_pi_subagent_config(
             "apiKey": key,
             "model": model["id"],
             "contextWindow": window,
-            "maxTokens": opencode_output_limit(window),
+            "maxTokens": _agent_output_limit(window, max_tokens),

P2 Badge Preserve the requested limit when subagent context is unknown

When Studio returns a model without either context-length field, write_pi_subagent_config substitutes 32,768 and then treats that fabricated fallback as a known window. Consequently, pi --as-subagent --max-tokens 40000 silently writes 16,384, while the normal Pi path correctly writes the requested 40,000 for the same metadata-less model. Apply the half-window cap only when Studio supplied an actual context length.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Intentional: in subagent mode the same config also pins contextWindow to 32768 and the extension registers the model with it, and pi-ai clamps every request's output to the room left in that window (clampMaxTokensToContext). 40000 can never be sent there, so capping at half the window Pi actually uses keeps the conversation room. The normal path writes no contextWindow, so Pi uses its 128k default and 40000 fits.

Verdict

The round did not reach a clean review on the mirror before it closed.

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants