Skip to content

Commit db089cb

Browse files
Harden max_cache_rows against invalid env override
Catch ValueError when CLAUDE_CODE_CHAT_BROWSER_SUMMARY_CACHE_MAX_ROWS is not an integer and fall back to DEFAULT_MAX_ROWS so put_summary() does not fail on the session-list path.
1 parent 90c5aa7 commit db089cb

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

tests/test_session_summary_cache.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ def test_rules_fingerprint_empty() -> None:
4343
assert rules_fingerprint([]) == "none"
4444

4545

46+
def test_max_cache_rows_invalid_env_falls_back(
47+
monkeypatch: pytest.MonkeyPatch,
48+
) -> None:
49+
monkeypatch.setenv("CLAUDE_CODE_CHAT_BROWSER_SUMMARY_CACHE_MAX_ROWS", "not-a-number")
50+
from utils.session_summary_cache import DEFAULT_MAX_ROWS, max_cache_rows
51+
52+
assert max_cache_rows() == DEFAULT_MAX_ROWS
53+
54+
55+
def test_max_cache_rows_valid_env_enforces_minimum(
56+
monkeypatch: pytest.MonkeyPatch,
57+
) -> None:
58+
monkeypatch.setenv("CLAUDE_CODE_CHAT_BROWSER_SUMMARY_CACHE_MAX_ROWS", "0")
59+
from utils.session_summary_cache import max_cache_rows
60+
61+
assert max_cache_rows() == 1
62+
63+
4664
def test_rules_fingerprint_stable() -> None:
4765
rules = [[("word", "secret")]]
4866
assert rules_fingerprint(rules) == rules_fingerprint(rules)

utils/session_summary_cache.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def max_cache_rows() -> int:
2222
raw = os.environ.get("CLAUDE_CODE_CHAT_BROWSER_SUMMARY_CACHE_MAX_ROWS", "").strip()
2323
if not raw:
2424
return DEFAULT_MAX_ROWS
25-
return max(1, int(raw))
25+
try:
26+
return max(1, int(raw))
27+
except ValueError:
28+
return DEFAULT_MAX_ROWS
2629

2730

2831
_lock = threading.Lock()

0 commit comments

Comments
 (0)