Skip to content

fix: use raw context window for auto-compact percentage display - #748

Merged
kevincodex1 merged 1 commit into
Twigpine:mainfrom
bpawnzZ:fix/autocompact-percentage-v2
Apr 19, 2026
Merged

kevincodex1 merged 1 commit into
Twigpine:mainfrom
bpawnzZ:fix/autocompact-percentage-v2

Conversation

@bpawnzZ

@bpawnzZ bpawnzZ commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Problem: After auto-compaction with DeepSeek models (e.g., deepseek-chat), the status line displayed ~16% remaining until next auto-compact, but users expected ~30% (since compaction reduces usage to roughly half of the full 128k context).

Root cause: calculateTokenWarningState() used the auto-compaction threshold (effectiveContextWindow - 13k buffer) as the denominator for percentLeft. For DeepSeek-chat:

  • Raw context: 128,000
  • Effective: 119,808 (128k - 8,192 output reservation)
  • Threshold: 106,808 (effective - 13k buffer) At 90k usage:
    • Old: (106,808 - 90k) / 106,808 ≈ 16%
    • Expected: (128,000 - 90k) / 128,000 ≈ 30%

Fix: Change percentLeft calculation to use raw context window from getContextWindowForModel() as denominator, while keeping threshold-based warnings/triggers unchanged. This makes the displayed percentage show remaining capacity relative to the model's full context size.

Impact:

  • UI now shows correct % of total context remaining
  • Auto-compaction trigger point unchanged (still ~90% of effective window)
  • All other threshold calculations unaffected

Testing:

  • Manual verification: DeepSeek-chat at 90k tokens shows 30% remaining (was 16%)
  • Manual verification: Threshold still triggers at ~106k tokens
  • Build succeeds: npm run build
  • No breaking changes: Callers only depend on percentLeft for display; threshold logic unchanged

Fixes the user-reported discrepancy for DeepSeek and other OpenAI-compatible models.

Summary

  • what changed
  • why it changed

Impact

  • user-facing impact:
  • developer/maintainer impact:

Testing

  • bun run build
  • bun run smoke
  • focused tests:

Notes

  • provider/model path tested:
  • screenshots attached (if UI changed):
  • follow-up work or known limitations:

Problem: After auto-compaction with DeepSeek models (e.g., deepseek-chat),
the status line displayed ~16% remaining until next auto-compact, but users
expected ~30% (since compaction reduces usage to roughly half of the full
128k context).

Root cause: calculateTokenWarningState() used the auto-compaction threshold
(effectiveContextWindow - 13k buffer) as the denominator for percentLeft.
For DeepSeek-chat:
- Raw context: 128,000
- Effective: 119,808 (128k - 8,192 output reservation)
- Threshold: 106,808 (effective - 13k buffer)
At 90k usage:
  - Old: (106,808 - 90k) / 106,808 ≈ 16%
  - Expected: (128,000 - 90k) / 128,000 ≈ 30%

Fix: Change percentLeft calculation to use raw context window from
getContextWindowForModel() as denominator, while keeping threshold-based
warnings/triggers unchanged. This makes the displayed percentage show
remaining capacity relative to the model's full context size.

Impact:
- UI now shows correct % of total context remaining
- Auto-compaction trigger point unchanged (still ~90% of effective window)
- All other threshold calculations unaffected

Testing:
- Manual verification: DeepSeek-chat at 90k tokens shows 30% remaining (was 16%)
- Manual verification: Threshold still triggers at ~106k tokens
- Build succeeds: npm run build
- No breaking changes: Callers only depend on percentLeft for display; threshold logic unchanged

Fixes the user-reported discrepancy for DeepSeek and other OpenAI-compatible models.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: PR #748 — Use raw context window for auto-compact percentage display

Reviewed on head d1c9db9. No CI runs. 1 file, +6/-1.

Small, targeted fix for a real UX confusion. The old formula used threshold (effective context minus 13k buffer) as the denominator, making the percentage look much lower than users expected. The new formula uses rawContextWindow from getContextWindowForModel(), so users see remaining capacity relative to the model's full context size.

✅ What looks good

  • Correct fix: Display should show % of full context remaining, not % of compaction trigger remaining
  • Behavior unchanged: Threshold-based warnings and auto-compact triggers still use the old threshold value
  • Well-commented: The 3-line comment explains why raw context is used for display
  • Edge cases handled: Math.max(0, ...) prevents negative percentages when over context
  • Consistent with PR #636: getContextWindowForModel() now has 128k fallback + safety floor, so division by zero isn't a concern

🟡 Non-blocking

  • No test coverage for calculateTokenWarningState: There are no existing tests for this function. A unit test would be nice to lock in the percentLeft formula (especially to prevent future regressions where someone might revert to using threshold), but for a 4-line display-only change this is acceptable.
  • No CI: Needs CI verification before merge.

Verdict: Approve-ready ✅ (pending CI)

@bpawnzZ bpawnzZ closed this Apr 18, 2026
@bpawnzZ bpawnzZ reopened this Apr 18, 2026
@bpawnzZ

bpawnzZ commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

🚀 PR #748 has been reviewed and approved by @Vasanthdev2004! The fix changes calculateTokenWarningState() to use rawContextWindow for percentage display while keeping threshold-based warnings unchanged. This resolves the UX confusion where DeepSeek models showed ~16% remaining instead of the expected ~30%.

Status: Approved, mergeable, but blocked on CI checks. No new comments or issues detected. The build passes locally.

@bpawnzZ

bpawnzZ commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

✅ Manual verification: Build succeeds locally with bun run build. The fix correctly changes calculateTokenWarningState() to use rawContextWindow for percentage display while keeping threshold-based warnings unchanged. This resolves the UX confusion where DeepSeek models showed ~16% remaining instead of the expected ~30%.

@bpawnzZ bpawnzZ closed this Apr 18, 2026
@bpawnzZ bpawnzZ reopened this Apr 18, 2026
@bpawnzZ

bpawnzZ commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

🚨 CI Issue Detected: The PR checks workflow shows 'action_required' but no jobs were created. This appears to be a GitHub Actions configuration issue rather than a problem with the code. The fix builds successfully locally with 🔇 no-telemetry: stubbed 21 modules
✓ Built openclaude v0.4.0 → dist/cli.mjs
🔄 feature-flags: pre-processed 205 files (restored) and has been approved.

Recommendation: A maintainer with admin rights needs to rerun the workflow or manually merge since the code is correct and builds successfully.

@bpawnzZ

bpawnzZ commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @Vasanthdev2004!

I've analyzed your review and here's my assessment:

✅ Build verification: The code compiles successfully with 🔇 no-telemetry: stubbed 21 modules
✓ Built openclaude v0.4.0 → dist/cli.mjs
🔄 feature-flags: pre-processed 205 files (restored)
✅ Code analysis: The fix correctly uses for percentage display while maintaining for warnings/compaction
⚠️ Test coverage: As noted, there are no existing unit tests for - this would be a good addition but isn't blocking
⚠️ CI status: The commit status is currently 'pending' - CI needs to run before merge

Recommendations:

  1. Wait for CI to complete and verify all checks pass
  2. Consider adding a unit test for in a follow-up PR to prevent regressions
  3. Merge once CI is green

The fix looks solid and addresses the UX confusion as intended.

@kevincodex1
kevincodex1 merged commit 55c5f26 into Twigpine:main Apr 19, 2026
1 check passed
hotmanxp pushed a commit to hotmanxp/openclaude that referenced this pull request Apr 20, 2026
…pine#748)

Problem: After auto-compaction with DeepSeek models (e.g., deepseek-chat),
the status line displayed ~16% remaining until next auto-compact, but users
expected ~30% (since compaction reduces usage to roughly half of the full
128k context).

Root cause: calculateTokenWarningState() used the auto-compaction threshold
(effectiveContextWindow - 13k buffer) as the denominator for percentLeft.
For DeepSeek-chat:
- Raw context: 128,000
- Effective: 119,808 (128k - 8,192 output reservation)
- Threshold: 106,808 (effective - 13k buffer)
At 90k usage:
  - Old: (106,808 - 90k) / 106,808 ≈ 16%
  - Expected: (128,000 - 90k) / 128,000 ≈ 30%

Fix: Change percentLeft calculation to use raw context window from
getContextWindowForModel() as denominator, while keeping threshold-based
warnings/triggers unchanged. This makes the displayed percentage show
remaining capacity relative to the model's full context size.

Impact:
- UI now shows correct % of total context remaining
- Auto-compaction trigger point unchanged (still ~90% of effective window)
- All other threshold calculations unaffected

Testing:
- Manual verification: DeepSeek-chat at 90k tokens shows 30% remaining (was 16%)
- Manual verification: Threshold still triggers at ~106k tokens
- Build succeeds: npm run build
- No breaking changes: Callers only depend on percentLeft for display; threshold logic unchanged

Fixes the user-reported discrepancy for DeepSeek and other OpenAI-compatible models.
C1ph3r404 pushed a commit to C1ph3r404/openclaude that referenced this pull request Apr 29, 2026
…pine#748)

Problem: After auto-compaction with DeepSeek models (e.g., deepseek-chat),
the status line displayed ~16% remaining until next auto-compact, but users
expected ~30% (since compaction reduces usage to roughly half of the full
128k context).

Root cause: calculateTokenWarningState() used the auto-compaction threshold
(effectiveContextWindow - 13k buffer) as the denominator for percentLeft.
For DeepSeek-chat:
- Raw context: 128,000
- Effective: 119,808 (128k - 8,192 output reservation)
- Threshold: 106,808 (effective - 13k buffer)
At 90k usage:
  - Old: (106,808 - 90k) / 106,808 ≈ 16%
  - Expected: (128,000 - 90k) / 128,000 ≈ 30%

Fix: Change percentLeft calculation to use raw context window from
getContextWindowForModel() as denominator, while keeping threshold-based
warnings/triggers unchanged. This makes the displayed percentage show
remaining capacity relative to the model's full context size.

Impact:
- UI now shows correct % of total context remaining
- Auto-compaction trigger point unchanged (still ~90% of effective window)
- All other threshold calculations unaffected

Testing:
- Manual verification: DeepSeek-chat at 90k tokens shows 30% remaining (was 16%)
- Manual verification: Threshold still triggers at ~106k tokens
- Build succeeds: npm run build
- No breaking changes: Callers only depend on percentLeft for display; threshold logic unchanged

Fixes the user-reported discrepancy for DeepSeek and other OpenAI-compatible models.
The-FOOL-00 pushed a commit to The-FOOL-00/openclaude that referenced this pull request May 24, 2026
…pine#748)

Problem: After auto-compaction with DeepSeek models (e.g., deepseek-chat),
the status line displayed ~16% remaining until next auto-compact, but users
expected ~30% (since compaction reduces usage to roughly half of the full
128k context).

Root cause: calculateTokenWarningState() used the auto-compaction threshold
(effectiveContextWindow - 13k buffer) as the denominator for percentLeft.
For DeepSeek-chat:
- Raw context: 128,000
- Effective: 119,808 (128k - 8,192 output reservation)
- Threshold: 106,808 (effective - 13k buffer)
At 90k usage:
  - Old: (106,808 - 90k) / 106,808 ≈ 16%
  - Expected: (128,000 - 90k) / 128,000 ≈ 30%

Fix: Change percentLeft calculation to use raw context window from
getContextWindowForModel() as denominator, while keeping threshold-based
warnings/triggers unchanged. This makes the displayed percentage show
remaining capacity relative to the model's full context size.

Impact:
- UI now shows correct % of total context remaining
- Auto-compaction trigger point unchanged (still ~90% of effective window)
- All other threshold calculations unaffected

Testing:
- Manual verification: DeepSeek-chat at 90k tokens shows 30% remaining (was 16%)
- Manual verification: Threshold still triggers at ~106k tokens
- Build succeeds: npm run build
- No breaking changes: Callers only depend on percentLeft for display; threshold logic unchanged

Fixes the user-reported discrepancy for DeepSeek and other OpenAI-compatible models.
discopops pushed a commit to discopops/openclaude that referenced this pull request May 28, 2026
…pine#748)

Problem: After auto-compaction with DeepSeek models (e.g., deepseek-chat),
the status line displayed ~16% remaining until next auto-compact, but users
expected ~30% (since compaction reduces usage to roughly half of the full
128k context).

Root cause: calculateTokenWarningState() used the auto-compaction threshold
(effectiveContextWindow - 13k buffer) as the denominator for percentLeft.
For DeepSeek-chat:
- Raw context: 128,000
- Effective: 119,808 (128k - 8,192 output reservation)
- Threshold: 106,808 (effective - 13k buffer)
At 90k usage:
  - Old: (106,808 - 90k) / 106,808 ≈ 16%
  - Expected: (128,000 - 90k) / 128,000 ≈ 30%

Fix: Change percentLeft calculation to use raw context window from
getContextWindowForModel() as denominator, while keeping threshold-based
warnings/triggers unchanged. This makes the displayed percentage show
remaining capacity relative to the model's full context size.

Impact:
- UI now shows correct % of total context remaining
- Auto-compaction trigger point unchanged (still ~90% of effective window)
- All other threshold calculations unaffected

Testing:
- Manual verification: DeepSeek-chat at 90k tokens shows 30% remaining (was 16%)
- Manual verification: Threshold still triggers at ~106k tokens
- Build succeeds: npm run build
- No breaking changes: Callers only depend on percentLeft for display; threshold logic unchanged

Fixes the user-reported discrepancy for DeepSeek and other OpenAI-compatible models.
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.

4 participants