落地并存测服全端:智能体 Graph/路由、后台切 8180、主账与部署脚本齐备,便于线上重发与验收。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
linmianxun
2026-09-13 21:15:58 +08:00
co-authored by Cursor
parent 0eb1adecc8
commit 8103b3b651
143 changed files with 8968 additions and 277 deletions
@@ -0,0 +1,36 @@
"""
短幂等:同一 idempotency_key 在 TTL 内不重复入队。
本文件职责:SET NX + EX;成功表示「首次」、失败表示「重复」。
禁止:用本机制代替主账写幂等;禁止无 TTL 的永久键。
"""
from __future__ import annotations
import logging
from agent.redis_coord.client import RedisClient
from agent.redis_coord.keys import IDEMPOTENCY
logger = logging.getLogger(__name__)
def try_acquire(
client: RedisClient,
*,
scope: str,
idempotency_key: str,
ttl_seconds: int = 300,
) -> bool:
"""
尝试占用短幂等键。
返回 True=首次(可入队);False=TTL 内重复。
副作用:写带过期的 Redis 键。
"""
key = client.key(IDEMPOTENCY, scope, idempotency_key)
ok = client.raw.set(key, "1", ex=ttl_seconds, nx=True)
acquired = bool(ok)
if not acquired:
logger.info("短幂等命中重复 scope=%s key=%s", scope, idempotency_key)
return acquired