fix(honcho): truncate resolve_session_name output to Honcho's 100-char limit (#13868)#13931
Closed
Sanjays2402 wants to merge 0 commit into
Closed
Conversation
19 tasks
cb6eaab to
5d3be89
Compare
Contributor
Author
|
Closing — this fix already landed on main as cd1c481 ( |
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?
HonchoClientConfig.resolve_session_name()sanitizes thegateway_session_keyto strip characters Honcho doesn't accept, but never enforces Honcho's 100-character limit on session IDs. For gateways that build rich session keys — Matrix!room:server+ thread event IDs, Telegram supergroup reply chains, Slack thread IDs with long workspace prefixes — the sanitized ID overflows the limit and every Honcho API call for that session 400s withsession_id too long.This PR adds a length-enforcement helper,
_enforce_session_id_limit, at the end of the gateway-key branch inresolve_session_name. If the sanitized ID is over 100 characters, it's truncated to a shorter prefix and a deterministic-<sha256 prefix>suffix is appended — so two long keys that share a leading segment can't collide onto the same ID. Short keys (the common case) are unchanged: the fast path returns the sanitized string as-is with zero extra work.The hash is taken over the original pre-sanitization key, so two inputs that sanitize to the same string still collide intentionally (same logical session), but two inputs that only share a prefix do not.
Related Issue
Fixes #13868
Type of Change
Changes Made
plugins/memory/honcho/client.py(+37 / −1): new_enforce_session_id_limit(sanitized, original)classmethod + two class constants;resolve_session_namegateway-key branch routes through it.tests/honcho_plugin/test_client.py(+76): newTestResolveSessionNameLengthLimitclass with 7 regression cases.Implementation diff (core change):
if gateway_session_key: sanitized = re.sub(r'[^a-zA-Z0-9_-]+', '-', gateway_session_key).strip('-') if sanitized: - return sanitized + return self._enforce_session_id_limit(sanitized, gateway_session_key)How to Test
Reporter-style repro:
Before:
len(resolved)> 300, Honcho rejects the session with HTTP 400session_id too long.After:
len(resolved) == 100, deterministic, collision-resistant across distinct long keys.Run the regression suite:
Checklist
Code
fix(honcho):)pytest tests/honcho_plugin/test_client.py -q(scoped to the affected file) and all tests passDocumentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys — N/A (no new config)CONTRIBUTING.mdorAGENTS.md— N/Ahashlibonly, no OS-specific behaviorScreenshots / Logs
Regression tests added
test_short_gateway_key_unchangedtest_key_at_exact_limit_unchangedtest_long_gateway_key_truncated_to_limittest_truncation_is_deterministictest_truncated_result_respects_char_allowlist[a-zA-Z0-9_-]+allowlisttest_distinct_long_keys_do_not_collidetest_truncated_result_has_hash_suffix-<8 hex chars>Verification
(11 tests = 7 new
LengthLimitcases + 4 existingGatewayKeycases, all green.)The truncation branch only fires when the sanitized ID actually exceeds 100 characters, so short-key callers (the common case across Telegram DMs, Discord DMs, single-room Matrix channels, per-session CLI strategy) see zero behavioral change — the fast path short-circuits before any hashing. The hash suffix is deterministic (same input → same output), so session lookups are stable across restarts and processes.