Skip to content

feat: add contextManagement.compactionTriggerAt to lower the auto-compaction trigger - #493

Open
yujiachen-y wants to merge 1 commit into
mainfrom
feat/compaction-trigger-config
Open

yujiachen-y wants to merge 1 commit into
mainfrom
feat/compaction-trigger-config

Conversation

@yujiachen-y

@yujiachen-y yujiachen-y commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Change

Adds contextManagement.compactionTriggerAt to config.yaml so users can make automatic context compaction start earlier, for example to keep requests smaller. Refs #488.

contextManagement:
  compactionTriggerAt: 0.8 # ratio of the context window, or an absolute token count such as 300000
  • A value in (0, 1] is a ratio of the current model's context window; an integer above 1 is an absolute token count.
  • The effective trigger is min(setting, built-in trigger). The setting can only start compaction earlier, never later, so it cannot push requests past the Provider input limit. Comparable to Codex's model_auto_compact_token_limit, which is clamped to 90% of the window.
  • No lower bound by design: the user owns the choice. The docs state that a value below the post-compaction size compacts before every request.
  • Invalid numbers (1.5, 0, negatives, non-finite) are logged once as context_compaction_trigger_config_ignored and treated as unset. Non-number YAML values are dropped by the config parser. A failing config read falls back to the built-in trigger instead of throwing.
  • Unset keeps the current behavior exactly.

Out of scope, intentionally: disabling automatic compaction, per-model settings (the ratio already scales with each model's window), and the tool-result watermark (toolResultCompaction). Showing the effective trigger in /context needs the trigger threaded through the context-usage snapshot and is left for a follow-up.

Implementation:

  • @mavis/context-manager: resolveCompactionTokenBudget takes an optional compactionTriggerAt; validation lives in isValidCompactionTriggerSetting / resolveConfiguredCompactionTrigger. Only automaticTriggerAt changes; providerInputLimit and its other consumers (manual compaction, reminder admission) are untouched.
  • local-runtime-v2: AutomaticContextCompactor reads the setting per call through an injected getter wired in production-composition.ts.
  • @mavis/config: parses the new key; it only keeps numbers because @mavis/config cannot depend on @mavis/context-manager.
  • Docs: new "Automatic context compaction trigger" section in docs/tui-capabilities.md.

Validation

  • Checks run and results: pnpm verify (full profile) on 2a8d121, darwin: 15 gates passed; test:windows and test:release-package not applicable locally.
  • New tests: provider-budget.test.ts (ratio, absolute, above built-in, invalid values), automatic-context-compactor.test.ts (probe starts earlier only from a valid setting; invalid or throwing getter keeps the built-in trigger), packages/config/test/context-management-config.test.ts (parsing). The compactor test fails on the baseline compactor and passes with this change.
  • Sandbox check (temporary data dir, real config.yaml, 200K window / 32K output): 0.5 → 100,000; 120000 → 120,000; 0.95, 1.5 and "0.5" → built-in 159,600.
  • Performance: basic. Unset configuration does not change any runtime path; no history construction, serialization or token-estimation changes.
  • NOT RUN: a live long session against a real model; Linux/Windows locally (covered by CI).

Publication and contribution checks

  • I have permission to contribute these changes under the existing licenses applicable to the changed files/packages; imported material and its provenance are identified and existing notices are preserved.
  • No credentials, account data, real user content, internal source history or private review material is included.
  • Added/removed source files were reviewed before regenerating release/public-source.json; new tests are declared in test/vitest-suites.json where applicable.
  • Shared English/Chinese documentation and capability/verification records are updated where applicable. Mock/offline results are not described as live-service acceptance.

Maintainer handoff

Publication scope or license changes (if any): none; one new test file.

Shared-source port: pending.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…paction trigger

Users can set an upper bound for the automatic context compaction trigger in
config.yaml, as a ratio of the context window in (0, 1] or as an absolute token
count above 1. The effective trigger is min(setting, built-in trigger), so the
setting can only start compaction earlier; there is no lower bound by design.
Invalid numbers such as 1.5 are logged once and ignored, and an unreadable
config falls back to the built-in trigger.

Refs #488
@yujiachen-y yujiachen-y added enhancement New feature or request tui Interactive terminal UI (TUI) cli Standalone mcode: TUI, headless, ACP and source builds/tooling labels Oct 15, 2026

@hetaoBackend hetaoBackend 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.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Standalone mcode: TUI, headless, ACP and source builds/tooling enhancement New feature or request tui Interactive terminal UI (TUI)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants