feat(webui): configure idle compaction timeout (NAN-305) (#6383)

* feat(webui): configure idle compaction timeout (NAN-305)

* fix(webui): clarify idle compaction timeout and tradeoff

* refactor(webui): remove unused idle compaction minimum

* fix(webui): match idle compaction loading skeleton
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 13:41:05 +08:00
1 parent c6babb20e8
commit f11ea5f9e0
25 files changed
+523 -15

No files matched your search

+54
View File
@@ -13,6 +13,7 @@ from nanobot.webui.settings_runtime import (
runtime_config_payload,
update_runtime_config,
)
from nanobot.webui.settings_services import WebUISettingsServices
def test_web_proxy_roundtrip_while_disabled_preserves_model_proxy(tmp_path):
@@ -66,6 +67,13 @@ def test_runtime_patch_persists_and_preserves_other_domains(tmp_path):
{"tools.exec": {"enable": False}},
{"agents.defaults.max_concurrent_subagents": 0},
{"agents.defaults.max_tool_iterations": True},
{"agents.defaults.session_ttl_minutes": -1},
{"agents.defaults.session_ttl_minutes": 1.5},
{"agents.defaults.session_ttl_minutes": 15.0},
{"agents.defaults.session_ttl_minutes": "15"},
{"agents.defaults.session_ttl_minutes": True},
{"agents.defaults.session_ttl_minutes": False},
{"agents.defaults.session_ttl_minutes": None},
{"tools.exec.timeout": -1},
{"tools.exec.timeout": 86401},
{"tools.exec.timeout": "60"},
@@ -194,3 +202,49 @@ def test_sandbox_backend_persists_with_path_permissions(tmp_path, backend):
assert saved.sandbox_rw_binds == ["shared/write"]
assert payload["runtime_config"]["tools.exec.sandbox"] == backend
assert payload["requires_restart"]
def test_idle_compaction_settings_roundtrip_and_restart_contract(tmp_path):
path = tmp_path / "config.json"
config = Config()
config.providers.openai.api_key = "${PRIVATE_API_KEY}"
save_config(config, path)
services = WebUISettingsServices.create(path)
key = "agents.defaults.session_ttl_minutes"
assert runtime_config_payload(config)[key] == 15
for minutes in (0, 720, 721, 37, 15):
payload = services.mutate(update_runtime_config_settings, {key: minutes})
assert payload["runtime_config"][key] == minutes
assert payload["requires_restart"] is True
saved = load_config(path)
assert saved.agents.defaults.session_ttl_minutes == minutes
assert saved.agents.defaults.idle_compact_check_interval_seconds == 60
assert saved.providers.openai.api_key == "${PRIVATE_API_KEY}"
defaults = json.loads(path.read_text(encoding="utf-8"))["agents"]["defaults"]
assert defaults["idleCompactAfterMinutes"] == minutes
assert "sessionTtlMinutes" not in defaults
assert "session_ttl_minutes" not in defaults
unchanged = services.mutate(update_runtime_config_settings, {key: minutes})
assert unchanged["runtime_config"][key] == minutes
assert unchanged["requires_restart"] is False
def test_idle_compaction_legacy_config_can_be_read_and_updated(tmp_path):
path = tmp_path / "config.json"
path.write_text(json.dumps({"agents": {"defaults": {
"sessionTtlMinutes": 720, "idleCompactCheckIntervalSeconds": 91,
}}}), encoding="utf-8")
key = "agents.defaults.session_ttl_minutes"
assert runtime_config_payload(load_config(path))[key] == 720
payload = update_runtime_config_settings({key: 0}, config_path=path)
assert payload["runtime_config"][key] == 0
assert payload["requires_restart"] is True
saved = load_config(path)
assert saved.agents.defaults.session_ttl_minutes == 0
assert saved.agents.defaults.idle_compact_check_interval_seconds == 91
defaults = json.loads(path.read_text(encoding="utf-8"))["agents"]["defaults"]
assert defaults["idleCompactAfterMinutes"] == 0
assert "sessionTtlMinutes" not in defaults