Skip to content

feat(compaction): add configurable protectedTools to exempt tools from pruning#6557

Open
marlian wants to merge 1 commit intoKilo-Org:mainfrom
legate-dev:feature/configurable-prune-protected-tools
Open

feat(compaction): add configurable protectedTools to exempt tools from pruning#6557
marlian wants to merge 1 commit intoKilo-Org:mainfrom
legate-dev:feature/configurable-prune-protected-tools

Conversation

@marlian
Copy link

@marlian marlian commented Mar 3, 2026

Summary

  • Adds compaction.protectedTools config option (string[]) to specify additional tool names that should be exempt from context pruning
  • The built-in "skill" tool remains always protected as a hardcoded default
  • User-specified tools are merged with defaults using concat + dedup, following the existing pattern for plugin and instructions arrays

Problem

The pruner (prune() in compaction.ts) replaces old tool outputs with "[Old tool result content cleared]" to save context window space. Currently, only the built-in skill tool is protected from this behavior via a hardcoded array.

Users who rely on MCP-based skill/context loaders (or any tool whose output must persist throughout the session) have no way to prevent their content from being silently erased after ~40k tokens of newer tool output accumulate. This causes the model to lose critical operational context mid-session.

Solution

Make the protection list configurable:

{
  "compaction": {
    "protectedTools": ["my_mcp_server_skill_loader", "another_context_tool"]
  }
}

Changes

File Change
src/config/config.ts Add protectedTools: z.array(z.string()).optional() to compaction schema
src/config/config.ts Extend mergeConfigConcatArrays() to handle nested compaction.protectedTools array
src/session/compaction.ts Read protectedTools from config and merge with built-in default ["skill"]

Design decisions

  • Additive merge, not replace: User config extends the default list rather than replacing it, so "skill" is always protected even if not explicitly listed
  • Follows existing pattern: plugin and instructions already use concat + dedup in mergeConfigConcatArrays() — this adds the same logic for a nested field
  • Fully backward-compatible: Without explicit config, behavior is identical to current main
  • Zero runtime cost when unused: Falls back to spread of empty array (?? [])

…m pruning

The pruner replaces old tool outputs with a placeholder to save context,
but only protects the built-in 'skill' tool. Users with MCP-based skill
loaders or other context-injecting tools have no way to prevent their
content from being silently erased after ~40k tokens of newer output.

Add compaction.protectedTools config option (string[]) that merges with
the built-in default. Multiple config layers concat+dedup via
mergeConfigConcatArrays, matching the existing pattern for plugin and
instructions arrays.

Backward-compatible: no behavior change without explicit config.
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.

1 participant