Skip to content

fix: prevent infinite auto-compact loop for unknown 3P models (#635) - #636

Merged
kevincodex1 merged 1 commit into
Twigpine:mainfrom
Vasanthdev2004:fix/auto-compact-infinite-loop-635
Apr 12, 2026
Merged

kevincodex1 merged 1 commit into
Twigpine:mainfrom
Vasanthdev2004:fix/auto-compact-infinite-loop-635

Conversation

@Vasanthdev2004

Copy link
Copy Markdown
Collaborator

Summary

Fixes #635 — auto-compact fires on every message for 3P models not in the context window table.

Root cause

The 8,000 token fallback in getContextWindowForModel() was too low. Combined with output token reservation (8k–20k) and the 13k auto-compact buffer, the effective context window went negative, causing isAboveAutoCompactThreshold to be true for any non-zero token usage.

Changes

1. Raise fallback from 8k → 128k (src/utils/context.ts)

  • Unknown 3P models now get OPENAI_FALLBACK_CONTEXT_WINDOW = 128_000 instead of 8,000
  • 128k is a reasonable conservative default for modern 3P models (most support 128k+)
  • Effective context: 128k - 20k = 108k → healthy positive threshold

2. Add safety floor in getEffectiveContextWindowSize() (src/services/compact/autoCompact.ts)

  • Math.max(effectiveContext, reservedTokensForSummary + 13_000)
  • Even if someone sets CLAUDE_CODE_AUTO_COMPACT_WINDOW to a very low value, the effective context can never go below the summary reservation plus buffer
  • This is a defense-in-depth guard: even if the fallback changes again, the floor prevents infinite loops

3. Add missing MiniMax model entries (src/utils/model/openaiContextWindows.ts)

  • MiniMax-M2.7-highspeed, MiniMax-M2.5, MiniMax-M2.5-highspeed, MiniMax-M2.1, MiniMax-M2.1-highspeed (and lowercase variants)
  • All at 204,800 context / 131,072 max output per MiniMax docs
  • These were falling through to the 8k fallback because MiniMax-M2.5 doesn't prefix-match MiniMax-M2.7

4. Tests

  • Updated existing test: unknown 3P model → 128k (was 8k)
  • Added test: MiniMax M2.5/M2.1 variants resolve to 204,800 context
  • Added autoCompact.test.ts: getEffectiveContextWindowSize never returns negative, getAutoCompactThreshold never returns negative

Validation

+5 files, +100/-9

CI should pass — all changes are additive or value corrections, no breaking API changes.

…ne#635)

- Raise context window fallback from 8k to 128k for unknown OpenAI-compat models.
  The 8k fallback caused effective context (8k minus output reservation) to go
  negative, making auto-compact fire on every single message.
- Add safety floor in getEffectiveContextWindowSize(): effective context is
  always at least reservedTokensForSummary + 13k buffer, ensuring the
  auto-compact threshold stays positive.
- Add missing MiniMax model entries (M2.5, M2.5-highspeed, M2.1, M2.1-highspeed)
  all at 204,800 context / 131,072 max output per MiniMax docs.
- Add tests for MiniMax variants, 128k fallback, and autoCompact floor.

Fixes Twigpine#635
@kevincodex1
kevincodex1 merged commit aeaa658 into Twigpine:main Apr 12, 2026
1 check passed
lunamonke pushed a commit to lunamonke/openclaude that referenced this pull request Apr 12, 2026
…ne#635) (Twigpine#636)

- Raise context window fallback from 8k to 128k for unknown OpenAI-compat models.
  The 8k fallback caused effective context (8k minus output reservation) to go
  negative, making auto-compact fire on every single message.
- Add safety floor in getEffectiveContextWindowSize(): effective context is
  always at least reservedTokensForSummary + 13k buffer, ensuring the
  auto-compact threshold stays positive.
- Add missing MiniMax model entries (M2.5, M2.5-highspeed, M2.1, M2.1-highspeed)
  all at 204,800 context / 131,072 max output per MiniMax docs.
- Add tests for MiniMax variants, 128k fallback, and autoCompact floor.

Fixes Twigpine#635

Co-authored-by: root <root@vm7508.lumadock.com>
euxaristia pushed a commit to euxaristia/openclaude that referenced this pull request Apr 13, 2026
…ne#635) (Twigpine#636)

- Raise context window fallback from 8k to 128k for unknown OpenAI-compat models.
  The 8k fallback caused effective context (8k minus output reservation) to go
  negative, making auto-compact fire on every single message.
- Add safety floor in getEffectiveContextWindowSize(): effective context is
  always at least reservedTokensForSummary + 13k buffer, ensuring the
  auto-compact threshold stays positive.
- Add missing MiniMax model entries (M2.5, M2.5-highspeed, M2.1, M2.1-highspeed)
  all at 204,800 context / 131,072 max output per MiniMax docs.
- Add tests for MiniMax variants, 128k fallback, and autoCompact floor.

Fixes Twigpine#635

Co-authored-by: root <root@vm7508.lumadock.com>
C1ph3r404 pushed a commit to C1ph3r404/openclaude that referenced this pull request Apr 29, 2026
…ne#635) (Twigpine#636)

- Raise context window fallback from 8k to 128k for unknown OpenAI-compat models.
  The 8k fallback caused effective context (8k minus output reservation) to go
  negative, making auto-compact fire on every single message.
- Add safety floor in getEffectiveContextWindowSize(): effective context is
  always at least reservedTokensForSummary + 13k buffer, ensuring the
  auto-compact threshold stays positive.
- Add missing MiniMax model entries (M2.5, M2.5-highspeed, M2.1, M2.1-highspeed)
  all at 204,800 context / 131,072 max output per MiniMax docs.
- Add tests for MiniMax variants, 128k fallback, and autoCompact floor.

Fixes Twigpine#635

Co-authored-by: root <root@vm7508.lumadock.com>
The-FOOL-00 pushed a commit to The-FOOL-00/openclaude that referenced this pull request May 24, 2026
…ne#635) (Twigpine#636)

- Raise context window fallback from 8k to 128k for unknown OpenAI-compat models.
  The 8k fallback caused effective context (8k minus output reservation) to go
  negative, making auto-compact fire on every single message.
- Add safety floor in getEffectiveContextWindowSize(): effective context is
  always at least reservedTokensForSummary + 13k buffer, ensuring the
  auto-compact threshold stays positive.
- Add missing MiniMax model entries (M2.5, M2.5-highspeed, M2.1, M2.1-highspeed)
  all at 204,800 context / 131,072 max output per MiniMax docs.
- Add tests for MiniMax variants, 128k fallback, and autoCompact floor.

Fixes Twigpine#635

Co-authored-by: root <root@vm7508.lumadock.com>
discopops pushed a commit to discopops/openclaude that referenced this pull request May 28, 2026
…ne#635) (Twigpine#636)

- Raise context window fallback from 8k to 128k for unknown OpenAI-compat models.
  The 8k fallback caused effective context (8k minus output reservation) to go
  negative, making auto-compact fire on every single message.
- Add safety floor in getEffectiveContextWindowSize(): effective context is
  always at least reservedTokensForSummary + 13k buffer, ensuring the
  auto-compact threshold stays positive.
- Add missing MiniMax model entries (M2.5, M2.5-highspeed, M2.1, M2.1-highspeed)
  all at 204,800 context / 131,072 max output per MiniMax docs.
- Add tests for MiniMax variants, 128k fallback, and autoCompact floor.

Fixes Twigpine#635

Co-authored-by: root <root@vm7508.lumadock.com>
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.

bug: auto-compact fires every turn for 3P models not in context window table (8k fallback causes infinite loop)

3 participants