feat(gateway): make agent cache idle TTL configurable - #47848
Open
HwangJohn wants to merge 1 commit into
Open
Conversation
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating a real remaining configuration gap. Upstream main still hard-codes the one-hour idle TTL at gateway/run.py:68 and uses it in the sweep at gateway/run.py:16756; the maintainer resolution on linked #33563 also identifies this PR as the open config-exposure follow-up.
Problems
- The new parser's
ttl < 0guard does not reject non-finite floats.float("nan")succeeds and passes that comparison; current sweep checks (idle_ttl_secs <= 0andage > idle_ttl_secs) are both false for NaN, silently disabling eviction rather than taking the documented fallback. See addedgateway/run.py:1512and currentgateway/run.py:16756. - The branch predates the session-finalizability safeguard now in
gateway/run.py:16756-16795. The salvage must preserve its behavior for finite, unexpired sessions; the proposed tests do not cover that current path.
Suggested changes
- Reject non-finite TTLs with
math.isfinite()and add NaN/Infinity fallback tests. - Carry the setting onto the current sweep while retaining the session-store guard; test mode=
noneconfigured TTLs and finite-session preservation.
Automated hermes-sweeper review.
| ) | ||
| return _AGENT_CACHE_IDLE_TTL_SECS | ||
| if ttl < 0: | ||
| logger.warning( |
Contributor
There was a problem hiding this comment.
float("nan") succeeds and nan < 0 is false. The sweep's later <= 0 and age-comparison checks also both evaluate false for NaN, so this accidentally disables eviction instead of falling back to 3600. Reject non-finite values (for example with math.isfinite(ttl)) and add a regression test.
HwangJohn
force-pushed
the
fix/47730-agent-cache-idle-ttl
branch
from
July 20, 2026 05:52
66be724 to
0df9971
Compare
4 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds
agent.cache_idle_ttl_secondsso gateway users can tune how long idle in-memory agents remain cached between messages.The default remains
3600seconds, preserving the existing one-hour eviction behavior. Setting the value to0disables idle eviction for long-lived messaging threads, while the existing hard cache size cap still bounds growth.This is related to, but not a duplicate of, #31856. That PR changes when the idle sweep may evict agents relative to session expiry. This PR adds an explicit user-facing TTL setting for deployments that need a different idle retention window.
Fixes #47730
Related Issue
Fixes #47730
Type of Change
Changes Made
agent.cache_idle_ttl_secondstoDEFAULT_CONFIG.GatewayRunnerstartup.0/falseas idle eviction disabled while falling back to the historical default for invalid or negative values.cli-config.yaml.exampleandwebsite/docs/user-guide/configuration.md.How to Test
agent.cache_idle_ttl_seconds: 0and start the gateway. Idle cached agents are no longer evicted by the idle TTL sweep.agent.cache_idle_ttl_seconds: 7200and restart the gateway. Idle eviction uses that configured TTL.Validation run:
scripts/run_tests.sh tests/gateway/test_config_env_bridge_authority.py tests/gateway/test_agent_cache.py-> 77 passed.~/.hermes/hermes-agent/venv/bin/python -m ruff check gateway/run.py hermes_cli/config.py tests/gateway/test_agent_cache.py-> passed.git diff --check origin/main...fix/47730-agent-cache-idle-ttl-> passed after rebase..\\.venv\\Scripts\\python -m pytest tests\\gateway\\test_agent_cache.py -q-> 71 passed..\\.venv\\Scripts\\python -m ruff check gateway\\run.py hermes_cli\\config.py tests\\gateway\\test_agent_cache.py-> passed.Broader gateway sweep:
scripts/run_tests.sh tests/gatewayreached 6905 passed, 6 failed intests/gateway/test_matrix_voice.py.origin/main, so they are pre-existing and unrelated to this branch.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings)cli-config.yaml.exampleif I added/changed config keysCONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs
Not applicable. This is a gateway configuration behavior change covered by tests.