调整并发模拟,减少明文

This commit is contained in:
Sakura-RanChen 2026-11-18 14:54:51 +08:00
parent f441703e6c
commit 4c04b9dd37
3 changed files with 11 additions and 2 deletions

View file

@ -1122,7 +1122,13 @@ class ConnectionHandler:
# 仅在该说话人首次出现时把身份注入 system,之后靠对话历史首轮保留,
# 避免每轮在 system 重复出现名字诱导模型反复称呼
speaker_for_system = None
cs = (self.current_speaker or "").strip()
# 展示名优先取本轮 speaker 快照:manual 模式下两轮 chat 线程可能并发,
# conn.current_speaker 已被下一轮覆盖,连接态仅在无快照路径作兜底
cs = ""
if speaker is not None:
cs = (speaker.name or "").strip()
if not cs:
cs = (self.current_speaker or "").strip()
if cs and cs != UNKNOWN_SPEAKER_NAME and cs not in self.system_introduced_speakers:
self.system_introduced_speakers.add(cs)
speaker_for_system = cs

View file

@ -362,7 +362,8 @@ async def call_mcp_endpoint_tool(
message = json.dumps(payload)
log_suffix = ""
if meta:
log_suffix = f",_meta: {json.dumps(meta, ensure_ascii=False)}"
# 只记是否附带身份及字段名,不输出 speakerId/speakerName 明文
log_suffix = f",_meta: 附带身份字段 {list(meta.keys())}"
logger.bind(tag=TAG).info(
f"发送MCP接入点工具调用请求: {actual_name},参数: {json.dumps(arguments, ensure_ascii=False)}{log_suffix}"
)

View file

@ -153,6 +153,8 @@ async def test_executor_reads_snapshot_not_conn_state(monkeypatch):
monkeypatch.setattr(executor_mod, "call_mcp_endpoint_tool", fake_call)
conn = _Conn()
# 模拟并发场景:连接态已被下一轮覆盖成另一个人,meta 仍必须取自快照
conn.current_speaker = "旧说话人"
await executor_mod.MCPEndpointExecutor(conn).execute(
conn,
"HassTurnOn",