Skip to content

fix(config): guard SessionKey.from_safe_name against separator collision#3178

Open
nankingjing wants to merge 1 commit into
volcengine:mainfrom
nankingjing:fix/session-key-separator-collision
Open

fix(config): guard SessionKey.from_safe_name against separator collision#3178
nankingjing wants to merge 1 commit into
volcengine:mainfrom
nankingjing:fix/session-key-separator-collision

Conversation

@nankingjing

Copy link
Copy Markdown
Contributor

Bug fix for SessionKey.from_safe_name: split('__') without maxsplit truncates chat_id when it contains the separator. Use maxsplit=2 and raise ValueError on too-few parts. 6 regression tests in tests/unit/test_config/test_session_key.py.

SessionKey.from_safe_name used safe_name.split('__') without a maxsplit.
When a field value (typically chat_id, e.g. a feishu topic id or a Discord
thread id like 'thread__42') contained the '__' separator itself, the
round trip through safe_name() -> from_safe_name() silently truncated the
value: the part before the first inner '__' inflated channel_id and the
rest overwrote chat_id — or, when the result had exactly 3 parts, the
construction succeeded with corrupt fields.

Use split('__', maxsplit=2) so chat_id captures everything after the
second separator verbatim, and raise ValueError when the input has fewer
than 3 parts (i.e. not even a type/channel_id pair is present).

Regression test in tests/unit/test_config/test_session_key.py covers:
- basic round trip
- chat_id with one '__' (regression: was truncated before fix)
- chat_id with multiple '__' substrings
- too-few parts -> ValueError
- empty input -> ValueError
@nankingjing

Copy link
Copy Markdown
Contributor Author
Self-reviewed: diff is correct, minimal, and well-tested. No issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant