fix(chat): guard non-numeric agent tool budget setting

Guard the agent_max_tool_calls settings read so hand-edited or agent-written non-numeric settings.json values fall back to 0 instead of crashing agent-mode chat stream initialization. Add regression coverage for guarded coercion.
This commit is contained in:
Solanki Sumit
2026-06-27 23:50:48 +05:30
committed by GitHub
parent e7c61a75b6
commit 7e9bfb1700
2 changed files with 78 additions and 1 deletions
+8 -1
View File
@@ -1255,7 +1255,14 @@ def setup_chat_routes(
try:
from src.settings import get_setting
from src.agent_tools import MAX_AGENT_ROUNDS as _DEFAULT_ROUNDS
_tool_budget = int(get_setting("agent_max_tool_calls", 0))
# Per-message tool budget from settings; guard defensively in
# case settings.json was hand-edited to a non-numeric value
# (the HTTP admin endpoint validates, but direct edits bypass
# it). 0 = unlimited, matching auth_routes set_settings().
try:
_tool_budget = int(get_setting("agent_max_tool_calls", 0))
except (TypeError, ValueError):
_tool_budget = 0
# Per-message round cap from settings; clamp defensively in
# case settings.json was hand-edited to a bad value.
try: