Skip to content

fix(session): honor compaction.reserved without limit.input [AI-generated, unverified] - #48813

Closed
Moonbius-lab wants to merge 1 commit into
anomalyco:devfrom
Moonbius-lab:compaction-reserved
Closed

Moonbius-lab wants to merge 1 commit into
anomalyco:devfrom
Moonbius-lab:compaction-reserved

Conversation

@Moonbius-lab

Copy link
Copy Markdown

Warning

AI-generated, not human-reviewed. This PR was produced by an AI coding agent and has not been reviewed or tested by a human. It is provided for reference only — please do not merge without independent review and verification.

Summary

usable() in packages/opencode/src/session/overflow.ts silently ignores a user-configured compaction.reserved whenever the model does not define limit.input.

In that branch the limit is computed as context - maxOutputTokens(...), while the already-computed reserved value is discarded. As a result compaction.reserved has no effect for such models and auto-compaction fires much later than configured. For example, a model with limit.context: 1000000 only compacts around ~968k tokens (context - min(limit.output, OUTPUT_TOKEN_MAX=32000)), even if the user set compaction.reserved to a much larger value.

Change

  • Compute the reserved buffer once and use the configured compaction.reserved in both branches.
  • Preserve existing defaults when compaction.reserved is unset:
    • limit.input present: limit.input - min(COMPACTION_BUFFER, maxOutputTokens)
    • otherwise: context - maxOutputTokens
-  const reserved =
-    input.cfg.compaction?.reserved ??
-    Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
-  return input.model.limit.input
-    ? Math.max(0, input.model.limit.input - reserved)
-    : Math.max(0, context - ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax))
+  const reserved = input.cfg.compaction?.reserved
+  const output = ProviderTransform.maxOutputTokens(input.model, input.outputTokenMax)
+  return input.model.limit.input
+    ? Math.max(0, input.model.limit.input - (reserved ?? Math.min(COMPACTION_BUFFER, output)))
+    : Math.max(0, context - (reserved ?? output))

Verification status

  • Not verified. I could not run bun typecheck or the test suite (no Bun toolchain available in the environment this was authored in).
  • Change is intentionally small and localized.

Related reports

Not addressed here

Old media (images / PDFs) is persisted as base64 and replayed from history; the stripMedia option in packages/opencode/src/session/message-v2.ts currently has no callers. That is a separate concern and is not changed by this PR.

@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title [AI-generated, unverified] fix(session): honor compaction.reserved without limit.input doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

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

Potential duplicate/related PRs found:

  1. PR fix(session): trigger auto-compaction at the effective input ceiling (#45168) #45933 - fix(session): trigger auto-compaction at the effective input ceiling — Directly addresses auto-compaction triggering logic with effective input ceilings, likely overlapping with this fix's core issue.

  2. PR fix(compaction): use cumulative token usage for auto-compaction overflow check #46136 - fix(compaction): use cumulative token usage for auto-compaction overflow check — Related to compaction overflow behavior and token usage calculation.

  3. PR feat(opencode): support per-model compaction config #43713 - feat(opencode): support per-model compaction config — Earlier feature work on per-model compaction configuration, foundational to the issue this PR addresses.

  4. PR feat(core): enhanced compaction with ratios and combined context-restoration advancement #45125 - feat(core): enhanced compaction with ratios and combined context-restoration advancement — Related compaction enhancement work.

These PRs appear to be addressing related compaction and auto-trigger issues in the session management system. PR #45933 seems most closely related to the logic this PR modifies.

@Moonbius-lab Moonbius-lab changed the title [AI-generated, unverified] fix(session): honor compaction.reserved without limit.input fix(session): honor compaction.reserved without limit.input [AI-generated, unverified] Sep 13, 2026
@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.

@Moonbius-lab

Copy link
Copy Markdown
Author

Closing as superseded by #45933, which rewrites usable() in the same file and already honors a configured compaction.reserved (and adds unit tests, including a deepseek 1M/384k case). No need for a duplicate. (This PR was AI-generated and unverified.)

@Moonbius-lab
Moonbius-lab deleted the compaction-reserved branch September 13, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant