From 2b0f2fe6f272f72efd7e771bc416a80eeb1d6741 Mon Sep 17 00:00:00 2001 From: Fasthei <167957975+Fasthei@users.noreply.github.com> Date: Fri, 12 Jun 2026 17:11:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(redis):=20cluster=20=E6=A8=A1=E5=BC=8F=20ke?= =?UTF-8?q?ys()=20=E8=B7=A8=E6=89=80=E6=9C=89=E4=B8=BB=E5=88=86=E7=89=87?= =?UTF-8?q?=20fan-out=20+=20=E4=BF=AE=20Dockerfile=20=E6=BC=8F=E6=8B=B7=20?= =?UTF-8?q?benchmark/(#44)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测 heicode-rd(OSSCluster,2 分片):默认 keys() 只命中单节点, 漏掉其它分片上的 key → agent_registry/task_queue 枚举不全。 cluster 模式下改用 target_nodes=PRIMARIES,redis-py 合并各节点结果。 附带修 agent_swarm#44 Bug1:Dockerfile.orchestrator 漏 COPY benchmark/ (orchestrator/quality.py 启动即 import benchmark.fixtures/metrics)→ 原镜像 CrashLoopBackOff。新增 .dockerignore 控制构建上下文。 影响范围:仅 agent_swarm orchestrator(连接层 + 构建物料); 不改契约/计费/审计/密钥落地。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .dockerignore | 9 +++++++++ Dockerfile.orchestrator | 4 ++++ orchestrator/redis_client.py | 11 ++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..828d046 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +**/__pycache__ +**/*.pyc +*.md +desktop-client +test-data +artifacts +kind-config.yaml +.github diff --git a/Dockerfile.orchestrator b/Dockerfile.orchestrator index 4d508d0..931de0e 100644 --- a/Dockerfile.orchestrator +++ b/Dockerfile.orchestrator @@ -9,6 +9,10 @@ RUN pip install --no-cache-dir -r requirements.txt # Copy orchestrator code COPY orchestrator/ ./orchestrator/ +# orchestrator/quality.py imports benchmark.fixtures / benchmark.metrics at startup, +# so the package must be present in the image (agent_swarm#44). stdlib-only — no extra pip. +COPY benchmark/ ./benchmark/ + # Expose port EXPOSE 8000 diff --git a/orchestrator/redis_client.py b/orchestrator/redis_client.py index 7df6782..1987e08 100644 --- a/orchestrator/redis_client.py +++ b/orchestrator/redis_client.py @@ -172,7 +172,16 @@ class RedisClient: await self.client.hdel(name, *keys) async def keys(self, pattern: str) -> list: - """Get keys matching pattern.""" + """Get keys matching pattern. + + In cluster mode KEYS must fan out to every primary and merge — the default + routing hits a single node, so on a multi-shard cluster it silently drops + keys living on other shards (breaks agent/task enumeration). redis-py merges + the per-node results into one flat list. + """ + if self.cluster: + from redis.asyncio.cluster import RedisCluster + return await self.client.keys(pattern, target_nodes=RedisCluster.PRIMARIES) return await self.client.keys(pattern) async def lpush(self, key: str, *values: str):