Skip to content

fix(langfuse): fall back on an invalid HERMES_LANGFUSE_MAX_CHARS instead of raising - #450

Open
fredheathcote007 wants to merge 1 commit into
NousResearch:mainfrom
fredheathcote007:fix/langfuse-invalid-max-chars
Open

fredheathcote007 wants to merge 1 commit into
NousResearch:mainfrom
fredheathcote007:fix/langfuse-invalid-max-chars

Conversation

@fredheathcote007

Copy link
Copy Markdown

What

_safe_value parses HERMES_LANGFUSE_MAX_CHARS with a bare int() on every call:

Value On main
12k, abc ValueError from every capture call
-5 accepted; a 20,000-char payload comes back 20,022 chars long, labelled "truncated 20005 chars"

HERMES_LANGFUSE_MAX_DEPTH already handles this case in _resolve_max_depth.

Fix

Added _resolve_max_chars, which mirrors _resolve_max_depth. It is an lru_cache keyed on the raw string, so a changed env var is still picked up. An invalid or negative value warns once per distinct value and falls back to the default of 12000.

Tests

test_invalid_max_chars_warns_once_and_falls_back_instead_of_raising[abc|-5|12k] checks that the payload is truncated at 12000 and that exactly one warning is logged. The existing cache-clearing fixture now clears both resolvers.

The full langfuse suite passes (181 tests) and hermes plugins validate passes. Both were run on Linux with Python 3.14 against current hermes-agent main. I haven't run them on macOS or Windows locally; CI covers those.

🤖 Generated with Claude Code

…ead of raising

A non-integer value (e.g. "12k") raised ValueError from every _safe_value
call, so every captured payload failed; a negative value was accepted and
truncated nonsensically. Parse it like HERMES_LANGFUSE_MAX_DEPTH: warn once
per distinct value and fall back to the 12000 default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant