Skip to content

Commit 38417a8

Browse files
committed
fix: pass atespace on self-suspend in agent-secret demo
Host parsing dropped the atespace label, so SuspendActor always failed with atespace required. Now uses resources.ParseActorDNSName to get both atespace and actor name.
1 parent c1ab095 commit 38417a8

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

demos/agent-secret/main.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626
"time"
2727

28+
"github.com/agent-substrate/substrate/internal/resources"
2829
"github.com/agent-substrate/substrate/pkg/proto/ateapipb"
2930
"google.golang.org/grpc"
3031
"google.golang.org/grpc/credentials"
@@ -64,16 +65,13 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
6465
if actorID == "" {
6566
actorID = r.Header.Get("x-agentset-session")
6667
}
68+
var atespace string
6769
if actorID == "" {
6870
host := r.Host
6971
if host == "" {
7072
host = r.Header.Get("Host")
7173
}
72-
// Extract the actor id (first label) from <id>.<atespace>.actors.resources.substrate.ate.dev
73-
parts := strings.Split(host, ".")
74-
if len(parts) > 1 {
75-
actorID = parts[0]
76-
}
74+
atespace, actorID, _ = resources.ParseActorDNSName(host)
7775
}
7876

7977
if actorID == "" {
@@ -108,12 +106,12 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
108106
go func() {
109107
// We linger for 7 seconds in this demo to make the multiplexing visible in the CLI.
110108
time.Sleep(7 * time.Second)
111-
suspendSelf(actorID)
109+
suspendSelf(atespace, actorID)
112110
}()
113111
}
114112
}
115113

116-
func suspendSelf(id string) {
114+
func suspendSelf(atespace, id string) {
117115
apiAddr := os.Getenv("ATE_API_ADDR")
118116
if apiAddr == "" {
119117
apiAddr = "api.ate-system.svc.cluster.local:443"
@@ -130,7 +128,7 @@ func suspendSelf(id string) {
130128
client := ateapipb.NewControlClient(conn)
131129

132130
log.Printf("Yielding compute. Requesting self-suspension for actor %s...", id)
133-
_, err = client.SuspendActor(context.Background(), &ateapipb.SuspendActorRequest{Actor: &ateapipb.ObjectRef{Name: id}})
131+
_, err = client.SuspendActor(context.Background(), &ateapipb.SuspendActorRequest{Actor: &ateapipb.ObjectRef{Atespace: atespace, Name: id}})
134132
if err != nil {
135133
log.Printf("Failed to self-suspend: %v", err)
136134
}

0 commit comments

Comments
 (0)