Skip to content

fix(models): preserve explicitly configured maxTokens when window-capping - #63

Merged
Leechael merged 1 commit into
mainfrom
fix/preserve-explicit-max-tokens
Jul 25, 2026
Merged

fix(models): preserve explicitly configured maxTokens when window-capping#63
Leechael merged 1 commit into
mainfrom
fix/preserve-explicit-max-tokens

Conversation

@Leechael

@Leechael Leechael commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Stacked on #59 — merge after it

#59 is from a fork, so its branch can't be a PR base here; this PR targets main and its diff will shrink to the single fix commit once #59 merges.

What

#59 window-caps every built model's maxTokens at its context window via withWindowCappedMaxTokens, which silently discards an explicitly configured model.maxTokens — home, project, and runtime settings all get reset to the window. This PR preserves the explicit cap and applies the window value only for the default/unset case.

How

  • "Unset" is detected by value (maxTokens === built-in default 32000), not by config source: ensureKimiCodeConfig materializes the full default config (including maxTokens) into the home config file, so source tracking reports home for users who never set the field — source-based detection would defeat the window-cap for exactly the users it targets.
  • Window-tracked caps follow discovery: buildKimiModelFromConfig caps before discovery runs, so applyKimiOAuthExtrasToModel captures the window-tracked state before extras grow the window, and only re-caps maxTokens to the new window when it was tracking. Explicit caps survive discovery unchanged.

Known edges (documented in code)

  • An explicit maxTokens: 32000 is indistinguishable from a materialized default and gets the window cap — acceptable, since that is the intended new default behavior.
  • An explicit value equal to the context window is treated as window-tracked (harmless: value equals the window anyway).

Tests

Two new cases: explicit cap preserved at build time, and preserved when discovery grows the window. tsc --noEmit, oxlint, and the full suite pass (235/235).


Summary by cubic

Preserves explicitly configured max tokens when window-capping models, so user-set limits are not overwritten. The window cap now applies only when the value is unset (default) or already tracking the window.

  • Bug Fixes
    • Detect “unset” by value (32000) instead of config source to handle materialized defaults.
    • Track window-capped state across discovery; re-cap only if it was tracking, keep explicit caps unchanged.
    • Added tests for build-time and for discovery when the window grows.

Written for commit e622aa9. Summary will update on new commits.

Review in cubic

…ping

PR #59 window-caps every built model's maxTokens at its context window,
which silently discards an explicitly configured model.maxTokens — home,
project, and runtime settings all get reset to the window.

Preserve the explicit cap and apply the window value only for the
default/unset case:

- "Unset" is detected by value (maxTokens === built-in default), not by
  config source: ensureKimiCodeConfig materializes the full default config
  (including maxTokens: 32000) into the home config file, so source
  tracking reports "home" for users who never set the field and would
  defeat the window-cap for them.
- A cap already equal to the context window is also treated as unset:
  buildKimiModelFromConfig caps before discovery runs, so
  applyKimiOAuthExtrasToModel captures the window-tracked state before
  extras grow the window, and only then re-caps maxTokens to the new
  window. Explicit caps survive discovery unchanged.

Known edges (documented in code): an explicit 32000 is indistinguishable
from a materialized default and gets the window cap; an explicit value
equal to the window is treated as window-tracked.

Stacked on #59.
@github-actions

Copy link
Copy Markdown
Contributor

CI summary

  • Test coverage: Lines 91.73, branches 80.85, functions 90.59
  • Package size: Packed 56 KB, unpacked 204 KB, files 18
Check Result
Tests passed
Type check success
Lint success
Format success

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@Leechael
Leechael merged commit 249d98b into main Jul 25, 2026
4 checks passed
@Leechael
Leechael deleted the fix/preserve-explicit-max-tokens branch July 25, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant