Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(handler): keep runtime pending redis keys in one slot

ZeroIce078f2aa65c48
diff --git a/server/internal/handler/runtime_local_skills_redis_store.go b/server/internal/handler/runtime_local_skills_redis_store.go
index b67c4eaaf2..57aed2fb7e 100644
--- a/server/internal/handler/runtime_local_skills_redis_store.go
+++ b/server/internal/handler/runtime_local_skills_redis_store.go
@@ -31,11 +31,13 @@ import (
// finding about the "request disappears under Redis hiccups" path.
const (
+ runtimePendingRedisHashTag = "{runtime_pending}"
+
// Namespaced so we don't collide with the realtime relay's ws:* keys.
- localSkillListKeyPrefix = "mul:local_skill:list:"
- localSkillListPendingPrefix = "mul:local_skill:list:pending:"
- localSkillImportKeyPrefix = "mul:local_skill:import:"
- localSkillImportPendingPrefix = "mul:local_skill:import:pending:"
+ localSkillListKeyPrefix = "mul:" + runtimePendingRedisHashTag + ":local_skill:list:"
+ localSkillListPendingPrefix = "mul:" + runtimePendingRedisHashTag + ":local_skill:list:pending:"
+ localSkillImportKeyPrefix = "mul:" + runtimePendingRedisHashTag + ":local_skill:import:"
+ localSkillImportPendingPrefix = "mul:" + runtimePendingRedisHashTag + ":local_skill:import:pending:"
localSkillRedisPopMaxRetries = 5
)
diff --git a/server/internal/handler/runtime_models_redis_store.go b/server/internal/handler/runtime_models_redis_store.go
index 0901773900..d19d280909 100644
--- a/server/internal/handler/runtime_models_redis_store.go
+++ b/server/internal/handler/runtime_models_redis_store.go
@@ -18,10 +18,10 @@ import (
//
// Key layout:
//
-// mul:model_list:req:<request_id> → JSON-encoded ModelListRequest, TTL = retention
-// mul:model_list:pending:<runtime_id> → ZSET { member = request_id, score = created_at UnixNano }
-// TTL = retention*2 (kept alive long enough for
-// lazy sweep on PopPending)
+// mul:{runtime_pending}:model_list:req:<request_id> → JSON-encoded ModelListRequest, TTL = retention
+// mul:{runtime_pending}:model_list:pending:<runtime_id> → ZSET { member = request_id, score = created_at UnixNano }
+// TTL = retention*2 (kept alive long enough for
+// lazy sweep on PopPending)
//
// PopPending uses claimPendingScript (defined in
// runtime_local_skills_redis_store.go) to atomically ZREM the pending entry
@@ -29,10 +29,10 @@ import (
// requests on a transient Redis hiccup between them.
const (
- // Namespaced under mul:model_list:* so the key set doesn't collide with
- // the realtime relay (ws:*) or the local-skill stores (mul:local_skill:*).
- modelListKeyPrefix = "mul:model_list:req:"
- modelListPendingPrefix = "mul:model_list:pending:"
+ // Namespaced under mul:*:model_list:* so the key set doesn't collide with
+ // the realtime relay (ws:*) or the local-skill stores.
+ modelListKeyPrefix = "mul:" + runtimePendingRedisHashTag + ":model_list:req:"
+ modelListPendingPrefix = "mul:" + runtimePendingRedisHashTag + ":model_list:pending:"
modelListRedisPopMaxRetries = 5
)
diff --git a/server/internal/handler/runtime_redis_keys_test.go b/server/internal/handler/runtime_redis_keys_test.go
new file mode 100644
index 0000000000..12760cae8a
--- /dev/null
+++ b/server/internal/handler/runtime_redis_keys_test.go
@@ -0,0 +1,56 @@
+package handler
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestRuntimePendingRedisKeysShareClusterHashTag(t *testing.T) {
+ for name, keys := range map[string][]string{
+ "model list claim": {
+ modelListPendingKey("runtime-1"),
+ modelListKey("req-1"),
+ },
+ "local skill list claim": {
+ localSkillListPendingKey("runtime-1"),
+ localSkillListKey("req-1"),
+ },
+ "local skill import claim": {
+ localSkillImportPendingKey("runtime-1"),
+ localSkillImportKey("req-1"),
+ },
+ "update claim": {
+ updatePendingKey("runtime-1"),
+ updateKey("req-1"),
+ },
+ "update active guard": {
+ updateActiveKey("runtime-1"),
+ updateKey("req-1"),
+ updatePendingKey("runtime-1"),
+ },
+ } {
+ t.Run(name, func(t *testing.T) {
+ want := redisClusterHashTag(keys[0])
+ if want == "" {
+ t.Fatalf("%q has no hash tag", keys[0])
+ }
+ for _, key := range keys[1:] {
+ if got := redisClusterHashTag(key); got != want {
+ t.Fatalf("key %q hash tag = %q, want %q; keys in one Lua script or transaction must share a Redis Cluster slot", key, got, want)
+ }
+ }
+ })
+ }
+}
+
+func redisClusterHashTag(key string) string {
+ start := strings.IndexByte(key, '{')
+ if start < 0 {
+ return ""
+ }
+ end := strings.IndexByte(key[start+1:], '}')
+ if end <= 0 {
+ return ""
+ }
+ return key[start+1 : start+1+end]
+}
diff --git a/server/internal/handler/runtime_update_redis_store.go b/server/internal/handler/runtime_update_redis_store.go
index 4be22a700d..1bb7db8a8e 100644
--- a/server/internal/handler/runtime_update_redis_store.go
+++ b/server/internal/handler/runtime_update_redis_store.go
@@ -18,9 +18,9 @@ import (
// shared storage.
const (
- updateKeyPrefix = "mul:update:req:"
- updatePendingPrefix = "mul:update:pending:"
- updateActivePrefix = "mul:update:active:"
+ updateKeyPrefix = "mul:" + runtimePendingRedisHashTag + ":update:req:"
+ updatePendingPrefix = "mul:" + runtimePendingRedisHashTag + ":update:pending:"
+ updateActivePrefix = "mul:" + runtimePendingRedisHashTag + ":update:active:"
updateRedisPopMaxRetries = 5
)