fix(agent): collision-safe thread keys
This commit is contained in:
parent
2fad1aaa66
commit
083be77404
2 changed files with 14 additions and 2 deletions
|
|
@ -10,7 +10,7 @@ from sdk.interface import MessageChunk, MessageResponse, PlatformError
|
|||
|
||||
|
||||
def build_thread_key(platform: str, user_id: str, chat_id: str) -> str:
|
||||
return f"{platform}:{user_id}:{chat_id}"
|
||||
return f"{len(platform)}:{platform}{len(user_id)}:{user_id}{len(chat_id)}:{chat_id}"
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
|
|
@ -75,6 +75,11 @@ class AgentSessionClient:
|
|||
payload.get("details", "Agent error"),
|
||||
code=payload.get("code", "AGENT_ERROR"),
|
||||
)
|
||||
elif msg_type == "GRACEFUL_DISCONNECT":
|
||||
raise PlatformError(
|
||||
"Agent disconnected gracefully",
|
||||
code="GRACEFUL_DISCONNECT",
|
||||
)
|
||||
else:
|
||||
raise PlatformError(
|
||||
f"Unexpected agent message: {payload}",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,14 @@ from sdk.agent_session import AgentSessionClient, AgentSessionConfig, build_thre
|
|||
|
||||
|
||||
def test_build_thread_key_uses_platform_user_and_chat_id():
|
||||
assert build_thread_key("matrix", "@alice:example.org", "C1") == "matrix:@alice:example.org:C1"
|
||||
assert build_thread_key("matrix", "@alice:example.org", "C1") == "6:matrix18:@alice:example.org2:C1"
|
||||
|
||||
|
||||
def test_build_thread_key_does_not_collide_when_user_id_contains_colons():
|
||||
left = build_thread_key("matrix", "@alice:example.org", "C1")
|
||||
right = build_thread_key("matrix", "@alice", "example.org:C1")
|
||||
|
||||
assert left != right
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue