Skip to content

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

Go

fix(runtime): support restricted Redis request stores (#7179)

Multica Eveec8027cbc66c
diff --git a/server/internal/handler/runtime_local_skills_redis_store.go b/server/internal/handler/runtime_local_skills_redis_store.go
index f0dd7fec6b..28345a9982 100644
--- a/server/internal/handler/runtime_local_skills_redis_store.go
+++ b/server/internal/handler/runtime_local_skills_redis_store.go
@@ -94,17 +94,24 @@ func (s *RedisLocalSkillListStore) Create(ctx context.Context, runtimeID string)
return nil, fmt.Errorf("marshal list request: %w", err)
}
- pipe := s.rdb.TxPipeline()
- pipe.Set(ctx, localSkillListKey(req.ID), data, runtimeLocalSkillStoreRetention)
- pipe.ZAdd(ctx, localSkillListPendingKey(runtimeID), redis.Z{
+ requestKey := localSkillListKey(req.ID)
+ pendingKey := localSkillListPendingKey(runtimeID)
+ // Creation does not require a Redis transaction: the request is not
+ // observable by dispatchers until it is added to the pending set. A plain
+ // pipeline also works on managed Redis deployments that deny MULTI.
+ pipe := s.rdb.Pipeline()
+ pipe.Set(ctx, requestKey, data, runtimeLocalSkillStoreRetention)
+ pipe.ZAdd(ctx, pendingKey, redis.Z{
Score: float64(now.UnixNano()),
Member: req.ID,
})
// Keep the pending ZSET alive a bit longer than the individual request
// so stale members still in the zset can be swept lazily on PopPending
// without blocking the create path on deletion.
- pipe.Expire(ctx, localSkillListPendingKey(runtimeID), runtimeLocalSkillStoreRetention*2)
+ pipe.Expire(ctx, pendingKey, runtimeLocalSkillStoreRetention*2)
if _, err := pipe.Exec(ctx); err != nil {
+ _ = s.rdb.Del(ctx, requestKey).Err()
+ _ = s.rdb.ZRem(ctx, pendingKey, req.ID).Err()
return nil, fmt.Errorf("persist list request: %w", err)
}
return req, nil
@@ -287,14 +294,20 @@ func (s *RedisLocalSkillImportStore) Create(ctx context.Context, input LocalSkil
return nil, err
}
- pipe := s.rdb.TxPipeline()
- pipe.Set(ctx, localSkillImportKey(req.ID), data, runtimeLocalSkillStoreRetention)
- pipe.ZAdd(ctx, localSkillImportPendingKey(input.RuntimeID), redis.Z{
+ requestKey := localSkillImportKey(req.ID)
+ pendingKey := localSkillImportPendingKey(input.RuntimeID)
+ // Match the other request stores: creation only needs ordered batching, and
+ // avoiding MULTI keeps this path compatible with restricted managed Redis.
+ pipe := s.rdb.Pipeline()
+ pipe.Set(ctx, requestKey, data, runtimeLocalSkillStoreRetention)
+ pipe.ZAdd(ctx, pendingKey, redis.Z{
Score: float64(now.UnixNano()),
Member: req.ID,
})
- pipe.Expire(ctx, localSkillImportPendingKey(input.RuntimeID), runtimeLocalSkillStoreRetention*2)
+ pipe.Expire(ctx, pendingKey, runtimeLocalSkillStoreRetention*2)
if _, err := pipe.Exec(ctx); err != nil {
+ _ = s.rdb.Del(ctx, requestKey).Err()
+ _ = s.rdb.ZRem(ctx, pendingKey, req.ID).Err()
return nil, fmt.Errorf("persist import request: %w", err)
}
return req, nil
diff --git a/server/internal/handler/runtime_local_skills_redis_store_test.go b/server/internal/handler/runtime_local_skills_redis_store_test.go
index 0fa3d7b1b0..5659dcb03f 100644
--- a/server/internal/handler/runtime_local_skills_redis_store_test.go
+++ b/server/internal/handler/runtime_local_skills_redis_store_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"sync"
+ "sync/atomic"
"testing"
"time"
@@ -13,6 +14,8 @@ import (
const redisTestDB = 14
+var redisACLTestUserSequence atomic.Uint64
+
// newRedisTestClient connects to the Redis instance indicated by REDIS_TEST_URL
// and flushes this package's logical test DB so each test starts from a clean
// slate. The helper skips the calling test if the env var is unset — matches
@@ -44,6 +47,37 @@ func newRedisTestClient(t *testing.T) *redis.Client {
return rdb
}
+func newRedisTestClientWithoutMulti(t *testing.T) *redis.Client {
+ t.Helper()
+ admin := newRedisTestClient(t)
+ ctx := context.Background()
+ username := fmt.Sprintf("runtime-no-multi-%d", redisACLTestUserSequence.Add(1))
+ const password = "runtime-no-multi-test-password"
+
+ if err := admin.Do(
+ ctx,
+ "ACL", "SETUSER", username,
+ "reset", "on", ">"+password, "~*", "+@all", "-multi", "-exec",
+ ).Err(); err != nil {
+ t.Fatalf("create restricted Redis user: %v", err)
+ }
+ t.Cleanup(func() {
+ if err := admin.Do(context.Background(), "ACL", "DELUSER", username).Err(); err != nil {
+ t.Errorf("delete restricted Redis user: %v", err)
+ }
+ })
+
+ opts := *admin.Options()
+ opts.Username = username
+ opts.Password = password
+ restricted := redis.NewClient(&opts)
+ t.Cleanup(func() { _ = restricted.Close() })
+ if err := restricted.Ping(ctx).Err(); err != nil {
+ t.Fatalf("connect as restricted Redis user: %v", err)
+ }
+ return restricted
+}
+
func TestRedisLocalSkillListStore_CreateGetComplete(t *testing.T) {
rdb := newRedisTestClient(t)
ctx := context.Background()
@@ -97,6 +131,31 @@ func TestRedisLocalSkillListStore_CreateGetComplete(t *testing.T) {
}
}
+func TestRedisLocalSkillListStore_CreateWithoutMultiPermission(t *testing.T) {
+ rdb := newRedisTestClientWithoutMulti(t)
+ ctx := context.Background()
+ store := NewRedisLocalSkillListStore(rdb)
+
+ req, err := store.Create(ctx, "runtime-no-multi")
+ if err != nil {
+ t.Fatalf("create without MULTI permission: %v", err)
+ }
+ got, err := store.Get(ctx, req.ID)
+ if err != nil {
+ t.Fatalf("get created request: %v", err)
+ }
+ if got == nil || got.ID != req.ID {
+ t.Fatalf("created request was not persisted: %+v", got)
+ }
+ pending, err := store.HasPending(ctx, "runtime-no-multi")
+ if err != nil {
+ t.Fatalf("check pending request: %v", err)
+ }
+ if !pending {
+ t.Fatal("created request was not queued")
+ }
+}
+
// TestRedisLocalSkillListStore_PopPendingAcrossInstances is the regression
// test for the exact bug this change fixes: two distinct *store* instances
// (i.e. two API nodes) share one Redis, one creates a pending request, the
@@ -276,6 +335,35 @@ func TestRedisLocalSkillImportStore_PreservesCreatorID(t *testing.T) {
}
}
+func TestRedisLocalSkillImportStore_CreateWithoutMultiPermission(t *testing.T) {
+ rdb := newRedisTestClientWithoutMulti(t)
+ ctx := context.Background()
+ store := NewRedisLocalSkillImportStore(rdb)
+
+ req, err := store.Create(ctx, LocalSkillImportRequestInput{
+ RuntimeID: "runtime-no-multi",
+ CreatorID: "user-1",
+ SkillKey: "review-helper",
+ })
+ if err != nil {
+ t.Fatalf("create without MULTI permission: %v", err)
+ }
+ got, err := store.Get(ctx, req.ID)
+ if err != nil {
+ t.Fatalf("get created request: %v", err)
+ }
+ if got == nil || got.ID != req.ID {
+ t.Fatalf("created request was not persisted: %+v", got)
+ }
+ pending, err := store.HasPending(ctx, "runtime-no-multi")
+ if err != nil {
+ t.Fatalf("check pending request: %v", err)
+ }
+ if !pending {
+ t.Fatal("created request was not queued")
+ }
+}
+
func TestRedisLocalSkillImportStore_CompletePreservesFiles(t *testing.T) {
rdb := newRedisTestClient(t)
ctx := context.Background()
diff --git a/server/internal/handler/runtime_models_redis_store.go b/server/internal/handler/runtime_models_redis_store.go
index d19d280909..828dbfb2e9 100644
--- a/server/internal/handler/runtime_models_redis_store.go
+++ b/server/internal/handler/runtime_models_redis_store.go
@@ -64,16 +64,23 @@ func (s *RedisModelListStore) Create(ctx context.Context, runtimeID string) (*Mo
return nil, err
}
- pipe := s.rdb.TxPipeline()
- pipe.Set(ctx, modelListKey(req.ID), data, modelListStoreRetention)
- pipe.ZAdd(ctx, modelListPendingKey(runtimeID), redis.Z{
+ requestKey := modelListKey(req.ID)
+ pendingKey := modelListPendingKey(runtimeID)
+ // Creation does not require a Redis transaction: the request is not
+ // observable by dispatchers until it is added to the pending set. A plain
+ // pipeline also works on managed Redis deployments that deny MULTI.
+ pipe := s.rdb.Pipeline()
+ pipe.Set(ctx, requestKey, data, modelListStoreRetention)
+ pipe.ZAdd(ctx, pendingKey, redis.Z{
Score: float64(now.UnixNano()),
Member: req.ID,
})
// Keep the pending zset alive past the per-record retention so stale
// members can be lazily swept on PopPending.
- pipe.Expire(ctx, modelListPendingKey(runtimeID), modelListStoreRetention*2)
+ pipe.Expire(ctx, pendingKey, modelListStoreRetention*2)
if _, err := pipe.Exec(ctx); err != nil {
+ _ = s.rdb.Del(ctx, requestKey).Err()
+ _ = s.rdb.ZRem(ctx, pendingKey, req.ID).Err()
return nil, fmt.Errorf("persist model list request: %w", err)
}
return req, nil
diff --git a/server/internal/handler/runtime_models_redis_store_test.go b/server/internal/handler/runtime_models_redis_store_test.go
index 60dc9e735b..06ca241ba2 100644
--- a/server/internal/handler/runtime_models_redis_store_test.go
+++ b/server/internal/handler/runtime_models_redis_store_test.go
@@ -98,6 +98,31 @@ func TestRedisModelListStore_CreateGetComplete(t *testing.T) {
}
}
+func TestRedisModelListStore_CreateWithoutMultiPermission(t *testing.T) {
+ rdb := newRedisTestClientWithoutMulti(t)
+ ctx := context.Background()
+ store := NewRedisModelListStore(rdb)
+
+ req, err := store.Create(ctx, "runtime-no-multi")
+ if err != nil {
+ t.Fatalf("create without MULTI permission: %v", err)
+ }
+ got, err := store.Get(ctx, req.ID)
+ if err != nil {
+ t.Fatalf("get created request: %v", err)
+ }
+ if got == nil || got.ID != req.ID {
+ t.Fatalf("created request was not persisted: %+v", got)
+ }
+ pending, err := store.HasPending(ctx, "runtime-no-multi")
+ if err != nil {
+ t.Fatalf("check pending request: %v", err)
+ }
+ if !pending {
+ t.Fatal("created request was not queued")
+ }
+}
+
// TestRedisModelListStore_PopPendingAcrossInstances is the regression test
// for the exact bug this PR fixes: two API replicas share one Redis, one
// receives the POST that creates the request, the other receives the daemon
diff --git a/server/internal/handler/runtime_update_redis_store.go b/server/internal/handler/runtime_update_redis_store.go
index 0e263a41ba..5cdeab056c 100644
--- a/server/internal/handler/runtime_update_redis_store.go
+++ b/server/internal/handler/runtime_update_redis_store.go
@@ -68,7 +68,12 @@ func (s *RedisUpdateStore) Create(ctx context.Context, runtimeID, targetVersion,
return nil, errUpdateInProgress
}
- pipe := s.rdb.TxPipeline()
+ // The active reservation above provides the concurrency guarantee this
+ // write needs. Use a plain pipeline so managed Redis deployments that allow
+ // SET/ZADD but deny MULTI can still create update requests. Exec failures
+ // remain safe because the compensation below removes every partially
+ // written key and releases the reservation.
+ pipe := s.rdb.Pipeline()
pipe.Set(ctx, updateKey(req.ID), data, updateStoreRetention)
pipe.ZAdd(ctx, updatePendingKey(runtimeID), redis.Z{
Score: float64(now.UnixNano()),
diff --git a/server/internal/handler/runtime_update_redis_store_test.go b/server/internal/handler/runtime_update_redis_store_test.go
index 1e196b512f..3953fbae81 100644
--- a/server/internal/handler/runtime_update_redis_store_test.go
+++ b/server/internal/handler/runtime_update_redis_store_test.go
@@ -80,6 +80,34 @@ func TestRedisUpdateStore_CreateGetComplete(t *testing.T) {
}
}
+func TestRedisUpdateStore_CreateWithoutMultiPermission(t *testing.T) {
+ rdb := newRedisTestClientWithoutMulti(t)
+ ctx := context.Background()
+ store := NewRedisUpdateStore(rdb)
+ req, err := store.Create(ctx, "runtime-no-multi", "v1.2.3", "user-1")
+ if err != nil {
+ t.Fatalf("create without MULTI permission: %v", err)
+ }
+ if req.Status != UpdatePending {
+ t.Fatalf("initial status = %s, want %s", req.Status, UpdatePending)
+ }
+
+ got, err := store.Get(ctx, req.ID)
+ if err != nil {
+ t.Fatalf("get created request: %v", err)
+ }
+ if got == nil || got.ID != req.ID {
+ t.Fatalf("created request was not persisted: %+v", got)
+ }
+ pending, err := store.HasPending(ctx, "runtime-no-multi")
+ if err != nil {
+ t.Fatalf("check pending request: %v", err)
+ }
+ if !pending {
+ t.Fatal("created request was not queued")
+ }
+}
+
func TestRedisUpdateStore_PopPendingAcrossInstances(t *testing.T) {
rdb := newRedisTestClient(t)
ctx := context.Background()