Skip to content

fix(caching): honor prompt_caching.cache_ttl disable in config (salvage #33555) - #76015

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/33555-cache-ttl-disable
Aug 1, 2026
Merged

fix(caching): honor prompt_caching.cache_ttl disable in config (salvage #33555)#76015
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/33555-cache-ttl-disable

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Setting prompt_caching.cache_ttl to a falsy value (false, null, "off", "disabled", "no", "none") now fully disables prompt caching instead of being silently ignored.

Changes

  • agent/agent_init.py: Added elif branch after existing "5m"/"1h" check that catches falsy values, sets _use_prompt_caching = False, _cache_ttl = None, and _cache_disabled = True
  • agent/agent_runtime_helpers.py: anthropic_prompt_cache_policy() early-returns (False, False) when _cache_disabled is set — ensures disable survives /model switch and fallback re-derivation
  • agent/agent_runtime_helpers.py: restore_primary_runtime() overrides cached _use_prompt_caching when _cache_disabled is set — ensures disable survives runtime snapshot restoration
  • hermes_cli/config_defaults.py: Updated inline comment
  • tests/run_agent/test_run_agent.py: 8 new tests (7 parametrized falsy variants + 1 policy re-derivation survival test)

The gap in the original PR (#33555)

The contributor's fix only set _use_prompt_caching = False in init_agent. Three other code paths re-derive _use_prompt_caching from anthropic_prompt_cache_policy() after init: restore_primary_runtime(), _switch_to_provider(), and fallback activation. All would override the disable. This was the same gap that caused #56105 to be reverted in #56126. This salvage fixes it by gating the policy function itself on the _cache_disabled flag.

Validation

Before After
cache_ttl: false at init Silently ignored, caching stays on Caching disabled
/model switch after disable Re-enables caching (bug) Caching stays disabled
Fallback activation Re-enables caching (bug) Caching stays disabled
test_run_agent.py 215 passed 228 passed (13 cache-related, all green)

Salvage of #33555 by @BB-light. Closes #33555.

@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 1, 2026 08:12
@alt-glitch alt-glitch added type/feature New feature or request comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Aug 1, 2026
Setting prompt_caching.cache_ttl to a falsy value (false, null, off,
disabled, no, none) now fully disables prompt caching instead of
being silently ignored.

The disable propagates through anthropic_prompt_cache_policy() (early
return when _cache_disabled flag is set) and restore_primary_runtime()
(override after snapshot restore), so it survives /model switches and
fallback re-derivation — the gap that caused NousResearch#56105 to be reverted in
NousResearch#56126.

Salvage of NousResearch#33555 by @BB-light, with model-switch/fallback survival
gap fixed on top.

Co-authored-by: BB-light <BB-light@users.noreply.github.com>
@kshitijk4poor
kshitijk4poor force-pushed the salvage/33555-cache-ttl-disable branch from d0a114d to 3fad25f Compare August 1, 2026 08:38
@kshitijk4poor
kshitijk4poor merged commit e9d52d2 into NousResearch:main Aug 1, 2026
35 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/33555-cache-ttl-disable branch August 5, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants