#15515: agents: add always mode for context pruning
stale
Cluster:
Compaction Enhancements and Features
## Summary
- add `agents.defaults.contextPruning.mode: "always"` as a provider-agnostic mode
- keep existing `cache-ttl` behavior unchanged (still Anthropic/OpenRouter Anthropic scoped)
- wire the new mode through runtime settings, config types, and zod schema
- document the new mode in session pruning + configuration reference + Pi docs
## Why
`cache-ttl` is optimized for Anthropic cache semantics. For providers that do not share those semantics (for example MiniMax/OpenAI-compatible endpoints), operators still need steady context pressure control. `always` enables the same pruning logic on every request without changing `cache-ttl` defaults.
## Tests
- `pnpm vitest src/agents/pi-extensions/context-pruning.test.ts src/config/config.pruning-defaults.test.ts --run`
- `pnpm check`
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR introduces a new provider-agnostic context pruning mode (`agents.defaults.contextPruning.mode: "always"`) that runs the existing pruning logic before every LLM call, while keeping the existing `cache-ttl` behavior scoped to Anthropic/OpenRouter Anthropic. The change is wired through config types + zod schema, the embedded runner’s extension activation logic, and updated docs describing the new mode and its semantics (including `ttl` being ignored in always mode).
<h3>Confidence Score: 4/5</h3>
- This PR looks safe to merge after fixing a small test fixture mismatch.
- Core runtime wiring for the new `always` mode is consistent (extension activates for always/cache-ttl, cache-ttl eligibility gating remains, and TTL checks run only in cache-ttl mode). The only issue found is in tests: the always-mode test passes `lastCacheTouchAt` even though production does not, which can hide regressions.
- src/agents/pi-extensions/context-pruning.test.ts
<sub>Last reviewed commit: 4b27cef</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#19329: feat: add per-agent compaction and context pruning overrides
by curtismercier · 2026-02-17
75.7%
#10997: fix: enable cache-ttl pruning on first load after restart
by anotb · 2026-02-07
75.3%
#14879: fix: persist session metadata to sessions.json after context pruning
by skylarkoo7 · 2026-02-12
73.9%
#10567: feat(agents): add configurable startup session pruning
by abutlabs · 2026-02-06
73.3%
#14744: fix(context): key MODEL_CACHE by provider/modelId to prevent collis...
by lailoo · 2026-02-12
72.8%
#14640: feat(agents): support per-agent temperature and maxTokens in agents...
by lailoo · 2026-02-12
71.9%
#22303: fix: extend cacheRetention auto-injection and runtime pass-through ...
by snese · 2026-02-21
71.8%
#8341: feat: add per-job cache control for cron jobs
by vishaltandale00 · 2026-02-03
71.4%
#15632: fix: use provider-qualified key in MODEL_CACHE for context window l...
by linwebs · 2026-02-13
71.3%
#14128: config: add readable durable/off mode for pre-compaction memory flush
by vpesh · 2026-02-11
71.0%