Skip to content

fix(core): ignore impossible usage reports in compaction preflight - #50796

Open
Veld101 wants to merge 1 commit into
anomalyco:v2from
Veld101:compaction-usage-guard
Open

Veld101 wants to merge 1 commit into
anomalyco:v2from
Veld101:compaction-usage-guard

Conversation

@Veld101

@Veld101 Veld101 commented Sep 23, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #50474

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

SessionCompaction.required compares estimateTokens() against the buffered prompt ceiling and never checks that the reported usage is possible. In #50474 a provider reported usage.input of 25-33M against a model whose context window is 1,048,576. estimateTokens() sums the anchor message's reported tokens, so the comparison is true on every step, auto-compaction runs again, and the loop only stops when the session is interrupted.

A real prompt cannot exceed the model's context window, so usage that does cannot be genuine and should not schedule a checkpoint. The guard runs before the ceiling comparison and only rejects impossible reports; a prompt that exactly fills the window still compacts. Genuine overflow still recovers through the context-overflow failure path, so no recovery capability is lost.

I did not change estimateTokens itself, which stays the pure size estimator the other call sites and tests rely on.

How did you verify your code works?

Added assertions to the existing auto compaction estimates current content against the buffered prompt ceiling test:

  • reported input of 25,391,744 against context: 1_048_576 returns false
  • a prompt that exactly fills the window (1_048_576) still returns true

Removing the guard makes both assertions fail.

bun test test/session-compaction.test.ts   # 11 pass, 0 fail
bun typecheck                              # packages/core, clean
bun run lint                               # clean

The full packages/core suite is 4736 pass / 27 fail. The failures reproduce on unmodified v2 — I verified a sample with this change stashed — and are Windows environment issues (shell, git worktrees, config discovery), unrelated to this change.

A V1 variant of the same fix is open as #50537. This PR is the v2 change for the report.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PRs Found

PR #50537 - fix(session): ignore impossible usage reports in compaction preflight

PR #44264 - feat(session): add suffix compaction

Note: PR #50796 is your current PR and is shown in the results, but should not be considered a duplicate of itself.

@Veld101
Veld101 force-pushed the compaction-usage-guard branch from f8b9c29 to 95ebdb4 Compare September 29, 2026 00:45

This branch has not been deployed

No deployments
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.

1 participant